File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.96: download - view: text, annotated - select for diffs
Fri Oct 24 21:04:21 2003 UTC (20 years, 7 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- Fixe for BUG#2280 is wrong, need to call registerurl to get the openbrowser etc helper routines.

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

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