File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.53: download - view: text, annotated - select for diffs
Thu Apr 3 20:25:08 2003 UTC (21 years, 2 months ago) by www
Branches: MAIN
CVS tags: HEAD
"No Remote" works as well and as bad as the "normal" textual interface now.

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

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