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

1.1       www         1: # The LearningOnline Network with CAPA
                      2: # Routines to control the menu
                      3: #
1.150   ! albertel    4: # $Id: lonmenu.pm,v 1.149 2005/02/21 00:32:04 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.115     albertel   42: use Apache::lonnet();
1.33      www        43: use Apache::Constants qw(:common);
1.47      matthew    44: use Apache::lonhtmlcommon();
1.115     albertel   45: use Apache::loncommon();
1.127     albertel   46: use Apache::lonenc();
1.88      www        47: use Apache::lonlocal;
                     48: 
1.2       www        49: use vars qw(@desklines $readdesk);
1.88      www        50: 
                     51: 
1.56      www        52: my @inlineremote;
1.58      www        53: my $font;
                     54: my $tabbg;
                     55: my $pgbg;
1.38      www        56: 
1.88      www        57: # ================================================================ Little texts
                     58: 
                     59: sub initlittle {
                     60:     return &Apache::lonlocal::texthash('ret' => 'Return to Last Location',
                     61: 				       'nav' => 'Navigate Contents',
                     62: 				       'main' => 'Main Menu',
1.149     www        63:                                        'roles' => ($ENV{'user.adv'}?
                     64:                                                     'Roles':'Courses'),
                     65:                                        'exit' => 'Exit',
1.88      www        66: 				       'launch' => 'Launch Remote Control');
                     67: }
                     68: 
1.40      www        69: # ============================= This gets called at the top of the body section
1.38      www        70: 
                     71: sub menubuttons {
                     72:     my $forcereg=shift;
                     73:     my $target  =shift;
1.40      www        74:     my $registration=shift;
1.131     raeburn    75:     my $titletable=shift;
1.112     albertel   76:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                     77: 					    ['inhibitmenu']);
1.149     www        78:     if (($ENV{'form.inhibitmenu'} eq 'yes') ||
                     79:         ($ENV{'REQUEST_URI'} eq '/adm/logout')) { return ''; }
1.112     albertel   80: 
1.55      www        81:     my $navmaps='';
1.59      www        82:     my $reloadlink='';
1.126     albertel   83:     my $escurl=&Apache::lonnet::escape(&Apache::lonenc::check_encrypt($ENV{'request.noversionuri'}));
                     84:     my $escsymb=&Apache::lonnet::escape(&Apache::lonenc::check_encrypt($ENV{'request.symb'}));
1.134     raeburn    85:     if ($ENV{'request.state'} eq 'construct') {
                     86:         if (($ENV{'request.noversionuri'} eq '') || (!defined($ENV{'request.noversionuri'}))) {
                     87:             my $returnurl = $ENV{'request.filename'};
                     88:             $returnurl =~ s:^/home/([^/]+)/public_html/(.*)$:/priv/$1/$2:;
                     89:             $escurl = &Apache::lonnet::escape($returnurl);
                     90:         }
                     91:     }
