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

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

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