File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.140: download - view: text, annotated - select for diffs
Tue Dec 7 23:59:52 2004 UTC (19 years, 5 months ago) by albertel
Branches: MAIN
CVS tags: version_1_3_1, version_1_3_0, version_1_2_99_1, HEAD
- PORT would disappear BUG#3685

    1: # The LearningOnline Network with CAPA
    2: # Routines to control the menu
    3: #
    4: # $Id: lonmenu.pm,v 1.140 2004/12/07 23:59:52 albertel 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: package Apache::lonmenu;
   40: 
   41: use strict;
   42: use Apache::lonnet();
   43: use Apache::Constants qw(:common);
   44: use Apache::lonhtmlcommon();
   45: use Apache::loncommon();
   46: use Apache::lonenc();
   47: use Apache::lonlocal;
   48: 
   49: use vars qw(@desklines $readdesk);
   50: 
   51: 
   52: my @inlineremote;
   53: my $font;
   54: my $tabbg;
   55: my $pgbg;
   56: 
   57: # ================================================================ Little texts
   58: 
   59: sub initlittle {
   60:     return &Apache::lonlocal::texthash('ret' => 'Return to Last Location',
   61: 				       'nav' => 'Navigate Contents',
   62: 				       'main' => 'Main Menu',
   63: 				       'launch' => 'Launch Remote Control');
   64: }
   65: 
   66: # ============================= This gets called at the top of the body section
   67: 
   68: sub menubuttons {
   69:     my $forcereg=shift;
   70:     my $target  =shift;
   71:     my $registration=shift;
   72:     my $titletable=shift;
   73:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
   74: 					    ['inhibitmenu']);
   75:     if ($ENV{'form.inhibitmenu'} eq 'yes') { return ''; }
   76: 
   77:     my $navmaps='';
   78:     my $reloadlink='';
   79:     my $escurl=&Apache::lonnet::escape(&Apache::lonenc::check_encrypt($ENV{'request.noversionuri'}));
   80:     my $escsymb=&Apache::lonnet::escape(&Apache::lonenc::check_encrypt($ENV{'request.symb'}));
   81:     if ($ENV{'request.state'} eq 'construct') {
   82:         if (($ENV{'request.noversionuri'} eq '') || (!defined($ENV{'request.noversionuri'}))) {
   83:             my $returnurl = $ENV{'request.filename'};
   84:             $returnurl =~ s:^/home/([^/]+)/public_html/(.*)$:/priv/$1/$2:;
   85:             $escurl = &Apache::lonnet::escape($returnurl);
   86:         }
   87:     }
   88:     if ($ENV{'browser.interface'} eq 'textual') {
   89: # Textual display only
   90: 	my %lt=&initlittle();
   91:         $pgbg='#FFFFFF';
   92:         $tabbg='#FFFFFF';
   93: 	$font='#000000';
   94:         if ($ENV{'request.course.id'}) {
   95: 	    $navmaps=(<<ENDNAV);
   96: <a href="/adm/navmaps?postdata=$escurl&postsymb=$escsymb" target="_top">$lt{'nav'}</a>
   97: ENDNAV
   98:             if (($ENV{'request.noversionuri'}=~/^\/adm\//) &&
   99:          ($ENV{'request.noversionuri'}!~/^\/adm\/wrapper\//) &&
  100:          ($ENV{'request.noversionuri'}!~/^\/adm\/.*\/(smppg|bulletinboard|aboutme)(\?|$)/)) {
  101:                 my $escreload=&Apache::lonnet::escape('return:');
  102:                 $reloadlink=(<<ENDRELOAD);
  103: <a href="/adm/flip?postdata=$escreload" target="_top"><font color="$font">$lt{'ret'}</font></a>
  104: ENDRELOAD
  105:             }
  106:         }
  107:         my $form=&serverform();
  108:         my $utility=&utilityfunctions();
  109: 	my $output=(<<ENDMAINMENU);
  110: <script type="text/javascript">
  111: // BEGIN LON-CAPA Internal
  112: $utility
  113: </script>
  114: <a href="/adm/menu" target="_top">$lt{'main'}</a>
  115: $reloadlink $navmaps<br />
  116: <script type="text/javascript">
  117: // END LON-CAPA Internal
  118: </script>
  119: $form
  120: ENDMAINMENU
  121:         if ($registration) { $output.=&innerregister($forcereg,$target); }
  122: 	return $output."<hr />";
  123:     } elsif ($ENV{'environment.remote'} eq 'off') {
  124: # Remote Control is switched off
  125: # figure out colors
  126: 	my %lt=&initlittle();
  127: 	my $function='student';
  128:         if ($ENV{'request.role'}=~/^(cc|in|ta|ep)/) {
  129: 	    $function='coordinator';
  130:         }
  131: 	if ($ENV{'request.role'}=~/^(su|dc|ad|li)/) {
  132:             $function='admin';
  133:         }
  134:         if (($ENV{'request.role'}=~/^(au|ca)/) ||
  135:             ($ENV{'request.noversionuri'}=~/^(\/priv|\~)/)) {
  136:             $function='author';
  137:         }
  138:         my $domain=&Apache::loncommon::determinedomain();
  139:         $pgbg=&Apache::loncommon::designparm($function.'.pgbg',$domain);
  140:         $tabbg=&Apache::loncommon::designparm($function.'.tabbg',$domain);
  141:         $font=&Apache::loncommon::designparm($function.'.font',$domain);
  142:         my $link=&Apache::loncommon::designparm($function.'.link',$domain);
  143:         my $alink=&Apache::loncommon::designparm($function.'.alink',$domain);
  144:         my $vlink=&Apache::loncommon::designparm($function.'.vlink',$domain);
  145:         my $sidebg=&Apache::loncommon::designparm($function.'.sidebg',$domain);
  146: # Do we have a NAV link?
  147:         if ($ENV{'request.course.id'}) {
  148:         	    $navmaps=(<<ENDNAV);
  149: <td bgcolor="$tabbg">
  150: <a href="javascript:gonav('/adm/navmaps?postdata=$escurl&amp;postsymb=$escsymb')"><font color="$font">$lt{'nav'}</font></a></td>
  151: ENDNAV
  152: 	    if (($ENV{'request.noversionuri'}=~/^\/adm\//) &&
  153:                 ($ENV{'request.noversionuri'}!~/^\/adm\/wrapper\//) &&
  154:          ($ENV{'request.noversionuri'}!~/^\/adm\/.*\/(smppg|bulletinboard|aboutme)(\?|$)/)) {
  155:                 my $escreload=&Apache::lonnet::escape('return:');
  156:                 $reloadlink=(<<ENDRELOAD);
  157: <td bgcolor="$tabbg">
  158: <a href="/adm/flip?postdata=$escreload" target="_top"><font color="$font">$lt{'ret'}</font></a></td>
  159: ENDRELOAD
  160:             }
  161:         }
  162:         my $reg='';
  163:         if ($registration) {
  164:            $reg=&innerregister($forcereg,$target,$titletable);
  165:         }
  166:         my $form=&serverform();
  167: 	my $utility=&utilityfunctions();
  168: 	return (<<ENDINLINEMENU);
  169: <script type="text/javascript">
  170: // BEGIN LON-CAPA Internal
  171: $utility
  172: </script>
  173: <font face="Arial,Helvetica,sans-serif"><table bgcolor="$pgbg" width="100%" border="0" cellpadding="1" cellspacing="1">
  174: <tr>
  175: <td bgcolor="$tabbg">
  176: <a href="/adm/menu" target="_top"><font color="$font">$lt{'main'}</font></a>
  177: </td>
  178: $reloadlink
  179: $navmaps
  180: <td bgcolor="$tabbg">
  181: <a href="/adm/remote?action=launch&amp;url=$escurl" target="_top">
  182: <font color="$font">$lt{'launch'}</font></a></td>
  183: <td bgcolor="$tabbg">
  184: <img align="right" src="/adm/lonIcons/minilogo.gif" />
  185: <b>LON-CAPA</b></td>
  186: $form
  187: </tr>
  188: </table>
  189: </font>
  190: <script type="text/javascript">
  191: // END LON-CAPA Internal
  192: </script>
  193: $reg
  194: ENDINLINEMENU
  195:     } else {
  196: 	return '';
  197:     }
  198: }
  199: 
  200: # ====================================== This gets called in the header section
  201: 
  202: sub registerurl {
  203:     my $forcereg=shift;
  204:     my $target = shift;
  205:     my $result = '';
  206:     if ($ENV{'request.noversionuri'} eq '/res/adm/pages/menu.html') { return ''; }
  207:     my $force_title='';
  208:     if ($ENV{'request.state'} eq 'construct') {
  209: 	$force_title=&Apache::lonxml::display_title();
  210:     }
  211:     if ($target eq 'edit') {
  212:         $result .="<script type=\"text/javascript\">\n".
  213:             "if (typeof swmenu != 'undefined') {swmenu.currentURL=null;}\n".
  214:             &Apache::loncommon::browser_and_searcher_javascript().
  215:                 "\n</script>\n";
  216:     }
  217:     if (($ENV{'browser.interface'} eq 'textual') ||
  218:         ($ENV{'environment.remote'} eq 'off') ||
  219:         ((($ENV{'request.publicaccess'}) || 
  220:          (!&Apache::lonnet::is_on_map(
  221: 	   &Apache::lonnet::unescape($ENV{'request.noversionuri'})))) &&
  222:         (!$forcereg))) {
  223:  	return $result.
  224:           '<script type="text/javascript">function LONCAPAreg(){;} function LONCAPAstale(){}</script>'.$force_title;
  225:     }
  226: # Graphical display after login only
  227:     if ($Apache::lonxml::registered && !$forcereg) { return ''; }
  228:     if ($target ne 'edit') {
  229: 	$result.=&innerregister($forcereg,$target);
  230:     }
  231:     return $result.$force_title;
  232: }
  233: 
  234: # =========== This gets called in order to register a URL, both with the Remote
  235: # =========== and in the body of the document
  236: 
  237: sub innerregister {
  238:     my $forcereg=shift;
  239:     my $target = shift;
  240:     my $titletable = shift;
  241:     my $result = '';
  242:     my ($uname,$thisdisfn);
  243:     my $const_space = ($ENV{'request.state'} eq 'construct');
  244:     my $is_const_dir = 0;
  245: 
  246:     if ($ENV{'request.noversionuri'} eq '/res/adm/pages/menu.html') { return ''; }
  247: 
  248:     $Apache::lonxml::registered=1;
  249: 
  250:     my $textinter=($ENV{'browser.interface'} eq 'textual');
  251:     my $noremote=($ENV{'environment.remote'} eq 'off');
  252:     
  253:     my $textual=($textinter || $noremote);
  254: 
  255:     @inlineremote=();
  256:     undef @inlineremote;
  257: 
  258:     my $reopen=&Apache::lonmenu::reopenmenu();
  259: 
  260:     my $newmail='';
  261:     if ($noremote) {
  262: 	$newmail='<font face="Arial,Helvetica,sans-serif"><table bgcolor="'.$pgbg.'" border="0" cellspacing="1" cellpadding="1" width="100%"><tr><td bgcolor="'.$tabbg.'">';
  263:     }
  264:     if (($textual) && ($ENV{'request.symb'}) && ($ENV{'request.course.id'})) {
  265: 	my ($mapurl,$rid,$resurl)=&Apache::lonnet::decode_symb($ENV{'request.symb'});
  266:         $newmail.=$ENV{'course.'.$ENV{'request.course.id'}.'.description'};
  267:         my $maptitle=&Apache::lonnet::gettitle($mapurl);
  268: 	my $restitle=&Apache::lonnet::gettitle($resurl);
  269:         if ($maptitle && $maptitle ne 'default.sequence') {
  270: 	    $newmail.=', '.$maptitle;
  271:         }
  272:         if ($restitle) {
  273: 	    $newmail.=': '.$restitle;
  274:         }
  275:         $newmail.='&nbsp;&nbsp;&nbsp;';
  276:     }
  277:     if (&Apache::lonmsg::newmail()) { 
  278:        $newmail=($textual?
  279:  '<b><a href="/adm/communicate" target="_top">You have new messages</a></b><br />':
  280:                           'swmenu.setstatus("you have","messages");');
  281:     }
  282:     if ($ENV{'request.state'} eq 'construct') {
  283:         $newmail = $titletable;
  284:     }
  285:     if ($noremote) {
  286: 	$newmail.='</td></tr></table></font>';
  287:     }
  288:     my $timesync=($textual?'':'swmenu.syncclock(1000*'.time.');');
  289:     my $tablestart=($noremote?'<font face="Arial,Helvetica,sans-serif"><table bgcolor="'.$pgbg.'" border="0" cellspacing="1" cellpadding="1" width="100%">':'').($textinter?'<br /><a href="#content">'.&mt('Skip to Content').'</a><br />':'');
  290:     my $tableend=($noremote?'</table></font>':'').($textinter?'<a name="content" />':'');
  291: # =============================================================================
  292: # ============================ This is for URLs that actually can be registered
  293:     if (($ENV{'request.noversionuri'}!~/^\/(res\/)*adm\//) || ($forcereg)) {
  294: # -- This applies to homework problems for users with grading privileges
  295: 	my $crs='/'.$ENV{'request.course.id'};
  296: 	if ($ENV{'request.course.sec'}) {
  297: 	    $crs.='_'.$ENV{'request.course.sec'};
  298: 	}
  299: 	$crs=~s/\_/\//g;
  300: 
  301:         my $hwkadd='';
  302:         if ($ENV{'request.filename'}=~/\.(problem|exam|quiz|assess|survey|form)$/) {
  303: 	    if (&Apache::lonnet::allowed('vgr',$crs)) {
  304: 		$hwkadd.=&switch('','',7,1,'subm.gif','view sub-[_1]','missions[_1]',
  305:                        "gocmd('/adm/grades','submission')",
  306: 		       'View user submissions for this assessment resource');
  307:             }
  308: 	    if (&Apache::lonnet::allowed('mgr',$crs)) {
  309: 		$hwkadd.=&switch('','',7,2,'pgrd.gif','problem[_1]','grades[_3]',
  310:                        "gocmd('/adm/grades','gradingmenu')",
  311:                        'Modify user grades for this assessment resource');
  312:             }
  313: 	}
  314: 	if (&Apache::lonnet::allowed('opa',$crs)) {
  315: 	    $hwkadd.=&switch('','',7,3,'pparm.gif','problem[_2]','parms[_2]',
  316: 			     "gocmd('/adm/parmset','set')",
  317: 			     'Modify deadlines, etc, for this resource');
  318: 	}
  319: # -- End Homework
  320:         ###
  321:         ### Determine whether or not to display the 'cstr' button for this
  322:         ### resource
  323:         ###
  324:         my $editbutton = '';
  325:         if ($ENV{'user.author'}) {
  326:             if ($ENV{'request.role'}=~/^(ca|au)/) {
  327:                 # Set defaults for authors
  328:                 my ($top,$bottom) = ('con-','struct');
  329:                 my $action = "go('/priv/".$ENV{'user.name'}."');";
  330:                 my $cadom  = $ENV{'request.role.domain'};
  331:                 my $caname = $ENV{'user.name'};
  332:                 my $desc = "Enter my resource construction space";
  333:                 # Set defaults for co-authors
  334:                 if ($ENV{'request.role'} =~ /^ca/) { 
  335:                     ($cadom,$caname)=($ENV{'request.role'}=~/(\w+)\/(\w+)$/);
  336:                     ($top,$bottom) = ('co con-','struct');
  337:                     $action = "go('/priv/".$caname."');";
  338:                     $desc = "Enter construction space as co-author";
  339:                 }
  340:                 # Check that we are on the correct machine
  341:                 my $home = &Apache::lonnet::homeserver($caname,$cadom);
  342: 		my $allowed=0;
  343: 		my @ids=&Apache::lonnet::current_machine_ids();
  344: 		foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
  345: 		if (!$allowed) {
  346: 		    $editbutton=&switch('','',6,1,$top,,$bottom,$action,$desc);
  347:                 }
  348:             }
  349:             ##
  350:             ## Determine if user can edit url.
  351:             ##
  352:             my $cfile='';
  353:             my $cfuname='';
  354:             my $cfudom='';
  355:             if ($ENV{'request.filename'}) {
  356:                 my $file=&Apache::lonnet::declutter($ENV{'request.filename'});
  357:                 $file=~s/^(\w+)\/(\w+)/\/priv\/$2/;
  358:                 # Check that the user has permission to edit this resource
  359:                 ($cfuname,$cfudom)=&Apache::loncacc::constructaccess($file,$1);
  360:                 if (defined($cfudom)) {
  361: 		    my $home=&Apache::lonnet::homeserver($cfuname,$cfudom);
  362: 		    my $allowed=0;
  363: 		    my @ids=&Apache::lonnet::current_machine_ids();
  364: 		    foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
  365: 		    if ($allowed) {
  366:                         $cfile=$file;
  367:                     }
  368:                 }
  369:             }        
  370:             # Finally, turn the button on or off
  371:             if ($cfile && !$const_space) {
  372:                 $editbutton=&switch
  373:                     ('','',6,1,'cstr.gif','edit[_1]','resource[_2]',
  374:                      "go('".$cfile."');","Edit this resource");
  375:             } elsif ($editbutton eq '') {
  376:                 $editbutton=&clear(6,1);
  377:             }
  378:         }
  379:         ###
  380:         ###
  381: # Prepare the rest of the buttons
  382:         my $menuitems;
  383:         if ($const_space) {
  384: 	    my ($uname,$thisdisfn) =
  385: 		($ENV{'request.filename'}=~m|^/home/([^/]+)/public_html/(.*)|);
  386:             my $currdir = '/priv/'.$uname.'/'.$thisdisfn;
  387:             if ($currdir =~ m-/$-) {
  388:                 $is_const_dir = 1;
  389:             } else {
  390:                 $currdir =~ s#[^/]+$##;
  391:                 $menuitems=(<<ENDMENUITEMS);
  392: s&6&1&list.gif&list[_1]&dir[_1]&golist('$currdir')&List current directory
  393: s&6&2&rtrv.gif&retrieve[_1]&version[_1]&gocstr('/adm/retrieve','/~$uname/$thisdisfn')&Retrieve old version
  394: s&6&3&pub.gif&publish[_1]&resource[_1]&gocstr('/adm/publish','/~$uname/$thisdisfn')&Publish this resource
  395: s&7&1&del.gif&delete[_1]&resource[_2]&gocstr('/adm/cfile?action=delete','/~$uname/$thisdisfn')&Delete this resource
  396: s&7&2&prt.gif&prepare[_1]&printout[_1]&gocstr('/adm/printout','/~$uname/$thisdisfn')&Prepare a printable document
  397: ENDMENUITEMS
  398:             }
  399:         } elsif (defined($ENV{'request.course.id'})) {
  400: 	    $menuitems=(<<ENDMENUITEMS);
  401: c&3&1
  402: s&2&1&back.gif&backward[_1]&&gopost('/adm/flip','back:'+currentURL)&Go to the previous resource in the course sequence&1
  403: s&2&3&forw.gif&forward[_1]&&gopost('/adm/flip','forward:'+currentURL)&Go to the next resource in the course sequence&3
  404: c&6&3
  405: c&8&1
  406: c&8&2
  407: s&8&3&prt.gif&prepare[_1]&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
  408: s&9&1&sbkm.gif&set[_1]&bookmark[_2]&set_bookmark()&Set a bookmark for this resource&2
  409: s&9&3&anot.gif&anno-[_1]&tations[_1]&annotate()&Make notes and annotations about this resource&2
  410: ENDMENUITEMS
  411:             unless ($ENV{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme)(\?|$)/) {
  412: 	        $menuitems.=(<<ENDREALRES);
  413: s&6&3&catalog.gif&catalog[_1]&info[_1]&catalog_info()&Show catalog information
  414: s&8&1&eval.gif&evaluate[_1]&this[_1]&gopost('/adm/evaluate',currentURL,1)&Provide my evaluation of this resource
  415: 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
  416: ENDREALRES
  417: 	    }
  418:         }
  419:         my $buttons='';
  420:         foreach (split(/\n/,$menuitems)) {
  421: 	    my ($command,@rest)=split(/\&/,$_);
  422:             if ($command eq 's') {
  423: 		$buttons.=&switch('','',@rest);
  424:             } else {
  425:                 $buttons.=&clear(@rest);
  426:             }
  427:         }
  428:         if ($textual) {
  429: # Registered, textual output
  430: 	    my $inlinebuttons='';
  431: 
  432: 	    if ($ENV{'browser.interface'} eq 'textual') {
  433: 		$inlinebuttons=
  434:                         join('',map { (defined($_)?$_:'') } @inlineremote);
  435: 	    } else {
  436: 		$inlinebuttons=(<<ENDINLINE);
  437: <tr><td>$inlineremote[21]</td><td>&nbsp;</td><td>$inlineremote[23]</td></tr>
  438: <tr><td>$inlineremote[61]</td><td>$inlineremote[62]</td><td>$inlineremote[63]</td></tr>
  439: <tr><td>$inlineremote[71]</td><td>$inlineremote[72]</td><td>$inlineremote[73]</td></tr>
  440: <tr><td>$inlineremote[81]</td><td>$inlineremote[82]</td><td>$inlineremote[83]</td></tr>
  441: <tr><td>$inlineremote[91]</td><td>$inlineremote[92]</td><td>$inlineremote[93]</td></tr>
  442: ENDINLINE
  443: 	    }
  444:             if ($const_space && $is_const_dir) {
  445:                 $inlinebuttons = '';
  446:             }
  447: 	    $result =(<<ENDREGTEXT);
  448: <script type="text/javascript">
  449: // BEGIN LON-CAPA Internal
  450: </script>
  451: $timesync
  452: $newmail
  453: $tablestart
  454: $inlinebuttons
  455: $tableend
  456: <script type="text/javascript">
  457: // END LON-CAPA Internal
  458: </script>
  459: 
  460: ENDREGTEXT
  461: # Registered, graphical output
  462:         } else {
  463: 	    my $requri=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$ENV{'request.noversionuri'}))[0]));
  464: 	    $requri=&Apache::lonenc::check_encrypt(&Apache::lonnet::unescape($requri));
  465: 	    my $cursymb=&Apache::lonenc::check_encrypt($ENV{'request.symb'});
  466: 	    my $navstatus=&get_nav_status();
  467: 	    my $clearcstr;
  468: 	    if ($ENV{'user.adv'}) { $clearcstr='clearbut(6,1)'; }
  469: 	    $result = (<<ENDREGTHIS);
  470:      
  471: <script type="text/javascript">
  472: // BEGIN LON-CAPA Internal
  473: var swmenu=null;
  474: 
  475:     function LONCAPAreg() {
  476: 	  swmenu=$reopen;
  477:           swmenu.clearTimeout(swmenu.menucltim);
  478:           $timesync
  479:           $newmail
  480:           $buttons
  481: 	  swmenu.currentURL="$requri";
  482:           swmenu.reloadURL=swmenu.currentURL+window.location.search;
  483:           swmenu.currentSymb="$cursymb";
  484:           swmenu.reloadSymb="$cursymb";
  485:           swmenu.currentStale=0;
  486: 	  $navstatus
  487:           $hwkadd
  488:           $editbutton
  489:     }
  490: 
  491:     function LONCAPAstale() {
  492: 	  swmenu=$reopen
  493:           swmenu.currentStale=1;
  494:           if (swmenu.reloadURL!='' && swmenu.reloadURL!= null) { 
  495:              swmenu.switchbutton
  496:              (3,1,'reload.gif','return','location','go(reloadURL)','Return to the last known location in the course sequence');
  497: 	  }
  498:           swmenu.clearbut(7,1);
  499:           swmenu.clearbut(7,2);
  500:           swmenu.clearbut(7,3);
  501:           swmenu.menucltim=swmenu.setTimeout(
  502:  'clearbut(2,1);clearbut(2,3);clearbut(8,1);clearbut(8,2);clearbut(8,3);'+
  503:  'clearbut(9,1);clearbut(9,3);clearbut(6,3);$clearcstr',
  504: 			  2000);
  505:       }
  506: 
  507: // END LON-CAPA Internal
  508: </script>
  509: ENDREGTHIS
  510:         }
  511: # =============================================================================
  512:     } else {
  513: # ========================================== This can or will not be registered
  514:         if ($textual) {
  515: # Not registered, textual
  516: 	    $result= (<<ENDDONOTREGTEXT);
  517: ENDDONOTREGTEXT
  518:         } else {
  519: # Not registered, graphical
  520:            $result = (<<ENDDONOTREGTHIS);
  521: 
  522: <script type="text/javascript">
  523: // BEGIN LON-CAPA Internal
  524: var swmenu=null;
  525: 
  526:     function LONCAPAreg() {
  527: 	  swmenu=$reopen
  528:           $timesync
  529:           swmenu.currentStale=1;
  530:           swmenu.clearbut(2,1);
  531:           swmenu.clearbut(2,3);
  532:           swmenu.clearbut(8,1);
  533:           swmenu.clearbut(8,2);
  534:           swmenu.clearbut(8,3);
  535:           if (swmenu.currentURL) {
  536:              swmenu.switchbutton
  537:               (3,1,'reload.gif','return','location','go(currentURL)');
  538:  	  } else {
  539: 	      swmenu.clearbut(3,1);
  540:           }
  541:     }
  542: 
  543:     function LONCAPAstale() {
  544:     }
  545: 
  546: // END LON-CAPA Internal
  547: </script>
  548: ENDDONOTREGTHIS
  549:        }
  550: # =============================================================================
  551:     }
  552:     return $result;
  553: }
  554: 
  555: sub loadevents() {
  556:     if ($ENV{'request.state'} eq 'construct' ||
  557: 	$ENV{'request.noversionuri'} eq '/res/adm/pages/menu.html') { return ''; }
  558:     return 'LONCAPAreg();';
  559: }
  560: 
  561: sub unloadevents() {
  562:     if ($ENV{'request.state'} eq 'construct' ||
  563: 	$ENV{'request.noversionuri'} eq '/res/adm/pages/menu.html') { return ''; }
  564:     return 'LONCAPAstale();';
  565: }
  566: 
  567: # ============================================================= Start up remote
  568: 
  569: sub startupremote {
  570:     my ($lowerurl)=@_;
  571:     if (($ENV{'browser.interface'} eq 'textual') ||
  572:         ($ENV{'environment.remote'} eq 'off')) {
  573:      return ('<meta HTTP-EQUIV="Refresh" CONTENT="0.5; url='.$lowerurl.'" />');
  574:     }
  575: #
  576: # The Remote actually gets launched!
  577: #
  578:     my $configmenu=&rawconfig();
  579:     my $esclowerurl=&Apache::lonnet::escape($lowerurl);
  580:     my $message=&mt('"Waiting for Remote Control window to load: "+[_1]','waited');
  581:     return(<<ENDREMOTESTARTUP);
  582: <script type="text/javascript">
  583: var timestart;
  584: function wheelswitch() {
  585:     if (typeof(document.wheel) != 'undefined') {
  586: 	if (typeof(document.wheel.spin) != 'undefined') {
  587: 	    var date=new Date();
  588: 	    var waited=Math.round(30-((date.getTime()-timestart)/1000));
  589: 	    document.wheel.spin.value=$message;
  590: 	}
  591:     }
  592:    if (window.status=='|') { 
  593:       window.status='/'; 
  594:    } else {
  595:       if (window.status=='/') {
  596:          window.status='-';
  597:       } else {
  598:          if (window.status=='-') { 
  599:             window.status='\\\\'; 
  600:          } else {
  601:             if (window.status=='\\\\') { window.status='|'; }
  602:          }
  603:       }
  604:    } 
  605: }
  606: 
  607: // ---------------------------------------------------------- The wait function
  608: var canceltim;
  609: function wait() {
  610:    if ((menuloaded==1) || (tim==1)) {
  611:       window.status='Done.';
  612:       if (tim==0) {
  613:          clearTimeout(canceltim);
  614:          $configmenu
  615:          window.location='$lowerurl';  
  616:       } else {
  617: 	  window.location='/adm/remote?action=collapse&url=$esclowerurl';
  618:       }
  619:    } else {
  620:       wheelswitch();
  621:       setTimeout('wait();',200);
  622:    }
  623: }
  624: 
  625: function main() {
  626:    canceltim=setTimeout('tim=1;',30000);
  627:    window.status='-';
  628:    var date=new Date();
  629:    timestart=date.getTime();
  630:    wait();
  631: }
  632: 
  633: </script>
  634: ENDREMOTESTARTUP
  635: }
  636: 
  637: sub setflags() {
  638:     return(<<ENDSETFLAGS);
  639: <script type="text/javascript">
  640:     menuloaded=0;
  641:     tim=0;
  642: </script>
  643: ENDSETFLAGS
  644: }
  645: 
  646: sub maincall() {
  647:     if (($ENV{'browser.interface'} eq 'textual') ||
  648:         ($ENV{'environment.remote'} eq 'off')) { return ''; }
  649:     return(<<ENDMAINCALL);
  650: <script type="text/javascript">
  651:     main();
  652: </script>
  653: ENDMAINCALL
  654: }
  655: 
  656: sub load_remote_msg {
  657:     my ($lowerurl)=@_;
  658: 
  659:     if (($ENV{'browser.interface'} eq 'textual') ||
  660:         ($ENV{'environment.remote'} eq 'off')) { return ''; }
  661: 
  662:     my $esclowerurl=&Apache::lonnet::escape($lowerurl);
  663:     my $link=&mt('<a href="[_1]">Continue</a> on in Inline Menu mode',
  664: 		    "/adm/remote?action=collapse?url=$esclowerurl");
  665:     return(<<ENDREMOTEFORM);
  666: <p>
  667: <form name="wheel">
  668: <input name="spin" type="text" size="60" />
  669: </form>
  670: </p>
  671: <p>$link</p>
  672: ENDREMOTEFORM
  673: }
  674: # ================================================================= Reopen menu
  675: 
  676: sub reopenmenu {
  677:    if (($ENV{'browser.interface'} eq 'textual') ||
  678:        ($ENV{'environment.remote'} eq 'off')) { return ''; }
  679:    my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
  680:    my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
  681:    return('window.open('.$nothing.',"'.$menuname.'","",false);');
  682: } 
  683: 
  684: # =============================================================== Open the menu
  685: 
  686: sub open {
  687:     my $returnval='';
  688:     if (($ENV{'browser.interface'} eq 'textual') ||
  689:         ($ENV{'environment.remote'} eq 'off')) { 
  690: 	return '<script type="text/javascript">self.name="loncapaclient";</script>';
  691:     }
  692:     my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
  693:     unless (shift eq 'unix') {
  694: # resizing does not work on linux because of virtual desktop sizes
  695:        $returnval.=(<<ENDRESIZE);
  696: if (window.screen) {
  697:     self.resizeTo(screen.availWidth-215,screen.availHeight-55);
  698:     self.moveTo(190,15);
  699: }
  700: ENDRESIZE
  701:     }
  702:     $returnval.=(<<ENDOPEN);
  703: window.status='Opening LON-CAPA Remote Control';
  704: var menu=window.open("/res/adm/pages/menu.html","$menuname",
  705: "height=350,width=150,scrollbars=no,menubar=no,top=5,left=5,screenX=5,screenY=5");
  706: self.name='loncapaclient';
  707: ENDOPEN
  708:     return '<script type="text/javascript">'.$returnval.'</script>';
  709: }
  710: 
  711: 
  712: # ================================================================== Raw Config
  713: 
  714: sub clear {
  715:     my ($row,$col)=@_;
  716:     unless (($ENV{'browser.interface'} eq 'textual') ||
  717:             ($ENV{'environment.remote'} eq 'off')) {
  718:        return "\n".qq(window.status+='.';swmenu.clearbut($row,$col););
  719:    } else { 
  720:        $inlineremote[10*$row+$col]='';
  721:        return ''; 
  722:    }
  723: }
  724: 
  725: # ============================================ Switch a button or create a link
  726: # Switch acts on the javascript that is executed when a button is clicked.  
  727: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
  728: 
  729: sub switch {
  730:     my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$nobreak)=@_;
  731:     $act=~s/\$uname/$uname/g;
  732:     $act=~s/\$udom/$udom/g;
  733:     $top=&mt($top);
  734:     $bot=&mt($bot);
  735:     $desc=&mt($desc);
  736:     $img=&mt($img);
  737:     unless (($ENV{'browser.interface'} eq 'textual')  ||
  738:             ($ENV{'environment.remote'} eq 'off')) {
  739: # Remote
  740:        return "\n".
  741:  qq(window.status+='.';swmenu.switchbutton($row,$col,"$img","$top","$bot","$act","$desc"););
  742:    } elsif ($ENV{'browser.interface'} eq 'textual') {
  743: # Accessibility
  744:        if ($nobreak==2) { return ''; }
  745:        my $text=$top.' '.$bot;
  746:        $text=~s/\s*\-\s*//gs;
  747:        if ($nobreak) {
  748: 	   $inlineremote[10*$row+$col]=
  749: 	       '<a href="javascript:'.$act.';">'.$text.'</a>';
  750:        } else {
  751: 	   $inlineremote[10*$row+$col]="\n<br />".
  752: 	       $desc.' <a href="javascript:'.$act.';">'.$text.'</a>';
  753:        }
  754:    } else {
  755: # Inline Remote
  756:        if ($nobreak==2) { return ''; }
  757:        my $text=$top.' '.$bot;
  758:        $text=~s/\s*\-\s*//gs;
  759: 
  760:        my $lonhttpdPort=$Apache::lonnet::perlvar{'lonhttpdPort'};
  761:        if (!defined($lonhttpdPort)) { $lonhttpdPort='8080'; }
  762:        my $pic=
  763: 	   '<img border="0" alt="'.$text.'" src="http://'.$ENV{'HTTP_HOST'}.
  764: 	   ':'.$lonhttpdPort.'/res/adm/pages/'.$img.'" align="'.
  765: 	   ($nobreak==3?'right':'left').'" />';
  766:        if (($ENV{'browser.interface'} eq 'textual') || ($ENV{'browser.interface'} eq 'faketextual')) {
  767: # Accessibility
  768: 	   if ($nobreak==3) {
  769: 	       $inlineremote[10*$row+$col]="\n".
  770: 		   '<td width="40%" align="right"><font color="'.$font.'" size="+1">'.$text.
  771: 		   '</font></td><td width="10%" align="right" bgcolor="'.$tabbg.'">'.
  772: 		   '<a href="javascript:'.$act.';">'.$pic.'</a></td></tr>';
  773: 	   } elsif ($nobreak) {
  774: 	       $inlineremote[10*$row+$col]="\n<tr>".
  775: 		   '<td width="10%" align="left" bgcolor="'.$tabbg.'">'.
  776: 		   '<a href="javascript:'.$act.';">'.$pic.
  777: 		   '</a></td><td width="40%" align="left"><font color="'.$font.'" size="+1">'.$text.'</font></td>';
  778: 	   } else {
  779: 	       $inlineremote[10*$row+$col]="\n<tr>".
  780: 		   '<td width="10%" align="left" bgcolor="'.$tabbg.'">'.
  781: 		   '<a href="javascript:'.$act.';">'.$pic.
  782: 		   '</a></td><td colspan="3"><font color="'.$font.'">'.$desc.
  783: 		   '</font></td></tr>';       
  784: 	   }
  785:        } else {
  786: # Inline Menu
  787: 	   $inlineremote[10*$row+$col]=
  788: 		   '<a href="javascript:'.$act.';">'.$pic.
  789: 		   '</a><font color="'.$font.'" size="2">'.$desc.
  790: 		   '</font>';
  791:        }
  792:    }
  793:     return '';
  794: }
  795: 
  796: sub secondlevel {
  797:     my $output='';
  798:     my 
  799:     ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc)=@_;
  800:     if ($prt eq 'any') {
  801: 	   $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
  802:     } elsif ($prt=~/^r(\w+)/) {
  803:         if ($rol eq $1) {
  804:            $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
  805:         }
  806:     }
  807:     return $output;
  808: }
  809: 
  810: sub openmenu {
  811:     my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
  812:     if (($ENV{'browser.interface'} eq 'textual') ||
  813:         ($ENV{'environment.remote'} eq 'off')) { return ''; }
  814:     my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
  815:     return "window.open(".$nothing.",'".$menuname."');";
  816: }
  817: 
  818: sub inlinemenu {
  819:     @inlineremote=();
  820:     undef @inlineremote;
  821:     &rawconfig(1);
  822:     return join('',map { (defined($_)?$_:'') } @inlineremote);
  823: }
  824: 
  825: sub rawconfig {
  826:     my $textualoverride=shift;
  827:     my $output='';
  828:     unless (($ENV{'browser.interface'} eq 'textual') ||
  829:             ($ENV{'environment.remote'} eq 'off')) {
  830:        $output.=
  831:  "window.status='Opening Remote Control';var swmenu=".&openmenu().
  832: "\nwindow.status='Configuring Remote Control ';";
  833:     } else {
  834:        unless ($textualoverride) { return ''; }
  835:     }
  836:     my $uname=$ENV{'user.name'};
  837:     my $udom=$ENV{'user.domain'};
  838:     my $adv=$ENV{'user.adv'};
  839:     my $author=$ENV{'user.author'};
  840:     my $crs='';
  841:     if ($ENV{'request.course.id'}) {
  842:        $crs='/'.$ENV{'request.course.id'};
  843:        if ($ENV{'request.course.sec'}) {
  844: 	   $crs.='_'.$ENV{'request.course.sec'};
  845:        }
  846:        $crs=~s/\_/\//g;
  847:     }
  848:     my $pub=($ENV{'request.state'} eq 'published');
  849:     my $con=($ENV{'request.state'} eq 'construct');
  850:     my $rol=$ENV{'request.role'};
  851:     my $requested_domain = $ENV{'request.role.domain'};
  852:     foreach (@desklines) {
  853:         my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc)=split(/\:/,$_);
  854:         $prt=~s/\$uname/$uname/g;
  855:         $prt=~s/\$udom/$udom/g;
  856:         $prt=~s/\$crs/$crs/g; 
  857:         $prt=~s/\$requested_domain/$requested_domain/g;
  858:         if ($pro eq 'clear') {
  859: 	    $output.=&clear($row,$col);
  860:         } elsif ($pro eq 'any') {
  861:                $output.=&secondlevel(
  862: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
  863: 	} elsif ($pro eq 'smp') {
  864:             unless ($adv) {
  865:                $output.=&secondlevel(
  866:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
  867:             }
  868:         } elsif ($pro eq 'adv') {
  869:             if ($adv) {
  870:                $output.=&secondlevel(
  871: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
  872:             }
  873:         } elsif (($pro=~/^p(\w+)/) && ($prt)) {
  874: 	    if (&Apache::lonnet::allowed($1,$prt)) {
  875:                $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
  876:             }
  877:         } elsif ($pro eq 'course') {
  878:             if ($ENV{'request.course.fn'}) {
  879:                $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
  880: 	    }
  881:         } elsif ($pro =~ /^courseenv_(.*)$/) {
  882:             my $key = $1;
  883:             if ($ENV{'course.'.$ENV{'request.course.id'}.'.'.$key}) {
  884:                 $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
  885:             }
  886:         } elsif ($pro =~ /^course_(.*)$/) {
  887:             # Check for permissions inside of a course
  888:             if (($ENV{'request.course.id'}) &&
  889:                 (&Apache::lonnet::allowed($1,$ENV{'request.course.id'}.
  890:             ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))
  891:                  )) {
  892:                 $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
  893: 	    }
  894:         } elsif ($pro eq 'author') {
  895:             if ($author) {
  896:                 if ((($prt eq 'rca') && ($ENV{'request.role'}=~/^ca/)) ||
  897:                     (($prt eq 'rau') && ($ENV{'request.role'}=~/^au/))) {
  898:                     # Check that we are on the correct machine
  899:                     my $cadom=$requested_domain;
  900:                     my $caname=$ENV{'user.name'};
  901:                     if ($prt eq 'rca') {
  902: 		       ($cadom,$caname)=
  903:                                ($ENV{'request.role'}=~/(\w+)\/(\w+)$/);
  904:                     }                       
  905:                     $act =~ s/\$caname/$caname/g;
  906:                     my $home = &Apache::lonnet::homeserver($caname,$cadom);
  907: 		    my $allowed=0;
  908: 		    my @ids=&Apache::lonnet::current_machine_ids();
  909: 		    foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
  910: 		    if ($allowed) {
  911:                         $output.=switch($caname,$cadom,
  912:                                         $row,$col,$img,$top,$bot,$act,$desc);
  913:                     }
  914:                 }
  915:             }
  916:         }
  917:     }
  918:     unless (($ENV{'browser.interface'} eq 'textual') ||
  919:             ($ENV{'environment.remote'} eq 'off')) {
  920:        $output.="\nwindow.status='Synchronizing Time';swmenu.syncclock(1000*".time.");\nwindow.status='Remote Control Configured.';";
  921:        if (&Apache::lonmsg::newmail()) { 
  922: 	   $output.='swmenu.setstatus("you have","messages");';
  923:        }
  924:     }
  925: 
  926:     return $output;
  927: }
  928: 
  929: # ======================================================================= Close
  930: 
  931: sub close {
  932:     if (($ENV{'browser.interface'} eq 'textual') ||
  933:         ($ENV{'environment.remote'} eq 'off')) { return ''; }
  934:     my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
  935:     return(<<ENDCLOSE);
  936: <script type="text/javascript">
  937: window.status='Accessing Remote Control';
  938: menu=window.open("/adm/rat/empty.html","$menuname",
  939:                  "height=350,width=150,scrollbars=no,menubar=no");
  940: window.status='Disabling Remote Control';
  941: menu.active=0;
  942: menu.autologout=0;
  943: window.status='Closing Remote Control';
  944: menu.close();
  945: window.status='Done.';
  946: </script>
  947: ENDCLOSE
  948: }
  949: 
  950: # ====================================================================== Footer
  951: 
  952: sub footer {
  953: 
  954: }
  955: 
  956: sub nav_control_js {
  957:     my $nav=($ENV{'environment.remotenavmap'} eq 'on');
  958:     return (<<NAVCONTROL);
  959:     var w_loncapanav_flag="$nav";
  960: 
  961: 
  962: function gonav(url) {
  963:    if (w_loncapanav_flag != 1) {
  964:       gopost(url,'');
  965:    }  else {
  966:       navwindow=window.open(url,
  967:                   "loncapanav","height=600,width=400,scrollbars=1"); 
  968:    }
  969: }
  970: NAVCONTROL
  971: }
  972: 
  973: sub utilityfunctions {
  974:     my $caller = shift;
  975:     unless (($ENV{'browser.interface'} eq 'textual')  ||
  976:         ($ENV{'environment.remote'} eq 'off') || ($caller eq '/adm/menu')) { return ''; }
  977:     my $currenturl=&Apache::lonenc::check_encrypt($ENV{'request.noversionuri'});
  978:     
  979:     my $currentsymb=&Apache::lonenc::check_encrypt($ENV{'request.symb'});
  980:     my $nav_control=&nav_control_js();
  981: return (<<ENDUTILITY)
  982: 
  983:     var currentURL="$currenturl";
  984:     var reloadURL="$currenturl";
  985:     var currentSymb="$currentsymb";
  986: 
  987: $nav_control
  988: 
  989: function go(url) {
  990:    if (url!='' && url!= null) {
  991:        currentURL = null;
  992:        currentSymb= null;
  993:        window.location.href=url;
  994:    }
  995: }
  996: 
  997: function gopost(url,postdata) {
  998:    if (url!='') {
  999:       this.document.server.action=url;
 1000:       this.document.server.postdata.value=postdata;
 1001:       this.document.server.command.value='';
 1002:       this.document.server.url.value='';
 1003:       this.document.server.symb.value='';
 1004:       this.document.server.submit();
 1005:    }
 1006: }
 1007: 
 1008: function gocmd(url,cmd) {
 1009:    if (url!='') {
 1010:       this.document.server.action=url;
 1011:       this.document.server.postdata.value='';
 1012:       this.document.server.command.value=cmd;
 1013:       this.document.server.url.value=currentURL;
 1014:       this.document.server.symb.value=currentSymb;
 1015:       this.document.server.submit();
 1016:    }
 1017: }
 1018: 
 1019: function gocstr(url,filename) {
 1020:     if (url == '/adm/cfile?action=delete') {
 1021:         this.document.cstrdelete.filename.value = filename
 1022:         this.document.cstrdelete.submit();
 1023:         return;
 1024:     }
 1025:     if (url == '/adm/printout') {
 1026:         this.document.cstrprint.postdata.value = filename
 1027:         this.document.cstrprint.curseed.value = 0;
 1028:         this.document.cstrprint.problemtype.value = 0;
 1029:         if (this.document.lonhomework) {
 1030:             if ((this.document.lonhomework.rndseed) && (this.document.lonhomework.rndseed.value != null) && (this.document.lonhomework.rndseed.value != '')) {
 1031:                 this.document.cstrprint.curseed.value = this.document.lonhomework.rndseed.value
 1032:             }
 1033:             if (this.document.lonhomework.problemtype) {
 1034:                 for (var i=0; i<this.document.lonhomework.problemtype.options.length; i++) {
 1035:                     if (this.document.lonhomework.problemtype.options[i].selected) {
 1036:                         if (this.document.lonhomework.problemtype.options[i].value != null && this.document.lonhomework.problemtype.options[i].value != '') { 
 1037:                             this.document.cstrprint.problemtype.value = this.document.lonhomework.problemtype.options[i].value
 1038:                         }
 1039:                     }
 1040:                 }
 1041:             }
 1042:         }
 1043:         this.document.cstrprint.submit();
 1044:         return;
 1045:     }
 1046:     if (url !='') {
 1047:         this.document.constspace.filename.value = filename;
 1048:         this.document.constspace.action = url;
 1049:         this.document.constspace.submit();
 1050:     }
 1051: }
 1052: 
 1053: function golist(url) {
 1054:    if (url!='' && url!= null) {
 1055:        currentURL = null;
 1056:        currentSymb= null;
 1057:        top.location.href=url;
 1058:    }
 1059: }
 1060: 
 1061: 
 1062: 
 1063: function catalog_info() {
 1064:    loncatinfo=window.open(window.location.pathname+'.meta',"LONcatInfo",'height=320,width=280,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
 1065: }
 1066: 
 1067: function chat_win() {
 1068:    lonchat=window.open('/res/adm/pages/chatroom.html',"LONchat",'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
 1069: }
 1070: ENDUTILITY
 1071: }
 1072: 
 1073: sub serverform {
 1074:     return(<<ENDSERVERFORM);
 1075: 
 1076: <form name="server" action="/adm/logout" method="post" target="_top">
 1077: <input type="hidden" name="postdata" value="none" />
 1078: <input type="hidden" name="command" value="none" />
 1079: <input type="hidden" name="url" value="none" />
 1080: <input type="hidden" name="symb" value="none" />
 1081: </form>
 1082: ENDSERVERFORM
 1083: }
 1084: 
 1085: sub constspaceform {
 1086:     return(<<ENDCONSTSPACEFORM);
 1087: <form name="constspace" action="/adm/logout" method="post" target="_top">
 1088: <input type="hidden" name="filename" value="" />
 1089: </form>
 1090: <form name="cstrdelete" action="/adm/cfile" method="post" target="_top">
 1091: <input type="hidden" name="action" value="delete" /> 
 1092: <input type="hidden" name="filename" value="" />
 1093: </form>
 1094: <form name="cstrprint" action="/adm/printout" target="_parent" method="post">
 1095: <input type="hidden" name="postdata" value="" />
 1096: <input type="hidden" name="curseed" value="" />
 1097: <input type="hidden" name="problemtype" value="" />
 1098: </form>
 1099: 
 1100: ENDCONSTSPACEFORM
 1101: }
 1102: 
 1103: 
 1104: sub get_nav_status {
 1105:     my $navstatus="swmenu.w_loncapanav_flag=";
 1106:     if ($ENV{'environment.remotenavmap'} eq 'on') {
 1107: 	$navstatus.="1";
 1108:     } else {
 1109: 	$navstatus.="-1";
 1110:     }
 1111:     return $navstatus;
 1112: }
 1113: 
 1114: # ================================================ Handler when called directly
 1115: 
 1116: 
 1117: sub handler {
 1118:     my $r = shift;
 1119:     &Apache::loncommon::content_type($r,'text/html');
 1120:     $r->send_http_header;
 1121:     return OK if $r->header_only;
 1122: 
 1123:     my $form;
 1124:     if ($ENV{'environment.remote'} ne 'off' &&
 1125: 	$ENV{'browser.interface'} ne 'textual') {
 1126: 	$form=&serverform();
 1127:     }
 1128:     my $bodytag=&Apache::loncommon::bodytag('Main Menu');
 1129:     my $function='student';
 1130:     if ($ENV{'request.role'}=~/^(cc|in|ta|ep)/) {
 1131: 	$function='coordinator';
 1132:     }
 1133:     if ($ENV{'request.role'}=~/^(su|dc|ad|li)/) {
 1134: 	$function='admin';
 1135:     }
 1136:     if (($ENV{'request.role'}=~/^(au|ca)/) ||
 1137: 	($ENV{'request.noversionuri'}=~/^(\/priv|\~)/)) {
 1138: 	$function='author';
 1139:     }
 1140:     my $domain=&Apache::loncommon::determinedomain();
 1141:     $pgbg=&Apache::loncommon::designparm($function.'.pgbg',$domain);
 1142:     $tabbg=&Apache::loncommon::designparm($function.'.tabbg',$domain);
 1143:     $font=&Apache::loncommon::designparm($function.'.font',$domain);
 1144:     my $script_tag;
 1145:     if ($ENV{'environment.remote'} eq 'on') {
 1146:         my $utility=&utilityfunctions('/adm/menu');
 1147:         $script_tag=(<<ENDSCRIPT);
 1148: <script type="text/javascript">
 1149: $utility
 1150: </script>
 1151: ENDSCRIPT
 1152:     }
 1153: # ---- Print the screen, pretend to be in text mode to generate text-based menu
 1154:     unless ($ENV{'browser.interface'} eq 'textual') {
 1155: 	$ENV{'browser.interface'}='faketextual';
 1156: 	$ENV{'environment.remote'}='off';
 1157:     }
 1158:     $r->print(<<ENDHEADER);
 1159: <html><head>
 1160: <title>LON-CAPA Main Menu</title>
 1161: $script_tag
 1162: </head>
 1163: $bodytag
 1164: ENDHEADER
 1165:     $r->print('<table>'.&inlinemenu().'</table>'.$form);
 1166:     $r->print('</body></html>');
 1167:     return OK;
 1168: }
 1169: 
 1170: # ================================================================ Main Program
 1171: 
 1172: BEGIN {
 1173:   if (! defined($readdesk)) {
 1174:    {
 1175:     my $tabfile = $Apache::lonnet::perlvar{'lonTabDir'}.'/mydesk.tab';
 1176:     if ( CORE::open( my $config,"<$tabfile") ) {
 1177:         while (my $configline=<$config>) {
 1178:             $configline=(split(/\#/,$configline))[0];
 1179:             $configline=~s/^\s+//;
 1180:             chomp($configline);
 1181:             if ($configline) {
 1182:                 $desklines[$#desklines+1]=$configline;
 1183:             }
 1184:         }
 1185:         CORE::close($config);
 1186:     }
 1187:    }
 1188:    $readdesk='done';
 1189:   }
 1190: }
 1191: 
 1192: 1;
 1193: __END__
 1194: 
 1195: 
 1196: 
 1197: 
 1198: 
 1199: 
 1200: 

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