1.48      www        92:     if ($ENV{'browser.interface'} eq 'textual') {
1.41      www        93: # Textual display only
1.88      www        94: 	my %lt=&initlittle();
1.101     www        95:         $pgbg='#FFFFFF';
                     96:         $tabbg='#FFFFFF';
                     97: 	$font='#000000';
1.55      www        98:         if ($ENV{'request.course.id'}) {
                     99: 	    $navmaps=(<<ENDNAV);
1.88      www       100: <a href="/adm/navmaps?postdata=$escurl&postsymb=$escsymb" target="_top">$lt{'nav'}</a>
1.55      www       101: ENDNAV
1.97      www       102:             if (($ENV{'request.noversionuri'}=~/^\/adm\//) &&
                    103:          ($ENV{'request.noversionuri'}!~/^\/adm\/wrapper\//) &&
                    104:          ($ENV{'request.noversionuri'}!~/^\/adm\/.*\/(smppg|bulletinboard|aboutme)(\?|$)/)) {
1.59      www       105:                 my $escreload=&Apache::lonnet::escape('return:');
                    106:                 $reloadlink=(<<ENDRELOAD);
1.88      www       107: <a href="/adm/flip?postdata=$escreload" target="_top"><font color="$font">$lt{'ret'}</font></a>
1.59      www       108: ENDRELOAD
                    109:             }
1.149     www       110: 	}
1.130     albertel  111:         my $form=&serverform();
1.116     albertel  112:         my $utility=&utilityfunctions();
1.48      www       113: 	my $output=(<<ENDMAINMENU);
1.129     albertel  114: <script type="text/javascript">
1.150   ! albertel  115: // BEGIN LON-CAPA Internal
1.116     albertel  116: $utility
1.44      www       117: </script>
1.88      www       118: <a href="/adm/menu" target="_top">$lt{'main'}</a>
1.149     www       119: $reloadlink $navmaps
                    120: <a href="/adm/roles" target="_top"><font color="$font">$lt{'roles'}</font></a>
                    121: <a href="/adm/logout" target="_top"><font color="$font">$lt{'exit'}</font></a>
                    122: <br />
1.129     albertel  123: <script type="text/javascript">
1.44      www       124: // END LON-CAPA Internal
                    125: </script>
1.130     albertel  126: $form
1.44      www       127: ENDMAINMENU
1.48      www       128:         if ($registration) { $output.=&innerregister($forcereg,$target); }
                    129: 	return $output."<hr />";
                    130:     } elsif ($ENV{'environment.remote'} eq 'off') {
                    131: # Remote Control is switched off
1.58      www       132: # figure out colors
1.88      www       133: 	my %lt=&initlittle();
1.58      www       134: 	my $function='student';
                    135:         if ($ENV{'request.role'}=~/^(cc|in|ta|ep)/) {
                    136: 	    $function='coordinator';
                    137:         }
                    138: 	if ($ENV{'request.role'}=~/^(su|dc|ad|li)/) {
                    139:             $function='admin';
                    140:         }
                    141:         if (($ENV{'request.role'}=~/^(au|ca)/) ||
1.97      www       142:             ($ENV{'request.noversionuri'}=~/^(\/priv|\~)/)) {
1.58      www       143:             $function='author';
                    144:         }
                    145:         my $domain=&Apache::loncommon::determinedomain();
                    146:         $pgbg=&Apache::loncommon::designparm($function.'.pgbg',$domain);
                    147:         $tabbg=&Apache::loncommon::designparm($function.'.tabbg',$domain);
                    148:         $font=&Apache::loncommon::designparm($function.'.font',$domain);
                    149:         my $link=&Apache::loncommon::designparm($function.'.link',$domain);
                    150:         my $alink=&Apache::loncommon::designparm($function.'.alink',$domain);
                    151:         my $vlink=&Apache::loncommon::designparm($function.'.vlink',$domain);
                    152:         my $sidebg=&Apache::loncommon::designparm($function.'.sidebg',$domain);
                    153: # Do we have a NAV link?
1.55      www       154:         if ($ENV{'request.course.id'}) {
1.141     albertel  155: 	    my $link='/adm/navmaps?postdata='.$escurl.'&amp;postsymb='.
                    156: 		$escsymb;
                    157: 	    if ($ENV{'environment.remotenavmap'} eq 'on') {
                    158: 		$link="javascript:gonav('".$link."')";
                    159: 	    }
                    160: 	    $navmaps=(<<ENDNAV);
1.58      www       161: <td bgcolor="$tabbg">
1.141     albertel  162: <a href="$link"><font color="$font">$lt{'nav'}</font></a></td>
1.114     albertel  163: ENDNAV
1.144     albertel  164: 	    if (
                    165: 		($ENV{'request.noversionuri'}=~m[^/(res|public)/] &&
1.145     albertel  166: 		 $ENV{'request.symb'} eq '')
1.144     albertel  167: 		||
                    168: 		(($ENV{'request.noversionuri'}=~/^\/adm\//) &&
                    169: 		 ($ENV{'request.noversionuri'}!~/^\/adm\/wrapper\//) &&
                    170: 		 ($ENV{'request.noversionuri'}!~
                    171: 		        m[^/adm/.*/(smppg|bulletinboard|aboutme)($|\?)])
                    172: 		  )
                    173: 		 ) {
1.59      www       174:                 my $escreload=&Apache::lonnet::escape('return:');
                    175:                 $reloadlink=(<<ENDRELOAD);
                    176: <td bgcolor="$tabbg">
1.88      www       177: <a href="/adm/flip?postdata=$escreload" target="_top"><font color="$font">$lt{'ret'}</font></a></td>
1.59      www       178: ENDRELOAD
                    179:             }
1.55      www       180:         }
1.58      www       181:         my $reg='';
                    182:         if ($registration) {
1.131     raeburn   183:            $reg=&innerregister($forcereg,$target,$titletable);
1.58      www       184:         }
1.130     albertel  185:         my $form=&serverform();
1.116     albertel  186: 	my $utility=&utilityfunctions();
1.146     albertel  187: 	my $logo=&Apache::loncommon::lonhttpdurl("/adm/lonIcons/minilogo.gif");
1.58      www       188: 	return (<<ENDINLINEMENU);
1.129     albertel  189: <script type="text/javascript">
1.150   ! albertel  190: // BEGIN LON-CAPA Internal
        !           191: // <![CDATA[
1.116     albertel  192: $utility
1.150   ! albertel  193: // ]]>
1.48      www       194: </script>
1.99      www       195: <font face="Arial,Helvetica,sans-serif"><table bgcolor="$pgbg" width="100%" border="0" cellpadding="1" cellspacing="1">
1.58      www       196: <tr>
                    197: <td bgcolor="$tabbg">
1.88      www       198: <a href="/adm/menu" target="_top"><font color="$font">$lt{'main'}</font></a>
1.58      www       199: </td>
1.59      www       200: $reloadlink
1.55      www       201: $navmaps
1.58      www       202: <td bgcolor="$tabbg">
1.129     albertel  203: <a href="/adm/remote?action=launch&amp;url=$escurl" target="_top">
1.88      www       204: <font color="$font">$lt{'launch'}</font></a></td>
1.65      www       205: <td bgcolor="$tabbg">
1.149     www       206: <a href="/adm/roles" target="_top"><font color="$font">$lt{'roles'}</font></a>
                    207: </td>
                    208: <td bgcolor="$tabbg">
                    209: <a href="/adm/logout" target="_top"><font color="$font">$lt{'exit'}</font></a>
                    210: </td>
                    211: <td bgcolor="$tabbg">
1.146     albertel  212: <img align="right" src="$logo" />
1.65      www       213: <b>LON-CAPA</b></td>
1.130     albertel  214: $form
1.58      www       215: </tr>
                    216: </table>
1.99      www       217: </font>
1.129     albertel  218: <script type="text/javascript">
1.48      www       219: // END LON-CAPA Internal
                    220: </script>
1.58      www       221: $reg
1.48      www       222: ENDINLINEMENU
                    223:     } else {
                    224: 	return '';
                    225:     }
1.72      www       226: }
                    227: 
1.40      www       228: # ====================================== This gets called in the header section
1.38      www       229: 
                    230: sub registerurl {
                    231:     my $forcereg=shift;
                    232:     my $target = shift;
                    233:     my $result = '';
1.97      www       234:     if ($ENV{'request.noversionuri'} eq '/res/adm/pages/menu.html') { return ''; }
1.66      albertel  235:     my $force_title='';
                    236:     if ($ENV{'request.state'} eq 'construct') {
                    237: 	$force_title=&Apache::lonxml::display_title();
                    238:     }
1.38      www       239:     if ($target eq 'edit') {
1.45      www       240:         $result .="<script type=\"text/javascript\">\n".
1.38      www       241:             "if (typeof swmenu != 'undefined') {swmenu.currentURL=null;}\n".
                    242:             &Apache::loncommon::browser_and_searcher_javascript().
                    243:                 "\n</script>\n";
                    244:     }
                    245:     if (($ENV{'browser.interface'} eq 'textual') ||
1.53      www       246:         ($ENV{'environment.remote'} eq 'off') ||
1.38      www       247:         ((($ENV{'request.publicaccess'}) || 
1.83      www       248:          (!&Apache::lonnet::is_on_map(
1.97      www       249: 	   &Apache::lonnet::unescape($ENV{'request.noversionuri'})))) &&
1.38      www       250:         (!$forcereg))) {
1.76      www       251:  	return $result.
                    252:           '<script type="text/javascript">function LONCAPAreg(){;} function LONCAPAstale(){}</script>'.$force_title;
1.38      www       253:     }
1.41      www       254: # Graphical display after login only
1.38      www       255:     if ($Apache::lonxml::registered && !$forcereg) { return ''; }
1.96      albertel  256:     if ($target ne 'edit') {
                    257: 	$result.=&innerregister($forcereg,$target);
                    258:     }
1.66      albertel  259:     return $result.$force_title;
1.40      www       260: }
                    261: 
                    262: # =========== This gets called in order to register a URL, both with the Remote
                    263: # =========== and in the body of the document
                    264: 
                    265: sub innerregister {
                    266:     my $forcereg=shift;
                    267:     my $target = shift;
1.131     raeburn   268:     my $titletable = shift;
1.40      www       269:     my $result = '';
1.120     raeburn   270:     my ($uname,$thisdisfn);
1.128     albertel  271:     my $const_space = ($ENV{'request.state'} eq 'construct');
1.131     raeburn   272:     my $is_const_dir = 0;
1.120     raeburn   273: 
1.97      www       274:     if ($ENV{'request.noversionuri'} eq '/res/adm/pages/menu.html') { return ''; }
1.40      www       275: 
1.38      www       276:     $Apache::lonxml::registered=1;
1.40      www       277: 
1.49      www       278:     my $textinter=($ENV{'browser.interface'} eq 'textual');
                    279:     my $noremote=($ENV{'environment.remote'} eq 'off');
                    280:     
                    281:     my $textual=($textinter || $noremote);
                    282: 
1.56      www       283:     @inlineremote=();
                    284:     undef @inlineremote;
                    285: 
1.38      www       286:     my $reopen=&Apache::lonmenu::reopenmenu();
1.40      www       287: 
1.38      www       288:     my $newmail='';
1.65      www       289:     if ($noremote) {
1.99      www       290: 	$newmail='<font face="Arial,Helvetica,sans-serif"><table bgcolor="'.$pgbg.'" border="0" cellspacing="1" cellpadding="1" width="100%"><tr><td bgcolor="'.$tabbg.'">';
1.65      www       291:     }
1.61      www       292:     if (($textual) && ($ENV{'request.symb'}) && ($ENV{'request.course.id'})) {
1.87      www       293: 	my ($mapurl,$rid,$resurl)=&Apache::lonnet::decode_symb($ENV{'request.symb'});
1.65      www       294:         $newmail.=$ENV{'course.'.$ENV{'request.course.id'}.'.description'};
1.61      www       295:         my $maptitle=&Apache::lonnet::gettitle($mapurl);
                    296: 	my $restitle=&Apache::lonnet::gettitle($resurl);
1.133     albertel  297:         if ($maptitle && $maptitle ne 'default.sequence') {
1.61      www       298: 	    $newmail.=', '.$maptitle;
                    299:         }
                    300:         if ($restitle) {
                    301: 	    $newmail.=': '.$restitle;
                    302:         }
                    303:         $newmail.='&nbsp;&nbsp;&nbsp;';
1.60      www       304:     }
1.38      www       305:     if (&Apache::lonmsg::newmail()) { 
1.41      www       306:        $newmail=($textual?
1.80      www       307:  '<b><a href="/adm/communicate" target="_top">You have new messages</a></b><br />':
1.40      www       308:                           'swmenu.setstatus("you have","messages");');
1.65      www       309:     }
1.131     raeburn   310:     if ($ENV{'request.state'} eq 'construct') {
                    311:         $newmail = $titletable;
1.150   ! albertel  312:     } else {
        !           313: 	if ($noremote) {
        !           314: 	    $newmail.='</td></tr></table></font>';
        !           315: 	}
1.38      www       316:     }
1.40      www       317:     my $timesync=($textual?'':'swmenu.syncclock(1000*'.time.');');
1.100     www       318:     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 />':'');
                    319:     my $tableend=($noremote?'</table></font>':'').($textinter?'<a name="content" />':'');
1.41      www       320: # =============================================================================
                    321: # ============================ This is for URLs that actually can be registered
1.145     albertel  322:     if (($ENV{'request.noversionuri'}!~m|^/(res/)*adm/|) || ($forcereg)) {
1.40      www       323: # -- This applies to homework problems for users with grading privileges
1.107     albertel  324: 	my $crs='/'.$ENV{'request.course.id'};
                    325: 	if ($ENV{'request.course.sec'}) {
                    326: 	    $crs.='_'.$ENV{'request.course.sec'};
                    327: 	}
                    328: 	$crs=~s/\_/\//g;
                    329: 
1.38      www       330:         my $hwkadd='';
1.145     albertel  331:         if ($ENV{'request.symb'} ne '' &&
                    332: 	    $ENV{'request.filename'}=~/\.(problem|exam|quiz|assess|survey|form)$/) {
1.79      www       333: 	    if (&Apache::lonnet::allowed('vgr',$crs)) {
1.106     www       334: 		$hwkadd.=&switch('','',7,1,'subm.gif','view sub-[_1]','missions[_1]',
1.40      www       335:                        "gocmd('/adm/grades','submission')",
                    336: 		       'View user submissions for this assessment resource');
1.38      www       337:             }
1.79      www       338: 	    if (&Apache::lonnet::allowed('mgr',$crs)) {
1.106     www       339: 		$hwkadd.=&switch('','',7,2,'pgrd.gif','problem[_1]','grades[_3]',
1.40      www       340:                        "gocmd('/adm/grades','gradingmenu')",
                    341:                        'Modify user grades for this assessment resource');
1.38      www       342:             }
1.107     albertel  343: 	}
1.145     albertel  344: 	if ($ENV{'request.symb'} ne '' &&
                    345: 	    &Apache::lonnet::allowed('opa',$crs)) {
1.107     albertel  346: 	    $hwkadd.=&switch('','',7,3,'pparm.gif','problem[_2]','parms[_2]',
                    347: 			     "gocmd('/adm/parmset','set')",
                    348: 			     'Modify deadlines, etc, for this resource');
1.38      www       349: 	}
1.40      www       350: # -- End Homework
1.38      www       351:         ###
                    352:         ### Determine whether or not to display the 'cstr' button for this
                    353:         ### resource
                    354:         ###
                    355:         my $editbutton = '';
                    356:         if ($ENV{'user.author'}) {
                    357:             if ($ENV{'request.role'}=~/^(ca|au)/) {
                    358:                 # Set defaults for authors
                    359:                 my ($top,$bottom) = ('con-','struct');
                    360:                 my $action = "go('/priv/".$ENV{'user.name'}."');";
                    361:                 my $cadom  = $ENV{'request.role.domain'};
                    362:                 my $caname = $ENV{'user.name'};
                    363:                 my $desc = "Enter my resource construction space";
                    364:                 # Set defaults for co-authors
                    365:                 if ($ENV{'request.role'} =~ /^ca/) { 
                    366:                     ($cadom,$caname)=($ENV{'request.role'}=~/(\w+)\/(\w+)$/);
                    367:                     ($top,$bottom) = ('co con-','struct');
                    368:                     $action = "go('/priv/".$caname."');";
                    369:                     $desc = "Enter construction space as co-author";
                    370:                 }
                    371:                 # Check that we are on the correct machine
                    372:                 my $home = &Apache::lonnet::homeserver($caname,$cadom);
1.109     albertel  373: 		my $allowed=0;
                    374: 		my @ids=&Apache::lonnet::current_machine_ids();
                    375: 		foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
                    376: 		if (!$allowed) {
                    377: 		    $editbutton=&switch('','',6,1,$top,,$bottom,$action,$desc);
1.38      www       378:                 }
                    379:             }
                    380:             ##
                    381:             ## Determine if user can edit url.
                    382:             ##
                    383:             my $cfile='';
                    384:             my $cfuname='';
                    385:             my $cfudom='';
                    386:             if ($ENV{'request.filename'}) {
                    387:                 my $file=&Apache::lonnet::declutter($ENV{'request.filename'});
                    388:                 $file=~s/^(\w+)\/(\w+)/\/priv\/$2/;
1.109     albertel  389:                 # Check that the user has permission to edit this resource
1.38      www       390:                 ($cfuname,$cfudom)=&Apache::loncacc::constructaccess($file,$1);
                    391:                 if (defined($cfudom)) {
1.109     albertel  392: 		    my $home=&Apache::lonnet::homeserver($cfuname,$cfudom);
                    393: 		    my $allowed=0;
                    394: 		    my @ids=&Apache::lonnet::current_machine_ids();
                    395: 		    foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
                    396: 		    if ($allowed) {
1.38      www       397:                         $cfile=$file;
                    398:                     }
                    399:                 }
                    400:             }        
                    401:             # Finally, turn the button on or off
1.120     raeburn   402:             if ($cfile && !$const_space) {
1.40      www       403:                 $editbutton=&switch
1.106     www       404:                     ('','',6,1,'cstr.gif','edit[_1]','resource[_2]',
1.38      www       405:                      "go('".$cfile."');","Edit this resource");
                    406:             } elsif ($editbutton eq '') {
1.40      www       407:                 $editbutton=&clear(6,1);
1.38      www       408:             }
                    409:         }
                    410:         ###
                    411:         ###
1.41      www       412: # Prepare the rest of the buttons
1.120     raeburn   413:         my $menuitems;
                    414:         if ($const_space) {
1.128     albertel  415: 	    my ($uname,$thisdisfn) =
                    416: 		($ENV{'request.filename'}=~m|^/home/([^/]+)/public_html/(.*)|);
1.121     raeburn   417:             my $currdir = '/priv/'.$uname.'/'.$thisdisfn;
1.131     raeburn   418:             if ($currdir =~ m-/$-) {
                    419:                 $is_const_dir = 1;
                    420:             } else {
                    421:                 $currdir =~ s#[^/]+$##;
                    422:                 $menuitems=(<<ENDMENUITEMS);
                    423: s&6&1&list.gif&list[_1]&dir[_1]&golist('$currdir')&List current directory
                    424: s&6&2&rtrv.gif&retrieve[_1]&version[_1]&gocstr('/adm/retrieve','/~$uname/$thisdisfn')&Retrieve old version
1.121     raeburn   425: s&6&3&pub.gif&publish[_1]&resource[_1]&gocstr('/adm/publish','/~$uname/$thisdisfn')&Publish this resource
                    426: s&7&1&del.gif&delete[_1]&resource[_2]&gocstr('/adm/cfile?action=delete','/~$uname/$thisdisfn')&Delete this resource
1.137     raeburn   427: s&7&2&prt.gif&prepare[_1]&printout[_1]&gocstr('/adm/printout','/~$uname/$thisdisfn')&Prepare a printable document
1.120     raeburn   428: ENDMENUITEMS
1.131     raeburn   429:             }
1.145     albertel  430:         } elsif (defined($ENV{'request.course.id'}) && 
                    431: 		 $ENV{'request.symb'} ne '') {
1.120     raeburn   432: 	    $menuitems=(<<ENDMENUITEMS);
1.41      www       433: c&3&1
1.106     www       434: s&2&1&back.gif&backward[_1]&&gopost('/adm/flip','back:'+currentURL)&Go to the previous resource in the course sequence&1
                    435: s&2&3&forw.gif&forward[_1]&&gopost('/adm/flip','forward:'+currentURL)&Go to the next resource in the course sequence&3
1.77      www       436: c&6&3
                    437: c&8&1
                    438: c&8&2
1.106     www       439: s&8&3&prt.gif&prepare[_1]&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
                    440: s&9&1&sbkm.gif&set[_1]&bookmark[_2]&set_bookmark()&Set a bookmark for this resource&2
                    441: s&9&3&anot.gif&anno-[_1]&tations[_1]&annotate()&Make notes and annotations about this resource&2
1.41      www       442: ENDMENUITEMS
1.120     raeburn   443:             unless ($ENV{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme)(\?|$)/) {
                    444: 	        $menuitems.=(<<ENDREALRES);
1.106     www       445: s&6&3&catalog.gif&catalog[_1]&info[_1]&catalog_info()&Show catalog information
                    446: s&8&1&eval.gif&evaluate[_1]&this[_1]&gopost('/adm/evaluate',currentURL,1)&Provide my evaluation of this resource
                    447: 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
1.77      www       448: ENDREALRES
1.120     raeburn   449: 	    }
                    450:         }
1.41      www       451:         my $buttons='';
                    452:         foreach (split(/\n/,$menuitems)) {
                    453: 	    my ($command,@rest)=split(/\&/,$_);
                    454:             if ($command eq 's') {
                    455: 		$buttons.=&switch('','',@rest);
                    456:             } else {
                    457:                 $buttons.=&clear(@rest);
                    458:             }
                    459:         }
1.148     albertel  460: 
                    461:         if ($textual) {
                    462: 	    my $addremote=0;
                    463: 	    foreach (@inlineremote) { if ($_ ne '') { $addremote=1; } }
                    464: 	    my $inlinebuttons='';
                    465: 	    if ($addremote) {
1.41      www       466: # Registered, textual output
1.103     www       467: 
1.148     albertel  468: 		if ($ENV{'browser.interface'} eq 'textual') {
                    469: 		    $inlinebuttons=
1.56      www       470:                         join('',map { (defined($_)?$_:'') } @inlineremote);
1.148     albertel  471: 		} else {
                    472: 		    $inlinebuttons=(<<ENDINLINE);
1.129     albertel  473: <tr><td>$inlineremote[21]</td><td>&nbsp;</td><td>$inlineremote[23]</td></tr>
1.103     www       474: <tr><td>$inlineremote[61]</td><td>$inlineremote[62]</td><td>$inlineremote[63]</td></tr>
                    475: <tr><td>$inlineremote[71]</td><td>$inlineremote[72]</td><td>$inlineremote[73]</td></tr>
                    476: <tr><td>$inlineremote[81]</td><td>$inlineremote[82]</td><td>$inlineremote[83]</td></tr>
                    477: <tr><td>$inlineremote[91]</td><td>$inlineremote[92]</td><td>$inlineremote[93]</td></tr>
                    478: ENDINLINE
1.148     albertel  479:                 }
1.103     www       480: 	    }
1.41      www       481: 	    $result =(<<ENDREGTEXT);
1.129     albertel  482: <script type="text/javascript">
1.42      www       483: // BEGIN LON-CAPA Internal
                    484: </script>
1.41      www       485: $timesync
                    486: $newmail
1.58      www       487: $tablestart
1.56      www       488: $inlinebuttons
1.58      www       489: $tableend
1.129     albertel  490: <script type="text/javascript">
1.64      www       491: // END LON-CAPA Internal
1.42      www       492: </script>
                    493: 
1.41      www       494: ENDREGTEXT
                    495: # Registered, graphical output
                    496:         } else {
1.139     albertel  497: 	    my $requri=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$ENV{'request.noversionuri'}))[0]));
1.126     albertel  498: 	    $requri=&Apache::lonenc::check_encrypt(&Apache::lonnet::unescape($requri));
                    499: 	    my $cursymb=&Apache::lonenc::check_encrypt($ENV{'request.symb'});
1.113     albertel  500: 	    my $navstatus=&get_nav_status();
1.140     albertel  501: 	    my $clearcstr;
1.148     albertel  502: 
1.140     albertel  503: 	    if ($ENV{'user.adv'}) { $clearcstr='clearbut(6,1)'; }
1.41      www       504: 	    $result = (<<ENDREGTHIS);
1.38      www       505:      
1.129     albertel  506: <script type="text/javascript">
1.150   ! albertel  507: // BEGIN LON-CAPA Internal
1.42      www       508: var swmenu=null;
1.38      www       509: 
                    510:     function LONCAPAreg() {
                    511: 	  swmenu=$reopen;
                    512:           swmenu.clearTimeout(swmenu.menucltim);
                    513:           $timesync
                    514:           $newmail
1.41      www       515:           $buttons
1.84      www       516: 	  swmenu.currentURL="$requri";
1.85      www       517:           swmenu.reloadURL=swmenu.currentURL+window.location.search;
1.125     albertel  518:           swmenu.currentSymb="$cursymb";
                    519:           swmenu.reloadSymb="$cursymb";
1.38      www       520:           swmenu.currentStale=0;
1.113     albertel  521: 	  $navstatus
1.38      www       522:           $hwkadd
                    523:           $editbutton
                    524:     }
                    525: 
                    526:     function LONCAPAstale() {
                    527: 	  swmenu=$reopen
                    528:           swmenu.currentStale=1;
                    529:           if (swmenu.reloadURL!='' && swmenu.reloadURL!= null) { 
                    530:              swmenu.switchbutton
                    531:              (3,1,'reload.gif','return','location','go(reloadURL)','Return to the last known location in the course sequence');
                    532: 	  }
                    533:           swmenu.clearbut(7,1);
                    534:           swmenu.clearbut(7,2);
                    535:           swmenu.clearbut(7,3);
                    536:           swmenu.menucltim=swmenu.setTimeout(
                    537:  'clearbut(2,1);clearbut(2,3);clearbut(8,1);clearbut(8,2);clearbut(8,3);'+
1.140     albertel  538:  'clearbut(9,1);clearbut(9,3);clearbut(6,3);$clearcstr',
1.38      www       539: 			  2000);
                    540:       }
                    541: 
1.150   ! albertel  542: // END LON-CAPA Internal 
1.38      www       543: </script>
                    544: ENDREGTHIS
1.41      www       545:         }
                    546: # =============================================================================
1.38      www       547:     } else {
1.41      www       548: # ========================================== This can or will not be registered
                    549:         if ($textual) {
                    550: # Not registered, textual
                    551: 	    $result= (<<ENDDONOTREGTEXT);
                    552: ENDDONOTREGTEXT
                    553:         } else {
                    554: # Not registered, graphical
                    555:            $result = (<<ENDDONOTREGTHIS);
1.38      www       556: 
1.129     albertel  557: <script type="text/javascript">
1.38      www       558: // BEGIN LON-CAPA Internal
1.42      www       559: var swmenu=null;
1.38      www       560: 
                    561:     function LONCAPAreg() {
                    562: 	  swmenu=$reopen
                    563:           $timesync
                    564:           swmenu.currentStale=1;
                    565:           swmenu.clearbut(2,1);
                    566:           swmenu.clearbut(2,3);
                    567:           swmenu.clearbut(8,1);
                    568:           swmenu.clearbut(8,2);
                    569:           swmenu.clearbut(8,3);
                    570:           if (swmenu.currentURL) {
                    571:              swmenu.switchbutton
                    572:               (3,1,'reload.gif','return','location','go(currentURL)');
                    573:  	  } else {
                    574: 	      swmenu.clearbut(3,1);
                    575:           }
                    576:     }
                    577: 
                    578:     function LONCAPAstale() {
                    579:     }
                    580: 
                    581: // END LON-CAPA Internal
                    582: </script>
                    583: ENDDONOTREGTHIS
1.41      www       584:        }
                    585: # =============================================================================
1.38      www       586:     }
                    587:     return $result;
                    588: }
                    589: 
                    590: sub loadevents() {
1.135     albertel  591:     if ($ENV{'request.state'} eq 'construct' ||
                    592: 	$ENV{'request.noversionuri'} eq '/res/adm/pages/menu.html') { return ''; }
1.38      www       593:     return 'LONCAPAreg();';
                    594: }
                    595: 
                    596: sub unloadevents() {
1.135     albertel  597:     if ($ENV{'request.state'} eq 'construct' ||
                    598: 	$ENV{'request.noversionuri'} eq '/res/adm/pages/menu.html') { return ''; }
1.38      www       599:     return 'LONCAPAstale();';
                    600: }
