File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.276: download - view: text, annotated - select for diffs
Tue Jul 21 14:36:08 2009 UTC (14 years, 10 months ago) by droeschl
Branches: MAIN
CVS tags: HEAD
- refactoring
- removed obsolete parameter $registration from sub menubuttons
- added translations

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

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