File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.268: download - view: text, annotated - select for diffs
Tue May 26 20:30:28 2009 UTC (15 years ago) by droeschl
Branches: MAIN
CVS tags: HEAD
Resolved some translation issues regarding breadcrumbs.

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

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