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

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

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