File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.243: download - view: text, annotated - select for diffs
Thu Sep 11 21:05:19 2008 UTC (15 years, 8 months ago) by tempelho
Branches: MAIN
CVS tags: HEAD
loncommom.pm: Inserted the functions clean_symb() and get_annotations() from adannotations.pm
lonmenu.pm: Fixed the Bug 1736: Check whether a user already made an annotation for the resource. In a case of an annotation, the icon is replaced by an other icon. This does not work with the remote control and the display option "buttons and text".

    1: # The LearningOnline Network with CAPA
    2: # Routines to control the menu
    3: #
    4: # $Id: lonmenu.pm,v 1.243 2008/09/11 21:05:19 tempelho 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: 
  519: my $currentURL = &Apache::loncommon::get_symb();
  520: my ($symb_old,$symb_old_enc) = &Apache::loncommon::clean_symb($currentURL);
  521: my $annotation = &Apache::loncommon::get_annotation($symb_old,$symb_old_enc);
  522: $menuitems.="s&9&3&";
  523: if(length($annotation) > 0){
  524: 	$menuitems.="anot2.gif";
  525: }else{
  526: 	$menuitems.="anot.gif";
  527: }
  528: $menuitems.="&anno-[_1]&tations[_1]&annotate()&";
  529: $menuitems.="Make notes and annotations about this resource&&1\n";
  530: 
  531:             unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme)(\?|$)/) {
  532: 		if (!$env{'request.enc'}) {
  533: 		    $menuitems.=(<<ENDREALRES);
  534: s&6&3&catalog.gif&catalog[_1]&info[_1]&catalog_info()&Show catalog information
  535: ENDREALRES
  536:                 }
  537: 	        $menuitems.=(<<ENDREALRES);
  538: s&8&1&eval.gif&evaluate[_1]&this[_1]&gopost('/adm/evaluate',currentURL,1)&Provide my evaluation of this resource
  539: 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
  540: ENDREALRES
  541: 	    }
  542:         }
  543: 	if ($env{'request.uri'} =~ /^\/res/) {
  544: 	    $menuitems .= (<<ENDMENUITEMS);
  545: s&8&3&prt.gif&prepare[_1]&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
  546: ENDMENUITEMS
  547: 	}
  548:         my $buttons='';
  549:         foreach (split(/\n/,$menuitems)) {
  550: 	    my ($command,@rest)=split(/\&/,$_);
  551:             my $idx=10*$rest[0]+$rest[1];
  552:             if (&hidden_button_check() eq 'yes') {
  553:                 if ($idx == 21 ||$idx == 23) {
  554:                     $buttons.=&switch('','',@rest);
  555:                 } else {
  556:                     $buttons.=&clear(@rest);
  557:                 }
  558:             } else {  
  559:                 if ($command eq 's') {
  560: 	            $buttons.=&switch('','',@rest);
  561:                 } else {
  562:                     $buttons.=&clear(@rest);
  563:                 }
  564:             }
  565:         }
  566: 
  567:         if ($textual) {
  568: 	    my $addremote=0;
  569: 	    foreach (@inlineremote) { if ($_ ne '') { $addremote=1; } }
  570: 	    my $inlinebuttons='';
  571: 	    if ($addremote) {
  572: # Registered, textual output
  573: 		if ($env{'browser.interface'} eq 'textual') {
  574: 		    $inlinebuttons=
  575:                         join('',map { (defined($_)?$_:'') } @inlineremote);
  576: 		} else {
  577:                     if ($env{'environment.icons'} eq 'iconsonly') {
  578:                         $inlinebuttons=(<<ENDARROWSINLINE);
  579: <tr><td>
  580: $inlineremote[21] $inlineremote[23]
  581: ENDARROWSINLINE
  582:                         if (&hidden_button_check() ne 'yes') {
  583:                             $inlinebuttons .= (<<ENDINLINEICONS);
  584: $inlineremote[61] $inlineremote[63]
  585: $inlineremote[71] $inlineremote[72] $inlineremote[73]
  586: $inlineremote[81] $inlineremote[82] $inlineremote[83]
  587: $inlineremote[91] $inlineremote[92] $inlineremote[93]</td></tr>
  588: ENDINLINEICONS
  589:                         }
  590:                     } else {
  591: 			if ($inlineremote[21] ne '' || $inlineremote[23] ne '') {
  592: 			    $inlinebuttons=(<<ENDFIRSTLINE);
  593: <tr><td>$inlineremote[21]</td><td>&nbsp;</td><td>$inlineremote[23]</td></tr>
  594: ENDFIRSTLINE
  595:                         }
  596:                         if (&hidden_button_check() ne 'yes') { 
  597: 			    foreach my $row (6..9) {
  598: 				if ($inlineremote[${row}.'1'] ne ''
  599: 				    || $inlineremote[$row.'2'] ne ''
  600: 				    || $inlineremote[$row.'3'] ne '') {
  601: 				    $inlinebuttons .= <<"ENDLINE";
  602: <tr><td>$inlineremote["${row}1"]</td><td>$inlineremote["${row}2"]</td><td>$inlineremote["${row}3"]</td></tr>
  603: ENDLINE
  604: 				}
  605: 			    }
  606: 			}
  607: 		    }
  608: 		}
  609: 	    }
  610: 	    $result =(<<ENDREGTEXT);
  611: <script type="text/javascript">
  612: // BEGIN LON-CAPA Internal
  613: </script>
  614: $timesync
  615: $tablestart
  616: $inlinebuttons
  617: $tableend
  618: $newmail
  619: <script type="text/javascript">
  620: // END LON-CAPA Internal
  621: </script>
  622: 
  623: ENDREGTEXT
  624: # Registered, graphical output
  625:         } else {
  626: 	    my $requri=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
  627: 	    $requri=&Apache::lonenc::check_encrypt(&unescape($requri));
  628: 	    my $cursymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
  629: 	    my $navstatus=&get_nav_status();
  630: 	    my $clearcstr;
  631: 
  632: 	    if ($env{'user.adv'}) { $clearcstr='clearbut(6,1)'; }
  633: 	    $result = (<<ENDREGTHIS);
  634:      
  635: <script type="text/javascript">
  636: // BEGIN LON-CAPA Internal
  637: var swmenu=null;
  638: 
  639:     function LONCAPAreg() {
  640: 	  swmenu=$reopen;
  641:           swmenu.clearTimeout(swmenu.menucltim);
  642:           $timesync
  643:           $newmail
  644:           $buttons
  645: 	  swmenu.currentURL="$requri";
  646:           swmenu.reloadURL=swmenu.currentURL+window.location.search;
  647:           swmenu.currentSymb="$cursymb";
  648:           swmenu.reloadSymb="$cursymb";
  649:           swmenu.currentStale=0;
  650: 	  $navstatus
  651:           $hwkadd
  652:           $editbutton
  653:     }
  654: 
  655:     function LONCAPAstale() {
  656: 	  swmenu=$reopen
  657:           swmenu.currentStale=1;
  658:           if (swmenu.reloadURL!='' && swmenu.reloadURL!= null) { 
  659:              swmenu.switchbutton
  660:              (3,1,'reload.gif','return','location','go(reloadURL)','Return to the last known location in the course sequence');
  661: 	  }
  662:           swmenu.clearbut(7,2);
  663:           swmenu.clearbut(7,3);
  664:           swmenu.menucltim=swmenu.setTimeout(
  665:  'clearbut(2,1);clearbut(2,3);clearbut(8,1);clearbut(8,2);clearbut(8,3);'+
  666:  'clearbut(9,1);clearbut(9,3);clearbut(6,3);$clearcstr',
  667: 			  2000);
  668:       }
  669: 
  670: // END LON-CAPA Internal 
  671: </script>
  672: ENDREGTHIS
  673:         }
  674: # =============================================================================
  675:     } else {
  676: # ========================================== This can or will not be registered
  677:         if ($textual) {
  678: # Not registered, textual
  679: 	    $result= (<<ENDDONOTREGTEXT);
  680: ENDDONOTREGTEXT
  681:         } else {
  682: # Not registered, graphical
  683:            $result = (<<ENDDONOTREGTHIS);
  684: 
  685: <script type="text/javascript">
  686: // BEGIN LON-CAPA Internal
  687: var swmenu=null;
  688: 
  689:     function LONCAPAreg() {
  690: 	  swmenu=$reopen
  691:           $timesync
  692:           swmenu.currentStale=1;
  693:           swmenu.clearbut(2,1);
  694:           swmenu.clearbut(2,3);
  695:           swmenu.clearbut(8,1);
  696:           swmenu.clearbut(8,2);
  697:           swmenu.clearbut(8,3);
  698:           if (swmenu.currentURL) {
  699:              swmenu.switchbutton
  700:               (3,1,'reload.gif','return','location','go(currentURL)');
  701:  	  } else {
  702: 	      swmenu.clearbut(3,1);
  703:           }
  704:     }
  705: 
  706:     function LONCAPAstale() {
  707:     }
  708: 
  709: // END LON-CAPA Internal
  710: </script>
  711: ENDDONOTREGTHIS
  712:        }
  713: # =============================================================================
  714:     }
  715:     return $result;
  716: }
  717: 
  718: sub loadevents() {
  719:     if ($env{'request.state'} eq 'construct' ||
  720: 	$env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
  721:     return 'LONCAPAreg();';
  722: }
  723: 
  724: sub unloadevents() {
  725:     if ($env{'request.state'} eq 'construct' ||
  726: 	$env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
  727:     return 'LONCAPAstale();';
  728: }
  729: 
  730: # ============================================================= Start up remote
  731: 
  732: sub startupremote {
  733:     my ($lowerurl)=@_;
  734:     if (($env{'browser.interface'} eq 'textual') ||
  735:         ($env{'environment.remote'} eq 'off')) {
  736:      return ('<meta HTTP-EQUIV="Refresh" CONTENT="0.5; url='.$lowerurl.'" />');
  737:     }
  738: #
  739: # The Remote actually gets launched!
  740: #
  741:     my $configmenu=&rawconfig();
  742:     my $esclowerurl=&escape($lowerurl);
  743:     my $message=&mt('"Waiting for Remote Control window to load: "+[_1]','waited');
  744:     return(<<ENDREMOTESTARTUP);
  745: <script type="text/javascript">
  746: var timestart;
  747: function wheelswitch() {
  748:     if (typeof(document.wheel) != 'undefined') {
  749: 	if (typeof(document.wheel.spin) != 'undefined') {
  750: 	    var date=new Date();
  751: 	    var waited=Math.round(30-((date.getTime()-timestart)/1000));
  752: 	    document.wheel.spin.value=$message;
  753: 	}
  754:     }
  755:    if (window.status=='|') { 
  756:       window.status='/'; 
  757:    } else {
  758:       if (window.status=='/') {
  759:          window.status='-';
  760:       } else {
  761:          if (window.status=='-') { 
  762:             window.status='\\\\'; 
  763:          } else {
  764:             if (window.status=='\\\\') { window.status='|'; }
  765:          }
  766:       }
  767:    } 
  768: }
  769: 
  770: // ---------------------------------------------------------- The wait function
  771: var canceltim;
  772: function wait() {
  773:    if ((menuloaded==1) || (tim==1)) {
  774:       window.status='Done.';
  775:       if (tim==0) {
  776:          clearTimeout(canceltim);
  777:          $configmenu
  778:          window.location='$lowerurl';  
  779:       } else {
  780: 	  window.location='/adm/remote?action=collapse&url=$esclowerurl';
  781:       }
  782:    } else {
  783:       wheelswitch();
  784:       setTimeout('wait();',200);
  785:    }
  786: }
  787: 
  788: function main() {
  789:    canceltim=setTimeout('tim=1;',30000);
  790:    window.status='-';
  791:    var date=new Date();
  792:    timestart=date.getTime();
  793:    wait();
  794: }
  795: 
  796: </script>
  797: ENDREMOTESTARTUP
  798: }
  799: 
  800: sub setflags() {
  801:     return(<<ENDSETFLAGS);
  802: <script type="text/javascript">
  803:     menuloaded=0;
  804:     tim=0;
  805: </script>
  806: ENDSETFLAGS
  807: }
  808: 
  809: sub maincall() {
  810:     if (($env{'browser.interface'} eq 'textual') ||
  811:         ($env{'environment.remote'} eq 'off')) { return ''; }
  812:     return(<<ENDMAINCALL);
  813: <script type="text/javascript">
  814:     main();
  815: </script>
  816: ENDMAINCALL
  817: }
  818: 
  819: sub load_remote_msg {
  820:     my ($lowerurl)=@_;
  821: 
  822:     if (($env{'browser.interface'} eq 'textual') ||
  823:         ($env{'environment.remote'} eq 'off')) { return ''; }
  824: 
  825:     my $esclowerurl=&escape($lowerurl);
  826:     my $link=&mt('<a href="[_1]">Continue</a> on in Inline Menu mode',
  827: 		 "/adm/remote?action=collapse&amp;url=$esclowerurl");
  828:     return(<<ENDREMOTEFORM);
  829: <p>
  830: <form name="wheel">
  831: <input name="spin" type="text" size="60" />
  832: </form>
  833: </p>
  834: <p>$link</p>
  835: ENDREMOTEFORM
  836: }
  837: 
  838: sub get_menu_name {
  839:     my $hostid = $Apache::lonnet::perlvar{'lonHostID'};
  840:     $hostid =~ s/\W//g;
  841:     return 'LCmenu'.$hostid;
  842: }
  843: 
  844: # ================================================================= Reopen menu
  845: 
  846: sub reopenmenu {
  847:    if (($env{'browser.interface'} eq 'textual') ||
  848:        ($env{'environment.remote'} eq 'off')) { return ''; }
  849:    my $menuname = &get_menu_name();
  850:    my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
  851:    return('window.open('.$nothing.',"'.$menuname.'","",false);');
  852: } 
  853: 
  854: # =============================================================== Open the menu
  855: 
  856: sub open {
  857:     my $returnval='';
  858:     if (($env{'browser.interface'} eq 'textual') ||
  859:         ($env{'environment.remote'} eq 'off')) { 
  860: 	return '<script type="text/javascript">self.name="loncapaclient";</script>';
  861:     }
  862:     my $menuname = &get_menu_name();
  863:     
  864: #    unless (shift eq 'unix') {
  865: # resizing does not work on linux because of virtual desktop sizes
  866: #       $returnval.=(<<ENDRESIZE);
  867: #if (window.screen) {
  868: #    self.resizeTo(screen.availWidth-215,screen.availHeight-55);
  869: #    self.moveTo(190,15);
  870: #}
  871: #ENDRESIZE
  872: #    }
  873:     $returnval.=(<<ENDOPEN);
  874: window.status='Opening LON-CAPA Remote Control';
  875: var menu=window.open("/res/adm/pages/menu.html","$menuname",
  876: "height=375,width=150,scrollbars=no,menubar=no,top=5,left=5,screenX=5,screenY=5");
  877: self.name='loncapaclient';
  878: ENDOPEN
  879:     return '<script type="text/javascript">'.$returnval.'</script>';
  880: }
  881: 
  882: 
  883: # ================================================================== Raw Config
  884: 
  885: sub clear {
  886:     my ($row,$col)=@_;
  887:     unless (($env{'browser.interface'} eq 'textual') ||
  888:             ($env{'environment.remote'} eq 'off')) {
  889:        return "\n".qq(window.status+='.';swmenu.clearbut($row,$col););
  890:    } else { 
  891:        $inlineremote[10*$row+$col]='';
  892:        return ''; 
  893:    }
  894: }
  895: 
  896: # ============================================ Switch a button or create a link
  897: # Switch acts on the javascript that is executed when a button is clicked.  
  898: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
  899: 
  900: sub switch {
  901:     my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat,$nobreak)=@_;
  902:     $act=~s/\$uname/$uname/g;
  903:     $act=~s/\$udom/$udom/g;
  904:     $top=&mt($top);
  905:     $bot=&mt($bot);
  906:     $desc=&mt($desc);
  907:     if (($env{'environment.remote'} ne 'off') || ($env{'environment.icons'} eq 'classic')) {
  908:        $img=&mt($img);
  909:     }
  910:     my $idx=10*$row+$col;
  911:     $category_members{$cat}.=':'.$idx;
  912: 
  913:     unless (($env{'browser.interface'} eq 'textual')  ||
  914:             ($env{'environment.remote'} eq 'off')) {
  915: # Remote
  916:        return "\n".
  917:  qq(window.status+='.';swmenu.switchbutton($row,$col,"$img","$top","$bot","$act","$desc"););
  918:    } elsif ($env{'browser.interface'} eq 'textual') {
  919: # Accessibility
  920:        if ($nobreak==2) { return ''; }
  921:        my $text=$top.' '.$bot;
  922:        $text=~s/\s*\-\s*//gs;
  923:        if ($nobreak) {
  924: 	   $inlineremote[$idx]=
  925: 	       '<a href="javascript:'.$act.';">'.$text.'</a>';
  926:        } else {
  927: 	   $inlineremote[$idx]="\n<br />".
  928: 	       $desc.' <a href="javascript:'.$act.';">'.$text.'</a>';
  929:        }
  930:    } else {
  931: # Inline Remote
  932:        if ($env{'environment.icons'} ne 'classic') {
  933:           $img=~s/\.gif$/\.png/;
  934:        }
  935:        if ($nobreak==2) { return ''; }
  936:        my $text=$top.' '.$bot;
  937:        $text=~s/\s*\-\s*//gs;
  938: 
  939:        my $pic=
  940: 	   '<img alt="'.$text.'" src="'.
  941: 	   &Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$img).
  942: 	   '" align="'.($nobreak==3?'right':'left').'" />';
  943:        if ($env{'browser.interface'} eq 'faketextual') {
  944: # Accessibility
  945: 	   if ($nobreak==3) {
  946: 	       $inlineremote[$idx]="\n".
  947: 		   '<td class="LC_menubuttons_text" align="right">'.$text.
  948: 		   '</td><td class="LC_menubuttons_img" align="left">'.
  949: 		   '<a href="javascript:'.$act.';">'.$pic.'</a></td></tr>';
  950: 	   } elsif ($nobreak) {
  951: 	       $inlineremote[$idx]="\n<tr>".
  952: 		   '<td class="LC_menubuttons_img" align="left">'.
  953: 		   '<a href="javascript:'.$act.';">'.$pic.'</a></td>
  954:                     <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>';
  955: 	   } else {
  956: 	       $inlineremote[$idx]="\n<tr>".
  957: 		   '<td class="LC_menubuttons_img" align="left">'.
  958: 		   '<a href="javascript:'.$act.';">'.$pic.
  959: 		   '</a></td><td class="LC_menubuttons_text" colspan="3">'.
  960: 		   '<a class="LC_menubuttons_link" href="javascript:'.$act.';"><span class="LC_menubuttons_inline_text">'.$desc.'</span></a></td></tr>';
  961: 	   }
  962:        } else {
  963: # Inline Menu
  964:            if ($env{'environment.icons'} eq 'iconsonly') {
  965:               $inlineremote[$idx]='<a title="'.$desc.'" href="javascript:'.$act.';">'.$pic.'</a>';
  966:            } else {
  967: 	      $inlineremote[$idx]=
  968: 		   '<a class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.
  969: 		   '<span class="LC_menubuttons_inline_text">'.$desc.'</span></a>';
  970:            }
  971:        }
  972:    }
  973:     return '';
  974: }
  975: 
  976: sub secondlevel {
  977:     my $output='';
  978:     my 
  979:     ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat)=@_;
  980:     if ($prt eq 'any') {
  981: 	   $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
  982:     } elsif ($prt=~/^r(\w+)/) {
  983:         if ($rol eq $1) {
  984:            $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
  985:         }
  986:     }
  987:     return $output;
  988: }
  989: 
  990: sub openmenu {
  991:     my $menuname = &get_menu_name();
  992:     if (($env{'browser.interface'} eq 'textual') ||
  993:         ($env{'environment.remote'} eq 'off')) { return ''; }
  994:     my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
  995:     return "window.open(".$nothing.",'".$menuname."');";
  996: }
  997: 
  998: sub inlinemenu {
  999:     undef(@inlineremote);
 1000:     undef(%category_members);
 1001:     &rawconfig(1);
 1002:     my $output='<table id="LC_mainmenu"><tr>';
 1003:     for (my $col=1; $col<=2; $col++) {
 1004:         $output.='<td class="LC_mainmenu_col_fieldset">';
 1005:         for (my $row=1; $row<=8; $row++) {
 1006:             foreach my $cat (keys(%category_members)) {
 1007:                if ($category_positions{$cat} ne "$col,$row") { next; }
 1008:                #$output.='<table id="LC_menubuttons_mainmenu"><tr><td colspan="4" class="LC_menubuttons_category">'.&mt($category_names{$cat}).'</td></tr>';
 1009:                $output.='<fieldset id="LC_mainmenu_fieldset">';
 1010: 	       $output.='<legend class="LC_mainmenu_fieldset_category">'.&mt($category_names{$cat}).'</legend>';
 1011:                $output.='<table id="LC_menubuttons_mainmenu">';
 1012:                my %active=();
 1013:                foreach my $menu_item (split(/\:/,$category_members{$cat})) {
 1014:                   if ($inlineremote[$menu_item]) {
 1015:                      $active{$menu_item}=1;
 1016:                   }
 1017:                }  
 1018:                foreach my $item (sort(keys(%active))) {
 1019:                   $output.=$inlineremote[$item];
 1020: 		&Apache::lonnet::logthis("item=$item output=$inlineremote[$item]");
 1021:                }
 1022:                $output.='</table>';
 1023:                $output.='</fieldset>';
 1024:             }
 1025:          }
 1026:          $output.="</td>";
 1027:     }
 1028:     $output.="</tr></table>";
 1029:     return $output;
 1030: }
 1031: 
 1032: sub rawconfig {
 1033:     my $textualoverride=shift;
 1034:     my $output='';
 1035:     unless (($env{'browser.interface'} eq 'textual') ||
 1036:             ($env{'environment.remote'} eq 'off')) {
 1037:        $output.=
 1038:  "window.status='Opening Remote Control';var swmenu=".&openmenu().
 1039: "\nwindow.status='Configuring Remote Control ';";
 1040:     } else {
 1041:        unless ($textualoverride) { return ''; }
 1042:     }
 1043:     my $uname=$env{'user.name'};
 1044:     my $udom=$env{'user.domain'};
 1045:     my $adv=$env{'user.adv'};
 1046:     my $show_course=&show_course();
 1047:     my $author=$env{'user.author'};
 1048:     my $crs='';
 1049:     if ($env{'request.course.id'}) {
 1050:        $crs='/'.$env{'request.course.id'};
 1051:        if ($env{'request.course.sec'}) {
 1052: 	   $crs.='_'.$env{'request.course.sec'};
 1053:        }
 1054:        $crs=~s/\_/\//g;
 1055:     }
 1056:     my $pub=($env{'request.state'} eq 'published');
 1057:     my $con=($env{'request.state'} eq 'construct');
 1058:     my $rol=$env{'request.role'};
 1059:     my $requested_domain = $env{'request.role.domain'};
 1060:     foreach my $line (@desklines) {
 1061:         my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc,$cat)=split(/\:/,$line);
 1062:         $prt=~s/\$uname/$uname/g;
 1063:         $prt=~s/\$udom/$udom/g;
 1064:         $prt=~s/\$crs/$crs/g; 
 1065:         $prt=~s/\$requested_domain/$requested_domain/g;
 1066:         if ($category_names{$cat}!~/\w/) { $cat='oth'; }
 1067:         my $type = &Apache::loncommon::course_type();
 1068:         if ($type eq 'Group') {
 1069:             $desc = &convert_menu_function($desc,$type);
 1070:         }
 1071:         if ($pro eq 'clear') {
 1072: 	    $output.=&clear($row,$col);
 1073:         } elsif ($pro eq 'any') {
 1074:                $output.=&secondlevel(
 1075: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1076: 	} elsif ($pro eq 'smp') {
 1077:             unless ($adv) {
 1078:                $output.=&secondlevel(
 1079:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1080:             }
 1081:         } elsif ($pro eq 'adv') {
 1082:             if ($adv) {
 1083:                $output.=&secondlevel(
 1084: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1085:             }
 1086: 	} elsif ($pro eq 'shc') {
 1087:             if ($show_course) {
 1088:                $output.=&secondlevel(
 1089:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1090:             }
 1091:         } elsif ($pro eq 'nsc') {
 1092:             if (!$show_course) {
 1093:                $output.=&secondlevel(
 1094: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1095:             }
 1096:         } elsif (($pro=~/^p(\w+)/) && ($prt)) {
 1097: 	    if (&Apache::lonnet::allowed($1,$prt)) {
 1098:                $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1099:             }
 1100:         } elsif ($pro eq 'course') {
 1101:             if ($env{'request.course.fn'}) {
 1102:                $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1103: 	    }
 1104:         } elsif ($pro =~ /^courseenv_(.*)$/) {
 1105:             my $key = $1;
 1106:             if ($env{'course.'.$env{'request.course.id'}.'.'.$key}) {
 1107:                 $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1108:             }
 1109:         } elsif ($pro =~ /^course_(.*)$/) {
 1110:             # Check for permissions inside of a course
 1111:             if (($env{'request.course.id'}) &&
 1112:                 (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
 1113:             ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
 1114:                  )) {
 1115:                 $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1116: 	    }
 1117:         } elsif ($pro eq 'author') {
 1118:             if ($author) {
 1119:                 if ((($prt eq 'rca') && ($env{'request.role'}=~/^ca/)) ||
 1120:                     (($prt eq 'raa') && ($env{'request.role'}=~/^aa/)) || 
 1121:                     (($prt eq 'rau') && ($env{'request.role'}=~/^au/))) {
 1122:                     # Check that we are on the correct machine
 1123:                     my $cadom=$requested_domain;
 1124:                     my $caname=$env{'user.name'};
 1125:                     if (($prt eq 'rca') || ($prt eq 'raa')) {
 1126: 		       ($cadom,$caname)=
 1127:                                ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
 1128:                     }                       
 1129:                     $act =~ s/\$caname/$caname/g;
 1130:                     my $home = &Apache::lonnet::homeserver($caname,$cadom);
 1131: 		    my $allowed=0;
 1132: 		    my @ids=&Apache::lonnet::current_machine_ids();
 1133: 		    foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
 1134: 		    if ($allowed) {
 1135:                         $output.=&switch($caname,$cadom,
 1136:                                         $row,$col,$img,$top,$bot,$act,$desc,$cat);
 1137:                     }
 1138:                 }
 1139:             }
 1140:         }
 1141:     }
 1142:     unless (($env{'browser.interface'} eq 'textual') ||
 1143:             ($env{'environment.remote'} eq 'off')) {
 1144:        $output.="\nwindow.status='Synchronizing Time';swmenu.syncclock(1000*".time.");\nwindow.status='Remote Control Configured.';";
 1145:        if (&Apache::lonmsg::newmail()) { 
 1146: 	   $output.='swmenu.setstatus("you have","messages");';
 1147:        }
 1148:     }
 1149: 
 1150:     return $output;
 1151: }
 1152: 
 1153: # ======================================================================= Close
 1154: 
 1155: sub close {
 1156:     if (($env{'browser.interface'} eq 'textual') ||
 1157:         ($env{'environment.remote'} eq 'off')) { return ''; }
 1158:     my $menuname = &get_menu_name();
 1159:     return(<<ENDCLOSE);
 1160: <script type="text/javascript">
 1161: window.status='Accessing Remote Control';
 1162: menu=window.open("/adm/rat/empty.html","$menuname",
 1163:                  "height=350,width=150,scrollbars=no,menubar=no");
 1164: window.status='Disabling Remote Control';
 1165: menu.active=0;
 1166: menu.autologout=0;
 1167: window.status='Closing Remote Control';
 1168: menu.close();
 1169: window.status='Done.';
 1170: </script>
 1171: ENDCLOSE
 1172: }
 1173: 
 1174: # ====================================================================== Footer
 1175: 
 1176: sub footer {
 1177: 
 1178: }
 1179: 
 1180: sub nav_control_js {
 1181:     my $nav=($env{'environment.remotenavmap'} eq 'on');
 1182:     return (<<NAVCONTROL);
 1183:     var w_loncapanav_flag="$nav";
 1184: 
 1185: 
 1186: function gonav(url) {
 1187:    if (w_loncapanav_flag != 1) {
 1188:       gopost(url,'');
 1189:    }  else {
 1190:       navwindow=window.open(url,
 1191:                   "loncapanav","height=600,width=400,scrollbars=1"); 
 1192:    }
 1193: }
 1194: NAVCONTROL
 1195: }
 1196: 
 1197: sub utilityfunctions {
 1198:     my $caller = shift;
 1199:     unless (($env{'browser.interface'} eq 'textual')  ||
 1200:         ($env{'environment.remote'} eq 'off') || ($caller eq '/adm/menu')) { return ''; }
 1201:     my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
 1202:     $currenturl=&Apache::lonenc::check_encrypt(&unescape($currenturl));
 1203:     
 1204:     my $currentsymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
 1205:     my $nav_control=&nav_control_js();
 1206: 
 1207:     my $start_page_annotate = 
 1208:         &Apache::loncommon::start_page('Annotator',undef,
 1209: 				       {'only_body' => 1,
 1210: 					'js_ready'  => 1,
 1211: 					'bgcolor'   => '#BBBBBB',
 1212: 					'add_entries' => {
 1213: 					    'onload' => 'javascript:document.goannotate.submit();'}});
 1214: 
 1215:     my $end_page_annotate = 
 1216:         &Apache::loncommon::end_page({'js_ready' => 1});
 1217: 
 1218:     my $start_page_bookmark = 
 1219:         &Apache::loncommon::start_page('Bookmarks',undef,
 1220: 				       {'only_body' => 1,
 1221: 					'js_ready'  => 1,
 1222: 					'bgcolor'   => '#BBBBBB',});
 1223: 
 1224:     my $end_page_bookmark = 
 1225:         &Apache::loncommon::end_page({'js_ready' => 1});
 1226: 
 1227: return (<<ENDUTILITY)
 1228: 
 1229:     var currentURL="$currenturl";
 1230:     var reloadURL="$currenturl";
 1231:     var currentSymb="$currentsymb";
 1232: 
 1233: $nav_control
 1234: 
 1235: function go(url) {
 1236:    if (url!='' && url!= null) {
 1237:        currentURL = null;
 1238:        currentSymb= null;
 1239:        window.location.href=url;
 1240:    }
 1241: }
 1242: 
 1243: function gopost(url,postdata) {
 1244:    if (url!='') {
 1245:       this.document.server.action=url;
 1246:       this.document.server.postdata.value=postdata;
 1247:       this.document.server.command.value='';
 1248:       this.document.server.url.value='';
 1249:       this.document.server.symb.value='';
 1250:       this.document.server.submit();
 1251:    }
 1252: }
 1253: 
 1254: function gocmd(url,cmd) {
 1255:    if (url!='') {
 1256:       this.document.server.action=url;
 1257:       this.document.server.postdata.value='';
 1258:       this.document.server.command.value=cmd;
 1259:       this.document.server.url.value=currentURL;
 1260:       this.document.server.symb.value=currentSymb;
 1261:       this.document.server.submit();
 1262:    }
 1263: }
 1264: 
 1265: function gocstr(url,filename) {
 1266:     if (url == '/adm/cfile?action=delete') {
 1267:         this.document.cstrdelete.filename.value = filename
 1268:         this.document.cstrdelete.submit();
 1269:         return;
 1270:     }
 1271:     if (url == '/adm/printout') {
 1272:         this.document.cstrprint.postdata.value = filename
 1273:         this.document.cstrprint.curseed.value = 0;
 1274:         this.document.cstrprint.problemtype.value = 0;
 1275:         if (this.document.lonhomework) {
 1276:             if ((this.document.lonhomework.rndseed) && (this.document.lonhomework.rndseed.value != null) && (this.document.lonhomework.rndseed.value != '')) {
 1277:                 this.document.cstrprint.curseed.value = this.document.lonhomework.rndseed.value
 1278:             }
 1279:             if (this.document.lonhomework.problemtype) {
 1280: 		if (this.document.lonhomework.problemtype.value) {
 1281: 		    this.document.cstrprint.problemtype.value = 
 1282: 			this.document.lonhomework.problemtype.value;
 1283: 		} else if (this.document.lonhomework.problemtype.options) {
 1284: 		    for (var i=0; i<this.document.lonhomework.problemtype.options.length; i++) {
 1285: 			if (this.document.lonhomework.problemtype.options[i].selected) {
 1286: 			    if (this.document.lonhomework.problemtype.options[i].value != null && this.document.lonhomework.problemtype.options[i].value != '') { 
 1287: 				this.document.cstrprint.problemtype.value = this.document.lonhomework.problemtype.options[i].value
 1288: 				}
 1289: 			}
 1290: 		    }
 1291: 		}
 1292: 	    }
 1293: 	}
 1294:         this.document.cstrprint.submit();
 1295:         return;
 1296:     }
 1297:     if (url !='') {
 1298:         this.document.constspace.filename.value = filename;
 1299:         this.document.constspace.action = url;
 1300:         this.document.constspace.submit();
 1301:     }
 1302: }
 1303: 
 1304: function golist(url) {
 1305:    if (url!='' && url!= null) {
 1306:        currentURL = null;
 1307:        currentSymb= null;
 1308:        top.location.href=url;
 1309:    }
 1310: }
 1311: 
 1312: 
 1313: 
 1314: function catalog_info() {
 1315:    loncatinfo=window.open(window.location.pathname+'.meta',"LONcatInfo",'height=320,width=280,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
 1316: }
 1317: 
 1318: function chat_win() {
 1319:    lonchat=window.open('/res/adm/pages/chatroom.html',"LONchat",'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
 1320: }
 1321: 
 1322: function group_chat(group) {
 1323:    var url = '/adm/groupchat?group='+group;
 1324:    var winName = 'LONchat_'+group;
 1325:    grpchat=window.open(url,winName,'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
 1326: }
 1327: 
 1328: function edit_bookmarks() {
 1329:    go('');
 1330:    w_BookmarkPal_flag=1;
 1331:    bookmarkpal=window.open("/adm/bookmarks",
 1332:                "BookmarkPal", "width=400,height=505,scrollbars=0");
 1333: }
 1334: 
 1335: function annotate() {
 1336:    w_Annotator_flag=1;
 1337:    annotator=window.open('','Annotator','width=365,height=265,scrollbars=0');
 1338:    annotator.document.write(
 1339:    '$start_page_annotate'
 1340:   +"<form name='goannotate' target='Annotator' method='post' "
 1341:   +"action='/adm/annotations'>"
 1342:   +"<input type='hidden' name='symbnew' value='"+currentSymb+"' />"
 1343:   +"<\\/form>"
 1344:   +'$end_page_annotate');
 1345:    annotator.document.close();
 1346: }
 1347: 
 1348: function set_bookmark() {
 1349:    go('');
 1350:    clienttitle=document.title;
 1351:    clienthref=location.pathname;
 1352:    w_bmquery_flag=1;
 1353:    bmquery=window.open('','bmquery','width=365,height=165,scrollbars=0');
 1354:    bmquery.document.write(
 1355:    '$start_page_bookmark'
 1356:    +"<center><form method='post'"
 1357:    +" name='newlink' action='/adm/bookmarks' target='bmquery' "
 1358:    +">\\n <table width=340 height=150 "
 1359:    +"bgcolor='ffffff' align=center><tr><td>Link Name:<br /><input "
 1360:    +"type='text' name='title' size=45 value='"+clienttitle+"' />"
 1361:    +"<br />Address:<br /><input type='text' name='address' size='45' "
 1362:    +"value='"+clienthref+"' /><br /><center><input type='submit' "
 1363:    +"value='Save' /> <input type='button' value='Close (no save)' "
 1364:    +"onclick='javascript:window.close();' /><\\/center><\\/td>"
 1365:    +"<\\/tr><\\/table><\\/form><\\/center>"
 1366:    +'$end_page_bookmark' );
 1367:    bmquery.document.close();
 1368: }
 1369: 
 1370: ENDUTILITY
 1371: }
 1372: 
 1373: sub serverform {
 1374:     return(<<ENDSERVERFORM);
 1375: <form name="server" action="/adm/logout" method="post" target="_top">
 1376: <input type="hidden" name="postdata" value="none" />
 1377: <input type="hidden" name="command" value="none" />
 1378: <input type="hidden" name="url" value="none" />
 1379: <input type="hidden" name="symb" value="none" />
 1380: </form>
 1381: ENDSERVERFORM
 1382: }
 1383: 
 1384: sub constspaceform {
 1385:     return(<<ENDCONSTSPACEFORM);
 1386: <form name="constspace" action="/adm/logout" method="post" target="_top">
 1387: <input type="hidden" name="filename" value="" />
 1388: </form>
 1389: <form name="cstrdelete" action="/adm/cfile" method="post" target="_top">
 1390: <input type="hidden" name="action" value="delete" /> 
 1391: <input type="hidden" name="filename" value="" />
 1392: </form>
 1393: <form name="cstrprint" action="/adm/printout" target="_parent" method="post">
 1394: <input type="hidden" name="postdata" value="" />
 1395: <input type="hidden" name="curseed" value="" />
 1396: <input type="hidden" name="problemtype" value="" />
 1397: </form>
 1398: 
 1399: ENDCONSTSPACEFORM
 1400: }
 1401: 
 1402: 
 1403: sub get_nav_status {
 1404:     my $navstatus="swmenu.w_loncapanav_flag=";
 1405:     if ($env{'environment.remotenavmap'} eq 'on') {
 1406: 	$navstatus.="1";
 1407:     } else {
 1408: 	$navstatus.="-1";
 1409:     }
 1410:     return $navstatus;
 1411: }
 1412: 
 1413: #FIXME this needs to move into mydesktab and the other locations 
 1414: # the text is generated
 1415: sub convert_menu_function {
 1416:     my ($rolename,$type) = @_;
 1417:     if ($type eq 'Group') {
 1418:         $rolename =~ s/student/member/g;
 1419:         $rolename =~ s/group/team/g;
 1420:         $rolename =~ s/course/group/g;
 1421:         $rolename =~ s/Course/Group/g;
 1422:     }
 1423:     return $rolename;
 1424: }
 1425: 
 1426: sub hidden_button_check {
 1427:     my $hidden;
 1428:     if ($env{'request.course.id'} eq '') {
 1429:         return;
 1430:     }
 1431:     if ($env{'request.role.adv'}) {
 1432:         return;
 1433:     }
 1434:     my $buttonshide = &Apache::lonnet::EXT('resource.0.buttonshide');
 1435:     return $buttonshide; 
 1436: }
 1437: 
 1438: sub roles_selector {
 1439:     my ($cdom,$cnum) = @_;
 1440:     my $now = time;
 1441:     my (%courseroles,%seccount,%gotnosection);
 1442:     my $is_cc;
 1443:     my $role_selector;
 1444:     if ($env{'user.role.cc./'.$cdom.'/'.$cnum}) {
 1445:         my ($start,$end) = split(/\./,$env{'user.role.cc./'.$cdom.'/'.$cnum});
 1446:         
 1447:         if ((($start) && ($start<0)) || 
 1448:             (($end) && ($end<$now))  ||
 1449:             (($start) && ($now<$start))) {
 1450:             $is_cc = 0;
 1451:         } else {
 1452:             $is_cc = 1;
 1453:         }
 1454:     }
 1455:     if ($is_cc) {
 1456:         my %adv_roles =
 1457:              &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
 1458:         foreach my $role (keys(%adv_roles)) {
 1459:             my ($urole,$usec) = split(/:/,$role);
 1460:             if (!$gotnosection{$urole}) {
 1461:                 $seccount{$urole} ++;
 1462:                 $gotnosection{$urole} = 1;
 1463:             }
 1464:             if (ref($courseroles{$urole}) eq 'ARRAY') {
 1465:                 if ($usec ne '') {
 1466:                     if (!grep(/^Q$usec\E$/,@{$courseroles{$urole}})) {
 1467:                         push(@{$courseroles{$urole}},$usec);
 1468:                         $seccount{$urole} ++;
 1469:                     }
 1470:                 }
 1471:             } else {
 1472:                 @{$courseroles{$urole}} = ();
 1473:                 if ($usec ne '') {
 1474:                     $seccount{$urole} ++;
 1475:                     push(@{$courseroles{$urole}},$usec);
 1476:                 }
 1477:             }
 1478:         }
 1479:         my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
 1480:         @{$courseroles{'st'}} = ();
 1481:         if (keys(%sections_count) > 0) {
 1482:             push(@{$courseroles{'st'}},keys(%sections_count));
 1483:         }
 1484:     } else {
 1485:         foreach my $item (keys(%env)) {
 1486:             if ($item =~ m-^user\.role\.([^.]+)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
 1487:                 my $role = $1;
 1488:                 my $sec = $2;
 1489:                 next if ($role eq 'gr');
 1490:                 my ($start,$end) = split(/\./,$env{$item});
 1491:                 next if (($start && $start > $now) || ($end && $end < $now));
 1492:                 if ($sec eq '') {
 1493:                     if (!$gotnosection{$role}) {
 1494:                         $seccount{$role} ++;
 1495:                         $gotnosection{$role} = 1;
 1496:                     }
 1497:                 }
 1498:                 if (ref($courseroles{$role}) eq 'ARRAY') {
 1499:                     if ($sec ne '') {
 1500:                         if (!grep(/^Q$sec\E$/,@{$courseroles{$role}})) {
 1501:                             push(@{$courseroles{$role}},$sec);
 1502:                             $seccount{$role} ++;
 1503:                         }
 1504:                     }
 1505:                 } else {
 1506:                     @{$courseroles{$role}} = ();
 1507:                     if ($sec ne '') {
 1508:                         $seccount{$role} ++;
 1509:                         push(@{$courseroles{$role}},$sec);
 1510:                     }
 1511:                 }
 1512:             }
 1513:         }
 1514:     }
 1515:     my @roles_order = ('cc','in','ta','ep','ad','st');
 1516:     if (keys(%courseroles) > 1) {
 1517:         $role_selector = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles);
 1518:         $role_selector .= '<form name="rolechooser" method="post" action="/adm/roles">
 1519:                           <select name="switchrole" onchange="javascript:adhocRole('."'switchrole'".')">';
 1520:         $role_selector .= '<option value="">'.&mt('Switch course role to...').'</option>';
 1521:         foreach my $role (@roles_order) {
 1522:             if (defined($courseroles{$role})) {
 1523:                 $role_selector .= "\n".'<option value="'.$role.'">'.&Apache::lonnet::plaintext($role).'</option>'; 
 1524:             }
 1525:         }
 1526:         foreach my $role (sort(keys(%courseroles))) {
 1527:             if ($role =~ /^cr/) {
 1528:                 $role_selector .= "\n".'<option value="'.$role.'">'.&Apache::lonnet::plaintext($role).'</option>'; 
 1529:             }
 1530:         }
 1531:         $role_selector .= '</select>'."\n".
 1532:                '<input type="hidden" name="destinationurl" value="'.
 1533:                $ENV{'REQUEST_URI'}.'" />'."\n".
 1534:                '<input type="hidden" name="gotorole" value="1" />'."\n".
 1535:                '<input type="hidden" name="selectrole" value="" />'."\n".
 1536:                '<input type="hidden" name="switch" value="1" />'."\n".
 1537:                '</form>';
 1538:     }
 1539:     return $role_selector;
 1540: }
 1541: 
 1542: sub jump_to_role {
 1543:     my ($cdom,$cnum,$seccount,$courseroles) = @_;
 1544:     my %lt = &Apache::lonlocal::texthash(
 1545:                 this => 'This role has section(s) associated with it.',
 1546:                 ente => 'Enter a specific section.',
 1547:                 orlb => 'Enter a specific section, or leave blank for no section.',
 1548:                 avai => 'Available sections are:',
 1549:                 youe => 'You entered an invalid section choice:',
 1550:                 plst => 'Please try again',
 1551:     );
 1552:     my $js;
 1553:     if (ref($courseroles) eq 'HASH') {
 1554:         $js = '    var secpick = new Array("'.$lt{'ente'}.'","'.$lt{'orlb'}.'");'."\n". 
 1555:               '    var numsec = new Array();'."\n".
 1556:               '    var rolesections = new Array();'."\n".
 1557:               '    var rolenames = new Array();'."\n".
 1558:               '    var roleseclist = new Array();'."\n";
 1559:         my @items = keys(%{$courseroles});
 1560:         for (my $i=0; $i<@items; $i++) {
 1561:             $js .= '    rolenames['.$i.'] = "'.$items[$i].'";'."\n";
 1562:             my ($secs,$secstr);
 1563:             if (ref($courseroles->{$items[$i]}) eq 'ARRAY') {
 1564:                 my @sections = sort { $a <=> $b } @{$courseroles->{$items[$i]}};
 1565:                 $secs = join('","',@sections);
 1566:                 $secstr = join(', ',@sections);
 1567:             }
 1568:             $js .= '    rolesections['.$i.'] = new Array("'.$secs.'");'."\n".
 1569:                    '    roleseclist['.$i.'] = "'.$secstr.'";'."\n".
 1570:                    '    numsec['.$i.'] = "'.$seccount->{$items[$i]}.'";'."\n";
 1571:         }
 1572:     }
 1573:     my $output = <<"END";
 1574: <script type="text/javascript">
 1575: function adhocRole(roleitem) {
 1576:     $js
 1577:     var newrole =  document.rolechooser.elements[roleitem].options[document.rolechooser.elements[roleitem].selectedIndex].value;
 1578:     if (newrole == '') {
 1579:         return; 
 1580:     } 
 1581:     var fullrole = newrole+'./$cdom/$cnum';
 1582:     var selidx = '';
 1583:     for (var i=0; i<rolenames.length; i++) {
 1584:         if (rolenames[i] == newrole) {
 1585:             selidx = i;
 1586:         }
 1587:     }
 1588:     var secok = 1;
 1589:     var secchoice = '';
 1590:     if (selidx >= 0) {
 1591:         if (numsec[selidx] > 1) {
 1592:             secok = 0;
 1593:             var numrolesec = rolesections[selidx].length;
 1594:             var msgidx = numsec[selidx] - numrolesec;
 1595:             secchoice = prompt("$lt{'this'}\\n"+secpick[msgidx]+"\\n$lt{'avai'} "+roleseclist[selidx],"");
 1596:             if (secchoice == '') {
 1597:                 if (msgidx > 0) {
 1598:                     secok = 1;
 1599:                 }
 1600:             } else {
 1601:                 for (var j=0; j<rolesections[selidx].length; j++) {
 1602:                     if (rolesections[selidx][j] == secchoice) {
 1603:                         secok = 1;
 1604:                     }
 1605:                 }
 1606:             }
 1607:         } else {
 1608:             if (rolesections[selidx].length == 1) {
 1609:                 secchoice = rolesections[selidx][0];
 1610:             }
 1611:         }
 1612:     }
 1613:     if (secok == 1) {
 1614:         if (secchoice != '') {
 1615:             fullrole += '/'+secchoice;
 1616:         }
 1617:     } else {
 1618:         document.rolechooser.elements[roleitem].selectedIndex = 0;
 1619:         if (secchoice != null) {
 1620:             alert("$lt{'youe'} \\""+secchoice+"\\".\\n $lt{'plst'}");
 1621:         }
 1622:         return;
 1623:     }
 1624:     if (fullrole == "$env{'request.role'}") {
 1625:         return;
 1626:     }
 1627:     itemid = retrieveIndex('gotorole');
 1628:     if (itemid != -1) {
 1629:         document.rolechooser.elements[itemid].name = fullrole;
 1630:     }
 1631:     document.rolechooser.elements[roleitem].options[document.rolechooser.elements[roleitem].selectedIndex].value = fullrole;
 1632:     document.rolechooser.selectrole.value = '1';
 1633:     document.rolechooser.submit();
 1634:     return;
 1635: }
 1636: 
 1637: function retrieveIndex(item) {
 1638:     for (var i=0;i<document.rolechooser.elements.length;i++) {
 1639:         if (document.rolechooser.elements[i].name == item) {
 1640:             return i;
 1641:         }
 1642:     }
 1643:     return -1;
 1644: }
 1645: 
 1646: 
 1647: </script>
 1648: END
 1649:     return $output;
 1650: }
 1651: 
 1652: 
 1653: # ================================================================ Main Program
 1654: 
 1655: BEGIN {
 1656:     if (! defined($readdesk)) {
 1657: 	{
 1658: 	    my $tabfile = $Apache::lonnet::perlvar{'lonTabDir'}.'/mydesk.tab';
 1659: 	    if ( CORE::open( my $config,"<$tabfile") ) {
 1660: 		while (my $configline=<$config>) {
 1661: 		    $configline=(split(/\#/,$configline))[0];
 1662: 		    $configline=~s/^\s+//;
 1663: 		    chomp($configline);
 1664:                     if ($configline=~/^cat\:/) {
 1665:                        my @entries=split(/\:/,$configline);
 1666:                        $category_positions{$entries[2]}=$entries[1];
 1667:                        $category_names{$entries[2]}=$entries[3];
 1668: 		    } elsif ($configline) {
 1669: 			push(@desklines,$configline);
 1670: 		    }
 1671: 		}
 1672: 		CORE::close($config);
 1673: 	    }
 1674: 	}
 1675: 	$readdesk='done';
 1676:     }
 1677: }
 1678: 
 1679: 1;
 1680: __END__
 1681: 
 1682: 
 1683: 
 1684: 
 1685: 
 1686: 
 1687: 

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