File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.92: download - view: text, annotated - select for diffs
Fri Sep 19 15:45:14 2003 UTC (20 years, 8 months ago) by bowersj2
Branches: MAIN
CVS tags: HEAD
Trying and failing to get the print button to appear always while in a
course. (Tried a couple of other things, too.)

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

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