File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.116: download - view: text, annotated - select for diffs
Sat Sep 18 16:28:35 2004 UTC (19 years, 8 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- need the utility fucntions basically always

    1: # The LearningOnline Network with CAPA
    2: # Routines to control the menu
    3: #
    4: # $Id: lonmenu.pm,v 1.116 2004/09/18 16:28:35 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::lonnavmaps();
   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:     my $forcereg=shift;
   70:     my $target  =shift;
   71:     my $registration=shift;
   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 $utility=&utilityfunctions();
  100: 	my $output=(<<ENDMAINMENU);
  101: <script>
  102: // BEGIN LON-CAPA Internal
  103: $utility
  104: </script>
  105: <a href="/adm/menu" target="_top">$lt{'main'}</a>
  106: $reloadlink $navmaps<br />
  107: <script>
  108: // END LON-CAPA Internal
  109: </script>
  110: ENDMAINMENU
  111:         if ($registration) { $output.=&innerregister($forcereg,$target); }
  112: 	return $output."<hr />";
  113:     } elsif ($ENV{'environment.remote'} eq 'off') {
  114: # Remote Control is switched off
  115: # figure out colors
  116: 	my %lt=&initlittle();
  117: 	my $function='student';
  118:         if ($ENV{'request.role'}=~/^(cc|in|ta|ep)/) {
  119: 	    $function='coordinator';
  120:         }
  121: 	if ($ENV{'request.role'}=~/^(su|dc|ad|li)/) {
  122:             $function='admin';
  123:         }
  124:         if (($ENV{'request.role'}=~/^(au|ca)/) ||
  125:             ($ENV{'request.noversionuri'}=~/^(\/priv|\~)/)) {
  126:             $function='author';
  127:         }
  128:         my $domain=&Apache::loncommon::determinedomain();
  129:         $pgbg=&Apache::loncommon::designparm($function.'.pgbg',$domain);
  130:         $tabbg=&Apache::loncommon::designparm($function.'.tabbg',$domain);
  131:         $font=&Apache::loncommon::designparm($function.'.font',$domain);
  132:         my $link=&Apache::loncommon::designparm($function.'.link',$domain);
  133:         my $alink=&Apache::loncommon::designparm($function.'.alink',$domain);
  134:         my $vlink=&Apache::loncommon::designparm($function.'.vlink',$domain);
  135:         my $sidebg=&Apache::loncommon::designparm($function.'.sidebg',$domain);
  136: # Do we have a NAV link?
  137:         if ($ENV{'request.course.id'}) {
  138:         	    $navmaps=(<<ENDNAV);
  139: <td bgcolor="$tabbg">
  140: <a href="javascript:gonav('/adm/navmaps?postdata=$escurl&postsymb=$escsymb')"><font color="$font">$lt{'nav'}</font></a></td>
  141: ENDNAV
  142: 	    if (($ENV{'request.noversionuri'}=~/^\/adm\//) &&
  143:                 ($ENV{'request.noversionuri'}!~/^\/adm\/wrapper\//) &&
  144:          ($ENV{'request.noversionuri'}!~/^\/adm\/.*\/(smppg|bulletinboard|aboutme)(\?|$)/)) {
  145:                 my $escreload=&Apache::lonnet::escape('return:');
  146:                 $reloadlink=(<<ENDRELOAD);
  147: <td bgcolor="$tabbg">
  148: <a href="/adm/flip?postdata=$escreload" target="_top"><font color="$font">$lt{'ret'}</font></a></td>
  149: ENDRELOAD
  150:             }
  151:         }
  152:         my $reg='';
  153:         if ($registration) {
  154:            $reg=&innerregister($forcereg,$target);
  155:         }
  156: 	my $utility=&utilityfunctions();
  157: 	return (<<ENDINLINEMENU);
  158: <script>
  159: // BEGIN LON-CAPA Internal
  160: $utility
  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">
  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 $form=&serverform();
  392: 	    my $inlinebuttons='';
  393: 
  394: 	    if ($ENV{'browser.interface'} eq 'textual') {
  395: 		$inlinebuttons=
  396:                         join('',map { (defined($_)?$_:'') } @inlineremote);
  397: 	    } else {
  398: 		$inlinebuttons=(<<ENDINLINE);
  399: <tr><td>$inlineremote[21]</td><td>&nbsp</td><td>$inlineremote[23]</td></tr>
  400: <tr><td>$inlineremote[61]</td><td>$inlineremote[62]</td><td>$inlineremote[63]</td></tr>
  401: <tr><td>$inlineremote[71]</td><td>$inlineremote[72]</td><td>$inlineremote[73]</td></tr>
  402: <tr><td>$inlineremote[81]</td><td>$inlineremote[82]</td><td>$inlineremote[83]</td></tr>
  403: <tr><td>$inlineremote[91]</td><td>$inlineremote[92]</td><td>$inlineremote[93]</td></tr>
  404: ENDINLINE
  405: 	    }
  406: 	    $result =(<<ENDREGTEXT);
  407: <script>
  408: // BEGIN LON-CAPA Internal
  409: </script>
  410: $timesync
  411: $newmail
  412: $tablestart
  413: $inlinebuttons
  414: $tableend
  415: $form
  416: <script>
  417: // END LON-CAPA Internal
  418: </script>
  419: 
  420: ENDREGTEXT
  421: # Registered, graphical output
  422:         } else {
  423: 	    my $requri=(split(/\?/,$ENV{'request.noversionuri'}))[0];
  424: 	    $requri=&Apache::lonnet::unescape($requri);
  425: 	    my $navstatus=&get_nav_status();
  426: 	    $result = (<<ENDREGTHIS);
  427:      
  428: <script language="JavaScript">
  429: // BEGIN LON-CAPA Internal
  430: var swmenu=null;
  431: 
  432:     function LONCAPAreg() {
  433: 	  swmenu=$reopen;
  434:           swmenu.clearTimeout(swmenu.menucltim);
  435:           $timesync
  436:           $newmail
  437:           $buttons
  438: 	  swmenu.currentURL="$requri";
  439:           swmenu.reloadURL=swmenu.currentURL+window.location.search;
  440:           swmenu.currentSymb="$ENV{'request.symb'}";
  441:           swmenu.reloadSymb="$ENV{'request.symb'}";
  442:           swmenu.currentStale=0;
  443: 	  $navstatus
  444:           $hwkadd
  445:           $editbutton
  446:     }
  447: 
  448:     function LONCAPAstale() {
  449: 	  swmenu=$reopen
  450:           swmenu.currentStale=1;
  451:           if (swmenu.reloadURL!='' && swmenu.reloadURL!= null) { 
  452:              swmenu.switchbutton
  453:              (3,1,'reload.gif','return','location','go(reloadURL)','Return to the last known location in the course sequence');
  454: 	  }
  455:           swmenu.clearbut(7,1);
  456:           swmenu.clearbut(7,2);
  457:           swmenu.clearbut(7,3);
  458:           swmenu.menucltim=swmenu.setTimeout(
  459:  'clearbut(2,1);clearbut(2,3);clearbut(8,1);clearbut(8,2);clearbut(8,3);'+
  460:  'clearbut(9,1);clearbut(9,3);clearbut(6,3);clearbut(6,1)',
  461: 			  2000);
  462:       }
  463: 
  464: // END LON-CAPA Internal
  465: </script>
  466: ENDREGTHIS
  467:         }
  468: # =============================================================================
  469:     } else {
  470: # ========================================== This can or will not be registered
  471:         if ($textual) {
  472: # Not registered, textual
  473: 	    $result= (<<ENDDONOTREGTEXT);
  474: ENDDONOTREGTEXT
  475:         } else {
  476: # Not registered, graphical
  477:            $result = (<<ENDDONOTREGTHIS);
  478: 
  479: <script language="JavaScript">
  480: // BEGIN LON-CAPA Internal
  481: var swmenu=null;
  482: 
  483:     function LONCAPAreg() {
  484: 	  swmenu=$reopen
  485:           $timesync
  486:           swmenu.currentStale=1;
  487:           swmenu.clearbut(2,1);
  488:           swmenu.clearbut(2,3);
  489:           swmenu.clearbut(8,1);
  490:           swmenu.clearbut(8,2);
  491:           swmenu.clearbut(8,3);
  492:           if (swmenu.currentURL) {
  493:              swmenu.switchbutton
  494:               (3,1,'reload.gif','return','location','go(currentURL)');
  495:  	  } else {
  496: 	      swmenu.clearbut(3,1);
  497:           }
  498:     }
  499: 
  500:     function LONCAPAstale() {
  501:     }
  502: 
  503: // END LON-CAPA Internal
  504: </script>
  505: ENDDONOTREGTHIS
  506:        }
  507: # =============================================================================
  508:     }
  509:     return $result;
  510: }
  511: 
  512: sub loadevents() {
  513:     if ($ENV{'request.noversionuri'} eq '/res/adm/pages/menu.html') { return ''; }
  514:     return 'LONCAPAreg();';
  515: }
  516: 
  517: sub unloadevents() {
  518:     if ($ENV{'request.noversionuri'} eq '/res/adm/pages/menu.html') { return ''; }
  519:     return 'LONCAPAstale();';
  520: }
  521: 
  522: # ============================================================= Start up remote
  523: 
  524: sub startupremote {
  525:     my ($lowerurl)=@_;
  526:     if (($ENV{'browser.interface'} eq 'textual') ||
  527:         ($ENV{'environment.remote'} eq 'off')) {
  528:      return ('<meta HTTP-EQUIV="Refresh" CONTENT="0.5; url='.$lowerurl.'" />');
  529:     }
  530: #
  531: # The Remote actually gets launched!
  532: #
  533:     my $configmenu=&rawconfig();
  534:     my $esclowerurl=&Apache::lonnet::escape($lowerurl);
  535: 
  536:     return(<<ENDREMOTESTARTUP);
  537: <script>
  538: 
  539: function wheelswitch() {
  540:    if (window.status=='|') { 
  541:       window.status='/'; 
  542:    } else {
  543:       if (window.status=='/') {
  544:          window.status='-';
  545:       } else {
  546:          if (window.status=='-') { 
  547:             window.status='\\\\'; 
  548:          } else {
  549:             if (window.status=='\\\\') { window.status='|'; }
  550:          }
  551:       }
  552:    } 
  553: }
  554: 
  555: // ---------------------------------------------------------- The wait function
  556: var canceltim;
  557: function wait() {
  558:    if ((menuloaded==1) || (tim==1)) {
  559:       window.status='Done.';
  560:       if (tim==0) {
  561:          clearTimeout(canceltim);
  562:          $configmenu
  563:          window.location='$lowerurl';  
  564:       } else {
  565: 	  window.location='/adm/remote?action=collapse&url=$esclowerurl';
  566:       }
  567:    } else {
  568:       wheelswitch();
  569:       setTimeout('wait();',200);
  570:    }
  571: }
  572: 
  573: function main() {
  574:    canceltim=setTimeout('tim=1;',30000);
  575:    window.status='-';
  576:    wait();
  577: }
  578: 
  579: </script>
  580: ENDREMOTESTARTUP
  581: }
  582: 
  583: sub setflags() {
  584:     return(<<ENDSETFLAGS);
  585: <script>
  586:     menuloaded=0;
  587:     tim=0;
  588: </script>
  589: ENDSETFLAGS
  590: }
  591: 
  592: sub maincall() {
  593:     if (($ENV{'browser.interface'} eq 'textual') ||
  594:         ($ENV{'environment.remote'} eq 'off')) { return ''; }
  595:     return(<<ENDMAINCALL);
  596: <script>
  597:     main();
  598: </script>
  599: ENDMAINCALL
  600: }
  601: # ================================================================= Reopen menu
  602: 
  603: sub reopenmenu {
  604:    if (($ENV{'browser.interface'} eq 'textual') ||
  605:        ($ENV{'environment.remote'} eq 'off')) { return ''; }
  606:    my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
  607:    my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
  608:    return('window.open('.$nothing.',"'.$menuname.'","",false);');
  609: } 
  610: 
  611: # =============================================================== Open the menu
  612: 
  613: sub open {
  614:     my $returnval='';
  615:     if (($ENV{'browser.interface'} eq 'textual') ||
  616:         ($ENV{'environment.remote'} eq 'off')) { 
  617: 	return '<script type="text/javascript">self.name="loncapaclient";</script>';
  618:     }
  619:     my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
  620:     unless (shift eq 'unix') {
  621: # resizing does not work on linux because of virtual desktop sizes
  622:        $returnval.=(<<ENDRESIZE);
  623: if (window.screen) {
  624:     self.resizeTo(screen.availWidth-215,screen.availHeight-55);
  625:     self.moveTo(190,15);
  626: }
  627: ENDRESIZE
  628:     }
  629:     $returnval.=(<<ENDOPEN);
  630: window.status='Opening LON-CAPA Remote Control';
  631: var menu=window.open("/res/adm/pages/menu.html","$menuname",
  632: "height=350,width=150,scrollbars=no,menubar=no,top=5,left=5,screenX=5,screenY=5");
  633: self.name='loncapaclient';
  634: ENDOPEN
  635:     return '<script>'.$returnval.'</script>';
  636: }
  637: 
  638: 
  639: # ================================================================== Raw Config
  640: 
  641: sub clear {
  642:     my ($row,$col)=@_;
  643:     unless (($ENV{'browser.interface'} eq 'textual') ||
  644:             ($ENV{'environment.remote'} eq 'off')) {
  645:        return "\n".qq(window.status+='.';swmenu.clearbut($row,$col););
  646:    } else { 
  647:        $inlineremote[10*$row+$col]='';
  648:        return ''; 
  649:    }
  650: }
  651: 
  652: # ============================================ Switch a button or create a link
  653: # Switch acts on the javascript that is executed when a button is clicked.  
  654: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
  655: 
  656: sub switch {
  657:     my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$nobreak)=@_;
  658:     $act=~s/\$uname/$uname/g;
  659:     $act=~s/\$udom/$udom/g;
  660:     $top=&mt($top);
  661:     $bot=&mt($bot);
  662:     $desc=&mt($desc);
  663:     $img=&mt($img);
  664:     unless (($ENV{'browser.interface'} eq 'textual')  ||
  665:             ($ENV{'environment.remote'} eq 'off')) {
  666: # Remote
  667:        return "\n".
  668:  qq(window.status+='.';swmenu.switchbutton($row,$col,"$img","$top","$bot","$act","$desc"););
  669:    } elsif ($ENV{'browser.interface'} eq 'textual') {
  670: # Accessibility
  671:        if ($nobreak==2) { return ''; }
  672:        my $text=$top.' '.$bot;
  673:        $text=~s/\s*\-\s*//gs;
  674:        if ($nobreak) {
  675: 	   $inlineremote[10*$row+$col]=
  676: 	       '<a href="javascript:'.$act.';">'.$text.'</a>';
  677:        } else {
  678: 	   $inlineremote[10*$row+$col]="\n<br />".
  679: 	       $desc.' <a href="javascript:'.$act.';">'.$text.'</a>';
  680:        }
  681:    } else {
  682: # Inline Remote
  683:        if ($nobreak==2) { return ''; }
  684:        my $text=$top.' '.$bot;
  685:        $text=~s/\s*\-\s*//gs;
  686: 
  687:        my $lonhttpdPort=$Apache::lonnet::perlvar{'lonhttpdPort'};
  688:        if (!defined($lonhttpdPort)) { $lonhttpdPort='8080'; }
  689:        my $pic=
  690: 	   '<img border="0" alt="'.$text.'" src="http://'.$ENV{'HTTP_HOST'}.
  691: 	   ':'.$lonhttpdPort.'/res/adm/pages/'.$img.'" align="'.
  692: 	   ($nobreak==3?'right':'left').'" />';
  693:        if (($ENV{'browser.interface'} eq 'textual') || ($ENV{'browser.interface'} eq 'faketextual')) {
  694: # Accessibility
  695: 	   if ($nobreak==3) {
  696: 	       $inlineremote[10*$row+$col]="\n".
  697: 		   '<td width="40%" align="right"><font color="'.$font.'" size="+1">'.$text.
  698: 		   '</font></td><td width="10%" align="right" bgcolor="'.$tabbg.'">'.
  699: 		   '<a href="javascript:'.$act.';">'.$pic.'</a></td></tr>';
  700: 	   } elsif ($nobreak) {
  701: 	       $inlineremote[10*$row+$col]="\n<tr>".
  702: 		   '<td width="10%" align="left" bgcolor="'.$tabbg.'">'.
  703: 		   '<a href="javascript:'.$act.';">'.$pic.
  704: 		   '</a></td><td width="40%" align="left"><font color="'.$font.'" size="+1">'.$text.'</font></td>';
  705: 	   } else {
  706: 	       $inlineremote[10*$row+$col]="\n<tr>".
  707: 		   '<td width="10%" align="left" bgcolor="'.$tabbg.'">'.
  708: 		   '<a href="javascript:'.$act.';">'.$pic.
  709: 		   '</a></td><td colspan="3"><font color="'.$font.'">'.$desc.
  710: 		   '</font></td></tr>';       
  711: 	   }
  712:        } else {
  713: # Inline Menu
  714: 	   $inlineremote[10*$row+$col]=
  715: 		   '<a href="javascript:'.$act.';">'.$pic.
  716: 		   '</a><font color="'.$font.'" size="2">'.$desc.
  717: 		   '</font>';
  718:        }
  719:    }
  720:     return '';
  721: }
  722: 
  723: sub secondlevel {
  724:     my $output='';
  725:     my 
  726:     ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc)=@_;
  727:     if ($prt eq 'any') {
  728: 	   $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
  729:     } elsif ($prt=~/^r(\w+)/) {
  730:         if ($rol eq $1) {
  731:            $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
  732:         }
  733:     }
  734:     return $output;
  735: }
  736: 
  737: sub openmenu {
  738:     my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
  739:     if (($ENV{'browser.interface'} eq 'textual') ||
  740:         ($ENV{'environment.remote'} eq 'off')) { return ''; }
  741:     my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
  742:     return "window.open(".$nothing.",'".$menuname."');";
  743: }
  744: 
  745: sub inlinemenu {
  746:     @inlineremote=();
  747:     undef @inlineremote;
  748:     &rawconfig(1);
  749:     return join('',map { (defined($_)?$_:'') } @inlineremote);
  750: }
  751: 
  752: sub rawconfig {
  753:     my $textualoverride=shift;
  754:     my $output='';
  755:     unless (($ENV{'browser.interface'} eq 'textual') ||
  756:             ($ENV{'environment.remote'} eq 'off')) {
  757:        $output.=
  758:  "window.status='Opening Remote Control';var swmenu=".&openmenu().
  759: "\nwindow.status='Configuring Remote Control ';";
  760:     } else {
  761:        unless ($textualoverride) { return ''; }
  762:     }
  763:     my $uname=$ENV{'user.name'};
  764:     my $udom=$ENV{'user.domain'};
  765:     my $adv=$ENV{'user.adv'};
  766:     my $author=$ENV{'user.author'};
  767:     my $crs='';
  768:     if ($ENV{'request.course.id'}) {
  769:        $crs='/'.$ENV{'request.course.id'};
  770:        if ($ENV{'request.course.sec'}) {
  771: 	   $crs.='_'.$ENV{'request.course.sec'};
  772:        }
  773:        $crs=~s/\_/\//g;
  774:     }
  775:     my $pub=($ENV{'request.state'} eq 'published');
  776:     my $con=($ENV{'request.state'} eq 'construct');
  777:     my $rol=$ENV{'request.role'};
  778:     my $requested_domain = $ENV{'request.role.domain'};
  779:     foreach (@desklines) {
  780:         my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc)=split(/\:/,$_);
  781:         $prt=~s/\$uname/$uname/g;
  782:         $prt=~s/\$udom/$udom/g;
  783:         $prt=~s/\$crs/$crs/g; 
  784:         $prt=~s/\$requested_domain/$requested_domain/g;
  785:         if ($pro eq 'clear') {
  786: 	    $output.=&clear($row,$col);
  787:         } elsif ($pro eq 'any') {
  788:                $output.=&secondlevel(
  789: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
  790: 	} elsif ($pro eq 'smp') {
  791:             unless ($adv) {
  792:                $output.=&secondlevel(
  793:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
  794:             }
  795:         } elsif ($pro eq 'adv') {
  796:             if ($adv) {
  797:                $output.=&secondlevel(
  798: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
  799:             }
  800:         } elsif (($pro=~/^p(\w+)/) && ($prt)) {
  801: 	    if (&Apache::lonnet::allowed($1,$prt)) {
  802:                $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
  803:             }
  804:         } elsif ($pro eq 'course') {
  805:             if ($ENV{'request.course.fn'}) {
  806:                $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
  807: 	    }
  808:         } elsif ($pro =~ /^course_(.*)$/) {
  809:             # Check for permissions inside of a course
  810:             if (($ENV{'request.course.id'}) &&
  811:                 (&Apache::lonnet::allowed($1,$ENV{'request.course.id'}.
  812:             ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))
  813:                  )) {
  814:                 $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
  815: 	    }
  816:         } elsif ($pro eq 'author') {
  817:             if ($author) {
  818:                 if ((($prt eq 'rca') && ($ENV{'request.role'}=~/^ca/)) ||
  819:                     (($prt eq 'rau') && ($ENV{'request.role'}=~/^au/))) {
  820:                     # Check that we are on the correct machine
  821:                     my $cadom=$requested_domain;
  822:                     my $caname=$ENV{'user.name'};
  823:                     if ($prt eq 'rca') {
  824: 		       ($cadom,$caname)=
  825:                                ($ENV{'request.role'}=~/(\w+)\/(\w+)$/);
  826:                     }                       
  827:                     $act =~ s/\$caname/$caname/g;
  828:                     my $home = &Apache::lonnet::homeserver($caname,$cadom);
  829: 		    my $allowed=0;
  830: 		    my @ids=&Apache::lonnet::current_machine_ids();
  831: 		    foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
  832: 		    if ($allowed) {
  833:                         $output.=switch($caname,$cadom,
  834:                                         $row,$col,$img,$top,$bot,$act,$desc);
  835:                     }
  836:                 }
  837:             }
  838:         }
  839:     }
  840:     unless (($ENV{'browser.interface'} eq 'textual') ||
  841:             ($ENV{'environment.remote'} eq 'off')) {
  842:        $output.="\nwindow.status='Synchronizing Time';swmenu.syncclock(1000*".time.");\nwindow.status='Remote Control Configured.';";
  843:     }
  844:     return $output;
  845: }
  846: 
  847: # ======================================================================= Close
  848: 
  849: sub close {
  850:     if (($ENV{'browser.interface'} eq 'textual') ||
  851:         ($ENV{'environment.remote'} eq 'off')) { return ''; }
  852:     my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
  853:     return(<<ENDCLOSE);
  854: <script>
  855: window.status='Accessing Remote Control';
  856: menu=window.open("/adm/rat/empty.html","$menuname",
  857:                  "height=350,width=150,scrollbars=no,menubar=no");
  858: window.status='Disabling Remote Control';
  859: menu.active=0;
  860: menu.autologout=0;
  861: window.status='Closing Remote Control';
  862: menu.close();
  863: window.status='Done.';
  864: </script>
  865: ENDCLOSE
  866: }
  867: 
  868: # ====================================================================== Footer
  869: 
  870: sub footer {
  871: 
  872: }
  873: 
  874: sub utilityfunctions {
  875:     unless (($ENV{'browser.interface'} eq 'textual')  ||
  876:         ($ENV{'environment.remote'} eq 'off')) { return ''; }
  877:     my $currenturl=$ENV{'request.noversionuri'};
  878:     my $currentsymb=$ENV{'request.symb'};
  879:     my $nav_control=&Apache::lonnavmaps::nav_control_js();
  880: return (<<ENDUTILITY)
  881: 
  882:     var currentURL="$currenturl";
  883:     var reloadURL="$currenturl";
  884:     var currentSymb="$currentsymb";
  885: 
  886: $nav_control
  887: 
  888: function go(url) {
  889:    if (url!='' && url!= null) {
  890:        currentURL = null;
  891:        currentSymb= null;
  892:        window.location.href=url;
  893:    }
  894: }
  895: 
  896: function gopost(url,postdata) {
  897:    if (url!='') {
  898:       this.document.server.action=url;
  899:       this.document.server.postdata.value=postdata;
  900:       this.document.server.command.value='';
  901:       this.document.server.url.value='';
  902:       this.document.server.symb.value='';
  903:       this.document.server.submit();
  904:    }
  905: }
  906: 
  907: function gocmd(url,cmd) {
  908:    if (url!='') {
  909:       this.document.server.action=url;
  910:       this.document.server.postdata.value='';
  911:       this.document.server.command.value=cmd;
  912:       this.document.server.url.value=currentURL;
  913:       this.document.server.symb.value=currentSymb;
  914:       this.document.server.submit();
  915:    }
  916: }
  917: 
  918: function catalog_info() {
  919:    loncatinfo=window.open(window.location.pathname+'.meta',"LONcatInfo",'height=320,width=280,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
  920: }
  921: 
  922: function chat_win() {
  923:    lonchat=window.open('/res/adm/pages/chatroom.html',"LONchat",'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
  924: }
  925: ENDUTILITY
  926: }
  927: 
  928: sub serverform {
  929:     return(<<ENDSERVERFORM);
  930: 
  931: <form name="server" action="/adm/logout" method="post" target="_top">
  932: <input type="hidden" name="postdata" value="none" />
  933: <input type="hidden" name="command" value="none" />
  934: <input type="hidden" name="url" value="none" />
  935: <input type="hidden" name="symb" value="none" />
  936: </form>
  937: ENDSERVERFORM
  938: }
  939: 
  940: sub get_nav_status {
  941:     my $navstatus="swmenu.w_loncapanav_flag=";
  942:     if ($ENV{'environment.remotenavmap'} eq 'on') {
  943: 	$navstatus.="1";
  944:     } else {
  945: 	$navstatus.="-1";
  946:     }
  947:     return $navstatus;
  948: }
  949: 
  950: # ================================================ Handler when called directly
  951: 
  952: 
  953: sub handler {
  954:     my $r = shift;
  955:     &Apache::loncommon::content_type($r,'text/html');
  956:     $r->send_http_header;
  957:     return OK if $r->header_only;
  958: 
  959:     my $form=&serverform();
  960:     my $bodytag=&Apache::loncommon::bodytag('Main Menu');
  961:     my $function='student';
  962:     if ($ENV{'request.role'}=~/^(cc|in|ta|ep)/) {
  963: 	$function='coordinator';
  964:     }
  965:     if ($ENV{'request.role'}=~/^(su|dc|ad|li)/) {
  966: 	$function='admin';
  967:     }
  968:     if (($ENV{'request.role'}=~/^(au|ca)/) ||
  969: 	($ENV{'request.noversionuri'}=~/^(\/priv|\~)/)) {
  970: 	$function='author';
  971:     }
  972:     my $domain=&Apache::loncommon::determinedomain();
  973:     $pgbg=&Apache::loncommon::designparm($function.'.pgbg',$domain);
  974:     $tabbg=&Apache::loncommon::designparm($function.'.tabbg',$domain);
  975:     $font=&Apache::loncommon::designparm($function.'.font',$domain);
  976: # ---- Print the screen, pretent to be in text mode to generate text-based menu
  977:     unless ($ENV{'browser.interface'} eq 'textual') {
  978: 	$ENV{'browser.interface'}='faketextual';
  979: 	$ENV{'environment.remote'}='off';
  980:     }
  981:     $r->print(<<ENDHEADER);
  982: <html><head>
  983: <title>LON-CAPA Main Menu</title>
  984: </head>
  985: $bodytag
  986: ENDHEADER
  987:     $r->print('<table>'.&inlinemenu().'</table>'.$form);
  988:     $r->print('</body></html>');
  989:     return OK;
  990: }
  991: 
  992: # ================================================================ Main Program
  993: 
  994: BEGIN {
  995:   if (! defined($readdesk)) {
  996:    {
  997:     my $tabfile = $Apache::lonnet::perlvar{'lonTabDir'}.'/mydesk.tab';
  998:     if ( CORE::open( my $config,"<$tabfile") ) {
  999:         while (my $configline=<$config>) {
 1000:             $configline=(split(/\#/,$configline))[0];
 1001:             $configline=~s/^\s+//;
 1002:             chomp($configline);
 1003:             if ($configline) {
 1004:                 $desklines[$#desklines+1]=$configline;
 1005:             }
 1006:         }
 1007:         CORE::close($config);
 1008:     }
 1009:    }
 1010:    $readdesk='done';
 1011:   }
 1012: }
 1013: 
 1014: 1;
 1015: __END__
 1016: 
 1017: 
 1018: 
 1019: 
 1020: 
 1021: 
 1022: 

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