File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.265: download - view: text, annotated - select for diffs
Sat May 16 18:06:41 2009 UTC (15 years ago) by tempelho
Branches: MAIN
CVS tags: HEAD
Making some changes in the default color schemes. Insert a "subbox" for comming up navigation and breadcrumbs using the second color sidebg.

    1: # The LearningOnline Network with CAPA
    2: # Routines to control the menu
    3: #
    4: # $Id: lonmenu.pm,v 1.265 2009/05/16 18:06:41 tempelho Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: #
   29: # There are two parameters controlling the action of this module:
   30: #
   31: # browser.interface - if this is 'textual', it overrides the second parameter
   32: # and goes to screen reader PDA mode
   33: #
   34: # environment.remote - if this is 'on', the routines controll the remote
   35: # control, otherwise they render the main window controls; ignored it
   36: # browser.interface is 'textual'
   37: #
   38: 
   39: =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: <ul 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: </ul>
  380: $form
  381: <script type="text/javascript">
  382: // END LON-CAPA Internal
  383: </script>
  384: $reg
  385: ENDINLINEMENU
  386:     } else {
  387: 	return '';
  388:     }
  389: }
  390: 
  391: sub show_return_link {
  392:     return (($env{'request.noversionuri'}=~m{^/(res|public)/} &&
  393: 	     $env{'request.symb'} eq '')
  394: 	    ||
  395: 	    ($env{'request.noversionuri'}=~ m{^/cgi-bin/printout.pl})
  396: 	    ||
  397: 	    (($env{'request.noversionuri'}=~/^\/adm\//) &&
  398: 	     ($env{'request.noversionuri'}!~/^\/adm\/wrapper\//) &&
  399: 	     ($env{'request.noversionuri'}!~
  400: 	      m[^/adm/.*/(smppg|bulletinboard|aboutme)($|\?)])
  401: 	     ));
  402: }
  403: 
  404: 
  405: sub registerurl {
  406:     my ($forcereg) = @_;
  407:     my $result = '';
  408:     if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
  409:     my $force_title='';
  410:     if ($env{'request.state'} eq 'construct') {
  411: 	$force_title=&Apache::lonxml::display_title();
  412:     }
  413:     if (($env{'browser.interface'} eq 'textual') ||
  414:         ($env{'environment.remote'} eq 'off') ||
  415:         ((($env{'request.publicaccess'}) || 
  416:          (!&Apache::lonnet::is_on_map(
  417: 	   &unescape($env{'request.noversionuri'})))) &&
  418:         (!$forcereg))) {
  419:  	return $result.
  420:           '<script type="text/javascript">function LONCAPAreg(){;} function LONCAPAstale(){}</script>'.$force_title;
  421:     }
  422: # Graphical display after login only
  423:     if ($env{'request.registered'} && !$forcereg) { return ''; }
  424:     $result.=&innerregister($forcereg);
  425:     return $result.$force_title;
  426: }
  427: 
  428: sub innerregister {
  429:     my ($forcereg, $titletable) = @_;
  430:     my $result = '';
  431:     my ($uname,$thisdisfn);
  432:     my $const_space = ($env{'request.state'} eq 'construct');
  433:     my $is_const_dir = 0;
  434: 
  435:     if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
  436: 
  437:     $env{'request.registered'} = 1;
  438: 
  439:     my $textinter=($env{'browser.interface'} eq 'textual');
  440:     my $noremote=($env{'environment.remote'} eq 'off');
  441:     
  442:     my $textual=($textinter || $noremote);
  443: 
  444:     undef(@inlineremote);
  445: 
  446:     my $reopen=&Apache::lonmenu::reopenmenu();
  447: 
  448:     my $newmail='';
  449:     if ($noremote) {
  450: 	$newmail='<table id="LC_nav_location"><tr>';
  451:     }
  452:     if (&Apache::lonmsg::newmail()) { 
  453: 	if ($textual) {
  454: 	    $newmail.= '<td class="LC_new_mail">
  455:                    <a href="/adm/communicate" target="_top">'.
  456: 		   &mt('You have new messages').'</a></td>';
  457: 	} else {
  458: 	    $newmail= 'swmenu.setstatus("you have","messages");';
  459: 	}
  460:     } 
  461:     if (($textual) 
  462: 	     && ($env{'request.symb'}) 
  463: 	     && ($env{'request.course.id'})) {
  464: 	$newmail.= '<td class="LC_current_location">';
  465: 	my ($mapurl,$rid,$resurl)=
  466: 	    &Apache::lonnet::decode_symb(&Apache::lonnet::symbread());
  467:         my $coursetitle=$env{'course.'.$env{'request.course.id'}.'.description'};
  468:         $newmail.=$coursetitle;
  469:         my $maptitle=&Apache::lonnet::gettitle($mapurl);
  470: 	my $restitle=&Apache::lonnet::gettitle(&Apache::lonnet::symbread());
  471:         if ($maptitle && ($maptitle ne 'default.sequence') && ($maptitle ne $coursetitle)) {
  472: 	    $newmail.=', '.$maptitle;
  473:         }
  474:         if ($restitle) {
  475: 	    $newmail.=': '.$restitle;
  476:         }
  477:         $newmail.='&nbsp;&nbsp;&nbsp;</td>';
  478:     }
  479:     if ($env{'request.state'} eq 'construct') {
  480:         $newmail = $titletable;
  481:     } else {
  482: 	if ($noremote) {
  483: 	    $newmail.='</tr></table>';
  484: 	}
  485:     }
  486:     my $timesync=($textual?'':'swmenu.syncclock(1000*'.time.');');
  487:     my $tablestart=($noremote?'<table id="LC_menubuttons">':'').
  488: 	($textinter?'<br /><a href="#content">'.&mt('Skip to Content').'</a><br />':'');
  489:     my $tableend=($noremote?'</table>':'').($textinter?'<a name="content" />':'');
  490: # =============================================================================
  491: # ============================ This is for URLs that actually can be registered
  492:     if (($env{'request.noversionuri'}!~m|^/(res/)*adm/|) || ($forcereg)) {
  493: # -- This applies to homework problems for users with grading privileges
  494: 	my $crs='/'.$env{'request.course.id'};
  495: 	if ($env{'request.course.sec'}) {
  496: 	    $crs.='_'.$env{'request.course.sec'};
  497: 	}
  498: 	$crs=~s/\_/\//g;
  499: 
  500:         my $hwkadd='';
  501:         if ($env{'request.symb'} ne '' &&
  502: 	    $env{'request.filename'}=~/\.(problem|exam|quiz|assess|survey|form|task)$/) {
  503: 	    if (&Apache::lonnet::allowed('mgr',$crs)) {
  504: 		$hwkadd.=&switch('','',7,2,'pgrd.gif','problem[_1]','grades[_4]',
  505:                        "gocmd('/adm/grades','gradingmenu')",
  506:                        'Modify user grades for this assessment resource');
  507:             } elsif (&Apache::lonnet::allowed('vgr',$crs)) {
  508: 		$hwkadd.=&switch('','',7,2,'subm.gif','view sub-[_1]','missions[_1]',
  509:                        "gocmd('/adm/grades','submission')",
  510: 		       'View user submissions for this assessment resource');
  511:             }
  512: 	}
  513: 	if ($env{'request.symb'} ne '' &&
  514: 	    &Apache::lonnet::allowed('opa',$crs)) {
  515: 	    $hwkadd.=&switch('','',7,3,'pparm.gif','problem[_2]','parms[_2]',
  516: 			     "gocmd('/adm/parmset','set')",
  517: 			     'Modify parameter settings for this resource');
  518: 	}
  519: # -- End Homework
  520:         ###
  521:         ### Determine whether or not to display the 'cstr' button for this
  522:         ### resource
  523:         ###
  524:         my $editbutton = '';
  525:         my $noeditbutton = 1;
  526:         my ($cnum,$cdom);
  527:         if ($env{'request.course.id'}) {
  528:             $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
  529:             $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
  530:         }
  531:         if ($env{'user.author'}) {
  532:             if ($env{'request.role'}=~/^(aa|ca|au)/) {
  533:                 # Set defaults for authors
  534:                 my ($top,$bottom) = ('con-','struct');
  535:                 my $action = "go('/priv/".$env{'user.name'}."');";
  536:                 my $cadom  = $env{'request.role.domain'};
  537:                 my $caname = $env{'user.name'};
  538:                 my $desc = "Enter my construction space";
  539:                 # Set defaults for co-authors
  540:                 if ($env{'request.role'} =~ /^ca/) { 
  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 co-author";
  545:                 } elsif ($env{'request.role'} =~ /^aa/) {
  546:                     ($cadom,$caname)=($env{'request.role'}=~/($match_domain)\/($match_username)$/);
  547:                     ($top,$bottom) = ('co con-','struct');
  548:                     $action = "go('/priv/".$caname."');";
  549:                     $desc = "Enter construction space as assistant co-author";
  550:                 }
  551:                 # Check that we are on the correct machine
  552:                 my $home = &Apache::lonnet::homeserver($caname,$cadom);
  553: 		my $allowed=0;
  554: 		my @ids=&Apache::lonnet::current_machine_ids();
  555: 		foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
  556: 		if (!$allowed) {
  557: 		    $editbutton=&switch('','',6,1,$top,,$bottom,$action,$desc);
  558:                     $noeditbutton = 0;
  559:                 }
  560:             }
  561:             ##
  562:             ## Determine if user can edit url.
  563:             ##
  564:             my $cfile='';
  565:             my $cfuname='';
  566:             my $cfudom='';
  567:             my $uploaded;
  568:             if ($env{'request.filename'}) {
  569:                 my $file=&Apache::lonnet::declutter($env{'request.filename'});
  570:                 if (defined($cnum) && defined($cdom)) {
  571:                     $uploaded = &is_course_upload($file,$cnum,$cdom);
  572:                 }
  573:                 if (!$uploaded) {
  574:                     $file=~s/^($match_domain)\/($match_username)/\/priv\/$2/;
  575:                     # Check that the user has permission to edit this resource
  576:                     ($cfuname,$cfudom)=&Apache::loncacc::constructaccess($file,$1);
  577:                     if (defined($cfudom)) {
  578: 		        my $home=&Apache::lonnet::homeserver($cfuname,$cfudom);
  579: 		        my $allowed=0;
  580: 		        my @ids=&Apache::lonnet::current_machine_ids();
  581: 		        foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
  582: 		        if ($allowed) {
  583:                             $cfile=$file;
  584:                         }
  585:                     }
  586:                 }
  587:             }
  588:             # Finally, turn the button on or off
  589:             if ($cfile && !$const_space) {
  590:                 $editbutton=&switch
  591:                     ('','',6,1,'pcstr.gif','edit[_1]','resource[_2]',
  592:                      "go('".$cfile."');","Edit this resource");
  593:                 $noeditbutton = 0;
  594:             } elsif ($editbutton eq '') {
  595:                 $editbutton=&clear(6,1);
  596:             }
  597:         }
  598:         if (($noeditbutton) && ($env{'request.filename'})) { 
  599:             if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
  600:                 my $file=&Apache::lonnet::declutter($env{'request.filename'});
  601:                 if (defined($cnum) && defined($cdom)) {
  602:                     if (&is_course_upload($file,$cnum,$cdom)) {
  603:                         my $cfile = &edit_course_upload($file,$cnum,$cdom);
  604:                         if ($cfile) {
  605:                             $editbutton=&switch
  606:                                         ('','',6,1,'pcstr.gif','edit[_1]',
  607:                                          'resource[_2]',"go('".$cfile."');",
  608:                                          'Edit this resource');
  609:                         }
  610:                     }
  611:                 }
  612:             }
  613:         }
  614:         ###
  615:         ###
  616: # Prepare the rest of the buttons
  617:         my $menuitems;
  618:         if ($const_space) {
  619: 	    my ($uname,$thisdisfn) =
  620: 		($env{'request.filename'}=~m|^/home/([^/]+)/public_html/(.*)|);
  621:             my $currdir = '/priv/'.$uname.'/'.$thisdisfn;
  622:             if ($currdir =~ m-/$-) {
  623:                 $is_const_dir = 1;
  624:             } else {
  625:                 $currdir =~ s#[^/]+$##;
  626: 		my $cleandisfn = &Apache::loncommon::escape_single($thisdisfn);
  627: 		my $esc_currdir = &Apache::loncommon::escape_single($currdir);
  628:                 $menuitems=(<<ENDMENUITEMS);
  629: s&6&1&list.gif&list[_1]&dir[_1]&golist('$esc_currdir')&List current directory
  630: s&6&2&rtrv.gif&retrieve[_1]&version[_1]&gocstr('/adm/retrieve','/~$uname/$cleandisfn')&Retrieve old version
  631: s&6&3&pub.gif&publish[_1]&resource[_3]&gocstr('/adm/publish','/~$uname/$cleandisfn')&Publish this resource
  632: s&7&1&del.gif&delete[_1]&resource[_2]&gocstr('/adm/cfile?action=delete','/~$uname/$cleandisfn')&Delete this resource
  633: s&7&2&prt.gif&prepare[_1]&printout[_1]&gocstr('/adm/printout','/~$uname/$cleandisfn')&Prepare a printable document
  634: ENDMENUITEMS
  635:             }
  636:         } elsif ( defined($env{'request.course.id'}) && 
  637: 		 $env{'request.symb'} ne '' ) {
  638: 	    $menuitems=(<<ENDMENUITEMS);
  639: c&3&1
  640: s&2&1&back.gif&backward[_1]&&gopost('/adm/flip','back:'+currentURL)&Go to the previous resource in the course sequence&&1
  641: s&2&3&forw.gif&forward[_1]&&gopost('/adm/flip','forward:'+currentURL)&Go to the next resource in the course sequence&&3
  642: c&6&3
  643: c&8&1
  644: c&8&2
  645: s&8&3&prt.gif&prepare[_1]&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
  646: s&9&1&sbkm.gif&set[_1]&bookmark[_2]&set_bookmark()&Set a bookmark for this resource&&1
  647: ENDMENUITEMS
  648: 
  649: my $currentURL = &Apache::loncommon::get_symb();
  650: my ($symb_old,$symb_old_enc) = &Apache::loncommon::clean_symb($currentURL);
  651: my $annotation = &Apache::loncommon::get_annotation($symb_old,$symb_old_enc);
  652: $menuitems.="s&9&3&";
  653: if(length($annotation) > 0){
  654: 	$menuitems.="anot2.gif";
  655: }else{
  656: 	$menuitems.="anot.gif";
  657: }
  658: $menuitems.="&anno-[_1]&tations[_1]&annotate()&";
  659: $menuitems.="Make notes and annotations about this resource&&1\n";
  660: 
  661:             unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme)(\?|$)/) {
  662: 		if (!$env{'request.enc'}) {
  663: 		    $menuitems.=(<<ENDREALRES);
  664: s&6&3&catalog.gif&catalog[_2]&info[_1]&catalog_info()&Show Metadata
  665: ENDREALRES
  666:                 }
  667: 	        $menuitems.=(<<ENDREALRES);
  668: s&8&1&eval.gif&evaluate[_1]&this[_1]&gopost('/adm/evaluate',currentURL,1)&Provide my evaluation of this resource
  669: 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
  670: ENDREALRES
  671: 	    }
  672:         }
  673: 	if ($env{'request.uri'} =~ /^\/res/) {
  674: 	    $menuitems .= (<<ENDMENUITEMS);
  675: s&8&3&prt.gif&prepare[_1]&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
  676: ENDMENUITEMS
  677: 	}
  678:         my $buttons='';
  679:         foreach (split(/\n/,$menuitems)) {
  680: 	    my ($command,@rest)=split(/\&/,$_);
  681:             my $idx=10*$rest[0]+$rest[1];
  682:             if (&hidden_button_check() eq 'yes') {
  683:                 if ($idx == 21 ||$idx == 23) {
  684:                     $buttons.=&switch('','',@rest);
  685:                 } else {
  686:                     $buttons.=&clear(@rest);
  687:                 }
  688:             } else {  
  689:                 if ($command eq 's') {
  690: 	            $buttons.=&switch('','',@rest);
  691:                 } else {
  692:                     $buttons.=&clear(@rest);
  693:                 }
  694:             }
  695:         }
  696: 
  697:         if ($textual) {
  698: 	    my $addremote=0;
  699: 	    foreach (@inlineremote) { if ($_ ne '') { $addremote=1; } }
  700: 	    my $inlinebuttons='';
  701: 	    if ($addremote) {
  702: # Registered, textual output
  703: 		if ($env{'browser.interface'} eq 'textual') {
  704: 		    $inlinebuttons=
  705:                         join('',map { (defined($_)?$_:'') } @inlineremote);
  706: 		} else {
  707:                     if ($env{'environment.icons'} eq 'iconsonly') {
  708:                         $inlinebuttons=(<<ENDARROWSINLINE);
  709: <tr><td>
  710: $inlineremote[21] $inlineremote[23]
  711: ENDARROWSINLINE
  712:                         if (&hidden_button_check() ne 'yes') {
  713:                             $inlinebuttons .= (<<ENDINLINEICONS);
  714: $inlineremote[61] $inlineremote[63]
  715: $inlineremote[71] $inlineremote[72] $inlineremote[73]
  716: $inlineremote[81] $inlineremote[82] $inlineremote[83]
  717: $inlineremote[91] $inlineremote[92] $inlineremote[93]</td></tr>
  718: ENDINLINEICONS
  719:                         }
  720:                     } else {
  721: 			if ($inlineremote[21] ne '' || $inlineremote[23] ne '') {
  722: 			    $inlinebuttons=(<<ENDFIRSTLINE);
  723: <tr><td>$inlineremote[21]</td><td>&nbsp;</td><td>$inlineremote[23]</td></tr>
  724: ENDFIRSTLINE
  725:                         }
  726:                         if (&hidden_button_check() ne 'yes') { 
  727: 			    foreach my $row (6..9) {
  728: 				if ($inlineremote[${row}.'1'] ne ''
  729: 				    || $inlineremote[$row.'2'] ne ''
  730: 				    || $inlineremote[$row.'3'] ne '') {
  731: 				    $inlinebuttons .= <<"ENDLINE";
  732: <tr><td>$inlineremote["${row}1"]</td><td>$inlineremote["${row}2"]</td><td>$inlineremote["${row}3"]</td></tr>
  733: ENDLINE
  734: 				}
  735: 			    }
  736: 			}
  737: 		    }
  738: 		}
  739: 	    }
  740: 	    $result =(<<ENDREGTEXT);
  741: <script type="text/javascript">
  742: // BEGIN LON-CAPA Internal
  743: </script>
  744: $timesync
  745: $tablestart
  746: $inlinebuttons
  747: $tableend
  748: $newmail
  749: <script type="text/javascript">
  750: // END LON-CAPA Internal
  751: </script>
  752: 
  753: ENDREGTEXT
  754: # Registered, graphical output
  755:         } else {
  756: 	    my $requri=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
  757: 	    $requri=&Apache::lonenc::check_encrypt(&unescape($requri));
  758: 	    my $cursymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
  759: 	    my $navstatus=&get_nav_status();
  760: 	    my $clearcstr;
  761: 
  762: 	    if ($env{'user.adv'}) { $clearcstr='clearbut(6,1)'; }
  763: 	    $result = (<<ENDREGTHIS);
  764:      
  765: <script type="text/javascript">
  766: // BEGIN LON-CAPA Internal
  767: var swmenu=null;
  768: 
  769:     function LONCAPAreg() {
  770: 	  swmenu=$reopen;
  771:           swmenu.clearTimeout(swmenu.menucltim);
  772:           $timesync
  773:           $newmail
  774:           $buttons
  775: 	  swmenu.currentURL="$requri";
  776:           swmenu.reloadURL=swmenu.currentURL+window.location.search;
  777:           swmenu.currentSymb="$cursymb";
  778:           swmenu.reloadSymb="$cursymb";
  779:           swmenu.currentStale=0;
  780: 	  $navstatus
  781:           $hwkadd
  782:           $editbutton
  783:     }
  784: 
  785:     function LONCAPAstale() {
  786: 	  swmenu=$reopen
  787:           swmenu.currentStale=1;
  788:           if (swmenu.reloadURL!='' && swmenu.reloadURL!= null) { 
  789:              swmenu.switchbutton
  790:              (3,1,'reload.gif','return','location','go(reloadURL)','Return to the last known location in the course sequence');
  791: 	  }
  792:           swmenu.clearbut(7,2);
  793:           swmenu.clearbut(7,3);
  794:           swmenu.menucltim=swmenu.setTimeout(
  795:  'clearbut(2,1);clearbut(2,3);clearbut(8,1);clearbut(8,2);clearbut(8,3);'+
  796:  'clearbut(9,1);clearbut(9,3);clearbut(6,3);$clearcstr',
  797: 			  2000);
  798:       }
  799: 
  800: // END LON-CAPA Internal 
  801: </script>
  802: ENDREGTHIS
  803:         }
  804: # =============================================================================
  805:     } else {
  806: # ========================================== This can or will not be registered
  807:         if ($textual) {
  808: # Not registered, textual
  809: 	    $result= (<<ENDDONOTREGTEXT);
  810: ENDDONOTREGTEXT
  811:         } else {
  812: # Not registered, graphical
  813:            $result = (<<ENDDONOTREGTHIS);
  814: 
  815: <script type="text/javascript">
  816: // BEGIN LON-CAPA Internal
  817: var swmenu=null;
  818: 
  819:     function LONCAPAreg() {
  820: 	  swmenu=$reopen
  821:           $timesync
  822:           swmenu.currentStale=1;
  823:           swmenu.clearbut(2,1);
  824:           swmenu.clearbut(2,3);
  825:           swmenu.clearbut(8,1);
  826:           swmenu.clearbut(8,2);
  827:           swmenu.clearbut(8,3);
  828:           if (swmenu.currentURL) {
  829:              swmenu.switchbutton
  830:               (3,1,'reload.gif','return','location','go(currentURL)');
  831:  	  } else {
  832: 	      swmenu.clearbut(3,1);
  833:           }
  834:     }
  835: 
  836:     function LONCAPAstale() {
  837:     }
  838: 
  839: // END LON-CAPA Internal
  840: </script>
  841: ENDDONOTREGTHIS
  842:        }
  843: # =============================================================================
  844:     }
  845:     return $result;
  846: }
  847: 
  848: sub is_course_upload {
  849:     my ($file,$cnum,$cdom) = @_;
  850:     my $uploadpath = &LONCAPA::propath($cdom,$cnum);
  851:     $uploadpath =~ s{^\/}{};
  852:     if (($file =~ m{^\Q$uploadpath\E/userfiles/docs/}) ||
  853:         ($file =~ m{^userfiles/\Q$cdom\E/\Q$cnum\E/docs/})) {
  854:         return 1;
  855:     }
  856:     return;
  857: }
  858: 
  859: sub edit_course_upload {
  860:     my ($file,$cnum,$cdom) = @_;
  861:     my $cfile;
  862:     if ($file =~/\.(htm|html|css|js|txt)$/) {
  863:         my $ext = $1;
  864:         my $url = &Apache::lonnet::hreflocation('',$file);
  865:         my $home = &Apache::lonnet::homeserver($cnum,$cdom);
  866:         my @ids=&Apache::lonnet::current_machine_ids();
  867:         my $dest;
  868:         if ($home && grep(/^\Q$home\E$/,@ids)) {
  869:             $dest = $url.'?forceedit=1';
  870:         } else {
  871:             unless (&Apache::lonnet::get_locks()) {
  872:                 $dest = '/adm/switchserver?otherserver='.
  873:                         $home.'&role='.$env{'request.role'}.
  874:                         '&url='.$url.'&forceedit=1';
  875:             }
  876:         }
  877:         if ($dest) {
  878:             $cfile = &HTML::Entities::encode($dest,'"<>&');
  879:         }
  880:     }
  881:     return $cfile;
  882: }
  883: 
  884: sub loadevents() {
  885:     if ($env{'request.state'} eq 'construct' ||
  886: 	$env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
  887:     return 'LONCAPAreg();';
  888: }
  889: 
  890: sub unloadevents() {
  891:     if ($env{'request.state'} eq 'construct' ||
  892: 	$env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
  893:     return 'LONCAPAstale();';
  894: }
  895: 
  896: 
  897: sub startupremote {
  898:     my ($lowerurl)=@_;
  899:     if (($env{'browser.interface'} eq 'textual') ||
  900:         ($env{'environment.remote'} eq 'off')) {
  901:      return ('<meta HTTP-EQUIV="Refresh" CONTENT="0.5; url='.$lowerurl.'" />');
  902:     }
  903: #
  904: # The Remote actually gets launched!
  905: #
  906:     my $configmenu=&rawconfig();
  907:     my $esclowerurl=&escape($lowerurl);
  908:     my $message=&mt('"Waiting for Remote Control window to load: "+[_1]','waited');
  909:     return(<<ENDREMOTESTARTUP);
  910: <script type="text/javascript">
  911: var timestart;
  912: function wheelswitch() {
  913:     if (typeof(document.wheel) != 'undefined') {
  914: 	if (typeof(document.wheel.spin) != 'undefined') {
  915: 	    var date=new Date();
  916: 	    var waited=Math.round(30-((date.getTime()-timestart)/1000));
  917: 	    document.wheel.spin.value=$message;
  918: 	}
  919:     }
  920:    if (window.status=='|') { 
  921:       window.status='/'; 
  922:    } else {
  923:       if (window.status=='/') {
  924:          window.status='-';
  925:       } else {
  926:          if (window.status=='-') { 
  927:             window.status='\\\\'; 
  928:          } else {
  929:             if (window.status=='\\\\') { window.status='|'; }
  930:          }
  931:       }
  932:    } 
  933: }
  934: 
  935: // ---------------------------------------------------------- The wait function
  936: var canceltim;
  937: function wait() {
  938:    if ((menuloaded==1) || (tim==1)) {
  939:       window.status='Done.';
  940:       if (tim==0) {
  941:          clearTimeout(canceltim);
  942:          $configmenu
  943:          window.location='$lowerurl';  
  944:       } else {
  945: 	  window.location='/adm/remote?action=collapse&url=$esclowerurl';
  946:       }
  947:    } else {
  948:       wheelswitch();
  949:       setTimeout('wait();',200);
  950:    }
  951: }
  952: 
  953: function main() {
  954:    canceltim=setTimeout('tim=1;',30000);
  955:    window.status='-';
  956:    var date=new Date();
  957:    timestart=date.getTime();
  958:    wait();
  959: }
  960: 
  961: </script>
  962: ENDREMOTESTARTUP
  963: }
  964: 
  965: sub setflags() {
  966:     return(<<ENDSETFLAGS);
  967: <script type="text/javascript">
  968:     menuloaded=0;
  969:     tim=0;
  970: </script>
  971: ENDSETFLAGS
  972: }
  973: 
  974: sub maincall() {
  975:     if (($env{'browser.interface'} eq 'textual') ||
  976:         ($env{'environment.remote'} eq 'off')) { return ''; }
  977:     return(<<ENDMAINCALL);
  978: <script type="text/javascript">
  979:     main();
  980: </script>
  981: ENDMAINCALL
  982: }
  983: 
  984: sub load_remote_msg {
  985:     my ($lowerurl)=@_;
  986: 
  987:     if (($env{'browser.interface'} eq 'textual') ||
  988:         ($env{'environment.remote'} eq 'off')) { return ''; }
  989: 
  990:     my $esclowerurl=&escape($lowerurl);
  991:     my $link=&mt('[_1]Continue[_2] on in Inline Menu mode'
  992:                 ,'<a href="/adm/remote?action=collapse&amp;url='.$esclowerurl.'">'
  993:                 ,'</a>');
  994:     return(<<ENDREMOTEFORM);
  995: <p>
  996: <form name="wheel">
  997: <input name="spin" type="text" size="60" />
  998: </form>
  999: </p>
 1000: <p>$link</p>
 1001: ENDREMOTEFORM
 1002: }
 1003: 
 1004: sub get_menu_name {
 1005:     my $hostid = $Apache::lonnet::perlvar{'lonHostID'};
 1006:     $hostid =~ s/\W//g;
 1007:     return 'LCmenu'.$hostid;
 1008: }
 1009: 
 1010: 
 1011: sub reopenmenu {
 1012:    if (($env{'browser.interface'} eq 'textual') ||
 1013:        ($env{'environment.remote'} eq 'off')) { return ''; }
 1014:    my $menuname = &get_menu_name();
 1015:    my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
 1016:    return('window.open('.$nothing.',"'.$menuname.'","",false);');
 1017: } 
 1018: 
 1019: 
 1020: sub open {
 1021:     my $returnval='';
 1022:     if (($env{'browser.interface'} eq 'textual') ||
 1023:         ($env{'environment.remote'} eq 'off')) { 
 1024: 	return '<script type="text/javascript">self.name="loncapaclient";</script>';
 1025:     }
 1026:     my $menuname = &get_menu_name();
 1027:     
 1028: #    unless (shift eq 'unix') {
 1029: # resizing does not work on linux because of virtual desktop sizes
 1030: #       $returnval.=(<<ENDRESIZE);
 1031: #if (window.screen) {
 1032: #    self.resizeTo(screen.availWidth-215,screen.availHeight-55);
 1033: #    self.moveTo(190,15);
 1034: #}
 1035: #ENDRESIZE
 1036: #    }
 1037:     $returnval.=(<<ENDOPEN);
 1038: window.status='Opening LON-CAPA Remote Control';
 1039: var menu=window.open("/res/adm/pages/menu.html","$menuname",
 1040: "height=375,width=150,scrollbars=no,menubar=no,top=5,left=5,screenX=5,screenY=5");
 1041: self.name='loncapaclient';
 1042: ENDOPEN
 1043:     return '<script type="text/javascript">'.$returnval.'</script>';
 1044: }
 1045: 
 1046: 
 1047: # ================================================================== Raw Config
 1048: 
 1049: sub clear {
 1050:     my ($row,$col)=@_;
 1051:     unless (($env{'browser.interface'} eq 'textual') ||
 1052:             ($env{'environment.remote'} eq 'off')) {
 1053:        return "\n".qq(window.status+='.';swmenu.clearbut($row,$col););
 1054:    } else { 
 1055:        $inlineremote[10*$row+$col]='';
 1056:        return ''; 
 1057:    }
 1058: }
 1059: 
 1060: # ============================================ Switch a button or create a link
 1061: # Switch acts on the javascript that is executed when a button is clicked.  
 1062: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
 1063: 
 1064: sub switch {
 1065:     my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat,$nobreak)=@_;
 1066:     $act=~s/\$uname/$uname/g;
 1067:     $act=~s/\$udom/$udom/g;
 1068:     $top=&mt($top);
 1069:     $bot=&mt($bot);
 1070:     $desc=&mt($desc);
 1071:     if (($env{'environment.remote'} ne 'off') || ($env{'environment.icons'} eq 'classic')) {
 1072:        $img=&mt($img);
 1073:     }
 1074:     my $idx=10*$row+$col;
 1075:     $category_members{$cat}.=':'.$idx;
 1076: 
 1077:     unless (($env{'browser.interface'} eq 'textual')  ||
 1078:             ($env{'environment.remote'} eq 'off')) {
 1079: # Remote
 1080:        return "\n".
 1081:  qq(window.status+='.';swmenu.switchbutton($row,$col,"$img","$top","$bot","$act","$desc"););
 1082:    } elsif ($env{'browser.interface'} eq 'textual') {
 1083: # Accessibility
 1084:        if ($nobreak==2) { return ''; }
 1085:        my $text=$top.' '.$bot;
 1086:        $text=~s/\s*\-\s*//gs;
 1087:        if ($nobreak) {
 1088: 	   $inlineremote[$idx]=
 1089: 	       '<a href="javascript:'.$act.';">'.$text.'</a>';
 1090:        } else {
 1091: 	   $inlineremote[$idx]="\n<br />".
 1092: 	       $desc.' <a href="javascript:'.$act.';">'.$text.'</a>';
 1093:        }
 1094:    } else {
 1095: # Inline Remote
 1096:        if ($env{'environment.icons'} ne 'classic') {
 1097:           $img=~s/\.gif$/\.png/;
 1098:        }
 1099:        if ($nobreak==2) { return ''; }
 1100:        my $text=$top.' '.$bot;
 1101:        $text=~s/\s*\-\s*//gs;
 1102: 
 1103:        my $pic=
 1104: 	   '<img alt="'.$text.'" src="'.
 1105: 	   &Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$img).
 1106: 	   '" align="'.($nobreak==3?'right':'left').'" class="LC_noBorder" />';
 1107:        if ($env{'browser.interface'} eq 'faketextual') {
 1108: # Accessibility
 1109: 	   if ($nobreak==3) {
 1110: 	       $inlineremote[$idx]="\n".
 1111: 		   '<td class="LC_menubuttons_text" align="right">'.$text.
 1112: 		   '</td><td align="left">'.
 1113: 		   '<a href="javascript:'.$act.';">'.$pic.'</a></td></tr>';
 1114: 	   } elsif ($nobreak) {
 1115: 	       $inlineremote[$idx]="\n<tr>".
 1116: 		   '<td align="left">'.
 1117: 		   '<a href="javascript:'.$act.';">'.$pic.'</a></td>
 1118:                     <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>';
 1119: 	   } else {
 1120: 	       $inlineremote[$idx]="\n<tr>".
 1121: 		   '<td align="left">'.
 1122: 		   '<a href="javascript:'.$act.';">'.$pic.
 1123: 		   '</a></td><td class="LC_menubuttons_text" colspan="3">'.
 1124: 		   '<a class="LC_menubuttons_link" href="javascript:'.$act.';"><span class="LC_menubuttons_inline_text">'.$desc.'</span></a></td></tr>';
 1125: 	   }
 1126:        } else {
 1127: # Inline Menu
 1128:            if ($env{'environment.icons'} eq 'iconsonly') {
 1129:               $inlineremote[$idx]='<a title="'.$desc.'" href="javascript:'.$act.';">'.$pic.'</a>';
 1130:            } else {
 1131: 	      $inlineremote[$idx]=
 1132: 		   '<a class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.
 1133: 		   '<span class="LC_menubuttons_inline_text">'.$desc.'</span></a>';
 1134:            }
 1135:        }
 1136:    }
 1137:     return '';
 1138: }
 1139: 
 1140: sub secondlevel {
 1141:     my $output='';
 1142:     my 
 1143:     ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat)=@_;
 1144:     if ($prt eq 'any') {
 1145: 	   $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1146:     } elsif ($prt=~/^r(\w+)/) {
 1147:         if ($rol eq $1) {
 1148:            $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1149:         }
 1150:     }
 1151:     return $output;
 1152: }
 1153: 
 1154: sub openmenu {
 1155:     my $menuname = &get_menu_name();
 1156:     if (($env{'browser.interface'} eq 'textual') ||
 1157:         ($env{'environment.remote'} eq 'off')) { return ''; }
 1158:     my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
 1159:     return "window.open(".$nothing.",'".$menuname."');";
 1160: }
 1161: 
 1162: sub inlinemenu {
 1163:     undef(@inlineremote);
 1164:     undef(%category_members);
 1165:     &rawconfig(1);
 1166:     my $output='<table id="LC_mainmenu"><tr>';
 1167:     for (my $col=1; $col<=2; $col++) {
 1168:         $output.='<td class="LC_mainmenu_col_fieldset">';
 1169:         for (my $row=1; $row<=8; $row++) {
 1170:             foreach my $cat (keys(%category_members)) {
 1171:                if ($category_positions{$cat} ne "$col,$row") { next; }
 1172:                #$output.='<table><tr><td colspan="4" class="LC_menubuttons_category">'.&mt($category_names{$cat}).'</td></tr>';
 1173:                $output.='<div class="LC_ContentBoxSpecial">';
 1174: 	       $output.='<h4 class="LC_hcell">'.&mt($category_names{$cat}).'</h4>';
 1175:                $output.='<table>';
 1176:                my %active=();
 1177:                foreach my $menu_item (split(/\:/,$category_members{$cat})) {
 1178:                   if ($inlineremote[$menu_item]) {
 1179:                      $active{$menu_item}=1;
 1180:                   }
 1181:                }  
 1182:                foreach my $item (sort(keys(%active))) {
 1183:                   $output.=$inlineremote[$item];
 1184:                }
 1185:                $output.='</table>';
 1186:                $output.='</div>';
 1187:             }
 1188:          }
 1189:          $output.="</td>";
 1190:     }
 1191:     $output.="</tr></table>";
 1192:     return $output;
 1193: }
 1194: 
 1195: sub rawconfig {
 1196:     my $textualoverride=shift;
 1197:     my $output='';
 1198:     unless (($env{'browser.interface'} eq 'textual') ||
 1199:             ($env{'environment.remote'} eq 'off')) {
 1200:        $output.=
 1201:  "window.status='Opening Remote Control';var swmenu=".&openmenu().
 1202: "\nwindow.status='Configuring Remote Control ';";
 1203:     } else {
 1204:        unless ($textualoverride) { return ''; }
 1205:     }
 1206:     my $uname=$env{'user.name'};
 1207:     my $udom=$env{'user.domain'};
 1208:     my $adv=$env{'user.adv'};
 1209:     my $show_course=&show_course();
 1210:     my $author=$env{'user.author'};
 1211:     my $crs='';
 1212:     if ($env{'request.course.id'}) {
 1213:        $crs='/'.$env{'request.course.id'};
 1214:        if ($env{'request.course.sec'}) {
 1215: 	   $crs.='_'.$env{'request.course.sec'};
 1216:        }
 1217:        $crs=~s/\_/\//g;
 1218:     }
 1219:     my $pub=($env{'request.state'} eq 'published');
 1220:     my $con=($env{'request.state'} eq 'construct');
 1221:     my $rol=$env{'request.role'};
 1222:     my $requested_domain = $env{'request.role.domain'};
 1223:     foreach my $line (@desklines) {
 1224:         my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc,$cat)=split(/\:/,$line);
 1225:         $prt=~s/\$uname/$uname/g;
 1226:         $prt=~s/\$udom/$udom/g;
 1227:         $prt=~s/\$crs/$crs/g; 
 1228:         $prt=~s/\$requested_domain/$requested_domain/g;
 1229:         if ($category_names{$cat}!~/\w/) { $cat='oth'; }
 1230:         my $type = &Apache::loncommon::course_type();
 1231:         if ($type eq 'Group') {
 1232:             $desc = &convert_menu_function($desc,$type);
 1233:         }
 1234:         if ($pro eq 'clear') {
 1235: 	    $output.=&clear($row,$col);
 1236:         } elsif ($pro eq 'any') {
 1237:                $output.=&secondlevel(
 1238: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1239: 	} elsif ($pro eq 'smp') {
 1240:             unless ($adv) {
 1241:                $output.=&secondlevel(
 1242:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1243:             }
 1244:         } elsif ($pro eq 'adv') {
 1245:             if ($adv) {
 1246:                $output.=&secondlevel(
 1247: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1248:             }
 1249: 	} elsif ($pro eq 'shc') {
 1250:             if ($show_course) {
 1251:                $output.=&secondlevel(
 1252:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1253:             }
 1254:         } elsif ($pro eq 'nsc') {
 1255:             if (!$show_course) {
 1256:                $output.=&secondlevel(
 1257: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1258:             }
 1259:         } elsif (($pro=~/^p(\w+)/) && ($prt)) {
 1260: 	    if (&Apache::lonnet::allowed($1,$prt)) {
 1261:                $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1262:             }
 1263:         } elsif ($pro eq 'course') {
 1264:             if ($env{'request.course.fn'}) {
 1265:                $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1266: 	    }
 1267:         } elsif ($pro =~ /^courseenv_(.*)$/) {
 1268:             my $key = $1;
 1269:             if ($env{'course.'.$env{'request.course.id'}.'.'.$key}) {
 1270:                 $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1271:             }
 1272:         } elsif ($pro =~ /^course_(.*)$/) {
 1273:             # Check for permissions inside of a course
 1274:             if (($env{'request.course.id'}) &&
 1275:                 (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
 1276:             ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
 1277:                  )) {
 1278:                 $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
 1279: 	    }
 1280:         } elsif ($pro eq 'author') {
 1281:             if ($author) {
 1282:                 if ((($prt eq 'rca') && ($env{'request.role'}=~/^ca/)) ||
 1283:                     (($prt eq 'raa') && ($env{'request.role'}=~/^aa/)) || 
 1284:                     (($prt eq 'rau') && ($env{'request.role'}=~/^au/))) {
 1285:                     # Check that we are on the correct machine
 1286:                     my $cadom=$requested_domain;
 1287:                     my $caname=$env{'user.name'};
 1288:                     if (($prt eq 'rca') || ($prt eq 'raa')) {
 1289: 		       ($cadom,$caname)=
 1290:                                ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
 1291:                     }                       
 1292:                     $act =~ s/\$caname/$caname/g;
 1293:                     my $home = &Apache::lonnet::homeserver($caname,$cadom);
 1294: 		    my $allowed=0;
 1295: 		    my @ids=&Apache::lonnet::current_machine_ids();
 1296: 		    foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
 1297: 		    if ($allowed) {
 1298:                         $output.=&switch($caname,$cadom,
 1299:                                         $row,$col,$img,$top,$bot,$act,$desc,$cat);
 1300:                     }
 1301:                 }
 1302:             }
 1303:         } elsif ($pro eq 'tools') {
 1304:             my @tools = ('aboutme','blog','portfolio');
 1305:             if (grep(/^\Q$prt\E$/,@tools)) {
 1306:                 if (!&Apache::lonnet::usertools_access($env{'user.name'},
 1307:                                                        $env{'user.domain'},
 1308:                                                        $prt,undef,'tools')) {
 1309:                     $output.=&clear($row,$col);
 1310:                     next;
 1311:                 }
 1312:             } elsif ($prt eq 'reqcrs') {
 1313:                 my $showreqcrs = 0;
 1314:                 foreach my $type ('official','unofficial') {
 1315:                     if (&Apache::lonnet::usertools_access($env{'user.name'},
 1316:                                                     $env{'user.domain'},
 1317:                                                     $type,undef,'requestcourses')) {
 1318:                         $showreqcrs = 1;
 1319:                         last;
 1320:                     }
 1321:                 }
 1322:                 if (!$showreqcrs) {
 1323:                     $output.=&clear($row,$col);
 1324:                     next;
 1325:                 }
 1326:             }
 1327:             $prt='any';
 1328:             $output.=&secondlevel(
 1329:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
 1330:         }
 1331:     }
 1332:     unless (($env{'browser.interface'} eq 'textual') ||
 1333:             ($env{'environment.remote'} eq 'off')) {
 1334:        $output.="\nwindow.status='Synchronizing Time';swmenu.syncclock(1000*".time.");\nwindow.status='Remote Control Configured.';";
 1335:        if (&Apache::lonmsg::newmail()) { 
 1336: 	   $output.='swmenu.setstatus("you have","messages");';
 1337:        }
 1338:     }
 1339: 
 1340:     return $output;
 1341: }
 1342: 
 1343: # ======================================================================= Close
 1344: 
 1345: sub close {
 1346:     if (($env{'browser.interface'} eq 'textual') ||
 1347:         ($env{'environment.remote'} eq 'off')) { return ''; }
 1348:     my $menuname = &get_menu_name();
 1349:     return(<<ENDCLOSE);
 1350: <script type="text/javascript">
 1351: window.status='Accessing Remote Control';
 1352: menu=window.open("/adm/rat/empty.html","$menuname",
 1353:                  "height=350,width=150,scrollbars=no,menubar=no");
 1354: window.status='Disabling Remote Control';
 1355: menu.active=0;
 1356: menu.autologout=0;
 1357: window.status='Closing Remote Control';
 1358: menu.close();
 1359: window.status='Done.';
 1360: </script>
 1361: ENDCLOSE
 1362: }
 1363: 
 1364: # ====================================================================== Footer
 1365: 
 1366: sub footer {
 1367: 
 1368: }
 1369: 
 1370: sub nav_control_js {
 1371:     my $nav=($env{'environment.remotenavmap'} eq 'on');
 1372:     return (<<NAVCONTROL);
 1373:     var w_loncapanav_flag="$nav";
 1374: 
 1375: 
 1376: function gonav(url) {
 1377:    if (w_loncapanav_flag != 1) {
 1378:       gopost(url,'');
 1379:    }  else {
 1380:       navwindow=window.open(url,
 1381:                   "loncapanav","height=600,width=400,scrollbars=1"); 
 1382:    }
 1383: }
 1384: NAVCONTROL
 1385: }
 1386: 
 1387: sub utilityfunctions {
 1388:     my $caller = shift;
 1389:     unless (($env{'browser.interface'} eq 'textual')  ||
 1390:         ($env{'environment.remote'} eq 'off') || ($caller eq '/adm/menu')) { return ''; }
 1391:     my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
 1392:     $currenturl=&Apache::lonenc::check_encrypt(&unescape($currenturl));
 1393:     
 1394:     my $currentsymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
 1395:     my $nav_control=&nav_control_js();
 1396: 
 1397:     my $start_page_annotate = 
 1398:         &Apache::loncommon::start_page('Annotator',undef,
 1399: 				       {'only_body' => 1,
 1400: 					'js_ready'  => 1,
 1401: 					'bgcolor'   => '#BBBBBB',
 1402: 					'add_entries' => {
 1403: 					    'onload' => 'javascript:document.goannotate.submit();'}});
 1404: 
 1405:     my $end_page_annotate = 
 1406:         &Apache::loncommon::end_page({'js_ready' => 1});
 1407: 
 1408:     my $start_page_bookmark = 
 1409:         &Apache::loncommon::start_page('Bookmarks',undef,
 1410: 				       {'only_body' => 1,
 1411: 					'js_ready'  => 1,
 1412: 					'bgcolor'   => '#BBBBBB',});
 1413: 
 1414:     my $end_page_bookmark = 
 1415:         &Apache::loncommon::end_page({'js_ready' => 1});
 1416: 
 1417: return (<<ENDUTILITY)
 1418: 
 1419:     var currentURL="$currenturl";
 1420:     var reloadURL="$currenturl";
 1421:     var currentSymb="$currentsymb";
 1422: 
 1423: $nav_control
 1424: 
 1425: function go(url) {
 1426:    if (url!='' && url!= null) {
 1427:        currentURL = null;
 1428:        currentSymb= null;
 1429:        window.location.href=url;
 1430:    }
 1431: }
 1432: 
 1433: function gopost(url,postdata) {
 1434:    if (url!='') {
 1435:       this.document.server.action=url;
 1436:       this.document.server.postdata.value=postdata;
 1437:       this.document.server.command.value='';
 1438:       this.document.server.url.value='';
 1439:       this.document.server.symb.value='';
 1440:       this.document.server.submit();
 1441:    }
 1442: }
 1443: 
 1444: function gocmd(url,cmd) {
 1445:    if (url!='') {
 1446:       this.document.server.action=url;
 1447:       this.document.server.postdata.value='';
 1448:       this.document.server.command.value=cmd;
 1449:       this.document.server.url.value=currentURL;
 1450:       this.document.server.symb.value=currentSymb;
 1451:       this.document.server.submit();
 1452:    }
 1453: }
 1454: 
 1455: function gocstr(url,filename) {
 1456:     if (url == '/adm/cfile?action=delete') {
 1457:         this.document.cstrdelete.filename.value = filename
 1458:         this.document.cstrdelete.submit();
 1459:         return;
 1460:     }
 1461:     if (url == '/adm/printout') {
 1462:         this.document.cstrprint.postdata.value = filename
 1463:         this.document.cstrprint.curseed.value = 0;
 1464:         this.document.cstrprint.problemtype.value = 0;
 1465:         if (this.document.lonhomework) {
 1466:             if ((this.document.lonhomework.rndseed) && (this.document.lonhomework.rndseed.value != null) && (this.document.lonhomework.rndseed.value != '')) {
 1467:                 this.document.cstrprint.curseed.value = this.document.lonhomework.rndseed.value
 1468:             }
 1469:             if (this.document.lonhomework.problemtype) {
 1470: 		if (this.document.lonhomework.problemtype.value) {
 1471: 		    this.document.cstrprint.problemtype.value = 
 1472: 			this.document.lonhomework.problemtype.value;
 1473: 		} else if (this.document.lonhomework.problemtype.options) {
 1474: 		    for (var i=0; i<this.document.lonhomework.problemtype.options.length; i++) {
 1475: 			if (this.document.lonhomework.problemtype.options[i].selected) {
 1476: 			    if (this.document.lonhomework.problemtype.options[i].value != null && this.document.lonhomework.problemtype.options[i].value != '') { 
 1477: 				this.document.cstrprint.problemtype.value = this.document.lonhomework.problemtype.options[i].value
 1478: 				}
 1479: 			}
 1480: 		    }
 1481: 		}
 1482: 	    }
 1483: 	}
 1484:         this.document.cstrprint.submit();
 1485:         return;
 1486:     }
 1487:     if (url !='') {
 1488:         this.document.constspace.filename.value = filename;
 1489:         this.document.constspace.action = url;
 1490:         this.document.constspace.submit();
 1491:     }
 1492: }
 1493: 
 1494: function golist(url) {
 1495:    if (url!='' && url!= null) {
 1496:        currentURL = null;
 1497:        currentSymb= null;
 1498:        top.location.href=url;
 1499:    }
 1500: }
 1501: 
 1502: 
 1503: 
 1504: function catalog_info() {
 1505:    loncatinfo=window.open(window.location.pathname+'.meta',"LONcatInfo",'height=320,width=280,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
 1506: }
 1507: 
 1508: function chat_win() {
 1509:    lonchat=window.open('/res/adm/pages/chatroom.html',"LONchat",'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
 1510: }
 1511: 
 1512: function group_chat(group) {
 1513:    var url = '/adm/groupchat?group='+group;
 1514:    var winName = 'LONchat_'+group;
 1515:    grpchat=window.open(url,winName,'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
 1516: }
 1517: 
 1518: function edit_bookmarks() {
 1519:    go('');
 1520:    w_BookmarkPal_flag=1;
 1521:    bookmarkpal=window.open("/adm/bookmarks",
 1522:                "BookmarkPal", "width=400,height=505,scrollbars=0");
 1523: }
 1524: 
 1525: function annotate() {
 1526:    w_Annotator_flag=1;
 1527:    annotator=window.open('','Annotator','width=365,height=265,scrollbars=0');
 1528:    annotator.document.write(
 1529:    '$start_page_annotate'
 1530:   +"<form name='goannotate' target='Annotator' method='post' "
 1531:   +"action='/adm/annotations'>"
 1532:   +"<input type='hidden' name='symbnew' value='"+currentSymb+"' />"
 1533:   +"<\\/form>"
 1534:   +'$end_page_annotate');
 1535:    annotator.document.close();
 1536: }
 1537: 
 1538: function set_bookmark() {
 1539:    go('');
 1540:    clienttitle=document.title;
 1541:    clienthref=location.pathname;
 1542:    w_bmquery_flag=1;
 1543:    bmquery=window.open('','bmquery','width=365,height=165,scrollbars=0');
 1544:    bmquery.document.write(
 1545:    '$start_page_bookmark'
 1546:    +'<center><form method="post"'
 1547:    +' name="newlink" action="/adm/bookmarks" target="bmquery" '
 1548:    +'> <table width="340" height="150" '
 1549:    +'bgcolor="#FFFFFF" align="center"><tr><td>Link Name:<br /><input '
 1550:    +'type="text" name="title" size="45" value="'+clienttitle+'" />'
 1551:    +'<br />Address:<br /><input type="text" name="address" size="45" '
 1552:    +'value="'+clienthref+'" /><br /><center><input type="submit" '
 1553:    +'value="Save" /> <input type="button" value="Close" '
 1554:    +'onclick="javascript:window.close();" /></center></td>'
 1555:    +'</tr></table></form></center>'
 1556:    +'$end_page_bookmark' );
 1557:    bmquery.document.close();
 1558: }
 1559: 
 1560: ENDUTILITY
 1561: }
 1562: 
 1563: sub serverform {
 1564:     return(<<ENDSERVERFORM);
 1565: <form name="server" action="/adm/logout" method="post" target="_top">
 1566: <input type="hidden" name="postdata" value="none" />
 1567: <input type="hidden" name="command" value="none" />
 1568: <input type="hidden" name="url" value="none" />
 1569: <input type="hidden" name="symb" value="none" />
 1570: </form>
 1571: ENDSERVERFORM
 1572: }
 1573: 
 1574: sub constspaceform {
 1575:     return(<<ENDCONSTSPACEFORM);
 1576: <form name="constspace" action="/adm/logout" method="post" target="_top">
 1577: <input type="hidden" name="filename" value="" />
 1578: </form>
 1579: <form name="cstrdelete" action="/adm/cfile" method="post" target="_top">
 1580: <input type="hidden" name="action" value="delete" /> 
 1581: <input type="hidden" name="filename" value="" />
 1582: </form>
 1583: <form name="cstrprint" action="/adm/printout" target="_parent" method="post">
 1584: <input type="hidden" name="postdata" value="" />
 1585: <input type="hidden" name="curseed" value="" />
 1586: <input type="hidden" name="problemtype" value="" />
 1587: </form>
 1588: 
 1589: ENDCONSTSPACEFORM
 1590: }
 1591: 
 1592: 
 1593: sub get_nav_status {
 1594:     my $navstatus="swmenu.w_loncapanav_flag=";
 1595:     if ($env{'environment.remotenavmap'} eq 'on') {
 1596: 	$navstatus.="1";
 1597:     } else {
 1598: 	$navstatus.="-1";
 1599:     }
 1600:     return $navstatus;
 1601: }
 1602: 
 1603: #FIXME this needs to move into mydesktab and the other locations 
 1604: # the text is generated
 1605: sub convert_menu_function {
 1606:     my ($rolename,$type) = @_;
 1607:     if ($type eq 'Group') {
 1608:         $rolename =~ s/student/member/g;
 1609:         $rolename =~ s/group/team/g;
 1610:         $rolename =~ s/course/group/g;
 1611:         $rolename =~ s/Course/Group/g;
 1612:     }
 1613:     return $rolename;
 1614: }
 1615: 
 1616: sub hidden_button_check {
 1617:     my $hidden;
 1618:     if ($env{'request.course.id'} eq '') {
 1619:         return;
 1620:     }
 1621:     if ($env{'request.role.adv'}) {
 1622:         return;
 1623:     }
 1624:     my $buttonshide = &Apache::lonnet::EXT('resource.0.buttonshide');
 1625:     return $buttonshide; 
 1626: }
 1627: 
 1628: sub roles_selector {
 1629:     my ($cdom,$cnum) = @_;
 1630:     my $now = time;
 1631:     my (%courseroles,%seccount);
 1632:     my $is_cc;
 1633:     my $role_selector;
 1634:     if ($env{'user.role.cc./'.$cdom.'/'.$cnum}) {
 1635:         my ($start,$end) = split(/\./,$env{'user.role.cc./'.$cdom.'/'.$cnum});
 1636:         
 1637:         if ((($start) && ($start<0)) || 
 1638:             (($end) && ($end<$now))  ||
 1639:             (($start) && ($now<$start))) {
 1640:             $is_cc = 0;
 1641:         } else {
 1642:             $is_cc = 1;
 1643:         }
 1644:     }
 1645:     if ($is_cc) {
 1646:         &get_all_courseroles($cdom,$cnum,\%courseroles,\%seccount);
 1647:     } else {
 1648:         my %gotnosection;
 1649:         foreach my $item (keys(%env)) {
 1650:             if ($item =~ m-^user\.role\.([^.]+)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
 1651:                 my $role = $1;
 1652:                 my $sec = $2;
 1653:                 next if ($role eq 'gr');
 1654:                 my ($start,$end) = split(/\./,$env{$item});
 1655:                 next if (($start && $start > $now) || ($end && $end < $now));
 1656:                 if ($sec eq '') {
 1657:                     if (!$gotnosection{$role}) {
 1658:                         $seccount{$role} ++;
 1659:                         $gotnosection{$role} = 1;
 1660:                     }
 1661:                 }
 1662:                 if (ref($courseroles{$role}) eq 'ARRAY') {
 1663:                     if ($sec ne '') {
 1664:                         if (!grep(/^\Q$sec\E$/,@{$courseroles{$role}})) {
 1665:                             push(@{$courseroles{$role}},$sec);
 1666:                             $seccount{$role} ++;
 1667:                         }
 1668:                     }
 1669:                 } else {
 1670:                     @{$courseroles{$role}} = ();
 1671:                     if ($sec ne '') {
 1672:                         $seccount{$role} ++;
 1673:                         push(@{$courseroles{$role}},$sec);
 1674:                     }
 1675:                 }
 1676:             }
 1677:         }
 1678:     }
 1679:     my @roles_order = ('cc','in','ta','ep','ad','st');
 1680:     if (keys(%courseroles) > 1) {
 1681:         $role_selector = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles);
 1682:         $role_selector .= '<form name="rolechooser" method="post" action="/adm/roles">
 1683:                           <select name="switchrole" onchange="javascript:adhocRole('."'switchrole'".')">';
 1684:         $role_selector .= '<option value="">'.&mt('Switch course role to...').'</option>';
 1685:         foreach my $role (@roles_order) {
 1686:             if (defined($courseroles{$role})) {
 1687:                 $role_selector .= "\n".'<option value="'.$role.'">'.&Apache::lonnet::plaintext($role).'</option>'; 
 1688:             }
 1689:         }
 1690:         foreach my $role (sort(keys(%courseroles))) {
 1691:             if ($role =~ /^cr/) {
 1692:                 $role_selector .= "\n".'<option value="'.$role.'">'.&Apache::lonnet::plaintext($role).'</option>'; 
 1693:             }
 1694:         }
 1695:         $role_selector .= '</select>'."\n".
 1696:                '<input type="hidden" name="destinationurl" value="'.
 1697:                $ENV{'REQUEST_URI'}.'" />'."\n".
 1698:                '<input type="hidden" name="gotorole" value="1" />'."\n".
 1699:                '<input type="hidden" name="selectrole" value="" />'."\n".
 1700:                '<input type="hidden" name="switch" value="1" />'."\n".
 1701:                '</form>';
 1702:     }
 1703:     return $role_selector;
 1704: }
 1705: 
 1706: sub get_all_courseroles {
 1707:     my ($cdom,$cnum,$courseroles,$seccount) = @_;
 1708:     unless ((ref($courseroles) eq 'HASH') && (ref($seccount) eq 'HASH')) {
 1709:         return;
 1710:     }
 1711:     my ($result,$cached) = 
 1712:         &Apache::lonnet::is_cached_new('getcourseroles',$cdom.'_'.$cnum);
 1713:     if (defined($cached)) {
 1714:         if (ref($result) eq 'HASH') {
 1715:             if ((ref($result->{'roles'}) eq 'HASH') && 
 1716:                 (ref($result->{'seccount'}) eq 'HASH')) {
 1717:                 %{$courseroles} = %{$result->{'roles'}};
 1718:                 %{$seccount} = %{$result->{'seccount'}};
 1719:                 return;
 1720:             }
 1721:         }
 1722:     }
 1723:     my %gotnosection;
 1724:     my %adv_roles =
 1725:          &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
 1726:     foreach my $role (keys(%adv_roles)) {
 1727:         my ($urole,$usec) = split(/:/,$role);
 1728:         if (!$gotnosection{$urole}) {
 1729:             $seccount->{$urole} ++;
 1730:             $gotnosection{$urole} = 1;
 1731:         }
 1732:         if (ref($courseroles->{$urole}) eq 'ARRAY') {
 1733:             if ($usec ne '') {
 1734:                 if (!grep(/^Q$usec\E$/,@{$courseroles->{$urole}})) {
 1735:                     push(@{$courseroles->{$urole}},$usec);
 1736:                     $seccount->{$urole} ++;
 1737:                 }
 1738:             }
 1739:         } else {
 1740:             @{$courseroles->{$urole}} = ();
 1741:             if ($usec ne '') {
 1742:                 $seccount->{$urole} ++;
 1743:                 push(@{$courseroles->{$urole}},$usec);
 1744:             }
 1745:         }
 1746:     }
 1747:     my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum,['st']);
 1748:     @{$courseroles->{'st'}} = ();
 1749:     if (keys(%sections_count) > 0) {
 1750:         push(@{$courseroles->{'st'}},keys(%sections_count));
 1751:         $seccount->{'st'} = scalar(keys(%sections_count)); 
 1752:     }
 1753:     my $rolehash = {
 1754:                      'roles'    => $courseroles,
 1755:                      'seccount' => $seccount,
 1756:                    };
 1757:     &Apache::lonnet::do_cache_new('getcourseroles',$cdom.'_'.$cnum,$rolehash);
 1758:     return;
 1759: }
 1760: 
 1761: sub jump_to_role {
 1762:     my ($cdom,$cnum,$seccount,$courseroles) = @_;
 1763:     my %lt = &Apache::lonlocal::texthash(
 1764:                 this => 'This role has section(s) associated with it.',
 1765:                 ente => 'Enter a specific section.',
 1766:                 orlb => 'Enter a specific section, or leave blank for no section.',
 1767:                 avai => 'Available sections are:',
 1768:                 youe => 'You entered an invalid section choice:',
 1769:                 plst => 'Please try again',
 1770:     );
 1771:     my $js;
 1772:     if (ref($courseroles) eq 'HASH') {
 1773:         $js = '    var secpick = new Array("'.$lt{'ente'}.'","'.$lt{'orlb'}.'");'."\n". 
 1774:               '    var numsec = new Array();'."\n".
 1775:               '    var rolesections = new Array();'."\n".
 1776:               '    var rolenames = new Array();'."\n".
 1777:               '    var roleseclist = new Array();'."\n";
 1778:         my @items = keys(%{$courseroles});
 1779:         for (my $i=0; $i<@items; $i++) {
 1780:             $js .= '    rolenames['.$i.'] = "'.$items[$i].'";'."\n";
 1781:             my ($secs,$secstr);
 1782:             if (ref($courseroles->{$items[$i]}) eq 'ARRAY') {
 1783:                 my @sections = sort { $a <=> $b } @{$courseroles->{$items[$i]}};
 1784:                 $secs = join('","',@sections);
 1785:                 $secstr = join(', ',@sections);
 1786:             }
 1787:             $js .= '    rolesections['.$i.'] = new Array("'.$secs.'");'."\n".
 1788:                    '    roleseclist['.$i.'] = "'.$secstr.'";'."\n".
 1789:                    '    numsec['.$i.'] = "'.$seccount->{$items[$i]}.'";'."\n";
 1790:         }
 1791:     }
 1792:     my $output = <<"END";
 1793: <script type="text/javascript">
 1794: function adhocRole(roleitem) {
 1795:     $js
 1796:     var newrole =  document.rolechooser.elements[roleitem].options[document.rolechooser.elements[roleitem].selectedIndex].value;
 1797:     if (newrole == '') {
 1798:         return; 
 1799:     } 
 1800:     var fullrole = newrole+'./$cdom/$cnum';
 1801:     var selidx = '';
 1802:     for (var i=0; i<rolenames.length; i++) {
 1803:         if (rolenames[i] == newrole) {
 1804:             selidx = i;
 1805:         }
 1806:     }
 1807:     var secok = 1;
 1808:     var secchoice = '';
 1809:     if (selidx >= 0) {
 1810:         if (numsec[selidx] > 1) {
 1811:             secok = 0;
 1812:             var numrolesec = rolesections[selidx].length;
 1813:             var msgidx = numsec[selidx] - numrolesec;
 1814:             secchoice = prompt("$lt{'this'}\\n"+secpick[msgidx]+"\\n$lt{'avai'} "+roleseclist[selidx],"");
 1815:             if (secchoice == '') {
 1816:                 if (msgidx > 0) {
 1817:                     secok = 1;
 1818:                 }
 1819:             } else {
 1820:                 for (var j=0; j<rolesections[selidx].length; j++) {
 1821:                     if (rolesections[selidx][j] == secchoice) {
 1822:                         secok = 1;
 1823:                     }
 1824:                 }
 1825:             }
 1826:         } else {
 1827:             if (rolesections[selidx].length == 1) {
 1828:                 secchoice = rolesections[selidx][0];
 1829:             }
 1830:         }
 1831:     }
 1832:     if (secok == 1) {
 1833:         if (secchoice != '') {
 1834:             fullrole += '/'+secchoice;
 1835:         }
 1836:     } else {
 1837:         document.rolechooser.elements[roleitem].selectedIndex = 0;
 1838:         if (secchoice != null) {
 1839:             alert("$lt{'youe'} \\""+secchoice+"\\".\\n $lt{'plst'}");
 1840:         }
 1841:         return;
 1842:     }
 1843:     if (fullrole == "$env{'request.role'}") {
 1844:         return;
 1845:     }
 1846:     itemid = retrieveIndex('gotorole');
 1847:     if (itemid != -1) {
 1848:         document.rolechooser.elements[itemid].name = fullrole;
 1849:     }
 1850:     document.rolechooser.elements[roleitem].options[document.rolechooser.elements[roleitem].selectedIndex].value = fullrole;
 1851:     document.rolechooser.selectrole.value = '1';
 1852:     document.rolechooser.submit();
 1853:     return;
 1854: }
 1855: 
 1856: function retrieveIndex(item) {
 1857:     for (var i=0;i<document.rolechooser.elements.length;i++) {
 1858:         if (document.rolechooser.elements[i].name == item) {
 1859:             return i;
 1860:         }
 1861:     }
 1862:     return -1;
 1863: }
 1864: 
 1865: 
 1866: </script>
 1867: END
 1868:     return $output;
 1869: }
 1870: 
 1871: 
 1872: # ================================================================ Main Program
 1873: 
 1874: BEGIN {
 1875:     if (! defined($readdesk)) {
 1876: 	{
 1877: 	    my $tabfile = $Apache::lonnet::perlvar{'lonTabDir'}.'/mydesk.tab';
 1878: 	    if ( CORE::open( my $config,"<$tabfile") ) {
 1879: 		while (my $configline=<$config>) {
 1880: 		    $configline=(split(/\#/,$configline))[0];
 1881: 		    $configline=~s/^\s+//;
 1882: 		    chomp($configline);
 1883:                     if ($configline=~/^cat\:/) {
 1884:                        my @entries=split(/\:/,$configline);
 1885:                        $category_positions{$entries[2]}=$entries[1];
 1886:                        $category_names{$entries[2]}=$entries[3];
 1887: 		    } elsif ($configline) {
 1888: 			push(@desklines,$configline);
 1889: 		    }
 1890: 		}
 1891: 		CORE::close($config);
 1892: 	    }
 1893: 	}
 1894: 	$readdesk='done';
 1895:     }
 1896: }
 1897: 
 1898: 1;
 1899: __END__
 1900: 
 1901: 
 1902: 
 1903: 
 1904: 
 1905: 
 1906: 

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