File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.143: download - view: text, annotated - select for diffs
Wed Feb 2 19:24:45 2005 UTC (19 years, 3 months ago) by albertel
Branches: MAIN
CVS tags: version_1_3_X, version_1_3_3, version_1_3_2, HEAD
- BUG#3886 - currentURL should be versioned

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

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