File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.76: download - view: text, annotated - select for diffs
Fri Jun 6 02:24:49 2003 UTC (20 years, 11 months ago) by www
Branches: MAIN
CVS tags: version_0_99_2, HEAD
Rewinding changes on window registration.
Attempting to overcome JavaScript security by using POST to change window
location.

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

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