File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.253: download - view: text, annotated - select for diffs
Thu Feb 26 21:56:59 2009 UTC (15 years, 3 months ago) by kaisler
Branches: MAIN
CVS tags: HEAD
change the style of the top-level menu

Kaisler & Kalberlah

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

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