File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.104: download - view: text, annotated - select for diffs
Mon Dec 8 15:02:34 2003 UTC (20 years, 5 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
Replaced use of Apache::File to open files with CORE::open and CORE::close to allow use of lonmenu.pm outside Apache (i.e., in standalone mode when called by a cron job owned by www).

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

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