File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.48: download - view: text, annotated - select for diffs
Wed Apr 2 22:02:19 2003 UTC (21 years, 2 months ago) by www
Branches: MAIN
CVS tags: HEAD
Don't want the inline menu rendered inside of the Remote Control ...

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

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