Annotation of loncom/interface/lonmenu.pm, revision 1.66

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

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