File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.144: download - view: text, annotated - select for diffs
Mon Feb 7 23:37:45 2005 UTC (19 years, 4 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- part of BUG#3904, remote navigating a resource not in the course doesn't gie you a return location link

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

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