File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.244.2.3: download - view: text, annotated - select for diffs
Thu Aug 13 13:52:01 2009 UTC (14 years, 9 months ago) by raeburn
Branches: version_2_9_X
- Backport 1.277.

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

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