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

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

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