1.30      www       601: 
1.32      www       602: # ============================================================= Start up remote
                    603: 
                    604: sub startupremote {
                    605:     my ($lowerurl)=@_;
1.49      www       606:     if (($ENV{'browser.interface'} eq 'textual') ||
                    607:         ($ENV{'environment.remote'} eq 'off')) {
1.34      www       608:      return ('<meta HTTP-EQUIV="Refresh" CONTENT="0.5; url='.$lowerurl.'" />');
                    609:     }
1.49      www       610: #
                    611: # The Remote actually gets launched!
                    612: #
1.32      www       613:     my $configmenu=&rawconfig();
1.52      www       614:     my $esclowerurl=&Apache::lonnet::escape($lowerurl);
1.119     www       615:     my $message=&mt('"Waiting for Remote Control window to load: "+[_1]','waited');
1.32      www       616:     return(<<ENDREMOTESTARTUP);
1.129     albertel  617: <script type="text/javascript">
1.118     albertel  618: var timestart;
1.35      www       619: function wheelswitch() {
1.118     albertel  620:     if (typeof(document.wheel) != 'undefined') {
                    621: 	if (typeof(document.wheel.spin) != 'undefined') {
                    622: 	    var date=new Date();
                    623: 	    var waited=Math.round(30-((date.getTime()-timestart)/1000));
                    624: 	    document.wheel.spin.value=$message;
                    625: 	}
                    626:     }
1.35      www       627:    if (window.status=='|') { 
                    628:       window.status='/'; 
                    629:    } else {
                    630:       if (window.status=='/') {
                    631:          window.status='-';
                    632:       } else {
                    633:          if (window.status=='-') { 
                    634:             window.status='\\\\'; 
                    635:          } else {
                    636:             if (window.status=='\\\\') { window.status='|'; }
                    637:          }
                    638:       }
                    639:    } 
                    640: }
                    641: 
1.32      www       642: // ---------------------------------------------------------- The wait function
                    643: var canceltim;
                    644: function wait() {
                    645:    if ((menuloaded==1) || (tim==1)) {
1.35      www       646:       window.status='Done.';
1.32      www       647:       if (tim==0) {
                    648:          clearTimeout(canceltim);
                    649:          $configmenu
                    650:          window.location='$lowerurl';  
                    651:       } else {
1.52      www       652: 	  window.location='/adm/remote?action=collapse&url=$esclowerurl';
1.32      www       653:       }
                    654:    } else {
1.35      www       655:       wheelswitch();
                    656:       setTimeout('wait();',200);
1.32      www       657:    }
                    658: }
                    659: 
                    660: function main() {
1.52      www       661:    canceltim=setTimeout('tim=1;',30000);
1.35      www       662:    window.status='-';
1.118     albertel  663:    var date=new Date();
                    664:    timestart=date.getTime();
1.32      www       665:    wait();
                    666: }
                    667: 
                    668: </script>
                    669: ENDREMOTESTARTUP
                    670: }
                    671: 
                    672: sub setflags() {
                    673:     return(<<ENDSETFLAGS);
1.129     albertel  674: <script type="text/javascript">
1.32      www       675:     menuloaded=0;
                    676:     tim=0;
                    677: </script>
                    678: ENDSETFLAGS
                    679: }
                    680: 
                    681: sub maincall() {
1.49      www       682:     if (($ENV{'browser.interface'} eq 'textual') ||
                    683:         ($ENV{'environment.remote'} eq 'off')) { return ''; }
1.32      www       684:     return(<<ENDMAINCALL);
1.129     albertel  685: <script type="text/javascript">
1.32      www       686:     main();
                    687: </script>
                    688: ENDMAINCALL
                    689: }
