File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.72: download - view: text, annotated - select for diffs
Tue May 27 15:50:29 2003 UTC (21 years ago) by www
Branches: MAIN
CVS tags: HEAD
Bug #1496: long-running spreadsheet did not register with Remote before
completely loaded. Produces "extra windows".

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

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