File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.239.4.3: download - view: text, annotated - select for diffs
Tue Dec 30 18:39:03 2008 UTC (15 years, 5 months ago) by raeburn
Branches: version_2_8_X
CVS tags: version_2_8_0, version_2_7_99_1
Diff to branchpoint 1.239: preferred, unified
- Backport 1.243.

    1: # The LearningOnline Network with CAPA
    2: # Routines to control the menu
    3: #
    4: # $Id: lonmenu.pm,v 1.239.4.3 2008/12/30 18:39:03 raeburn Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: #
   29: # There are two parameters controlling the action of this module:
   30: #
   31: # browser.interface - if this is 'textual', it overrides the second parameter
   32: # and goes to screen reader PDA mode
   33: #
   34: # environment.remote - if this is 'on', the routines controll the remote
   35: # control, otherwise they render the main window controls; ignored it
   36: # browser.interface is 'textual'
   37: #
   38: 
   39: package Apache::lonmenu;
   40: 
   41: use strict;
   42: use Apache::lonnet;
   43: use Apache::lonhtmlcommon();
   44: use Apache::loncommon();
   45: use Apache::lonenc();
   46: use Apache::lonlocal;
   47: use LONCAPA qw(:DEFAULT :match);
   48: 
   49: use vars qw(@desklines %category_names %category_members %category_positions $readdesk);
   50: 
   51: 
   52: my @inlineremote;
   53: 
   54: 
   55: 
   56: # ================================================================ Little texts
   57: sub show_course {
   58:     my $course = !$env{'user.adv'};
   59:     if (!$env{'user.adv'}) {
   60: 	foreach my $env (keys(%env)) {
   61: 	    next if ($env !~ m/^user\.priv\./);
   62: 	    if ($env !~ m/^user\.priv\.(?:st|cm)/) {
   63: 		$course = 0;
   64: 		last;
   65: 	    }
   66: 	}
   67:     }
   68:     return $course;
   69: }
   70: 
   71: sub initlittle {
   72:     return &Apache::lonlocal::texthash('ret' => 'Return to Last Location',
   73: 				       'nav' => 'Navigate Contents',
   74: 				       'main' => 'Main Menu',
   75:                                        'roles' => (&show_course()?
   76:                                                     'Courses':'Roles'),
   77:                                        'other' => 'Other Roles',
   78:                                        'docs' => 'Edit Course',
   79:                                        'exit' => 'Exit',
   80:                                        'login' => 'Log In',
   81: 				       'launch' => 'Launch Remote Control',
   82:                                        'groups' => 'Groups',
   83:                                        'gdoc' => 'Group Documents',
   84:                                        );
   85: }
   86: 
   87: # ============================= This gets called at the top of the body section
   88: 
   89: sub menubuttons {
   90:     my $forcereg=shift;
   91:     my $registration=shift;
   92:     my $titletable=shift;
   93:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
   94: 					    ['inhibitmenu']);
   95:     if (($env{'form.inhibitmenu'} eq 'yes') ||
   96:         ($ENV{'REQUEST_URI'} eq '/adm/logout')) { return ''; }
   97: 
   98:     if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
   99: 
  100:     my %lt=&initlittle();
  101:     my $navmaps='';
  102:     my $reloadlink='';
  103:     my $docs='';
  104:     my $groups='';
  105:     my $roles='<a href="/adm/roles" target="_top">'.$lt{'roles'}.'</a>';
  106:     my $role_selector;
  107:     my $showgroups=0;
  108:     my ($cnum,$cdom);
  109:     my $escurl=&escape(&Apache::lonenc::check_encrypt($env{'request.noversionuri'}));
  110:     my $escsymb=&escape(&Apache::lonenc::check_encrypt($env{'request.symb'}));
  111: 
  112:     my $logo=&Apache::loncommon::lonhttpdurl("/adm/lonIcons/minilogo.gif");
  113:     $logo = '<td class="LC_top_nav_logo"><a href="/adm/about.html"><img src="'.
  114: 	$logo.'" alt="LON-CAPA Logo" /></a></td>';
  115: 
  116:     if ($env{'request.state'} eq 'construct') {
  117:         if (($env{'request.noversionuri'} eq '') || (!defined($env{'request.noversionuri'}))) {
  118:             my $returnurl = $env{'request.filename'};
  119:             $returnurl =~ s:^/home/([^/]+)/public_html/(.*)$:/priv/$1/$2:;
  120:             $escurl = &escape($returnurl);
  121:         }
  122:     }
  123:     if ($env{'request.course.id'}) {
  124:         $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
  125:         $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
  126:         my %coursegroups;
  127:         my $viewgrps_permission =
  128: 	    &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
  129:         if (!$viewgrps_permission) {
  130:             %coursegroups = &Apache::lonnet::get_active_groups($env{'user.domain'},$env{'user.name'},$cdom,$cnum);
  131: 	}
  132:         if ((keys(%coursegroups) > 0) || ($viewgrps_permission)) {
  133:             $showgroups = 1;
  134:         }
  135:         $role_selector = &roles_selector($cdom,$cnum);
  136:         if ($role_selector) {
  137:             $roles = '<span class="LC_nobreak">'.$role_selector.'&nbsp;&nbsp;<a href="/adm/roles" target="_top">'.$lt{'other'}.'</a></span>';
  138:         }
  139:     }
  140: 
  141:     if ($env{'browser.interface'} eq 'textual') {
  142: # Textual display only
  143:         if ($env{'request.course.id'}) {
  144: 	    $navmaps=(<<ENDNAV);
  145: <a href="/adm/navmaps?postdata=$escurl&amp;postsymb=$escsymb" target="_top">$lt{'nav'}</a>
  146: ENDNAV
  147:             if (&show_return_link()) {
  148:                 my $escreload=&escape('return:');
  149:                 $reloadlink=(<<ENDRELOAD);
  150: <a href="/adm/flip?postdata=$escreload" target="_top">$lt{'ret'}</a>
  151: ENDRELOAD
  152:             }
  153: 	    if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
  154:                $docs=(<<ENDDOCS);
  155: <a href="/adm/coursedocs" target="_top">$lt{'docs'}</a>
  156: ENDDOCS
  157:             }
  158:             if ($showgroups) {
  159:                 $groups =(<<ENDGROUPS);
  160: <a href="/adm/coursegroups" target="_top">$lt{'groups'}</a>
  161: ENDGROUPS
  162:             }
  163: 	}
  164:         my $form=&serverform();
  165:         my $utility=&utilityfunctions();
  166: 	my $output=(<<ENDMAINMENU);
  167: <script type="text/javascript">
  168: // BEGIN LON-CAPA Internal
  169: $utility
  170: </script>
  171: <div id="LC_top_nav">
  172: <a href="/adm/menu" target="_top">$lt{'main'}</a>
  173: $reloadlink $navmaps $docs $groups $roles
  174: <a href="/adm/logout" target="_top">$lt{'exit'}</a>
  175: </div>
  176: <br />
  177: <script type="text/javascript">
  178: // END LON-CAPA Internal
  179: </script>
  180: $form
  181: ENDMAINMENU
  182:         if ($registration) { $output.=&innerregister($forcereg); }
  183: 	return $output."<hr />";
  184:     } elsif ($env{'environment.remote'} eq 'off') {
  185: # Remote Control is switched off
  186: # figure out colors
  187: 	my %lt=&initlittle();
  188: 
  189:         my $domain=&Apache::loncommon::determinedomain();
  190: 	my $function =&Apache::loncommon::get_users_function();
  191:         my $link=&Apache::loncommon::designparm($function.'.link',$domain);
  192:         my $alink=&Apache::loncommon::designparm($function.'.alink',$domain);
  193:         my $vlink=&Apache::loncommon::designparm($function.'.vlink',$domain);
  194:         my $sidebg=&Apache::loncommon::designparm($function.'.sidebg',$domain);
  195: 	if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
  196: 	    return (<<ENDINLINEMENU);
  197:    <table id="LC_top_nav">
  198:     <tr>
  199:       $logo
  200:       <td></td>
  201:       <td class="LC_top_nav_login">
  202:         <a href="/adm/roles" target="_top">$lt{'login'}</a>
  203:      </td>
  204:     </tr>
  205:   </table>
  206: </font>
  207: ENDINLINEMENU
  208:         }
  209:         $roles = '<td><a href="/adm/roles" target="_top">'.$lt{'roles'}.'</a></td>';
  210: # Do we have a NAV link?
  211:         if ($env{'request.course.id'}) {
  212: 	    my $link='/adm/navmaps?postdata='.$escurl.'&amp;postsymb='.
  213: 		$escsymb;
  214: 	    if ($env{'environment.remotenavmap'} eq 'on') {
  215: 		$link="javascript:gonav('".$link."')";
  216: 	    }
  217: 	    $navmaps=(<<ENDNAV);
  218: <td><a href="$link" target="_top">$lt{'nav'}</a></td>
  219: ENDNAV
  220:             my $is_group = (&Apache::loncommon::course_type() eq 'Group');
  221: 	    if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
  222:                 my $text = ($is_group) ? $lt{'gdoc'} : $lt{'docs'};
  223: 		$docs=(<<ENDDOCS);
  224: <td><a href="/adm/coursedocs" target="_top">$text</a></td>
  225: ENDDOCS
  226:             }
  227:             if ($showgroups) {
  228:                 $groups =(<<ENDGROUPS);
  229: <td><a href="/adm/coursegroups" target="_top">$lt{'groups'}</a></td>
  230: ENDGROUPS
  231:             }
  232: 	    if (&show_return_link()) {
  233:                 my $escreload=&escape('return:');
  234:                 $reloadlink=(<<ENDRELOAD);
  235: <td><a href="/adm/flip?postdata=$escreload" target="_top">$lt{'ret'}</a></td>
  236: ENDRELOAD
  237:             }
  238:             if ($role_selector) {
  239:                 $roles = '<td>'.$role_selector.'</td><td><a href="/adm/roles" target="_top">'.$lt{'other'}.'</a></td>';
  240:             }
  241:         }
  242: 	if (($env{'request.state'} eq 'construct') && ($env{'request.course.id'})) {
  243: 	    my $escreload=&escape('return:');
  244: 	    $reloadlink=(<<ENDCRELOAD);
  245: <td><a href="/adm/flip?postdata=$escreload" target="_top">$lt{'ret'}</a></td>
  246: ENDCRELOAD
  247:         }
  248:         my $reg='';
  249:         if ($registration) {
  250:            $reg=&innerregister($forcereg,$titletable);
  251:         }
  252:         my $form=&serverform();
  253: 	my $utility=&utilityfunctions();
  254: 
  255:         my $helplink=&Apache::loncommon::top_nav_help('Help');
  256: 	return (<<ENDINLINEMENU);
  257: <script type="text/javascript">
  258: // BEGIN LON-CAPA Internal
  259: // <![CDATA[
  260: $utility
  261: // ]]>
  262: </script>
  263: <table id="LC_top_nav">
  264: <tr>
  265: $logo
  266: <td><a href="/adm/menu" target="_top">$lt{'main'}</a></td>
  267: $reloadlink
  268: $navmaps
  269: $docs
  270: $groups
  271: $roles
  272: <td class="LC_top_nav_help">$helplink</td>
  273: <td class="LC_top_nav_exit"><a href="/adm/logout" target="_top">$lt{'exit'}</a></td>
  274: </tr>
  275: </table>
  276: $form
  277: <script type="text/javascript">
  278: // END LON-CAPA Internal
  279: </script>
  280: $reg
  281: ENDINLINEMENU
  282:     } else {
  283: 	return '';
  284:     }
  285: }
  286: 
  287: sub show_return_link {
  288:     return (($env{'request.noversionuri'}=~m{^/(res|public)/} &&
  289: 	     $env{'request.symb'} eq '')
  290: 	    ||
  291: 	    ($env{'request.noversionuri'}=~ m{^/cgi-bin/printout.pl})
  292: 	    ||
  293: 	    (($env{'request.noversionuri'}=~/^\/adm\//) &&
  294: 	     ($env{'request.noversionuri'}!~/^\/adm\/wrapper\//) &&
  295: 	     ($env{'request.noversionuri'}!~
  296: 	      m[^/adm/.*/(smppg|bulletinboard|aboutme)($|\?)])
  297: 	     ));
  298: }
  299: 
  300: # ====================================== This gets called in the header section
  301: 
  302: sub registerurl {
  303:     my ($forcereg) = @_;
  304:     my $result = '';
  305:     if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
  306:     my $force_title='';
  307:     if ($env{'request.state'} eq 'construct') {
  308: 	$force_title=&Apache::lonxml::display_title();
  309:     }
  310:     if (($env{'browser.interface'} eq 'textual') ||
  311:         ($env{'environment.remote'} eq 'off') ||
  312:         ((($env{'request.publicaccess'}) || 
  313:          (!&Apache::lonnet::is_on_map(
  314: 	   &unescape($env{'request.noversionuri'})))) &&
  315:         (!$forcereg))) {
  316:  	return $result.
  317:           '<script type="text/javascript">function LONCAPAreg(){;} function LONCAPAstale(){}</script>'.$force_title;
  318:     }
  319: # Graphical display after login only
  320:     if ($env{'request.registered'} && !$forcereg) { return ''; }
  321:     $result.=&innerregister($forcereg);
  322:     return $result.$force_title;
  323: }
  324: 
  325: # =========== This gets called in order to register a URL, both with the Remote
  326: # =========== and in the body of the document
  327: 
  328: sub innerregister {
  329:     my ($forcereg, $titletable) = @_;
  330:     my $result = '';
  331:     my ($uname,$thisdisfn);
  332:     my $const_space = ($env{'request.state'} eq 'construct');
  333:     my $is_const_dir = 0;
  334: 
  335:     if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
  336: 
  337:     $env{'request.registered'} = 1;
  338: 
  339:     my $textinter=($env{'browser.interface'} eq 'textual');
  340:     my $noremote=($env{'environment.remote'} eq 'off');
  341:     
  342:     my $textual=($textinter || $noremote);
  343: 
  344:     undef(@inlineremote);
  345: 
  346:     my $reopen=&Apache::lonmenu::reopenmenu();
  347: 
  348:     my $newmail='';
  349:     if ($noremote) {
  350: 	$newmail='<table id="LC_nav_location"><tr>';
  351:     }
  352:     if (&Apache::lonmsg::newmail()) { 
  353: 	if ($textual) {
  354: 	    $newmail.= '<td class="LC_new_mail">
  355:                    <a href="/adm/communicate" target="_top">'.
  356: 		   &mt('You have new messages').'</a></td>';
  357: 	} else {
  358: 	    $newmail= 'swmenu.setstatus("you have","messages");';
  359: 	}
  360:     } 
  361:     if (($textual) 
  362: 	     && ($env{'request.symb'}) 
  363: 	     && ($env{'request.course.id'})) {
  364: 	$newmail.= '<td class="LC_current_location">';
  365: 	my ($mapurl,$rid,$resurl)=
  366: 	    &Apache::lonnet::decode_symb(&Apache::lonnet::symbread());
  367:         my $coursetitle=$env{'course.'.$env{'request.course.id'}.'.description'};
  368:         $newmail.=$coursetitle;
  369:         my $maptitle=&Apache::lonnet::gettitle($mapurl);
  370: 	my $restitle=&Apache::lonnet::gettitle(&Apache::lonnet::symbread());
  371:         if ($maptitle && ($maptitle ne 'default.sequence') && ($maptitle ne $coursetitle)) {
  372: 	    $newmail.=', '.$maptitle;
  373:         }
  374:         if ($restitle) {
  375: 	    $newmail.=': '.$restitle;
  376:         }
  377:         $newmail.='&nbsp;&nbsp;&nbsp;</td>';
  378:     }
  379:     if ($env{'request.state'} eq 'construct') {
  380:         $newmail = $titletable;
  381:     } else {
  382: 	if ($noremote) {
  383: 	    $newmail.='</tr></table>';
  384: 	}
  385:     }
  386:     my $timesync=($textual?'':'swmenu.syncclock(1000*'.time.');');
  387:     my $tablestart=($noremote?'<table id="LC_menubuttons">':'').
  388: 	($textinter?'<br /><a href="#content">'.&mt('Skip to Content').'</a><br />':'');
  389:     my $tableend=($noremote?'</table>':'').($textinter?'<a name="content" />':'');
  390: # =============================================================================
  391: # ============================ This is for URLs that actually can be registered
  392:     if (($env{'request.noversionuri'}!~m|^/(res/)*adm/|) || ($forcereg)) {
  393: # -- This applies to homework problems for users with grading privileges
  394: 	my $crs='/'.$env{'request.course.id'};
  395: 	if ($env{'request.course.sec'}) {
  396: 	    $crs.='_'.$env{'request.course.sec'};
  397: 	}
  398: 	$crs=~s/\_/\//g;
  399: 
  400:         my $hwkadd='';
  401:         if ($env{'request.symb'} ne '' &&
  402: 	    $env{'request.filename'}=~/\.(problem|exam|quiz|assess|survey|form|task)$/) {
  403: 	    if (&Apache::lonnet::allowed('mgr',$crs)) {
  404: 		$hwkadd.=&switch('','',7,2,'pgrd.gif','problem[_1]','grades[_3]',
  405:                        "gocmd('/adm/grades','gradingmenu')",
  406:                        'Modify user grades for this assessment resource');
  407:             } elsif (&Apache::lonnet::allowed('vgr',$crs)) {
  408: 		$hwkadd.=&switch('','',7,2,'subm.gif','view sub-[_1]','missions[_1]',
  409:                        "gocmd('/adm/grades','submission')",
  410: 		       'View user submissions for this assessment resource');
  411:             }
  412: 	}
  413: 	if ($env{'request.symb'} ne '' &&
  414: 	    &Apache::lonnet::allowed('opa',$crs)) {
  415: 	    $hwkadd.=&switch('','',7,3,'pparm.gif','problem[_2]','parms[_2]',
  416: 			     "gocmd('/adm/parmset','set')",
  417: 			     'Modify parameter settings for this resource');
  418: 	}
  419: # -- End Homework
  420:         ###
  421:         ### Determine whether or not to display the 'cstr' button for this
  422:         ### resource
  423:         ###
  424:         my $editbutton = '';
  425:         if ($env{'user.author'}) {
  426:             if ($env{'request.role'}=~/^(aa|ca|au)/) {
  427:                 # Set defaults for authors
  428:                 my ($top,$bottom) = ('con-','struct');
  429:                 my $action = "go('/priv/".$env{'user.name'}."');";
  430:                 my $cadom  = $env{'request.role.domain'};
  431:                 my $caname = $env{'user.name'};
  432:                 my $desc = "Enter my construction space";
  433:                 # Set defaults for co-authors
  434:                 if ($env{'request.role'} =~ /^ca/) { 
  435:                     ($cadom,$caname)=($env{'request.role'}=~/($match_domain)\/($match_username)$/);
  436:                     ($top,$bottom) = ('co con-','struct');
  437:                     $action = "go('/priv/".$caname."');";
  438:                     $desc = "Enter construction space as co-author";
  439:                 } elsif ($env{'request.role'} =~ /^aa/) {
  440:                     ($cadom,$caname)=($env{'request.role'}=~/($match_domain)\/($match_username)$/);
  441:                     ($top,$bottom) = ('co con-','struct');
  442:                     $action = "go('/priv/".$caname."');";
  443:                     $desc = "Enter construction space as assistant co-author";
  444:                 }
  445:                 # Check that we are on the correct machine
  446:                 my $home = &Apache::lonnet::homeserver($caname,$cadom);
  447: 		my $allowed=0;
  448: 		my @ids=&Apache::lonnet::current_machine_ids();
  449: 		foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
  450: 		if (!$allowed) {
  451: 		    $editbutton=&switch('','',6,1,$top,,$bottom,$action,$desc);
  452:                 }
  453:             }
  454:             ##
  455:             ## Determine if user can edit url.
  456:             ##
  457:             my $cfile='';
  458:             my $cfuname='';
  459:             my $cfudom='';
  460:             if ($env{'request.filename'}) {
  461:                 my $file=&Apache::lonnet::declutter($env{'request.filename'});
  462:                 $file=~s/^($match_domain)\/($match_username)/\/priv\/$2/;
  463:                 # Check that the user has permission to edit this resource
  464:                 ($cfuname,$cfudom)=&Apache::loncacc::constructaccess($file,$1);
  465:                 if (defined($cfudom)) {
  466: 		    my $home=&Apache::lonnet::homeserver($cfuname,$cfudom);
  467: 		    my $allowed=0;
  468: 		    my @ids=&Apache::lonnet::current_machine_ids();
  469: 		    foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
  470: 		    if ($allowed) {
  471:                         $cfile=$file;
  472:                     }
  473:                 }
  474:             }        
  475:             # Finally, turn the button on or off
  476:             if ($cfile && !$const_space) {
  477:                 $editbutton=&switch
  478:                     ('','',6,1,'pcstr.gif','edit[_1]','resource[_2]',
  479:                      "go('".$cfile."');","Edit this resource");
  480:             } elsif ($editbutton eq '') {
  481:                 $editbutton=&clear(6,1);
  482:             }
  483:         }
  484:         ###
  485:         ###
  486: # Prepare the rest of the buttons
  487:         my $menuitems;
  488:         if ($const_space) {
  489: 	    my ($uname,$thisdisfn) =
  490: 		($env{'request.filename'}=~m|^/home/([^/]+)/public_html/(.*)|);
  491:             my $currdir = '/priv/'.$uname.'/'.$thisdisfn;
  492:             if ($currdir =~ m-/$-) {
  493:                 $is_const_dir = 1;
  494:             } else {
  495:                 $currdir =~ s#[^/]+$##;
  496: 		my $cleandisfn = &Apache::loncommon::escape_single($thisdisfn);
  497: 		my $esc_currdir = &Apache::loncommon::escape_single($currdir);
  498:                 $menuitems=(<<ENDMENUITEMS);
  499: s&6&1&list.gif&list[_1]&dir[_1]&golist('$esc_currdir')&List current directory
  500: s&6&2&rtrv.gif&retrieve[_1]&version[_1]&gocstr('/adm/retrieve','/~$uname/$cleandisfn')&Retrieve old version
  501: s&6&3&pub.gif&publish[_1]&resource[_1]&gocstr('/adm/publish','/~$uname/$cleandisfn')&Publish this resource
  502: s&7&1&del.gif&delete[_1]&resource[_2]&gocstr('/adm/cfile?action=delete','/~$uname/$cleandisfn')&Delete this resource
  503: s&7&2&prt.gif&prepare[_1]&printout[_1]&gocstr('/adm/printout','/~$uname/$cleandisfn')&Prepare a printable document
  504: ENDMENUITEMS
  505:             }
  506:         } elsif ( defined($env{'request.course.id'}) && 
  507: 		 $env{'request.symb'} ne '' ) {
  508: 	    $menuitems=(<<ENDMENUITEMS);
  509: c&3&1
  510: s&2&1&back.gif&backward[_1]&&gopost('/adm/flip','back:'+currentURL)&Go to the previous resource in the course sequence&&1
  511: s&2&3&forw.gif&forward[_1]&&gopost('/adm/flip','forward:'+currentURL)&Go to the next resource in the course sequence&&3
  512: c&6&3
  513: c&8&1
  514: c&8&2
  515: s&8&3&prt.gif&prepare[_1]&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
  516: s&9&1&sbkm.gif&set[_1]&bookmark[_2]&set_bookmark()&Set a bookmark for this resource&&1
  517: ENDMENUITEMS
  518:             my $currentURL = &Apache::loncommon::get_symb();
  519:             my ($symb_old,$symb_old_enc) = &Apache::loncommon::clean_symb($currentURL);
  520:             my $annotation = &Apache::loncommon::get_annotation($symb_old,$symb_old_enc);
  521:             $menuitems.="s&9&3&";
  522:             if (length($annotation) > 0){
  523:                 $menuitems.="anot2.gif";
  524:             } else {
  525:                 $menuitems.="anot.gif";
  526:             }
  527:             $menuitems.="&anno-[_1]&tations[_1]&annotate()&";
  528:             $menuitems.="Make notes and annotations about this resource&&1\n";
  529: 
  530:             unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme)(\?|$)/) {
  531: 		if (!$env{'request.enc'}) {
  532: 		    $menuitems.=(<<ENDREALRES);
  533: s&6&3&catalog.gif&catalog[_1]&info[_1]&catalog_info()&Show catalog information
  534: ENDREALRES
  535:                 }
  536: 	        $menuitems.=(<<ENDREALRES);
  537: s&8&1&eval.gif&evaluate[_1]&this[_1]&gopost('/adm/evaluate',currentURL,1)&Provide my evaluation of this resource
  538: s&8&2&fdbk.gif&feedback[_1]&discuss[_1]&gopost('/adm/feedback',currentURL,1)&Provide feedback messages or contribute to the course discussion about this resource
  539: ENDREALRES
  540: 	    }
  541:         }
  542: 	if ($env{'request.uri'} =~ /^\/res/) {
  543: 	    $menuitems .= (<<ENDMENUITEMS);
  544: s&8&3&prt.gif&prepare[_1]&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
  545: ENDMENUITEMS
  546: 	}
  547:         my $buttons='';
  548:         foreach (split(/\n/,$menuitems)) {
  549: 	    my ($command,@rest)=split(/\&/,$_);
  550:             my $idx=10*$rest[0]+$rest[1];
  551:             if (&hidden_button_check() eq 'yes') {
  552:                 if ($idx == 21 ||$idx == 23) {
  553:                     $buttons.=&switch('','',@rest);
  554:                 } else {
  555:                     $buttons.=&clear(@rest);
  556:                 }
  557:             } else {  
  558:                 if ($command eq 's') {
  559: 	            $buttons.=&switch('','',@rest);
  560:                 } else {
  561:                     $buttons.=&clear(@rest);
  562:                 }
  563:             }
  564:         }
  565: 
  566:         if ($textual) {
  567: 	    my $addremote=0;
  568: 	    foreach (@inlineremote) { if ($_ ne '') { $addremote=1; } }
  569: 	    my $inlinebuttons='';
  570: 	    if ($addremote) {
  571: # Registered, textual output
  572: 		if ($env{'browser.interface'} eq 'textual') {
  573: 		    $inlinebuttons=
  574:                         join('',map { (defined($_)?$_:'') } @inlineremote);
  575: 		} else {
  576:                     if ($env{'environment.icons'} eq 'iconsonly') {
  577:                         $inlinebuttons=(<<ENDARROWSINLINE);
  578: <tr><td>
  579: $inlineremote[21] $inlineremote[23]
  580: ENDARROWSINLINE
  581:                         if (&hidden_button_check() ne 'yes') {
  582:                             $inlinebuttons .= (<<ENDINLINEICONS);
  583: $inlineremote[61] $inlineremote[63]
  584: $inlineremote[71] $inlineremote[72] $inlineremote[73]
  585: $inlineremote[81] $inlineremote[82] $inlineremote[83]
  586: $inlineremote[91] $inlineremote[92] $inlineremote[93]</td></tr>
  587: ENDINLINEICONS
  588:                         }
  589:                     } else {
  590: 			if ($inlineremote[21] ne '' || $inlineremote[23] ne '') {
  591: 			    $inlinebuttons=(<<ENDFIRSTLINE);
  592: <tr><td>$inlineremote[21]</td><td>&nbsp;</td><td>$inlineremote[23]</td></tr>
  593: ENDFIRSTLINE
  594:                         }
  595:                         if (&hidden_button_check() ne 'yes') { 
  596: 			    foreach my $row (6..9) {
  597: 				if ($inlineremote[${row}.'1'] ne ''
  598: 				    || $inlineremote[$row.'2'] ne ''
  599: 				    || $inlineremote[$row.'3'] ne '') {
  600: 				    $inlinebuttons .= <<"ENDLINE";
  601: <tr><td>$inlineremote["${row}1"]</td><td>$inlineremote["${row}2"]</td><td>$inlineremote["${row}3"]</td></tr>
  602: ENDLINE
  603: 				}
  604: 			    }
  605: 			}
  606: 		    }
  607: 		}
  608: 	    }
  609: 	    $result =(<<ENDREGTEXT);
  610: <script type="text/javascript">
  611: // BEGIN LON-CAPA Internal
  612: </script>
  613: $timesync
  614: $tablestart
  615: $inlinebuttons
  616: $tableend
  617: $newmail
  618: <script type="text/javascript">
  619: // END LON-CAPA Internal
  620: </script>
  621: 
  622: ENDREGTEXT
  623: # Registered, graphical output
  624:         } else {
  625: 	    my $requri=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
  626: 	    $requri=&Apache::lonenc::check_encrypt(&unescape($requri));
  627: 	    my $cursymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
  628: 	    my $navstatus=&get_nav_status();
  629: 	    my $clearcstr;
  630: 
  631: 	    if ($env{'user.adv'}) { $clearcstr='clearbut(6,1)'; }
  632: 	    $result = (<<ENDREGTHIS);
  633:      
  634: <script type="text/javascript">
  635: // BEGIN LON-CAPA Internal
  636: var swmenu=null;
  637: 
  638:     function LONCAPAreg() {
  639: 	  swmenu=$reopen;
  640:           swmenu.clearTimeout(swmenu.menucltim);
  641:           $timesync
  642:           $newmail
  643:           $buttons
  644: 	  swmenu.currentURL="$requri";
  645:           swmenu.reloadURL=swmenu.currentURL+window.location.search;
  646:           swmenu.currentSymb="$cursymb";
  647:           swmenu.reloadSymb="$cursymb";
  648:           swmenu.currentStale=0;
  649: 	  $navstatus
  650:           $hwkadd
  651:           $editbutton
  652:     }
  653: 
  654:     function LONCAPAstale() {
  655: 	  swmenu=$reopen
  656:           swmenu.currentStale=1;
  657:           if (swmenu.reloadURL!='' && swmenu.reloadURL!= null) { 
  658:              swmenu.switchbutton
  659:              (3,1,'reload.gif','return','location','go(reloadURL)','Return to the last known location in the course sequence');
  660: 	  }
  661:           swmenu.clearbut(7,2);
  662:           swmenu.clearbut(7,3);
  663:           swmenu.menucltim=swmenu.setTimeout(
  664:  'clearbut(2,1);clearbut(2,3);clearbut(8,1);clearbut(8,2);clearbut(8,3);'+
  665:  'clearbut(9,1);clearbut(9,3);clearbut(6,3);$clearcstr',
  666: 			  2000);
  667:       }
  668: 
  669: // END LON-CAPA Internal 
  670: </script>
  671: ENDREGTHIS
  672:         }
  673: # =============================================================================
  674:     } else {
  675: # ========================================== This can or will not be registered
  676:         if ($textual) {
  677: # Not registered, textual
  678: 	    $result= (<<ENDDONOTREGTEXT);
  679: ENDDONOTREGTEXT
  680:         } else {
  681: # Not registered, graphical
  682:            $result = (<<ENDDONOTREGTHIS);
  683: 
  684: <script type="text/javascript">
  685: // BEGIN LON-CAPA Internal
  686: var swmenu=null;
  687: 
  688:     function LONCAPAreg() {
  689: 	  swmenu=$reopen
  690:           $timesync
  691:           swmenu.currentStale=1;
  692:           swmenu.clearbut(2,1);
  693:           swmenu.clearbut(2,3);
  694:           swmenu.clearbut(8,1);
  695:           swmenu.clearbut(8,2);
  696:           swmenu.clearbut(8,3);
  697:           if (swmenu.currentURL) {
  698:              swmenu.switchbutton
  699:               (3,1,'reload.gif','return','location','go(currentURL)');
  700:  	  } else {
  701: 	      swmenu.clearbut(3,1);
  702:           }
  703:     }
  704: 
  705:     function LONCAPAstale() {
  706:     }
  707: 
  708: // END LON-CAPA Internal
  709: </script>
  710: ENDDONOTREGTHIS
  711:        }
  712: # =============================================================================
  713:     }
  714:     return $result;
  715: }
  716: 
  717: sub loadevents() {
  718:     if ($env{'request.state'} eq 'construct' ||
  719: 	$env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
  720:     return 'LONCAPAreg();';
  721: }
  722: 
  723: sub unloadevents() {
  724:     if ($env{'request.state'} eq 'construct' ||
  725: 	$env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
  726:     return 'LONCAPAstale();';
  727: }
  728: 
  729: # ============================================================= Start up remote
  730: 
  731: sub startupremote {
  732:     my ($lowerurl)=@_;
  733:     if (($env{'browser.interface'} eq 'textual') ||
  734:         ($env{'environment.remote'} eq 'off')) {
  735:      return ('<meta HTTP-EQUIV="Refresh" CONTENT="0.5; url='.$lowerurl.'" />');
  736:     }
  737: #
  738: # The Remote actually gets launched!
  739: #
  740:     my $configmenu=&rawconfig();
  741:     my $esclowerurl=&escape($lowerurl);
  742:     my $message=&mt('"Waiting for Remote Control window to load: "+[_1]','waited');
  743:     return(<<ENDREMOTESTARTUP);
  744: <script type="text/javascript">
  745: var timestart;
  746: function wheelswitch() {
  747:     if (typeof(document.wheel) != 'undefined') {
  748: 	if (typeof(document.wheel.spin) != 'undefined') {
  749: 	    var date=new Date();
  750: 	    var waited=Math.round(30-((date.getTime()-timestart)/1000));
  751: 	    document.wheel.spin.value=$message;
  752: 	}
  753:     }
  754:    if (window.status=='|') { 
  755:       window.status='/'; 
  756:    } else {
  757:       if (window.status=='/') {
  758:          window.status='-';
  759:       } else {
  760:          if (window.status=='-') { 
  761:             window.status='\\\\'; 
  762:          } else {
  763:             if (window.status=='\\\\') { window.status='|'; }
  764:          }
  765:       }
  766:    } 
  767: }
  768: 
  769: // ---------------------------------------------------------- The wait function
  770: var canceltim;
  771: function wait() {
  772:    if ((menuloaded==1) || (tim==1)) {
  773:       window.status='Done.';
  774:       if (tim==0) {
  775:          clearTimeout(canceltim);
  776:          $configmenu
  777:          window.location='$lowerurl';  
  778:       } else {
  779: 	  window.location='/adm/remote?action=collapse&url=$esclowerurl';
  780:       }
  781:    } else {
  782:       wheelswitch();
  783:       setTimeout('wait();',200);
  784:    }
  785: }
  786: 
  787: function main() {
  788:    canceltim=setTimeout('tim=1;',30000);
  789:    window.status='-';
  790:    var date=new Date();
  791:    timestart=date.getTime();
  792:    wait();
  793: }
  794: 
  795: </script>
  796: ENDREMOTESTARTUP
  797: }
  798: 
  799: sub setflags() {
  800:     return(<<ENDSETFLAGS);
  801: <script type="text/javascript">
  802:     menuloaded=0;
  803:     tim=0;
  804: </script>
  805: ENDSETFLAGS
  806: }
  807: 
  808: sub maincall() {
  809:     if (($env{'browser.interface'} eq 'textual') ||
  810:         ($env{'environment.remote'} eq 'off')) { return ''; }
  811:     return(<<ENDMAINCALL);
  812: <script type="text/javascript">
  813:     main();
  814: </script>
  815: ENDMAINCALL
  816: }
  817: 
  818: sub load_remote_msg {
  819:     my ($lowerurl)=@_;
  820: 
  821:     if (($env{'browser.interface'} eq 'textual') ||
  822:         ($env{'environment.remote'} eq 'off')) { return ''; }
  823: 
  824:     my $esclowerurl=&escape($lowerurl);
  825:     my $link=&mt('<a href="[_1]">Continue</a> on in Inline Menu mode',
  826: 		 "/adm/remote?action=collapse&amp;url=$esclowerurl");
  827:     return(<<ENDREMOTEFORM);
  828: <p>
  829: <form name="wheel">
  830: <input name="spin" type="text" size="60" />
  831: </form>
  832: </p>
  833: <p>$link</p>
  834: ENDREMOTEFORM
  835: }
  836: 
  837: sub get_menu_name {
  838:     my $hostid = $Apache::lonnet::perlvar{'lonHostID'};
  839:     $hostid =~ s/\W//g;
  840:     return 'LCmenu'.$hostid;
  841: }
  842: 
  843: # ================================================================= Reopen menu
  844: 
  845: sub reopenmenu {
  846:    if (($env{'browser.interface'} eq 'textual') ||
  847:        ($env{'environment.remote'} eq 'off')) { return ''; }
  848:    my $menuname = &get_menu_name();
  849:    my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
  850:    return('window.open('.$nothing.',"'.$menuname.'","",false);');
  851: } 
  852: 
  853: # =============================================================== Open the menu
  854: 
  855: sub open {
  856:     my $returnval='';
  857:     if (($env{'browser.interface'} eq 'textual') ||
  858:         ($env{'environment.remote'} eq 'off')) { 
  859: 	return '<script type="text/javascript">self.name="loncapaclient";</script>';
  860:     }
  861:     my $menuname = &get_menu_name();
  862:     
  863: #    unless (shift eq 'unix') {
  864: # resizing does not work on linux because of virtual desktop sizes
  865: #       $returnval.=(<<ENDRESIZE);
  866: #if (window.screen) {
  867: #    self.resizeTo(screen.availWidth-215,screen.availHeight-55);
  868: #    self.moveTo(190,15);
  869: #}
  870: #ENDRESIZE
  871: #    }
  872:     $returnval.=(<<ENDOPEN);
  873: window.status='Opening LON-CAPA Remote Control';
  874: var menu=window.open("/res/adm/pages/menu.html","$menuname",
  875: "height=375,width=150,scrollbars=no,menubar=no,top=5,left=5,screenX=5,screenY=5");
  876: self.name='loncapaclient';
  877: ENDOPEN
  878:     return '<script type="text/javascript">'.$returnval.'</script>';
  879: }
  880: 
  881: 
  882: # ================================================================== Raw Config
  883: 
  884: sub clear {
  885:     my ($row,$col)=@_;
  886:     unless (($env{'browser.interface'} eq 'textual') ||
  887:             ($env{'environment.remote'} eq 'off')) {
  888:        return "\n".qq(window.status+='.';swmenu.clearbut($row,$col););
  889:    } else { 
  890:        $inlineremote[10*$row+$col]='';
  891:        return ''; 
  892:    }
  893: }
  894: 
  895: # ============================================ Switch a button or create a link
  896: # Switch acts on the javascript that is executed when a button is clicked.  
  897: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
  898: 
  899: sub switch {
  900:     my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat,$nobreak)=@_;
  901:     $act=~s/\$uname/$uname/g;
  902:     $act=~s/\$udom/$udom/g;
  903:     $top=&mt($top);
  904:     $bot=&mt($bot);
  905:     $desc=&mt($desc);
  906:     if (($env{'environment.remote'} ne 'off') || ($env{'environment.icons'} eq 'classic')) {
  907:        $img=&mt($img);
  908:     }
  909:     my $idx=10*$row+$col;
  910:     $category_members{$cat}.=':'.$idx;
  911: 
  912:     unless (($env{'browser.interface'} eq 'textual')  ||
  913:             ($env{'environment.remote'} eq 'off')) {
  914: # Remote
  915:        return "\n".
  916:  qq(window.status+='.';swmenu.switchbutton($row,$col,"$img","$top","$bot","$act","$desc"););
  917:    } elsif ($env{'browser.interface'} eq 'textual') {
  918: # Accessibility
  919:        if ($nobreak==2) { return ''; }
  920:        my $text=$top.' '.$bot;
  921:        $text=~s/\s*\-\s*//gs;
  922:        if ($nobreak) {
  923: 	   $inlineremote[$idx]=
  924: 	       '<a href="javascript:'.$act.';">'.$text.'</a>';
  925:        } else {
  926: 	   $inlineremote[$idx]="\n<br />".
  927: 	       $desc.' <a href="javascript:'.$act.';">'.$text.'</a>';
  928:        }
  929:    } else {
  930: # Inline Remote
  931:        if ($env{'environment.icons'} ne 'classic') {
  932:           $img=~s/\.gif$/\.png/;
  933:        }
  934:        if ($nobreak==2) { return ''; }
  935:        my $text=$top.' '.$bot;
  936:        $text=~s/\s*\-\s*//gs;
  937: 
  938:        my $pic=
  939: 	   '<img alt="'.$text.'" src="'.
  940: 	   &Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$img).
  941: 	   '" align="'.($nobreak==3?'right':'left').'" />';
  942:        if ($env{'browser.interface'} eq 'faketextual') {
  943: # Accessibility
  944: 	   if ($nobreak==3) {
  945: 	       $inlineremote[$idx]="\n".
  946: 		   '<td class="LC_menubuttons_text" align="right">'.$text.
  947: 		   '</td><td class="LC_menubuttons_img" align="left">'.
  948: 		   '<a href="javascript:'.$act.';">'.$pic.'</a></td></tr>';
  949: 	   } elsif ($nobreak) {
  950: 	       $inlineremote[$idx]="\n<tr>".
  951: 		   '<td class="LC_menubuttons_img" align="left">'.
  952: 		   '<a href="javascript:'.$act.';">'.$pic.'</a></td>
  953:                     <td class="LC_menubuttons_text" align="left"><a class="LC_menubuttons_link" href="javascript:'.$act.';"><span class="LC_menubuttons_inline_text">'.$text.'</span></a></td>';
  954: 	   } else {
  955: 	       $inlineremote[$idx]="\n<tr>".
  956: 		   '<td class="LC_menubuttons_img" align="left">'.
  957: 		   '<a href="javascript:'.$act.';">'.$pic.
  958: 		   '</a></td><td class="LC_menubuttons_text" colspan="3">'.
  959: 		   '<a class="LC_menubuttons_link" href="javascript:'.$act.';"><span class="LC_menubuttons_inline_text">'.$desc.'</span></a></td></tr>';
  960: 	   }
  961:        } else {
  962: # Inline Menu
  963:            if ($env{'environment.icons'} eq 'iconsonly') {
  964:               $inlineremote[$idx]='<a title="'.$desc.'" href="javascript:'.$act.';">'.$pic.'</a>';
  965:            } else {
  966: 	      $inlineremote[$idx]=
  967: 		   '<a class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.
  968: 		   '<span class="LC_menubuttons_inline_text">'.$desc.'</span></a>';
  969:            }
  970:        }
  971:    }
  972:     return '';
  973: }
  974: 
  975: sub secondlevel {
  976:     my $output='';
  977:     my 
  978:     ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat)=@_;
  979:     if ($prt eq 'any') {
  980: 	   $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
  981:     } elsif ($prt=~/^r(\w+)/) {
  982:         if ($rol eq $1) {
  983:            $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
  984:         }
  985:     }
  986:     return $output;
  987: }
  988: 
  989: sub openmenu {
  990:     my $menuname = &get_menu_name();
  991:     if (($env{'browser.interface'} eq 'textual') ||
  992:         ($env{'environment.remote'} eq 'off')) { return ''; }
  993:     my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
  994:     return "window.open(".$nothing.",'".$menuname."');";
  995: }
  996: 
  997: sub inlinemenu {
  998:     undef(@inlineremote);
  999:     undef(%category_members);
 1000:     &rawconfig(1);
 1001:     my $output='<table id="LC_mainmenu"><tr>';
 1002:     for (my $col=1; $col<=2; $col++) {
 1003:         $output.='<td class="LC_mainmenu_column">';
 1004:         for (my $row=1; $row<=8; $row++) {
 1005:             foreach my $cat (keys(%category_members)) {
 1006:                if ($category_positions{$cat} ne "$col,$row") { next; }
 1007:                $output.='<table id="LC_menubuttons_mainmenu"><tr><td colspan="4" class="LC_menubuttons_category">'.&mt($category_names{$cat}).'</td></tr>';
 1008:                my %active=();
 1009:                foreach my $menu_item (split(/\:/,$category_members{$cat})) {
 1010:                   if ($inlineremote[$menu_item]) {
 1011:                      $active{$menu_item}=1;
 1012:                   }
 1013:                }  
 1014:                foreach my $item (sort(keys(%active))) {
 1015:                   $output.=$inlineremote[$item];
 1016:                }
 1017:                $output.='</table>';
 1018:             }
 1019:          }
 1020:          $output.="</td>";
 1021:     }
 1022:     $output.="</tr></table>";
 1023:     return $output;
 1024: }
 1025: 
 1026: sub rawconfig {
 1027:     my $textualoverride=shift;
 1028:     my $output='';
 1029:     unless (($env{'browser.interface'} eq 'textual') ||
 1030:             ($env{'environment.remote'} eq 'off')) {
 1031:        $output.=
 1032:  "window.status='Opening Remote Control';var swmenu=".&openmenu().
 1033: "\nwindow.status='Configuring Remote Control ';";
 1034:     } else {
 1035:        unless ($textualoverride) { return ''; }
 1036:     }
 1037:     my $uname=$env{'user.name'};
 1038:     my $udom=$env{'user.domain'};
 1039:     my $adv=$env{'user.adv'};
 1040:     my $show_course=&show_course();
 1041:     my $author=$env{'user.author'};
 1042:     my $crs='';
 1043:     if ($env{'request.course.id'}) {
 1044:        $crs='/'.$env{'request.course.id'};
 1045:        if ($env{'request.course.sec'}) {
 1046: 	   $crs.='_'.$env{'request.course.sec'};
 1047:        }
 1048:        $crs=~s/\_/\//g;
 1049:     }
 1050:     my $pub=($env{'request.state'} eq 'published');
 1051:     my $con=($env{'request.state'} eq 'construct');
 1052:     my $rol=$env{'request.role'};
 1053:     my $requested_domain = $env{'request.role.domain'};
 1054:     foreach my $line (@desklines) {
 1055:         my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc,$cat)=split(/\:/,$line);
 1056:         $prt=~s/\$uname/$uname/g;
 1057:         $prt=~s/\$udom/$udom/g;
 1058:         $prt=~s/\$crs/$crs/g; 
 1059:         $prt=~s/\$requested_domain/$requested_domain/g;
 1060:         if ($category_names{$cat}!~/\w/) { $cat='oth'; }
 1061:         my $type = &Apache::loncommon::course_type();
 1062:         if ($type eq 'Group') {
 1063:             $desc = &convert_menu_function($desc,$type);
 1064:         }
 1065:         if ($pro eq 'clear') {
 1066: 	    $output.=&clear($row,$col);
 1067:         } elsif ($pro eq 'any') {
 1068:                $output.=&secondlevel(
 1069: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1070: 	} elsif ($pro eq 'smp') {
 1071:             unless ($adv) {
 1072:                $output.=&secondlevel(
 1073:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1074:             }
 1075:         } elsif ($pro eq 'adv') {
 1076:             if ($adv) {
 1077:                $output.=&secondlevel(
 1078: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1079:             }
 1080: 	} elsif ($pro eq 'shc') {
 1081:             if ($show_course) {
 1082:                $output.=&secondlevel(
 1083:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1084:             }
 1085:         } elsif ($pro eq 'nsc') {
 1086:             if (!$show_course) {
 1087:                $output.=&secondlevel(
 1088: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1089:             }
 1090:         } elsif (($pro=~/^p(\w+)/) && ($prt)) {
 1091: 	    if (&Apache::lonnet::allowed($1,$prt)) {
 1092:                $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1093:             }
 1094:         } elsif ($pro eq 'course') {
 1095:             if ($env{'request.course.fn'}) {
 1096:                $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1097: 	    }
 1098:         } elsif ($pro =~ /^courseenv_(.*)$/) {
 1099:             my $key = $1;
 1100:             if ($env{'course.'.$env{'request.course.id'}.'.'.$key}) {
 1101:                 $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1102:             }
 1103:         } elsif ($pro =~ /^course_(.*)$/) {
 1104:             # Check for permissions inside of a course
 1105:             if (($env{'request.course.id'}) &&
 1106:                 (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
 1107:             ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
 1108:                  )) {
 1109:                 $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1110: 	    }
 1111:         } elsif ($pro eq 'author') {
 1112:             if ($author) {
 1113:                 if ((($prt eq 'rca') && ($env{'request.role'}=~/^ca/)) ||
 1114:                     (($prt eq 'raa') && ($env{'request.role'}=~/^aa/)) || 
 1115:                     (($prt eq 'rau') && ($env{'request.role'}=~/^au/))) {
 1116:                     # Check that we are on the correct machine
 1117:                     my $cadom=$requested_domain;
 1118:                     my $caname=$env{'user.name'};
 1119:                     if (($prt eq 'rca') || ($prt eq 'raa')) {
 1120: 		       ($cadom,$caname)=
 1121:                                ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
 1122:                     }                       
 1123:                     $act =~ s/\$caname/$caname/g;
 1124:                     my $home = &Apache::lonnet::homeserver($caname,$cadom);
 1125: 		    my $allowed=0;
 1126: 		    my @ids=&Apache::lonnet::current_machine_ids();
 1127: 		    foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
 1128: 		    if ($allowed) {
 1129:                         $output.=&switch($caname,$cadom,
 1130:                                         $row,$col,$img,$top,$bot,$act,$desc,$cat);
 1131:                     }
 1132:                 }
 1133:             }
 1134:         } elsif ($pro eq 'tools') {
 1135:             my @tools = ('aboutme','blog','portfolio');
 1136:             if (grep(/^\Q$prt\E$/,@tools)) {
 1137:                 if (!&Apache::lonnet::usertools_access($env{'user.name'},
 1138:                                                        $env{'user.domain'},$prt)) {
 1139:                     $output.=&clear($row,$col);
 1140:                     next;
 1141:                 }
 1142:             }
 1143:             $prt='any';
 1144:             $output.=&secondlevel(
 1145:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1146:         }
 1147:     }
 1148:     unless (($env{'browser.interface'} eq 'textual') ||
 1149:             ($env{'environment.remote'} eq 'off')) {
 1150:        $output.="\nwindow.status='Synchronizing Time';swmenu.syncclock(1000*".time.");\nwindow.status='Remote Control Configured.';";
 1151:        if (&Apache::lonmsg::newmail()) { 
 1152: 	   $output.='swmenu.setstatus("you have","messages");';
 1153:        }
 1154:     }
 1155: 
 1156:     return $output;
 1157: }
 1158: 
 1159: # ======================================================================= Close
 1160: 
 1161: sub close {
 1162:     if (($env{'browser.interface'} eq 'textual') ||
 1163:         ($env{'environment.remote'} eq 'off')) { return ''; }
 1164:     my $menuname = &get_menu_name();
 1165:     return(<<ENDCLOSE);
 1166: <script type="text/javascript">
 1167: window.status='Accessing Remote Control';
 1168: menu=window.open("/adm/rat/empty.html","$menuname",
 1169:                  "height=350,width=150,scrollbars=no,menubar=no");
 1170: window.status='Disabling Remote Control';
 1171: menu.active=0;
 1172: menu.autologout=0;
 1173: window.status='Closing Remote Control';
 1174: menu.close();
 1175: window.status='Done.';
 1176: </script>
 1177: ENDCLOSE
 1178: }
 1179: 
 1180: # ====================================================================== Footer
 1181: 
 1182: sub footer {
 1183: 
 1184: }
 1185: 
 1186: sub nav_control_js {
 1187:     my $nav=($env{'environment.remotenavmap'} eq 'on');
 1188:     return (<<NAVCONTROL);
 1189:     var w_loncapanav_flag="$nav";
 1190: 
 1191: 
 1192: function gonav(url) {
 1193:    if (w_loncapanav_flag != 1) {
 1194:       gopost(url,'');
 1195:    }  else {
 1196:       navwindow=window.open(url,
 1197:                   "loncapanav","height=600,width=400,scrollbars=1"); 
 1198:    }
 1199: }
 1200: NAVCONTROL
 1201: }
 1202: 
 1203: sub utilityfunctions {
 1204:     my $caller = shift;
 1205:     unless (($env{'browser.interface'} eq 'textual')  ||
 1206:         ($env{'environment.remote'} eq 'off') || ($caller eq '/adm/menu')) { return ''; }
 1207:     my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
 1208:     $currenturl=&Apache::lonenc::check_encrypt(&unescape($currenturl));
 1209:     
 1210:     my $currentsymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
 1211:     my $nav_control=&nav_control_js();
 1212: 
 1213:     my $start_page_annotate = 
 1214:         &Apache::loncommon::start_page('Annotator',undef,
 1215: 				       {'only_body' => 1,
 1216: 					'js_ready'  => 1,
 1217: 					'bgcolor'   => '#BBBBBB',
 1218: 					'add_entries' => {
 1219: 					    'onload' => 'javascript:document.goannotate.submit();'}});
 1220: 
 1221:     my $end_page_annotate = 
 1222:         &Apache::loncommon::end_page({'js_ready' => 1});
 1223: 
 1224:     my $start_page_bookmark = 
 1225:         &Apache::loncommon::start_page('Bookmarks',undef,
 1226: 				       {'only_body' => 1,
 1227: 					'js_ready'  => 1,
 1228: 					'bgcolor'   => '#BBBBBB',});
 1229: 
 1230:     my $end_page_bookmark = 
 1231:         &Apache::loncommon::end_page({'js_ready' => 1});
 1232: 
 1233: return (<<ENDUTILITY)
 1234: 
 1235:     var currentURL="$currenturl";
 1236:     var reloadURL="$currenturl";
 1237:     var currentSymb="$currentsymb";
 1238: 
 1239: $nav_control
 1240: 
 1241: function go(url) {
 1242:    if (url!='' && url!= null) {
 1243:        currentURL = null;
 1244:        currentSymb= null;
 1245:        window.location.href=url;
 1246:    }
 1247: }
 1248: 
 1249: function gopost(url,postdata) {
 1250:    if (url!='') {
 1251:       this.document.server.action=url;
 1252:       this.document.server.postdata.value=postdata;
 1253:       this.document.server.command.value='';
 1254:       this.document.server.url.value='';
 1255:       this.document.server.symb.value='';
 1256:       this.document.server.submit();
 1257:    }
 1258: }
 1259: 
 1260: function gocmd(url,cmd) {
 1261:    if (url!='') {
 1262:       this.document.server.action=url;
 1263:       this.document.server.postdata.value='';
 1264:       this.document.server.command.value=cmd;
 1265:       this.document.server.url.value=currentURL;
 1266:       this.document.server.symb.value=currentSymb;
 1267:       this.document.server.submit();
 1268:    }
 1269: }
 1270: 
 1271: function gocstr(url,filename) {
 1272:     if (url == '/adm/cfile?action=delete') {
 1273:         this.document.cstrdelete.filename.value = filename
 1274:         this.document.cstrdelete.submit();
 1275:         return;
 1276:     }
 1277:     if (url == '/adm/printout') {
 1278:         this.document.cstrprint.postdata.value = filename
 1279:         this.document.cstrprint.curseed.value = 0;
 1280:         this.document.cstrprint.problemtype.value = 0;
 1281:         if (this.document.lonhomework) {
 1282:             if ((this.document.lonhomework.rndseed) && (this.document.lonhomework.rndseed.value != null) && (this.document.lonhomework.rndseed.value != '')) {
 1283:                 this.document.cstrprint.curseed.value = this.document.lonhomework.rndseed.value
 1284:             }
 1285:             if (this.document.lonhomework.problemtype) {
 1286: 		if (this.document.lonhomework.problemtype.value) {
 1287: 		    this.document.cstrprint.problemtype.value = 
 1288: 			this.document.lonhomework.problemtype.value;
 1289: 		} else if (this.document.lonhomework.problemtype.options) {
 1290: 		    for (var i=0; i<this.document.lonhomework.problemtype.options.length; i++) {
 1291: 			if (this.document.lonhomework.problemtype.options[i].selected) {
 1292: 			    if (this.document.lonhomework.problemtype.options[i].value != null && this.document.lonhomework.problemtype.options[i].value != '') { 
 1293: 				this.document.cstrprint.problemtype.value = this.document.lonhomework.problemtype.options[i].value
 1294: 				}
 1295: 			}
 1296: 		    }
 1297: 		}
 1298: 	    }
 1299: 	}
 1300:         this.document.cstrprint.submit();
 1301:         return;
 1302:     }
 1303:     if (url !='') {
 1304:         this.document.constspace.filename.value = filename;
 1305:         this.document.constspace.action = url;
 1306:         this.document.constspace.submit();
 1307:     }
 1308: }
 1309: 
 1310: function golist(url) {
 1311:    if (url!='' && url!= null) {
 1312:        currentURL = null;
 1313:        currentSymb= null;
 1314:        top.location.href=url;
 1315:    }
 1316: }
 1317: 
 1318: 
 1319: 
 1320: function catalog_info() {
 1321:    loncatinfo=window.open(window.location.pathname+'.meta',"LONcatInfo",'height=320,width=280,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
 1322: }
 1323: 
 1324: function chat_win() {
 1325:    lonchat=window.open('/res/adm/pages/chatroom.html',"LONchat",'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
 1326: }
 1327: 
 1328: function group_chat(group) {
 1329:    var url = '/adm/groupchat?group='+group;
 1330:    var winName = 'LONchat_'+group;
 1331:    grpchat=window.open(url,winName,'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
 1332: }
 1333: 
 1334: function edit_bookmarks() {
 1335:    go('');
 1336:    w_BookmarkPal_flag=1;
 1337:    bookmarkpal=window.open("/adm/bookmarks",
 1338:                "BookmarkPal", "width=400,height=505,scrollbars=0");
 1339: }
 1340: 
 1341: function annotate() {
 1342:    w_Annotator_flag=1;
 1343:    annotator=window.open('','Annotator','width=365,height=265,scrollbars=0');
 1344:    annotator.document.write(
 1345:    '$start_page_annotate'
 1346:   +"<form name='goannotate' target='Annotator' method='post' "
 1347:   +"action='/adm/annotations'>"
 1348:   +"<input type='hidden' name='symbnew' value='"+currentSymb+"' />"
 1349:   +"<\\/form>"
 1350:   +'$end_page_annotate');
 1351:    annotator.document.close();
 1352: }
 1353: 
 1354: function set_bookmark() {
 1355:    go('');
 1356:    clienttitle=document.title;
 1357:    clienthref=location.pathname;
 1358:    w_bmquery_flag=1;
 1359:    bmquery=window.open('','bmquery','width=365,height=165,scrollbars=0');
 1360:    bmquery.document.write(
 1361:    '$start_page_bookmark'
 1362:    +"<center><form method='post'"
 1363:    +" name='newlink' action='/adm/bookmarks' target='bmquery' "
 1364:    +">\\n <table width=340 height=150 "
 1365:    +"bgcolor='ffffff' align=center><tr><td>Link Name:<br /><input "
 1366:    +"type='text' name='title' size=45 value='"+clienttitle+"' />"
 1367:    +"<br />Address:<br /><input type='text' name='address' size='45' "
 1368:    +"value='"+clienthref+"' /><br /><center><input type='submit' "
 1369:    +"value='Save' /> <input type='button' value='Close (no save)' "
 1370:    +"onclick='javascript:window.close();' /><\\/center><\\/td>"
 1371:    +"<\\/tr><\\/table><\\/form><\\/center>"
 1372:    +'$end_page_bookmark' );
 1373:    bmquery.document.close();
 1374: }
 1375: 
 1376: ENDUTILITY
 1377: }
 1378: 
 1379: sub serverform {
 1380:     return(<<ENDSERVERFORM);
 1381: <form name="server" action="/adm/logout" method="post" target="_top">
 1382: <input type="hidden" name="postdata" value="none" />
 1383: <input type="hidden" name="command" value="none" />
 1384: <input type="hidden" name="url" value="none" />
 1385: <input type="hidden" name="symb" value="none" />
 1386: </form>
 1387: ENDSERVERFORM
 1388: }
 1389: 
 1390: sub constspaceform {
 1391:     return(<<ENDCONSTSPACEFORM);
 1392: <form name="constspace" action="/adm/logout" method="post" target="_top">
 1393: <input type="hidden" name="filename" value="" />
 1394: </form>
 1395: <form name="cstrdelete" action="/adm/cfile" method="post" target="_top">
 1396: <input type="hidden" name="action" value="delete" /> 
 1397: <input type="hidden" name="filename" value="" />
 1398: </form>
 1399: <form name="cstrprint" action="/adm/printout" target="_parent" method="post">
 1400: <input type="hidden" name="postdata" value="" />
 1401: <input type="hidden" name="curseed" value="" />
 1402: <input type="hidden" name="problemtype" value="" />
 1403: </form>
 1404: 
 1405: ENDCONSTSPACEFORM
 1406: }
 1407: 
 1408: 
 1409: sub get_nav_status {
 1410:     my $navstatus="swmenu.w_loncapanav_flag=";
 1411:     if ($env{'environment.remotenavmap'} eq 'on') {
 1412: 	$navstatus.="1";
 1413:     } else {
 1414: 	$navstatus.="-1";
 1415:     }
 1416:     return $navstatus;
 1417: }
 1418: 
 1419: #FIXME this needs to move into mydesktab and the other locations 
 1420: # the text is generated
 1421: sub convert_menu_function {
 1422:     my ($rolename,$type) = @_;
 1423:     if ($type eq 'Group') {
 1424:         $rolename =~ s/student/member/g;
 1425:         $rolename =~ s/group/team/g;
 1426:         $rolename =~ s/course/group/g;
 1427:         $rolename =~ s/Course/Group/g;
 1428:     }
 1429:     return $rolename;
 1430: }
 1431: 
 1432: sub hidden_button_check {
 1433:     my $hidden;
 1434:     if ($env{'request.course.id'} eq '') {
 1435:         return;
 1436:     }
 1437:     if ($env{'request.role.adv'}) {
 1438:         return;
 1439:     }
 1440:     my $buttonshide = &Apache::lonnet::EXT('resource.0.buttonshide');
 1441:     return $buttonshide; 
 1442: }
 1443: 
 1444: sub roles_selector {
 1445:     my ($cdom,$cnum) = @_;
 1446:     my $now = time;
 1447:     my (%courseroles,%seccount,%gotnosection);
 1448:     my $is_cc;
 1449:     my $role_selector;
 1450:     if ($env{'user.role.cc./'.$cdom.'/'.$cnum}) {
 1451:         my ($start,$end) = split(/\./,$env{'user.role.cc./'.$cdom.'/'.$cnum});
 1452:         
 1453:         if ((($start) && ($start<0)) || 
 1454:             (($end) && ($end<$now))  ||
 1455:             (($start) && ($now<$start))) {
 1456:             $is_cc = 0;
 1457:         } else {
 1458:             $is_cc = 1;
 1459:         }
 1460:     }
 1461:     if ($is_cc) {
 1462:         my %adv_roles =
 1463:              &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
 1464:         foreach my $role (keys(%adv_roles)) {
 1465:             my ($urole,$usec) = split(/:/,$role);
 1466:             if (!$gotnosection{$urole}) {
 1467:                 $seccount{$urole} ++;
 1468:                 $gotnosection{$urole} = 1;
 1469:             }
 1470:             if (ref($courseroles{$urole}) eq 'ARRAY') {
 1471:                 if ($usec ne '') {
 1472:                     if (!grep(/^Q$usec\E$/,@{$courseroles{$urole}})) {
 1473:                         push(@{$courseroles{$urole}},$usec);
 1474:                         $seccount{$urole} ++;
 1475:                     }
 1476:                 }
 1477:             } else {
 1478:                 @{$courseroles{$urole}} = ();
 1479:                 if ($usec ne '') {
 1480:                     $seccount{$urole} ++;
 1481:                     push(@{$courseroles{$urole}},$usec);
 1482:                 }
 1483:             }
 1484:         }
 1485:         my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
 1486:         @{$courseroles{'st'}} = ();
 1487:         if (keys(%sections_count) > 0) {
 1488:             push(@{$courseroles{'st'}},keys(%sections_count));
 1489:         }
 1490:     } else {
 1491:         foreach my $item (keys(%env)) {
 1492:             if ($item =~ m-^user\.role\.([^.]+)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
 1493:                 my $role = $1;
 1494:                 my $sec = $2;
 1495:                 next if ($role eq 'gr');
 1496:                 my ($start,$end) = split(/\./,$env{$item});
 1497:                 next if (($start && $start > $now) || ($end && $end < $now));
 1498:                 if ($sec eq '') {
 1499:                     if (!$gotnosection{$role}) {
 1500:                         $seccount{$role} ++;
 1501:                         $gotnosection{$role} = 1;
 1502:                     }
 1503:                 }
 1504:                 if (ref($courseroles{$role}) eq 'ARRAY') {
 1505:                     if ($sec ne '') {
 1506:                         if (!grep(/^Q$sec\E$/,@{$courseroles{$role}})) {
 1507:                             push(@{$courseroles{$role}},$sec);
 1508:                             $seccount{$role} ++;
 1509:                         }
 1510:                     }
 1511:                 } else {
 1512:                     @{$courseroles{$role}} = ();
 1513:                     if ($sec ne '') {
 1514:                         $seccount{$role} ++;
 1515:                         push(@{$courseroles{$role}},$sec);
 1516:                     }
 1517:                 }
 1518:             }
 1519:         }
 1520:     }
 1521:     my @roles_order = ('cc','in','ta','ep','ad','st');
 1522:     if (keys(%courseroles) > 1) {
 1523:         $role_selector = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles);
 1524:         $role_selector .= '<form name="rolechooser" method="post" action="/adm/roles">
 1525:                           <select name="switchrole" onchange="javascript:adhocRole('."'switchrole'".')">';
 1526:         $role_selector .= '<option value="">'.&mt('Switch course role to...').'</option>';
 1527:         foreach my $role (@roles_order) {
 1528:             if (defined($courseroles{$role})) {
 1529:                 $role_selector .= "\n".'<option value="'.$role.'">'.&Apache::lonnet::plaintext($role).'</option>'; 
 1530:             }
 1531:         }
 1532:         foreach my $role (sort(keys(%courseroles))) {
 1533:             if ($role =~ /^cr/) {
 1534:                 $role_selector .= "\n".'<option value="'.$role.'">'.&Apache::lonnet::plaintext($role).'</option>'; 
 1535:             }
 1536:         }
 1537:         $role_selector .= '</select>'."\n".
 1538:                '<input type="hidden" name="destinationurl" value="'.
 1539:                $ENV{'REQUEST_URI'}.'" />'."\n".
 1540:                '<input type="hidden" name="gotorole" value="1" />'."\n".
 1541:                '<input type="hidden" name="selectrole" value="" />'."\n".
 1542:                '<input type="hidden" name="switch" value="1" />'."\n".
 1543:                '</form>';
 1544:     }
 1545:     return $role_selector;
 1546: }
 1547: 
 1548: sub jump_to_role {
 1549:     my ($cdom,$cnum,$seccount,$courseroles) = @_;
 1550:     my %lt = &Apache::lonlocal::texthash(
 1551:                 this => 'This role has section(s) associated with it.',
 1552:                 ente => 'Enter a specific section.',
 1553:                 orlb => 'Enter a specific section, or leave blank for no section.',
 1554:                 avai => 'Available sections are:',
 1555:                 youe => 'You entered an invalid section choice:',
 1556:                 plst => 'Please try again',
 1557:     );
 1558:     my $js;
 1559:     if (ref($courseroles) eq 'HASH') {
 1560:         $js = '    var secpick = new Array("'.$lt{'ente'}.'","'.$lt{'orlb'}.'");'."\n". 
 1561:               '    var numsec = new Array();'."\n".
 1562:               '    var rolesections = new Array();'."\n".
 1563:               '    var rolenames = new Array();'."\n".
 1564:               '    var roleseclist = new Array();'."\n";
 1565:         my @items = keys(%{$courseroles});
 1566:         for (my $i=0; $i<@items; $i++) {
 1567:             $js .= '    rolenames['.$i.'] = "'.$items[$i].'";'."\n";
 1568:             my ($secs,$secstr);
 1569:             if (ref($courseroles->{$items[$i]}) eq 'ARRAY') {
 1570:                 my @sections = sort { $a <=> $b } @{$courseroles->{$items[$i]}};
 1571:                 $secs = join('","',@sections);
 1572:                 $secstr = join(', ',@sections);
 1573:             }
 1574:             $js .= '    rolesections['.$i.'] = new Array("'.$secs.'");'."\n".
 1575:                    '    roleseclist['.$i.'] = "'.$secstr.'";'."\n".
 1576:                    '    numsec['.$i.'] = "'.$seccount->{$items[$i]}.'";'."\n";
 1577:         }
 1578:     }
 1579:     my $output = <<"END";
 1580: <script type="text/javascript">
 1581: function adhocRole(roleitem) {
 1582:     $js
 1583:     var newrole =  document.rolechooser.elements[roleitem].options[document.rolechooser.elements[roleitem].selectedIndex].value;
 1584:     if (newrole == '') {
 1585:         return; 
 1586:     } 
 1587:     var fullrole = newrole+'./$cdom/$cnum';
 1588:     var selidx = '';
 1589:     for (var i=0; i<rolenames.length; i++) {
 1590:         if (rolenames[i] == newrole) {
 1591:             selidx = i;
 1592:         }
 1593:     }
 1594:     var secok = 1;
 1595:     var secchoice = '';
 1596:     if (selidx >= 0) {
 1597:         if (numsec[selidx] > 1) {
 1598:             secok = 0;
 1599:             var numrolesec = rolesections[selidx].length;
 1600:             var msgidx = numsec[selidx] - numrolesec;
 1601:             secchoice = prompt("$lt{'this'}\\n"+secpick[msgidx]+"\\n$lt{'avai'} "+roleseclist[selidx],"");
 1602:             if (secchoice == '') {
 1603:                 if (msgidx > 0) {
 1604:                     secok = 1;
 1605:                 }
 1606:             } else {
 1607:                 for (var j=0; j<rolesections[selidx].length; j++) {
 1608:                     if (rolesections[selidx][j] == secchoice) {
 1609:                         secok = 1;
 1610:                     }
 1611:                 }
 1612:             }
 1613:         } else {
 1614:             if (rolesections[selidx].length == 1) {
 1615:                 secchoice = rolesections[selidx][0];
 1616:             }
 1617:         }
 1618:     }
 1619:     if (secok == 1) {
 1620:         if (secchoice != '') {
 1621:             fullrole += '/'+secchoice;
 1622:         }
 1623:     } else {
 1624:         document.rolechooser.elements[roleitem].selectedIndex = 0;
 1625:         if (secchoice != null) {
 1626:             alert("$lt{'youe'} \\""+secchoice+"\\".\\n $lt{'plst'}");
 1627:         }
 1628:         return;
 1629:     }
 1630:     if (fullrole == "$env{'request.role'}") {
 1631:         return;
 1632:     }
 1633:     itemid = retrieveIndex('gotorole');
 1634:     if (itemid != -1) {
 1635:         document.rolechooser.elements[itemid].name = fullrole;
 1636:     }
 1637:     document.rolechooser.elements[roleitem].options[document.rolechooser.elements[roleitem].selectedIndex].value = fullrole;
 1638:     document.rolechooser.selectrole.value = '1';
 1639:     document.rolechooser.submit();
 1640:     return;
 1641: }
 1642: 
 1643: function retrieveIndex(item) {
 1644:     for (var i=0;i<document.rolechooser.elements.length;i++) {
 1645:         if (document.rolechooser.elements[i].name == item) {
 1646:             return i;
 1647:         }
 1648:     }
 1649:     return -1;
 1650: }
 1651: 
 1652: 
 1653: </script>
 1654: END
 1655:     return $output;
 1656: }
 1657: 
 1658: 
 1659: # ================================================================ Main Program
 1660: 
 1661: BEGIN {
 1662:     if (! defined($readdesk)) {
 1663: 	{
 1664: 	    my $tabfile = $Apache::lonnet::perlvar{'lonTabDir'}.'/mydesk.tab';
 1665: 	    if ( CORE::open( my $config,"<$tabfile") ) {
 1666: 		while (my $configline=<$config>) {
 1667: 		    $configline=(split(/\#/,$configline))[0];
 1668: 		    $configline=~s/^\s+//;
 1669: 		    chomp($configline);
 1670:                     if ($configline=~/^cat\:/) {
 1671:                        my @entries=split(/\:/,$configline);
 1672:                        $category_positions{$entries[2]}=$entries[1];
 1673:                        $category_names{$entries[2]}=$entries[3];
 1674: 		    } elsif ($configline) {
 1675: 			push(@desklines,$configline);
 1676: 		    }
 1677: 		}
 1678: 		CORE::close($config);
 1679: 	    }
 1680: 	}
 1681: 	$readdesk='done';
 1682:     }
 1683: }
 1684: 
 1685: 1;
 1686: __END__
 1687: 
 1688: 
 1689: 
 1690: 
 1691: 
 1692: 
 1693: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>