1.118     albertel  690: 
                    691: sub load_remote_msg {
                    692:     my ($lowerurl)=@_;
                    693: 
                    694:     if (($ENV{'browser.interface'} eq 'textual') ||
                    695:         ($ENV{'environment.remote'} eq 'off')) { return ''; }
                    696: 
                    697:     my $esclowerurl=&Apache::lonnet::escape($lowerurl);
1.119     www       698:     my $link=&mt('<a href="[_1]">Continue</a> on in Inline Menu mode',
1.118     albertel  699: 		    "/adm/remote?action=collapse?url=$esclowerurl");
                    700:     return(<<ENDREMOTEFORM);
                    701: <p>
                    702: <form name="wheel">
1.119     www       703: <input name="spin" type="text" size="60" />
1.118     albertel  704: </form>
                    705: </p>
                    706: <p>$link</p>
                    707: ENDREMOTEFORM
                    708: }
1.30      www       709: # ================================================================= Reopen menu
                    710: 
                    711: sub reopenmenu {
1.49      www       712:    if (($ENV{'browser.interface'} eq 'textual') ||
                    713:        ($ENV{'environment.remote'} eq 'off')) { return ''; }
1.30      www       714:    my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
1.47      matthew   715:    my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
                    716:    return('window.open('.$nothing.',"'.$menuname.'","",false);');
1.30      www       717: } 
                    718: 
