File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.257: download - view: text, annotated - select for diffs
Wed Apr 1 14:43:06 2009 UTC (15 years, 2 months ago) by hauer
Branches: MAIN
CVS tags: HEAD
Edited Exit, Logout, log in, log out in eng/ger for consistent wording.

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

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