File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.109: download - view: text, annotated - select for diffs
Fri Jul 2 07:58:01 2004 UTC (19 years, 10 months ago) by albertel
Branches: MAIN
CVS tags: version_1_1_99_2, version_1_1_99_1, HEAD
- multi-domain authors weren't getting CSTR buttons, BUG#3153

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

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