File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.113: download - view: text, annotated - select for diffs
Fri Aug 13 20:12:11 2004 UTC (19 years, 10 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- BUG3231, now the nav link in remote remote mode should recreate the remote nav window

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

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