File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.57: download - view: text, annotated - select for diffs
Fri Apr 4 22:00:26 2003 UTC (21 years, 1 month ago) by www
Branches: MAIN
CVS tags: HEAD
Open new window for chat.

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

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