1.1       www       719: # =============================================================== Open the menu
                    720: 
                    721: sub open {
1.22      www       722:     my $returnval='';
1.49      www       723:     if (($ENV{'browser.interface'} eq 'textual') ||
1.111     albertel  724:         ($ENV{'environment.remote'} eq 'off')) { 
                    725: 	return '<script type="text/javascript">self.name="loncapaclient";</script>';
                    726:     }
1.30      www       727:     my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
1.22      www       728:     unless (shift eq 'unix') {
                    729: # resizing does not work on linux because of virtual desktop sizes
                    730:        $returnval.=(<<ENDRESIZE);
                    731: if (window.screen) {
1.28      www       732:     self.resizeTo(screen.availWidth-215,screen.availHeight-55);
1.22      www       733:     self.moveTo(190,15);
                    734: }
                    735: ENDRESIZE
                    736:     }
                    737:     $returnval.=(<<ENDOPEN);
1.35      www       738: window.status='Opening LON-CAPA Remote Control';
1.30      www       739: var menu=window.open("/res/adm/pages/menu.html","$menuname",
1.14      www       740: "height=350,width=150,scrollbars=no,menubar=no,top=5,left=5,screenX=5,screenY=5");
1.71      www       741: self.name='loncapaclient';
1.1       www       742: ENDOPEN
1.129     albertel  743:     return '<script type="text/javascript">'.$returnval.'</script>';
1.1       www       744: }
                    745: 
1.2       www       746: 
                    747: # ================================================================== Raw Config
                    748: 
1.3       www       749: sub clear {
                    750:     my ($row,$col)=@_;
1.49      www       751:     unless (($ENV{'browser.interface'} eq 'textual') ||
                    752:             ($ENV{'environment.remote'} eq 'off')) {
1.35      www       753:        return "\n".qq(window.status+='.';swmenu.clearbut($row,$col););
1.56      www       754:    } else { 
                    755:        $inlineremote[10*$row+$col]='';
                    756:        return ''; 
                    757:    }
1.3       www       758: }
                    759: 
1.40      www       760: # ============================================ Switch a button or create a link
1.25      matthew   761: # Switch acts on the javascript that is executed when a button is clicked.  
                    762: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
