File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.114: download - view: text, annotated - select for diffs
Mon Aug 23 21:05:03 2004 UTC (19 years, 9 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- inline remote with external navmap works well now

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

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