File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.281: download - view: text, annotated - select for diffs
Tue Sep 8 20:56:46 2009 UTC (14 years, 8 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Consistent wording.
  - Eliminate the word 'Navigate'.
  - Use 'supplemental docs' more widely.
- Localization files will require updates.

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

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