1.40      www       763: 
1.2       www       764: sub switch {
1.40      www       765:     my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$nobreak)=@_;
1.2       www       766:     $act=~s/\$uname/$uname/g;
                    767:     $act=~s/\$udom/$udom/g;
1.88      www       768:     $top=&mt($top);
                    769:     $bot=&mt($bot);
                    770:     $desc=&mt($desc);
1.105     www       771:     $img=&mt($img);
1.49      www       772:     unless (($ENV{'browser.interface'} eq 'textual')  ||
                    773:             ($ENV{'environment.remote'} eq 'off')) {
1.50      www       774: # Remote
1.34      www       775:        return "\n".
1.35      www       776:  qq(window.status+='.';swmenu.switchbutton($row,$col,"$img","$top","$bot","$act","$desc"););
1.50      www       777:    } elsif ($ENV{'browser.interface'} eq 'textual') {
                    778: # Accessibility
                    779:        if ($nobreak==2) { return ''; }
                    780:        my $text=$top.' '.$bot;
1.78      www       781:        $text=~s/\s*\-\s*//gs;
1.94      www       782:        if ($nobreak) {
                    783: 	   $inlineremote[10*$row+$col]=
                    784: 	       '<a href="javascript:'.$act.';">'.$text.'</a>';
                    785:        } else {
                    786: 	   $inlineremote[10*$row+$col]="\n<br />".
1.100     www       787: 	       $desc.' <a href="javascript:'.$act.';">'.$text.'</a>';
1.94      www       788:        }
1.34      www       789:    } else {
1.50      www       790: # Inline Remote
1.41      www       791:        if ($nobreak==2) { return ''; }
1.34      www       792:        my $text=$top.' '.$bot;
1.78      www       793:        $text=~s/\s*\-\s*//gs;
1.105     www       794: 
                    795:        my $lonhttpdPort=$Apache::lonnet::perlvar{'lonhttpdPort'};
                    796:        if (!defined($lonhttpdPort)) { $lonhttpdPort='8080'; }
1.99      www       797:        my $pic=
1.105     www       798: 	   '<img border="0" alt="'.$text.'" src="http://'.$ENV{'HTTP_HOST'}.
                    799: 	   ':'.$lonhttpdPort.'/res/adm/pages/'.$img.'" align="'.
1.103     www       800: 	   ($nobreak==3?'right':'left').'" />';
                    801:        if (($ENV{'browser.interface'} eq 'textual') || ($ENV{'browser.interface'} eq 'faketextual')) {
                    802: # Accessibility
                    803: 	   if ($nobreak==3) {
                    804: 	       $inlineremote[10*$row+$col]="\n".
                    805: 		   '<td width="40%" align="right"><font color="'.$font.'" size="+1">'.$text.
                    806: 		   '</font></td><td width="10%" align="right" bgcolor="'.$tabbg.'">'.
                    807: 		   '<a href="javascript:'.$act.';">'.$pic.'</a></td></tr>';
                    808: 	   } elsif ($nobreak) {
                    809: 	       $inlineremote[10*$row+$col]="\n<tr>".
                    810: 		   '<td width="10%" align="left" bgcolor="'.$tabbg.'">'.
                    811: 		   '<a href="javascript:'.$act.';">'.$pic.
                    812: 		   '</a></td><td width="40%" align="left"><font color="'.$font.'" size="+1">'.$text.'</font></td>';
                    813: 	   } else {
                    814: 	       $inlineremote[10*$row+$col]="\n<tr>".
                    815: 		   '<td width="10%" align="left" bgcolor="'.$tabbg.'">'.
                    816: 		   '<a href="javascript:'.$act.';">'.$pic.
                    817: 		   '</a></td><td colspan="3"><font color="'.$font.'">'.$desc.
                    818: 		   '</font></td></tr>';       
                    819: 	   }
1.94      www       820:        } else {
1.103     www       821: # Inline Menu
                    822: 	   $inlineremote[10*$row+$col]=
                    823: 		   '<a href="javascript:'.$act.';">'.$pic.
                    824: 		   '</a><font color="'.$font.'" size="2">'.$desc.
                    825: 		   '</font>';
1.94      www       826:        }
1.34      www       827:    }
1.56      www       828:     return '';
1.2       www       829: }
                    830: 
                    831: sub secondlevel {
                    832:     my $output='';
                    833:     my 
1.27      www       834:     ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc)=@_;
1.2       www       835:     if ($prt eq 'any') {
1.27      www       836: 	   $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
1.2       www       837:     } elsif ($prt=~/^r(\w+)/) {
                    838:         if ($rol eq $1) {
1.27      www       839:            $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
1.2       www       840:         }
                    841:     }
                    842:     return $output;
                    843: }
                    844: 
1.18      www       845: sub openmenu {
1.30      www       846:     my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
1.49      www       847:     if (($ENV{'browser.interface'} eq 'textual') ||
                    848:         ($ENV{'environment.remote'} eq 'off')) { return ''; }
1.47      matthew   849:     my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
                    850:     return "window.open(".$nothing.",'".$menuname."');";
1.18      www       851: }
                    852: 
1.56      www       853: sub inlinemenu {
                    854:     @inlineremote=();
                    855:     undef @inlineremote;
                    856:     &rawconfig(1);
                    857:     return join('',map { (defined($_)?$_:'') } @inlineremote);
                    858: }
                    859: 
