File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.51: download - view: text, annotated - select for diffs
Thu Apr 3 14:44:01 2003 UTC (21 years, 1 month ago) by www
Branches: MAIN
CVS tags: HEAD
lonremote can now actually launch and collapse the Remote

    1: # The LearningOnline Network with CAPA
    2: # Routines to control the menu
    3: #
    4: # $Id: lonmenu.pm,v 1.51 2003/04/03 14:44:01 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: 
   49: # ============================= This gets called at the top of the body section
   50: 
   51: sub menubuttons {
   52:     my $forcereg=shift;
   53:     my $target  =shift;
   54:     my $registration=shift;
   55:     if ($ENV{'browser.interface'} eq 'textual') {
   56: # Textual display only
   57: 	my $output=(<<ENDMAINMENU);
   58: <script>
   59: // BEGIN LON-CAPA Internal
   60: </script>
   61: <a href="/adm/menu" target="_top">Main Menu</a><br />
   62: <script>
   63: // END LON-CAPA Internal
   64: </script>
   65: ENDMAINMENU
   66:         if ($registration) { $output.=&innerregister($forcereg,$target); }
   67: 	return $output."<hr />";
   68:     } elsif ($ENV{'environment.remote'} eq 'off') {
   69: # Remote Control is switched off
   70: 	my $output=(<<ENDINLINEMENU);
   71: <script>
   72: // BEGIN LON-CAPA Internal
   73: </script>
   74: <a href="/adm/menu" target="_top">Main Menu</a>
   75: <a href="/adm/remote?action=launch" target="_top">Launch Remote Control</a>
   76: <script>
   77: // END LON-CAPA Internal
   78: </script>
   79: ENDINLINEMENU
   80:         if ($registration) { $output.=&innerregister($forcereg,$target); }
   81: 	return $output."<hr />";
   82:     } else {
   83: 	return '';
   84:     }
   85: }
   86: 
   87: # ====================================== This gets called in the header section
   88: 
   89: sub registerurl {
   90:     my $forcereg=shift;
   91:     my $target = shift;
   92:     my $result = '';
   93:     
   94:     if ($target eq 'edit') {
   95:         $result .="<script type=\"text/javascript\">\n".
   96:             "if (typeof swmenu != 'undefined') {swmenu.currentURL=null;}\n".
   97:             &Apache::loncommon::browser_and_searcher_javascript().
   98:                 "\n</script>\n";
   99:     }
  100:     if (($ENV{'browser.interface'} eq 'textual') ||
  101:         ((($ENV{'request.publicaccess'}) || 
  102:          (!&Apache::lonnet::is_on_map($ENV{'REQUEST_URI'}))) &&
  103:         (!$forcereg))) {
  104: 	return $result.
  105:          '<script type="text/javascript">function LONCAPAreg(){;} function LONCAPAstale(){}</script>';
  106:     }
  107: # Graphical display after login only
  108:     if ($Apache::lonxml::registered && !$forcereg) { return ''; }
  109:     $result.=&innerregister($forcereg,$target);
  110:     return $result;
  111: }
  112: 
  113: # =========== This gets called in order to register a URL, both with the Remote
  114: # =========== and in the body of the document
  115: 
  116: sub innerregister {
  117:     my $forcereg=shift;
  118:     my $target = shift;
  119:     my $result = '';
  120: 
  121:     $Apache::lonxml::registered=1;
  122: 
  123:     my $textinter=($ENV{'browser.interface'} eq 'textual');
  124:     my $noremote=($ENV{'environment.remote'} eq 'off');
  125:     
  126:     my $textual=($textinter || $noremote);
  127: 
  128:     my $reopen=&Apache::lonmenu::reopenmenu();
  129: 
  130:     my $newmail='';
  131:     if (&Apache::lonmsg::newmail()) { 
  132:        $newmail=($textual?
  133:  '<b><a href="/adm/communicate">You have new messages</a></b><br />':
  134:                           'swmenu.setstatus("you have","messages");');
  135:     }
  136:     my $timesync=($textual?'':'swmenu.syncclock(1000*'.time.');');
  137: # =============================================================================
  138: # ============================ This is for URLs that actually can be registered
  139:     if (($ENV{'REQUEST_URI'}!~/^\/(res\/)*adm\//) || ($forcereg)) {
  140: # -- This applies to homework problems for users with grading privileges
  141:         my $hwkadd='';
  142:         if 
  143:       ($ENV{'request.filename'}=~/\.(problem|exam|quiz|assess|survey|form)$/) {
  144: 	    if (&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'})) {
  145: 		$hwkadd.=&switch('','',7,1,'subm.gif','view sub','missions',
  146:                        "gocmd('/adm/grades','submission')",
  147: 		       'View user submissions for this assessment resource');
  148:             }
  149: 	    if (&Apache::lonnet::allowed('mgr',$ENV{'request.course.id'})) {
  150: 		$hwkadd.=&switch('','',7,2,'pgrd.gif','problem','grades',
  151:                        "gocmd('/adm/grades','gradingmenu')",
  152:                        'Modify user grades for this assessment resource');
  153:             }
  154: 	    if (&Apache::lonnet::allowed('opa',$ENV{'request.course.id'})) {
  155: 		$hwkadd.=&switch('','',7,3,'pparm.gif','problem','parms',
  156:                        "gocmd('/adm/parmset','set')",
  157:                        'Modify deadlines, etc, for this assessment resource');
  158:             }
  159: 	}
  160: # -- End Homework
  161:         ###
  162:         ### Determine whether or not to display the 'cstr' button for this
  163:         ### resource
  164:         ###
  165:         my $editbutton = '';
  166:         if ($ENV{'user.author'}) {
  167:             if ($ENV{'request.role'}=~/^(ca|au)/) {
  168:                 # Set defaults for authors
  169:                 my ($top,$bottom) = ('con-','struct');
  170:                 my $action = "go('/priv/".$ENV{'user.name'}."');";
  171:                 my $cadom  = $ENV{'request.role.domain'};
  172:                 my $caname = $ENV{'user.name'};
  173:                 my $desc = "Enter my resource construction space";
  174:                 # Set defaults for co-authors
  175:                 if ($ENV{'request.role'} =~ /^ca/) { 
  176:                     ($cadom,$caname)=($ENV{'request.role'}=~/(\w+)\/(\w+)$/);
  177:                     ($top,$bottom) = ('co con-','struct');
  178:                     $action = "go('/priv/".$caname."');";
  179:                     $desc = "Enter construction space as co-author";
  180:                 }
  181:                 # Check that we are on the correct machine
  182:                 my $home = &Apache::lonnet::homeserver($caname,$cadom);
  183:                 if ($home eq $Apache::lonnet::perlvar{'lonHostID'}) {
  184:                     $editbutton=&switch
  185:                         ('','',6,1,$top,,$bottom,$action,$desc);
  186:                 }
  187:             }
  188:             ##
  189:             ## Determine if user can edit url.
  190:             ##
  191:             my $cfile='';
  192:             my $cfuname='';
  193:             my $cfudom='';
  194:             if ($ENV{'request.filename'}) {
  195:                 my $file=&Apache::lonnet::declutter($ENV{'request.filename'});
  196:                 $file=~s/^(\w+)\/(\w+)/\/priv\/$2/;
  197:                 # Chech that the user has permission to edit this resource
  198:                 ($cfuname,$cfudom)=&Apache::loncacc::constructaccess($file,$1);
  199:                 if (defined($cfudom)) {
  200:                     if (&Apache::lonnet::homeserver($cfuname,$cfudom) 
  201:                         eq $Apache::lonnet::perlvar{'lonHostID'}) {
  202:                         $cfile=$file;
  203:                     }
  204:                 }
  205:             }        
  206:             # Finally, turn the button on or off
  207:             if ($cfile) {
  208:                 $editbutton=&switch
  209:                     ('','',6,1,'cstr.gif','edit','resource',
  210:                      "go('".$cfile."');","Edit this resource");
  211:             } elsif ($editbutton eq '') {
  212:                 $editbutton=&clear(6,1);
  213:             }
  214:         }
  215:         ###
  216:         ###
  217: # Prepare the rest of the buttons
  218: 	my $menuitems=(<<ENDMENUITEMS);
  219: c&3&1
  220: s&2&1&back.gif&backward&&gopost('/adm/flip','back:'+currentURL)&Go to the previous resource in the course sequence&1
  221: s&2&3&forw.gif&forward&&gopost('/adm/flip','forward:'+currentURL)&Go to the next resource in the course sequence&1
  222: s&6&3&catalog.gif&catalog&info&catalog_info()&Show catalog information
  223: s&8&1&eval.gif&evaluate&this&gopost('/adm/evaluate',currentURL)&Provide my evaluation of this resource
  224: s&8&2&fdbk.gif&feedback&discuss&gopost('/adm/feedback',currentURL)&Provide feedback messages or contribute to the course discussion about this resource
  225: s&8&3&prt.gif&prepare&printout&gopost('/adm/printout',currentURL)&Prepare a printable document
  226: s&9&1&sbkm.gif&set&bookmark&set_bookmark()&Set a bookmark for this resource&2
  227: s&9&2&vbkm.gif&view&bookmark&edit_bookmarks()&Use or edit my bookmark collection&2
  228: s&9&3&anot.gif&anno-&tations&annotate()&Make notes and annotations about this resource&2
  229: ENDMENUITEMS
  230:         my $buttons='';
  231:         foreach (split(/\n/,$menuitems)) {
  232: 	    my ($command,@rest)=split(/\&/,$_);
  233:             if ($command eq 's') {
  234: 		$buttons.=&switch('','',@rest);
  235:             } else {
  236:                 $buttons.=&clear(@rest);
  237:             }
  238:         }
  239:         if ($textual) {
  240: # Registered, textual output
  241:             my $utility=&utilityfunctions();
  242:             my $form=&serverform();
  243: 	    $result =(<<ENDREGTEXT);
  244: <script>
  245: // BEGIN LON-CAPA Internal
  246: $utility
  247: </script>
  248: $timesync
  249: $newmail
  250: $buttons
  251: $hwkadd
  252: $editbutton
  253: $form
  254: <script>
  255: //END LON-CAPA Internal
  256: </script>
  257: 
  258: ENDREGTEXT
  259: # Registered, graphical output
  260:         } else {
  261: 	    $result = (<<ENDREGTHIS);
  262:      
  263: <script language="JavaScript">
  264: // BEGIN LON-CAPA Internal
  265: var swmenu=null;
  266: 
  267:     function LONCAPAreg() {
  268: 	  swmenu=$reopen;
  269:           swmenu.clearTimeout(swmenu.menucltim);
  270:           $timesync
  271:           $newmail
  272:           $buttons
  273: 	  swmenu.currentURL=window.location.pathname;
  274:           swmenu.reloadURL=window.location.pathname+window.location.search;
  275:           swmenu.currentSymb="$ENV{'request.symb'}";
  276:           swmenu.reloadSymb="$ENV{'request.symb'}";
  277:           swmenu.currentStale=0;
  278:           $hwkadd
  279:           $editbutton
  280:     }
  281: 
  282:     function LONCAPAstale() {
  283: 	  swmenu=$reopen
  284:           swmenu.currentStale=1;
  285:           if (swmenu.reloadURL!='' && swmenu.reloadURL!= null) { 
  286:              swmenu.switchbutton
  287:              (3,1,'reload.gif','return','location','go(reloadURL)','Return to the last known location in the course sequence');
  288: 	  }
  289:           swmenu.clearbut(7,1);
  290:           swmenu.clearbut(7,2);
  291:           swmenu.clearbut(7,3);
  292:           swmenu.menucltim=swmenu.setTimeout(
  293:  'clearbut(2,1);clearbut(2,3);clearbut(8,1);clearbut(8,2);clearbut(8,3);'+
  294:  'clearbut(9,1);clearbut(9,2);clearbut(9,3);clearbut(6,3);clearbut(6,1)',
  295: 			  2000);
  296: 
  297:       }
  298: 
  299: // END LON-CAPA Internal
  300: </script>
  301: ENDREGTHIS
  302:         }
  303: # =============================================================================
  304:     } else {
  305: # ========================================== This can or will not be registered
  306:         if ($textual) {
  307: # Not registered, textual
  308: 	    $result= (<<ENDDONOTREGTEXT);
  309: ENDDONOTREGTEXT
  310:         } else {
  311: # Not registered, graphical
  312:            $result = (<<ENDDONOTREGTHIS);
  313: 
  314: <script language="JavaScript">
  315: // BEGIN LON-CAPA Internal
  316: var swmenu=null;
  317: 
  318:     function LONCAPAreg() {
  319: 	  swmenu=$reopen
  320:           $timesync
  321:           swmenu.currentStale=1;
  322:           swmenu.clearbut(2,1);
  323:           swmenu.clearbut(2,3);
  324:           swmenu.clearbut(8,1);
  325:           swmenu.clearbut(8,2);
  326:           swmenu.clearbut(8,3);
  327:           if (swmenu.currentURL) {
  328:              swmenu.switchbutton
  329:               (3,1,'reload.gif','return','location','go(currentURL)');
  330:  	  } else {
  331: 	      swmenu.clearbut(3,1);
  332:           }
  333:     }
  334: 
  335:     function LONCAPAstale() {
  336:     }
  337: 
  338: // END LON-CAPA Internal
  339: </script>
  340: ENDDONOTREGTHIS
  341:        }
  342: # =============================================================================
  343:     }
  344:     return $result;
  345: }
  346: 
  347: sub loadevents() {
  348:     return 'LONCAPAreg();';
  349: }
  350: 
  351: sub unloadevents() {
  352:     return 'LONCAPAstale();';
  353: }
  354: 
  355: # ============================================================= Start up remote
  356: 
  357: sub startupremote {
  358:     my ($lowerurl)=@_;
  359:     if (($ENV{'browser.interface'} eq 'textual') ||
  360:         ($ENV{'environment.remote'} eq 'off')) {
  361:      return ('<meta HTTP-EQUIV="Refresh" CONTENT="0.5; url='.$lowerurl.'" />');
  362:     }
  363: #
  364: # The Remote actually gets launched!
  365: #
  366:     my $configmenu=&rawconfig();
  367:     return(<<ENDREMOTESTARTUP);
  368: <script>
  369: 
  370: function wheelswitch() {
  371:    if (window.status=='|') { 
  372:       window.status='/'; 
  373:    } else {
  374:       if (window.status=='/') {
  375:          window.status='-';
  376:       } else {
  377:          if (window.status=='-') { 
  378:             window.status='\\\\'; 
  379:          } else {
  380:             if (window.status=='\\\\') { window.status='|'; }
  381:          }
  382:       }
  383:    } 
  384: }
  385: 
  386: // ---------------------------------------------------------- The wait function
  387: var canceltim;
  388: function wait() {
  389:    if ((menuloaded==1) || (tim==1)) {
  390:       window.status='Done.';
  391:       if (tim==0) {
  392:          clearTimeout(canceltim);
  393:          $configmenu
  394:          window.location='$lowerurl';  
  395:       } else {
  396:          alert("Remote Control timed out. It is possible that it was blocked by pop-up window filters.");
  397:       }
  398:    } else {
  399:       wheelswitch();
  400:       setTimeout('wait();',200);
  401:    }
  402: }
  403: 
  404: function main() {
  405:    canceltim=setTimeout('tim=1;',60000);
  406:    window.status='-';
  407:    wait();
  408: }
  409: 
  410: </script>
  411: ENDREMOTESTARTUP
  412: }
  413: 
  414: sub setflags() {
  415:     return(<<ENDSETFLAGS);
  416: <script>
  417:     menuloaded=0;
  418:     tim=0;
  419: </script>
  420: ENDSETFLAGS
  421: }
  422: 
  423: sub maincall() {
  424:     if (($ENV{'browser.interface'} eq 'textual') ||
  425:         ($ENV{'environment.remote'} eq 'off')) { return ''; }
  426:     return(<<ENDMAINCALL);
  427: <script>
  428:     main();
  429: </script>
  430: ENDMAINCALL
  431: }
  432: # ================================================================= Reopen menu
  433: 
  434: sub reopenmenu {
  435:    if (($ENV{'browser.interface'} eq 'textual') ||
  436:        ($ENV{'environment.remote'} eq 'off')) { return ''; }
  437:    my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
  438:    my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
  439:    return('window.open('.$nothing.',"'.$menuname.'","",false);');
  440: } 
  441: 
  442: # =============================================================== Open the menu
  443: 
  444: sub open {
  445:     my $returnval='';
  446:     if (($ENV{'browser.interface'} eq 'textual') ||
  447:         ($ENV{'environment.remote'} eq 'off')) { return ''; }
  448:     my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
  449:     unless (shift eq 'unix') {
  450: # resizing does not work on linux because of virtual desktop sizes
  451:        $returnval.=(<<ENDRESIZE);
  452: if (window.screen) {
  453:     self.resizeTo(screen.availWidth-215,screen.availHeight-55);
  454:     self.moveTo(190,15);
  455: }
  456: ENDRESIZE
  457:     }
  458:     $returnval.=(<<ENDOPEN);
  459: window.status='Opening LON-CAPA Remote Control';
  460: var menu=window.open("/res/adm/pages/menu.html","$menuname",
  461: "height=350,width=150,scrollbars=no,menubar=no,top=5,left=5,screenX=5,screenY=5");
  462: ENDOPEN
  463:     return '<script>'.$returnval.'</script>';
  464: }
  465: 
  466: 
  467: # ================================================================== Raw Config
  468: 
  469: sub clear {
  470:     my ($row,$col)=@_;
  471:     unless (($ENV{'browser.interface'} eq 'textual') ||
  472:             ($ENV{'environment.remote'} eq 'off')) {
  473:        return "\n".qq(window.status+='.';swmenu.clearbut($row,$col););
  474:    } else { return ''; }
  475: }
  476: 
  477: # ============================================ Switch a button or create a link
  478: # Switch acts on the javascript that is executed when a button is clicked.  
  479: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
  480: 
  481: sub switch {
  482:     my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$nobreak)=@_;
  483:     $act=~s/\$uname/$uname/g;
  484:     $act=~s/\$udom/$udom/g;
  485:     unless (($ENV{'browser.interface'} eq 'textual')  ||
  486:             ($ENV{'environment.remote'} eq 'off')) {
  487: # Remote
  488:        return "\n".
  489:  qq(window.status+='.';swmenu.switchbutton($row,$col,"$img","$top","$bot","$act","$desc"););
  490:    } elsif ($ENV{'browser.interface'} eq 'textual') {
  491: # Accessibility
  492:        if ($nobreak==2) { return ''; }
  493:        my $text=$top.' '.$bot;
  494:        $text=~s/\- //;
  495:        return "\n".($nobreak?' ':'<br />').
  496:         '<a href="javascript:'.$act.';" target="_top">'.$text.'</a> '.
  497:         ($nobreak?'':$desc);
  498:    } else {
  499: # Inline Remote
  500:        if ($nobreak==2) { return ''; }
  501:        my $text=$top.' '.$bot;
  502:        $text=~s/\- //;
  503:        return "\n".($nobreak?' ':'<br />').
  504:         '<a href="javascript:'.$act.';" target="_top">'.$text.'</a> '.
  505:         ($nobreak?'':$desc);
  506:    }
  507: }
  508: 
  509: sub secondlevel {
  510:     my $output='';
  511:     my 
  512:     ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc)=@_;
  513:     if ($prt eq 'any') {
  514: 	   $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
  515:     } elsif ($prt=~/^r(\w+)/) {
  516:         if ($rol eq $1) {
  517:            $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
  518:         }
  519:     }
  520:     return $output;
  521: }
  522: 
  523: sub openmenu {
  524:     my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
  525:     if (($ENV{'browser.interface'} eq 'textual') ||
  526:         ($ENV{'environment.remote'} eq 'off')) { return ''; }
  527:     my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
  528:     return "window.open(".$nothing.",'".$menuname."');";
  529: }
  530: 
  531: sub rawconfig {
  532:     my $textualoverride=shift;
  533:     my $output='';
  534:     unless (($ENV{'browser.interface'} eq 'textual') ||
  535:             ($ENV{'environment.remote'} eq 'off')) {
  536:        $output.=
  537:  "window.status='Opening Remote Control';var swmenu=".&openmenu().
  538: "\nwindow.status='Configuring Remote Control ';";
  539:     } else {
  540:        unless ($textualoverride) { return ''; }
  541:     }
  542:     my $uname=$ENV{'user.name'};
  543:     my $udom=$ENV{'user.domain'};
  544:     my $adv=$ENV{'user.adv'};
  545:     my $author=$ENV{'user.author'};
  546:     my $crs='';
  547:     if ($ENV{'request.course.id'}) {
  548:        $crs='/'.$ENV{'request.course.id'};
  549:        if ($ENV{'request.course.sec'}) {
  550: 	   $crs.='_'.$ENV{'request.course.sec'};
  551:        }
  552:        $crs=~s/\_/\//g;
  553:     }
  554:     my $pub=($ENV{'request.state'} eq 'published');
  555:     my $con=($ENV{'request.state'} eq 'construct');
  556:     my $rol=$ENV{'request.role'};
  557:     my $requested_domain = $ENV{'request.role.domain'};
  558:     foreach (@desklines) {
  559:         my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc)=split(/\:/,$_);
  560:         $prt=~s/\$uname/$uname/g;
  561:         $prt=~s/\$udom/$udom/g;
  562:         $prt=~s/\$crs/$crs/g; 
  563:         $prt=~s/\$requested_domain/$requested_domain/g;
  564:         if ($pro eq 'clear') {
  565: 	    $output.=&clear($row,$col);
  566:         } elsif ($pro eq 'any') {
  567:                $output.=&secondlevel(
  568: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
  569: 	} elsif ($pro eq 'smp') {
  570:             unless ($adv) {
  571:                $output.=&secondlevel(
  572:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
  573:             }
  574:         } elsif ($pro eq 'adv') {
  575:             if ($adv) {
  576:                $output.=&secondlevel(
  577: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
  578:             }
  579:         } elsif (($pro=~/p(\w+)/) && ($prt)) {
  580: 	    if (&Apache::lonnet::allowed($1,$prt)) {
  581:                $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
  582:             }
  583:         } elsif ($pro eq 'course') {
  584:             if ($ENV{'request.course.fn'}) {
  585:                $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
  586: 	    }
  587:         } elsif ($pro eq 'author') {
  588:             if ($author) {
  589:                 if ((($prt eq 'rca') && ($ENV{'request.role'}=~/^ca/)) ||
  590:                     (($prt eq 'rau') && ($ENV{'request.role'}=~/^au/))) {
  591:                     # Check that we are on the correct machine
  592:                     my $cadom=$requested_domain;
  593:                     my $caname=$ENV{'user.name'};
  594:                     if ($prt eq 'rca') {
  595: 		       ($cadom,$caname)=
  596:                                ($ENV{'request.role'}=~/(\w+)\/(\w+)$/);
  597:                     }                       
  598:                     $act =~ s/\$caname/$caname/g;
  599:                     my $home = &Apache::lonnet::homeserver($caname,$cadom);
  600:                     if ($home eq $Apache::lonnet::perlvar{'lonHostID'}) {
  601:                         $output.=switch($caname,$cadom,
  602:                                         $row,$col,$img,$top,$bot,$act,$desc);
  603:                     }
  604:                 }
  605:             }
  606:         }
  607:     }
  608:     unless (($ENV{'browser.interface'} eq 'textual') ||
  609:             ($ENV{'environment.remote'} eq 'off')) {
  610:        $output.="\nwindow.status='Synchronizing Time';swmenu.syncclock(1000*".time.");\nwindow.status='Remote Control Configured.';";
  611:     }
  612:     return $output;
  613: }
  614: 
  615: # ======================================================================= Close
  616: 
  617: sub close {
  618:     if (($ENV{'browser.interface'} eq 'textual') ||
  619:         ($ENV{'environment.remote'} eq 'off')) { return ''; }
  620:     my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
  621:     return(<<ENDCLOSE);
  622: <script>
  623: window.status='Accessing Remote Control';
  624: menu=window.open("/adm/rat/empty.html","$menuname",
  625:                  "height=350,width=150,scrollbars=no,menubar=no");
  626: window.status='Disabling Remote Control';
  627: menu.active=0;
  628: menu.autologout=0;
  629: window.status='Closing Remote Control';
  630: menu.close();
  631: window.status='Done.';
  632: </script>
  633: ENDCLOSE
  634: }
  635: 
  636: # ====================================================================== Footer
  637: 
  638: sub footer {
  639: 
  640: }
  641: 
  642: sub utilityfunctions {
  643:     unless (($ENV{'browser.interface'} eq 'textual')  ||
  644:         ($ENV{'environment.remote'} eq 'off')) { return ''; }
  645:     my $currenturl=$ENV{'REQUEST_URI'};
  646:     my $currentsymb=$ENV{'request.symb'};
  647: return (<<ENDUTILITY)
  648: 
  649:     var currentURL="$currenturl";
  650:     var reloadURL="$currenturl";
  651:     var currentSymb="$currentsymb";
  652: 
  653: function go(url) {
  654:    if (url!='' && url!= null) {
  655:        currentURL = null;
  656:        currentSymb= null;
  657:        window.location.href=url;
  658:    }
  659: }
  660: 
  661: function gopost(url,postdata) {
  662:    if (url!='') {
  663:       this.document.server.action=url;
  664:       this.document.server.postdata.value=postdata;
  665:       this.document.server.command.value='';
  666:       this.document.server.url.value='';
  667:       this.document.server.symb.value='';
  668:       this.document.server.submit();
  669:    }
  670: }
  671: 
  672: function gocmd(url,cmd) {
  673:    if (url!='') {
  674:       this.document.server.action=url;
  675:       this.document.server.postdata.value='';
  676:       this.document.server.command.value=cmd;
  677:       this.document.server.url.value=currentURL;
  678:       this.document.server.symb.value=currentSymb;
  679:       this.document.server.submit();
  680:    }
  681: }
  682: ENDUTILITY
  683: }
  684: 
  685: sub serverform {
  686:     return(<<ENDSERVERFORM);
  687: 
  688: <form name="server" action="/adm/logout" method="post">
  689: <input type="hidden" name="postdata" value="none" />
  690: <input type="hidden" name="command" value="none" />
  691: <input type="hidden" name="url" value="none" />
  692: <input type="hidden" name="symb" value="none" />
  693: </form>
  694: ENDSERVERFORM
  695: }
  696: # ================================================ Handler when called directly
  697: 
  698: 
  699: sub handler {
  700:     my $r = shift;
  701:     $r->content_type('text/html');
  702:     $r->send_http_header;
  703:     return OK if $r->header_only;
  704: 
  705:     my $utility=&utilityfunctions();
  706:     my $form=&serverform();
  707:     my $bodytag=&Apache::loncommon::bodytag('Main Menu');
  708: # ------------------------------------------------------------ Print the screen
  709:     $r->print(<<ENDHEADER);
  710: <html><head>
  711: <title>LON-CAPA Main Menu</title>
  712: <script>
  713: $utility
  714: </script>
  715: </head>
  716: $bodytag
  717: ENDHEADER
  718:     $r->print(&rawconfig(1).$form);
  719:     $r->print('</body></html>');
  720:     return OK;
  721: }
  722: 
  723: # ================================================================ Main Program
  724: 
  725: BEGIN {
  726:   if (! defined($readdesk)) {
  727:    {
  728:     my $config=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.
  729: 				  '/mydesk.tab');
  730:     while (my $configline=<$config>) {
  731:        $configline=(split(/\#/,$configline))[0];
  732:        $configline=~s/^\s+//;
  733:        chomp($configline);
  734:        if ($configline) {
  735:           $desklines[$#desklines+1]=$configline;
  736:        }
  737:     }
  738:    }
  739:    $readdesk='done';
  740:   }
  741: }
  742: 
  743: 1;
  744: __END__
  745: 
  746: 
  747: 
  748: 
  749: 
  750: 
  751: 

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