File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.244: download - view: text, annotated - select for diffs
Wed Nov 19 19:43:08 2008 UTC (15 years, 6 months ago) by jms
Branches: MAIN
CVS tags: version_2_9_X, HEAD
Added POD comments and documentation

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

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