File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.267: download - view: text, annotated - select for diffs
Tue May 19 14:05:19 2009 UTC (15 years ago) by droeschl
Branches: MAIN
CVS tags: HEAD
Changes related to modification of LON-CAPA screen header.
- Added breadcrumbs
- Removed the LC_nav_location table (breadcrumbs now show the current location within a course and new mail is shown in the top menu)
- Removed code related to textual interface

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

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