File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.149: download - view: text, annotated - select for diffs
Mon Feb 21 00:32:04 2005 UTC (19 years, 3 months ago) by www
Branches: MAIN
CVS tags: HEAD
"Logout" and "Roles/Courses" in inline menu.

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

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