File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.88: download - view: text, annotated - select for diffs
Wed Sep 17 01:45:14 2003 UTC (20 years, 8 months ago) by www
Branches: MAIN
CVS tags: HEAD
Better German lexicon, work on translator interface.

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

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