File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.62: download - view: text, annotated - select for diffs
Fri Apr 18 00:02:34 2003 UTC (21 years, 1 month ago) by www
Branches: MAIN
CVS tags: HEAD
Framed remote now works for Safari browser ... but not on Netscape, Explorer
and Mozilla ...

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

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