File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.58: download - view: text, annotated - select for diffs
Sat Apr 5 22:14:40 2003 UTC (21 years, 2 months ago) by www
Branches: MAIN
CVS tags: HEAD
Continued work on "inline" Remote and three modes of navigation.

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

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