1.2       www       860: sub rawconfig {
1.34      www       861:     my $textualoverride=shift;
                    862:     my $output='';
1.49      www       863:     unless (($ENV{'browser.interface'} eq 'textual') ||
                    864:             ($ENV{'environment.remote'} eq 'off')) {
1.35      www       865:        $output.=
                    866:  "window.status='Opening Remote Control';var swmenu=".&openmenu().
                    867: "\nwindow.status='Configuring Remote Control ';";
1.34      www       868:     } else {
                    869:        unless ($textualoverride) { return ''; }
                    870:     }
1.2       www       871:     my $uname=$ENV{'user.name'};
                    872:     my $udom=$ENV{'user.domain'};
                    873:     my $adv=$ENV{'user.adv'};
1.4       www       874:     my $author=$ENV{'user.author'};
1.5       www       875:     my $crs='';
                    876:     if ($ENV{'request.course.id'}) {
                    877:        $crs='/'.$ENV{'request.course.id'};
1.7       www       878:        if ($ENV{'request.course.sec'}) {
                    879: 	   $crs.='_'.$ENV{'request.course.sec'};
                    880:        }
1.8       www       881:        $crs=~s/\_/\//g;
1.5       www       882:     }
1.2       www       883:     my $pub=($ENV{'request.state'} eq 'published');
                    884:     my $con=($ENV{'request.state'} eq 'construct');
                    885:     my $rol=$ENV{'request.role'};
1.25      matthew   886:     my $requested_domain = $ENV{'request.role.domain'};
1.13      harris41  887:     foreach (@desklines) {
1.27      www       888:         my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc)=split(/\:/,$_);
1.3       www       889:         $prt=~s/\$uname/$uname/g;
                    890:         $prt=~s/\$udom/$udom/g;
1.5       www       891:         $prt=~s/\$crs/$crs/g; 
1.25      matthew   892:         $prt=~s/\$requested_domain/$requested_domain/g;
1.3       www       893:         if ($pro eq 'clear') {
1.4       www       894: 	    $output.=&clear($row,$col);
1.3       www       895:         } elsif ($pro eq 'any') {
1.2       www       896:                $output.=&secondlevel(
1.27      www       897: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
1.2       www       898: 	} elsif ($pro eq 'smp') {
                    899:             unless ($adv) {
                    900:                $output.=&secondlevel(
1.27      www       901:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
1.2       www       902:             }
                    903:         } elsif ($pro eq 'adv') {
                    904:             if ($adv) {
                    905:                $output.=&secondlevel(
1.27      www       906: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
1.2       www       907:             }
1.81      matthew   908:         } elsif (($pro=~/^p(\w+)/) && ($prt)) {
1.2       www       909: 	    if (&Apache::lonnet::allowed($1,$prt)) {
1.27      www       910:                $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
1.4       www       911:             }
1.26      www       912:         } elsif ($pro eq 'course') {
                    913:             if ($ENV{'request.course.fn'}) {
1.27      www       914:                $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
1.81      matthew   915: 	    }
1.124     matthew   916:         } elsif ($pro =~ /^courseenv_(.*)$/) {
                    917:             my $key = $1;
                    918:             if ($ENV{'course.'.$ENV{'request.course.id'}.'.'.$key}) {
                    919:                 $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
                    920:             }
1.81      matthew   921:         } elsif ($pro =~ /^course_(.*)$/) {
                    922:             # Check for permissions inside of a course
                    923:             if (($ENV{'request.course.id'}) &&
                    924:                 (&Apache::lonnet::allowed($1,$ENV{'request.course.id'}.
                    925:             ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))
                    926:                  )) {
                    927:                 $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
1.26      www       928: 	    }
1.4       www       929:         } elsif ($pro eq 'author') {
                    930:             if ($author) {
1.29      matthew   931:                 if ((($prt eq 'rca') && ($ENV{'request.role'}=~/^ca/)) ||
                    932:                     (($prt eq 'rau') && ($ENV{'request.role'}=~/^au/))) {
1.19      matthew   933:                     # Check that we are on the correct machine
1.29      matthew   934:                     my $cadom=$requested_domain;
                    935:                     my $caname=$ENV{'user.name'};
                    936:                     if ($prt eq 'rca') {
                    937: 		       ($cadom,$caname)=
1.6       www       938:                                ($ENV{'request.role'}=~/(\w+)\/(\w+)$/);
1.29      matthew   939:                     }                       
                    940:                     $act =~ s/\$caname/$caname/g;
1.19      matthew   941:                     my $home = &Apache::lonnet::homeserver($caname,$cadom);
1.109     albertel  942: 		    my $allowed=0;
                    943: 		    my @ids=&Apache::lonnet::current_machine_ids();
                    944: 		    foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
                    945: 		    if ($allowed) {
1.19      matthew   946:                         $output.=switch($caname,$cadom,
1.27      www       947:                                         $row,$col,$img,$top,$bot,$act,$desc);
1.19      matthew   948:                     }
1.6       www       949:                 }
1.2       www       950:             }
                    951:         }
1.13      harris41  952:     }
1.49      www       953:     unless (($ENV{'browser.interface'} eq 'textual') ||
                    954:             ($ENV{'environment.remote'} eq 'off')) {
1.35      www       955:        $output.="\nwindow.status='Synchronizing Time';swmenu.syncclock(1000*".time.");\nwindow.status='Remote Control Configured.';";
1.123     www       956:        if (&Apache::lonmsg::newmail()) { 
                    957: 	   $output.='swmenu.setstatus("you have","messages");';
                    958:        }
1.34      www       959:     }
1.123     www       960: 
1.2       www       961:     return $output;
                    962: }
                    963: 
                    964: # ======================================================================= Close
1.1       www       965: 
                    966: sub close {
1.49      www       967:     if (($ENV{'browser.interface'} eq 'textual') ||
                    968:         ($ENV{'environment.remote'} eq 'off')) { return ''; }
1.30      www       969:     my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
1.1       www       970:     return(<<ENDCLOSE);
1.129     albertel  971: <script type="text/javascript">
1.35      www       972: window.status='Accessing Remote Control';
1.30      www       973: menu=window.open("/adm/rat/empty.html","$menuname",
1.1       www       974:                  "height=350,width=150,scrollbars=no,menubar=no");
1.35      www       975: window.status='Disabling Remote Control';
                    976: menu.active=0;
1.31      www       977: menu.autologout=0;
1.35      www       978: window.status='Closing Remote Control';
1.1       www       979: menu.close();
1.35      www       980: window.status='Done.';
1.1       www       981: </script>
                    982: ENDCLOSE
                    983: }
                    984: 
                    985: # ====================================================================== Footer
                    986: 
                    987: sub footer {
                    988: 
1.33      www       989: }
                    990: 
1.122     albertel  991: sub nav_control_js {
                    992:     my $nav=($ENV{'environment.remotenavmap'} eq 'on');
                    993:     return (<<NAVCONTROL);
                    994:     var w_loncapanav_flag="$nav";
                    995: 
                    996: 
                    997: function gonav(url) {
                    998:    if (w_loncapanav_flag != 1) {
                    999:       gopost(url,'');
                   1000:    }  else {
                   1001:       navwindow=window.open(url,
                   1002:                   "loncapanav","height=600,width=400,scrollbars=1"); 
                   1003:    }
                   1004: }
                   1005: NAVCONTROL
                   1006: }
                   1007: 
1.42      www      1008: sub utilityfunctions {
1.132     raeburn  1009:     my $caller = shift;
1.51      www      1010:     unless (($ENV{'browser.interface'} eq 'textual')  ||
1.132     raeburn  1011:         ($ENV{'environment.remote'} eq 'off') || ($caller eq '/adm/menu')) { return ''; }
1.143     albertel 1012:     my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$ENV{'request.noversionuri'}))[0]));
                   1013:     $currenturl=&Apache::lonenc::check_encrypt(&Apache::lonnet::unescape($currenturl));
1.125     albertel 1014:     
1.126     albertel 1015:     my $currentsymb=&Apache::lonenc::check_encrypt($ENV{'request.symb'});
1.122     albertel 1016:     my $nav_control=&nav_control_js();
1.42      www      1017: return (<<ENDUTILITY)
                   1018: 
                   1019:     var currentURL="$currenturl";
                   1020:     var reloadURL="$currenturl";
                   1021:     var currentSymb="$currentsymb";
                   1022: 
1.114     albertel 1023: $nav_control
                   1024: 
1.42      www      1025: function go(url) {
                   1026:    if (url!='' && url!= null) {
                   1027:        currentURL = null;
                   1028:        currentSymb= null;
                   1029:        window.location.href=url;
                   1030:    }
                   1031: }
                   1032: 
                   1033: function gopost(url,postdata) {
                   1034:    if (url!='') {
                   1035:       this.document.server.action=url;
                   1036:       this.document.server.postdata.value=postdata;
                   1037:       this.document.server.command.value='';
                   1038:       this.document.server.url.value='';
                   1039:       this.document.server.symb.value='';
                   1040:       this.document.server.submit();
                   1041:    }
                   1042: }
                   1043: 
                   1044: function gocmd(url,cmd) {
                   1045:    if (url!='') {
                   1046:       this.document.server.action=url;
                   1047:       this.document.server.postdata.value='';
                   1048:       this.document.server.command.value=cmd;
                   1049:       this.document.server.url.value=currentURL;
                   1050:       this.document.server.symb.value=currentSymb;
                   1051:       this.document.server.submit();
                   1052:    }
1.57      www      1053: }
                   1054: 
