File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.54: download - view: text, annotated - select for diffs
Thu Apr 3 21:32:23 2003 UTC (21 years, 2 months ago) by www
Branches: MAIN
CVS tags: HEAD
Inline "remote" embedded into page headers (design obviously not decided yet).
Auto-lauch good-ole Remote when entering construction space, there is just
no other way right now, and authors should be more "robust" than the average
user.

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

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