File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.60: download - view: text, annotated - select for diffs
Thu Apr 17 13:21:36 2003 UTC (21 years, 1 month ago) by www
Branches: MAIN
CVS tags: HEAD
Inline Remote: show where we are.

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

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