File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.84: download - view: text, annotated - select for diffs
Fri Aug 15 14:55:45 2003 UTC (20 years, 9 months ago) by www
Branches: MAIN
CVS tags: HEAD
Do this instead of 1.39 of lonpageflip.pm
Also fixes problems with PRT of "special filename" documents, and fixes
NAV location info.

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

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