1.121     raeburn  1055: function gocstr(url,filename) {
                   1056:     if (url == '/adm/cfile?action=delete') {
                   1057:         this.document.cstrdelete.filename.value = filename
                   1058:         this.document.cstrdelete.submit();
                   1059:         return;
                   1060:     }
1.137     raeburn  1061:     if (url == '/adm/printout') {
                   1062:         this.document.cstrprint.postdata.value = filename
                   1063:         this.document.cstrprint.curseed.value = 0;
                   1064:         this.document.cstrprint.problemtype.value = 0;
1.138     raeburn  1065:         if (this.document.lonhomework) {
                   1066:             if ((this.document.lonhomework.rndseed) && (this.document.lonhomework.rndseed.value != null) && (this.document.lonhomework.rndseed.value != '')) {
                   1067:                 this.document.cstrprint.curseed.value = this.document.lonhomework.rndseed.value
                   1068:             }
                   1069:             if (this.document.lonhomework.problemtype) {
                   1070:                 for (var i=0; i<this.document.lonhomework.problemtype.options.length; i++) {
                   1071:                     if (this.document.lonhomework.problemtype.options[i].selected) {
                   1072:                         if (this.document.lonhomework.problemtype.options[i].value != null && this.document.lonhomework.problemtype.options[i].value != '') { 
                   1073:                             this.document.cstrprint.problemtype.value = this.document.lonhomework.problemtype.options[i].value
                   1074:                         }
                   1075:                     }
1.137     raeburn  1076:                 }
                   1077:             }
                   1078:         }
                   1079:         this.document.cstrprint.submit();
                   1080:         return;
                   1081:     }
1.121     raeburn  1082:     if (url !='') {
                   1083:         this.document.constspace.filename.value = filename;
                   1084:         this.document.constspace.action = url;
                   1085:         this.document.constspace.submit();
                   1086:     }
                   1087: }
                   1088: 
1.131     raeburn  1089: function golist(url) {
                   1090:    if (url!='' && url!= null) {
                   1091:        currentURL = null;
                   1092:        currentSymb= null;
                   1093:        top.location.href=url;
                   1094:    }
                   1095: }
                   1096: 
                   1097: 
1.121     raeburn  1098: 
1.57      www      1099: function catalog_info() {
1.102     albertel 1100:    loncatinfo=window.open(window.location.pathname+'.meta',"LONcatInfo",'height=320,width=280,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
1.57      www      1101: }
                   1102: 
                   1103: function chat_win() {
1.102     albertel 1104:    lonchat=window.open('/res/adm/pages/chatroom.html',"LONchat",'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
1.42      www      1105: }
                   1106: ENDUTILITY
                   1107: }
                   1108: 
                   1109: sub serverform {
                   1110:     return(<<ENDSERVERFORM);
                   1111: 
1.62      www      1112: <form name="server" action="/adm/logout" method="post" target="_top">
1.42      www      1113: <input type="hidden" name="postdata" value="none" />
                   1114: <input type="hidden" name="command" value="none" />
                   1115: <input type="hidden" name="url" value="none" />
                   1116: <input type="hidden" name="symb" value="none" />
                   1117: </form>
                   1118: ENDSERVERFORM
                   1119: }
1.113     albertel 1120: 
1.121     raeburn  1121: sub constspaceform {
                   1122:     return(<<ENDCONSTSPACEFORM);
                   1123: <form name="constspace" action="/adm/logout" method="post" target="_top">
                   1124: <input type="hidden" name="filename" value="" />
                   1125: </form>
                   1126: <form name="cstrdelete" action="/adm/cfile" method="post" target="_top">
                   1127: <input type="hidden" name="action" value="delete" /> 
                   1128: <input type="hidden" name="filename" value="" />
                   1129: </form>
1.137     raeburn  1130: <form name="cstrprint" action="/adm/printout" target="_parent" method="post">
                   1131: <input type="hidden" name="postdata" value="" />
                   1132: <input type="hidden" name="curseed" value="" />
                   1133: <input type="hidden" name="problemtype" value="" />
                   1134: </form>
                   1135: 
1.121     raeburn  1136: ENDCONSTSPACEFORM
                   1137: }
                   1138: 
                   1139: 
1.113     albertel 1140: sub get_nav_status {
                   1141:     my $navstatus="swmenu.w_loncapanav_flag=";
                   1142:     if ($ENV{'environment.remotenavmap'} eq 'on') {
                   1143: 	$navstatus.="1";
                   1144:     } else {
                   1145: 	$navstatus.="-1";
                   1146:     }
                   1147:     return $navstatus;
                   1148: }
                   1149: 
1.33      www      1150: # ================================================ Handler when called directly
                   1151: 
                   1152: 
                   1153: sub handler {
                   1154:     my $r = shift;
1.93      www      1155:     &Apache::loncommon::content_type($r,'text/html');
1.33      www      1156:     $r->send_http_header;
                   1157:     return OK if $r->header_only;
                   1158: 
1.130     albertel 1159:     my $form;
                   1160:     if ($ENV{'environment.remote'} ne 'off' &&
                   1161: 	$ENV{'browser.interface'} ne 'textual') {
                   1162: 	$form=&serverform();
                   1163:     }
1.34      www      1164:     my $bodytag=&Apache::loncommon::bodytag('Main Menu');
1.58      www      1165:     my $function='student';
                   1166:     if ($ENV{'request.role'}=~/^(cc|in|ta|ep)/) {
                   1167: 	$function='coordinator';
                   1168:     }
                   1169:     if ($ENV{'request.role'}=~/^(su|dc|ad|li)/) {
                   1170: 	$function='admin';
                   1171:     }
                   1172:     if (($ENV{'request.role'}=~/^(au|ca)/) ||
1.97      www      1173: 	($ENV{'request.noversionuri'}=~/^(\/priv|\~)/)) {
1.58      www      1174: 	$function='author';
                   1175:     }
                   1176:     my $domain=&Apache::loncommon::determinedomain();
                   1177:     $pgbg=&Apache::loncommon::designparm($function.'.pgbg',$domain);
                   1178:     $tabbg=&Apache::loncommon::designparm($function.'.tabbg',$domain);
                   1179:     $font=&Apache::loncommon::designparm($function.'.font',$domain);
1.132     raeburn  1180:     my $script_tag;
1.142     albertel 1181:     if ($ENV{'environment.remote'} ne 'off') {
1.132     raeburn  1182:         my $utility=&utilityfunctions('/adm/menu');
                   1183:         $script_tag=(<<ENDSCRIPT);
                   1184: <script type="text/javascript">
                   1185: $utility
                   1186: </script>
                   1187: ENDSCRIPT
                   1188:     }
                   1189: # ---- Print the screen, pretend to be in text mode to generate text-based menu
1.103     www      1190:     unless ($ENV{'browser.interface'} eq 'textual') {
                   1191: 	$ENV{'browser.interface'}='faketextual';
1.53      www      1192: 	$ENV{'environment.remote'}='off';
                   1193:     }
1.147     albertel 1194:     my $html=&Apache::lonxml::xmlbegin();
1.36      www      1195:     $r->print(<<ENDHEADER);
1.147     albertel 1196: $html
                   1197: <head>
1.36      www      1198: <title>LON-CAPA Main Menu</title>
1.132     raeburn  1199: $script_tag
1.36      www      1200: </head>
                   1201: $bodytag
                   1202: ENDHEADER
1.58      www      1203:     $r->print('<table>'.&inlinemenu().'</table>'.$form);
1.33      www      1204:     $r->print('</body></html>');
                   1205:     return OK;
1.1       www      1206: }
                   1207: 
1.2       www      1208: # ================================================================ Main Program
                   1209: 
1.16      harris41 1210: BEGIN {
1.15      matthew  1211:   if (! defined($readdesk)) {
1.14      www      1212:    {
1.104     raeburn  1213:     my $tabfile = $Apache::lonnet::perlvar{'lonTabDir'}.'/mydesk.tab';
                   1214:     if ( CORE::open( my $config,"<$tabfile") ) {
                   1215:         while (my $configline=<$config>) {
                   1216:             $configline=(split(/\#/,$configline))[0];
                   1217:             $configline=~s/^\s+//;
                   1218:             chomp($configline);
                   1219:             if ($configline) {
                   1220:                 $desklines[$#desklines+1]=$configline;
                   1221:             }
                   1222:         }
                   1223:         CORE::close($config);
1.2       www      1224:     }
1.14      www      1225:    }
                   1226:    $readdesk='done';
1.10      albertel 1227:   }
1.2       www      1228: }
1.30      www      1229: 
1.1       www      1230: 1;
                   1231: __END__
                   1232: 
                   1233: 
                   1234: 
                   1235: 
                   1236: 
                   1237: 
                   1238: 

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