File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.49: download - view: text, annotated - select for diffs
Thu Apr 3 00:52:21 2003 UTC (21 years, 2 months ago) by www
Branches: MAIN
CVS tags: HEAD
Continued work on "inline" Remote

    1: # The LearningOnline Network with CAPA
    2: # Routines to control the menu
    3: #
    4: # $Id: lonmenu.pm,v 1.49 2003/04/03 00:52:21 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:        return "\n".
  488:  qq(window.status+='.';swmenu.switchbutton($row,$col,"$img","$top","$bot","$act","$desc"););
  489:    } else {
  490:        if ($nobreak==2) { return ''; }
  491:        my $text=$top.' '.$bot;
  492:        $text=~s/\- //;
  493:        return "\n".($nobreak?' ':'<br />').
  494:         '<a href="javascript:'.$act.';" target="_top">'.$text.'</a> '.
  495:         ($nobreak?'':$desc);
  496:    }
  497: }
  498: 
  499: sub secondlevel {
  500:     my $output='';
  501:     my 
  502:     ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc)=@_;
  503:     if ($prt eq 'any') {
  504: 	   $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
  505:     } elsif ($prt=~/^r(\w+)/) {
  506:         if ($rol eq $1) {
  507:            $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
  508:         }
  509:     }
  510:     return $output;
  511: }
  512: 
  513: sub openmenu {
  514:     my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
  515:     if (($ENV{'browser.interface'} eq 'textual') ||
  516:         ($ENV{'environment.remote'} eq 'off')) { return ''; }
  517:     my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
  518:     return "window.open(".$nothing.",'".$menuname."');";
  519: }
  520: 
  521: sub rawconfig {
  522:     my $textualoverride=shift;
  523:     my $output='';
  524:     unless (($ENV{'browser.interface'} eq 'textual') ||
  525:             ($ENV{'environment.remote'} eq 'off')) {
  526:        $output.=
  527:  "window.status='Opening Remote Control';var swmenu=".&openmenu().
  528: "\nwindow.status='Configuring Remote Control ';";
  529:     } else {
  530:        unless ($textualoverride) { return ''; }
  531:     }
  532:     my $uname=$ENV{'user.name'};
  533:     my $udom=$ENV{'user.domain'};
  534:     my $adv=$ENV{'user.adv'};
  535:     my $author=$ENV{'user.author'};
  536:     my $crs='';
  537:     if ($ENV{'request.course.id'}) {
  538:        $crs='/'.$ENV{'request.course.id'};
  539:        if ($ENV{'request.course.sec'}) {
  540: 	   $crs.='_'.$ENV{'request.course.sec'};
  541:        }
  542:        $crs=~s/\_/\//g;
  543:     }
  544:     my $pub=($ENV{'request.state'} eq 'published');
  545:     my $con=($ENV{'request.state'} eq 'construct');
  546:     my $rol=$ENV{'request.role'};
  547:     my $requested_domain = $ENV{'request.role.domain'};
  548:     foreach (@desklines) {
  549:         my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc)=split(/\:/,$_);
  550:         $prt=~s/\$uname/$uname/g;
  551:         $prt=~s/\$udom/$udom/g;
  552:         $prt=~s/\$crs/$crs/g; 
  553:         $prt=~s/\$requested_domain/$requested_domain/g;
  554:         if ($pro eq 'clear') {
  555: 	    $output.=&clear($row,$col);
  556:         } elsif ($pro eq 'any') {
  557:                $output.=&secondlevel(
  558: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
  559: 	} elsif ($pro eq 'smp') {
  560:             unless ($adv) {
  561:                $output.=&secondlevel(
  562:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
  563:             }
  564:         } elsif ($pro eq 'adv') {
  565:             if ($adv) {
  566:                $output.=&secondlevel(
  567: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
  568:             }
  569:         } elsif (($pro=~/p(\w+)/) && ($prt)) {
  570: 	    if (&Apache::lonnet::allowed($1,$prt)) {
  571:                $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
  572:             }
  573:         } elsif ($pro eq 'course') {
  574:             if ($ENV{'request.course.fn'}) {
  575:                $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
  576: 	    }
  577:         } elsif ($pro eq 'author') {
  578:             if ($author) {
  579:                 if ((($prt eq 'rca') && ($ENV{'request.role'}=~/^ca/)) ||
  580:                     (($prt eq 'rau') && ($ENV{'request.role'}=~/^au/))) {
  581:                     # Check that we are on the correct machine
  582:                     my $cadom=$requested_domain;
  583:                     my $caname=$ENV{'user.name'};
  584:                     if ($prt eq 'rca') {
  585: 		       ($cadom,$caname)=
  586:                                ($ENV{'request.role'}=~/(\w+)\/(\w+)$/);
  587:                     }                       
  588:                     $act =~ s/\$caname/$caname/g;
  589:                     my $home = &Apache::lonnet::homeserver($caname,$cadom);
  590:                     if ($home eq $Apache::lonnet::perlvar{'lonHostID'}) {
  591:                         $output.=switch($caname,$cadom,
  592:                                         $row,$col,$img,$top,$bot,$act,$desc);
  593:                     }
  594:                 }
  595:             }
  596:         }
  597:     }
  598:     unless (($ENV{'browser.interface'} eq 'textual') ||
  599:             ($ENV{'environment.remote'} eq 'off')) {
  600:        $output.="\nwindow.status='Synchronizing Time';swmenu.syncclock(1000*".time.");\nwindow.status='Remote Control Configured.';";
  601:     }
  602:     return $output;
  603: }
  604: 
  605: # ======================================================================= Close
  606: 
  607: sub close {
  608:     if (($ENV{'browser.interface'} eq 'textual') ||
  609:         ($ENV{'environment.remote'} eq 'off')) { return ''; }
  610:     my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
  611:     return(<<ENDCLOSE);
  612: <script>
  613: window.status='Accessing Remote Control';
  614: menu=window.open("/adm/rat/empty.html","$menuname",
  615:                  "height=350,width=150,scrollbars=no,menubar=no");
  616: window.status='Disabling Remote Control';
  617: menu.active=0;
  618: menu.autologout=0;
  619: window.status='Closing Remote Control';
  620: menu.close();
  621: window.status='Done.';
  622: </script>
  623: ENDCLOSE
  624: }
  625: 
  626: # ====================================================================== Footer
  627: 
  628: sub footer {
  629: 
  630: }
  631: 
  632: sub utilityfunctions {
  633:     unless ($ENV{'browser.interface'} eq 'textual') { return ''; }
  634:     my $currenturl=$ENV{'REQUEST_URI'};
  635:     my $currentsymb=$ENV{'request.symb'};
  636: return (<<ENDUTILITY)
  637: 
  638:     var currentURL="$currenturl";
  639:     var reloadURL="$currenturl";
  640:     var currentSymb="$currentsymb";
  641: 
  642: function go(url) {
  643:    if (url!='' && url!= null) {
  644:        currentURL = null;
  645:        currentSymb= null;
  646:        window.location.href=url;
  647:    }
  648: }
  649: 
  650: function gopost(url,postdata) {
  651:    if (url!='') {
  652:       this.document.server.action=url;
  653:       this.document.server.postdata.value=postdata;
  654:       this.document.server.command.value='';
  655:       this.document.server.url.value='';
  656:       this.document.server.symb.value='';
  657:       this.document.server.submit();
  658:    }
  659: }
  660: 
  661: function gocmd(url,cmd) {
  662:    if (url!='') {
  663:       this.document.server.action=url;
  664:       this.document.server.postdata.value='';
  665:       this.document.server.command.value=cmd;
  666:       this.document.server.url.value=currentURL;
  667:       this.document.server.symb.value=currentSymb;
  668:       this.document.server.submit();
  669:    }
  670: }
  671: ENDUTILITY
  672: }
  673: 
  674: sub serverform {
  675:     return(<<ENDSERVERFORM);
  676: 
  677: <form name="server" action="/adm/logout" method="post">
  678: <input type="hidden" name="postdata" value="none" />
  679: <input type="hidden" name="command" value="none" />
  680: <input type="hidden" name="url" value="none" />
  681: <input type="hidden" name="symb" value="none" />
  682: </form>
  683: ENDSERVERFORM
  684: }
  685: # ================================================ Handler when called directly
  686: 
  687: 
  688: sub handler {
  689:     my $r = shift;
  690:     $r->content_type('text/html');
  691:     $r->send_http_header;
  692:     return OK if $r->header_only;
  693: 
  694:     my $utility=&utilityfunctions();
  695:     my $form=&serverform();
  696:     my $bodytag=&Apache::loncommon::bodytag('Main Menu');
  697: # ------------------------------------------------------------ Print the screen
  698:     $r->print(<<ENDHEADER);
  699: <html><head>
  700: <title>LON-CAPA Main Menu</title>
  701: <script>
  702: $utility
  703: </script>
  704: </head>
  705: $bodytag
  706: ENDHEADER
  707:     $r->print(&rawconfig(1).$form);
  708:     $r->print('</body></html>');
  709:     return OK;
  710: }
  711: 
  712: # ================================================================ Main Program
  713: 
  714: BEGIN {
  715:   if (! defined($readdesk)) {
  716:    {
  717:     my $config=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.
  718: 				  '/mydesk.tab');
  719:     while (my $configline=<$config>) {
  720:        $configline=(split(/\#/,$configline))[0];
  721:        $configline=~s/^\s+//;
  722:        chomp($configline);
  723:        if ($configline) {
  724:           $desklines[$#desklines+1]=$configline;
  725:        }
  726:     }
  727:    }
  728:    $readdesk='done';
  729:   }
  730: }
  731: 
  732: 1;
  733: __END__
  734: 
  735: 
  736: 
  737: 
  738: 
  739: 
  740: 

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