File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.103: download - view: text, annotated - select for diffs
Fri Nov 21 21:38:50 2003 UTC (20 years, 6 months ago) by www
Branches: MAIN
CVS tags: version_1_0_99, HEAD
Try to have Inline Remote take up less space on top.

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

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