File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.55: download - view: text, annotated - select for diffs
Fri Apr 4 19:35:04 2003 UTC (21 years, 2 months ago) by www
Branches: MAIN
CVS tags: HEAD
Cannot post symb to NAV under the name of "symb", since that parameter is
reserved for the symb of the resource you are looking at - lonacc chokes on
that.

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

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