File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.108: download - view: text, annotated - select for diffs
Sun Jun 27 16:03:57 2004 UTC (19 years, 11 months ago) by www
Branches: MAIN
CVS tags: HEAD
Bug #2151: VBKM button disappears no more.

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

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