File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.163: download - view: text, annotated - select for diffs
Tue Nov 8 17:57:41 2005 UTC (18 years, 6 months ago) by www
Branches: MAIN
CVS tags: HEAD
Return to Last Location also in Construction Space, eliminate stupid
"noidea.html" and go to Navigation instead.

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

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