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

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

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