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

1.1       www         1: # The LearningOnline Network with CAPA
                      2: # Routines to control the menu
                      3: #
1.49    ! www         4: # $Id: lonmenu.pm,v 1.48 2003/04/02 22:02:19 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.38      www        48: 
1.40      www        49: # ============================= This gets called at the top of the body section
1.38      www        50: 
                     51: sub menubuttons {
                     52:     my $forcereg=shift;
                     53:     my $target  =shift;
1.40      www        54:     my $registration=shift;
1.48      www        55:     if ($ENV{'browser.interface'} eq 'textual') {
1.41      www        56: # Textual display only
1.48      www        57: 	my $output=(<<ENDMAINMENU);
1.44      www        58: <script>
                     59: // BEGIN LON-CAPA Internal
                     60: </script>
                     61: <a href="/adm/menu" target="_top">Main Menu</a><br />
                     62: <script>
                     63: // END LON-CAPA Internal
                     64: </script>
                     65: ENDMAINMENU
1.48      www        66:         if ($registration) { $output.=&innerregister($forcereg,$target); }
                     67: 	return $output."<hr />";
                     68:     } elsif ($ENV{'environment.remote'} eq 'off') {
                     69: # Remote Control is switched off
                     70: 	my $output=(<<ENDINLINEMENU);
                     71: <script>
                     72: // BEGIN LON-CAPA Internal
                     73: </script>
                     74: <a href="/adm/menu" target="_top">Main Menu</a>
                     75: <a href="/adm/remote?action=launch" target="_top">Launch Remote Control</a>
                     76: <script>
                     77: // END LON-CAPA Internal
                     78: </script>
                     79: ENDINLINEMENU
                     80:         if ($registration) { $output.=&innerregister($forcereg,$target); }
                     81: 	return $output."<hr />";
                     82:     } else {
                     83: 	return '';
                     84:     }
1.38      www        85: }
                     86: 
1.40      www        87: # ====================================== This gets called in the header section
1.38      www        88: 
                     89: sub registerurl {
                     90:     my $forcereg=shift;
                     91:     my $target = shift;
                     92:     my $result = '';
                     93:     
                     94:     if ($target eq 'edit') {
1.45      www        95:         $result .="<script type=\"text/javascript\">\n".
1.38      www        96:             "if (typeof swmenu != 'undefined') {swmenu.currentURL=null;}\n".
                     97:             &Apache::loncommon::browser_and_searcher_javascript().
                     98:                 "\n</script>\n";
                     99:     }
                    100:     if (($ENV{'browser.interface'} eq 'textual') ||
                    101:         ((($ENV{'request.publicaccess'}) || 
                    102:          (!&Apache::lonnet::is_on_map($ENV{'REQUEST_URI'}))) &&
                    103:         (!$forcereg))) {
                    104: 	return $result.
                    105:          '<script type="text/javascript">function LONCAPAreg(){;} function LONCAPAstale(){}</script>';
                    106:     }
1.41      www       107: # Graphical display after login only
1.38      www       108:     if ($Apache::lonxml::registered && !$forcereg) { return ''; }
1.40      www       109:     $result.=&innerregister($forcereg,$target);
                    110:     return $result;
                    111: }
                    112: 
                    113: # =========== This gets called in order to register a URL, both with the Remote
                    114: # =========== and in the body of the document
                    115: 
                    116: sub innerregister {
                    117:     my $forcereg=shift;
                    118:     my $target = shift;
                    119:     my $result = '';
                    120: 
1.38      www       121:     $Apache::lonxml::registered=1;
1.40      www       122: 
1.49    ! www       123:     my $textinter=($ENV{'browser.interface'} eq 'textual');
        !           124:     my $noremote=($ENV{'environment.remote'} eq 'off');
        !           125:     
        !           126:     my $textual=($textinter || $noremote);
        !           127: 
1.38      www       128:     my $reopen=&Apache::lonmenu::reopenmenu();
1.40      www       129: 
1.38      www       130:     my $newmail='';
                    131:     if (&Apache::lonmsg::newmail()) { 
1.41      www       132:        $newmail=($textual?
                    133:  '<b><a href="/adm/communicate">You have new messages</a></b><br />':
1.40      www       134:                           'swmenu.setstatus("you have","messages");');
1.38      www       135:     }
1.40      www       136:     my $timesync=($textual?'':'swmenu.syncclock(1000*'.time.');');
1.41      www       137: # =============================================================================
                    138: # ============================ This is for URLs that actually can be registered
1.38      www       139:     if (($ENV{'REQUEST_URI'}!~/^\/(res\/)*adm\//) || ($forcereg)) {
1.40      www       140: # -- This applies to homework problems for users with grading privileges
1.38      www       141:         my $hwkadd='';
1.40      www       142:         if 
                    143:       ($ENV{'request.filename'}=~/\.(problem|exam|quiz|assess|survey|form)$/) {
1.38      www       144: 	    if (&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'})) {
1.40      www       145: 		$hwkadd.=&switch('','',7,1,'subm.gif','view sub','missions',
                    146:                        "gocmd('/adm/grades','submission')",
                    147: 		       'View user submissions for this assessment resource');
1.38      www       148:             }
                    149: 	    if (&Apache::lonnet::allowed('mgr',$ENV{'request.course.id'})) {
1.40      www       150: 		$hwkadd.=&switch('','',7,2,'pgrd.gif','problem','grades',
                    151:                        "gocmd('/adm/grades','gradingmenu')",
                    152:                        'Modify user grades for this assessment resource');
1.38      www       153:             }
                    154: 	    if (&Apache::lonnet::allowed('opa',$ENV{'request.course.id'})) {
1.40      www       155: 		$hwkadd.=&switch('','',7,3,'pparm.gif','problem','parms',
                    156:                        "gocmd('/adm/parmset','set')",
                    157:                        'Modify deadlines, etc, for this assessment resource');
1.38      www       158:             }
                    159: 	}
1.40      www       160: # -- End Homework
1.38      www       161:         ###
                    162:         ### Determine whether or not to display the 'cstr' button for this
                    163:         ### resource
                    164:         ###
                    165:         my $editbutton = '';
                    166:         if ($ENV{'user.author'}) {
                    167:             if ($ENV{'request.role'}=~/^(ca|au)/) {
                    168:                 # Set defaults for authors
                    169:                 my ($top,$bottom) = ('con-','struct');
                    170:                 my $action = "go('/priv/".$ENV{'user.name'}."');";
                    171:                 my $cadom  = $ENV{'request.role.domain'};
                    172:                 my $caname = $ENV{'user.name'};
                    173:                 my $desc = "Enter my resource construction space";
                    174:                 # Set defaults for co-authors
                    175:                 if ($ENV{'request.role'} =~ /^ca/) { 
                    176:                     ($cadom,$caname)=($ENV{'request.role'}=~/(\w+)\/(\w+)$/);
                    177:                     ($top,$bottom) = ('co con-','struct');
                    178:                     $action = "go('/priv/".$caname."');";
                    179:                     $desc = "Enter construction space as co-author";
                    180:                 }
                    181:                 # Check that we are on the correct machine
                    182:                 my $home = &Apache::lonnet::homeserver($caname,$cadom);
                    183:                 if ($home eq $Apache::lonnet::perlvar{'lonHostID'}) {
1.40      www       184:                     $editbutton=&switch
1.38      www       185:                         ('','',6,1,$top,,$bottom,$action,$desc);
                    186:                 }
                    187:             }
                    188:             ##
                    189:             ## Determine if user can edit url.
                    190:             ##
                    191:             my $cfile='';
                    192:             my $cfuname='';
                    193:             my $cfudom='';
                    194:             if ($ENV{'request.filename'}) {
                    195:                 my $file=&Apache::lonnet::declutter($ENV{'request.filename'});
                    196:                 $file=~s/^(\w+)\/(\w+)/\/priv\/$2/;
                    197:                 # Chech that the user has permission to edit this resource
                    198:                 ($cfuname,$cfudom)=&Apache::loncacc::constructaccess($file,$1);
                    199:                 if (defined($cfudom)) {
                    200:                     if (&Apache::lonnet::homeserver($cfuname,$cfudom) 
                    201:                         eq $Apache::lonnet::perlvar{'lonHostID'}) {
                    202:                         $cfile=$file;
                    203:                     }
                    204:                 }
                    205:             }        
                    206:             # Finally, turn the button on or off
                    207:             if ($cfile) {
1.40      www       208:                 $editbutton=&switch
1.38      www       209:                     ('','',6,1,'cstr.gif','edit','resource',
                    210:                      "go('".$cfile."');","Edit this resource");
                    211:             } elsif ($editbutton eq '') {
1.40      www       212:                 $editbutton=&clear(6,1);
1.38      www       213:             }
                    214:         }
                    215:         ###
                    216:         ###
1.41      www       217: # Prepare the rest of the buttons
                    218: 	my $menuitems=(<<ENDMENUITEMS);
                    219: c&3&1
                    220: s&2&1&back.gif&backward&&gopost('/adm/flip','back:'+currentURL)&Go to the previous resource in the course sequence&1
                    221: s&2&3&forw.gif&forward&&gopost('/adm/flip','forward:'+currentURL)&Go to the next resource in the course sequence&1
                    222: s&6&3&catalog.gif&catalog&info&catalog_info()&Show catalog information
                    223: s&8&1&eval.gif&evaluate&this&gopost('/adm/evaluate',currentURL)&Provide my evaluation of this resource
                    224: s&8&2&fdbk.gif&feedback&discuss&gopost('/adm/feedback',currentURL)&Provide feedback messages or contribute to the course discussion about this resource
                    225: s&8&3&prt.gif&prepare&printout&gopost('/adm/printout',currentURL)&Prepare a printable document
                    226: s&9&1&sbkm.gif&set&bookmark&set_bookmark()&Set a bookmark for this resource&2
                    227: s&9&2&vbkm.gif&view&bookmark&edit_bookmarks()&Use or edit my bookmark collection&2
                    228: s&9&3&anot.gif&anno-&tations&annotate()&Make notes and annotations about this resource&2
                    229: ENDMENUITEMS
                    230:         my $buttons='';
                    231:         foreach (split(/\n/,$menuitems)) {
                    232: 	    my ($command,@rest)=split(/\&/,$_);
                    233:             if ($command eq 's') {
                    234: 		$buttons.=&switch('','',@rest);
                    235:             } else {
                    236:                 $buttons.=&clear(@rest);
                    237:             }
                    238:         }
                    239:         if ($textual) {
                    240: # Registered, textual output
1.42      www       241:             my $utility=&utilityfunctions();
                    242:             my $form=&serverform();
1.41      www       243: 	    $result =(<<ENDREGTEXT);
1.42      www       244: <script>
                    245: // BEGIN LON-CAPA Internal
                    246: $utility
                    247: </script>
1.41      www       248: $timesync
                    249: $newmail
                    250: $buttons
                    251: $hwkadd
                    252: $editbutton
1.42      www       253: $form
                    254: <script>
                    255: //END LON-CAPA Internal
                    256: </script>
                    257: 
1.41      www       258: ENDREGTEXT
                    259: # Registered, graphical output
                    260:         } else {
                    261: 	    $result = (<<ENDREGTHIS);
1.38      www       262:      
                    263: <script language="JavaScript">
                    264: // BEGIN LON-CAPA Internal
1.42      www       265: var swmenu=null;
1.38      www       266: 
                    267:     function LONCAPAreg() {
                    268: 	  swmenu=$reopen;
                    269:           swmenu.clearTimeout(swmenu.menucltim);
                    270:           $timesync
                    271:           $newmail
1.41      www       272:           $buttons
1.38      www       273: 	  swmenu.currentURL=window.location.pathname;
1.46      www       274:           swmenu.reloadURL=window.location.pathname+window.location.search;
1.38      www       275:           swmenu.currentSymb="$ENV{'request.symb'}";
                    276:           swmenu.reloadSymb="$ENV{'request.symb'}";
                    277:           swmenu.currentStale=0;
                    278:           $hwkadd
                    279:           $editbutton
                    280:     }
                    281: 
                    282:     function LONCAPAstale() {
                    283: 	  swmenu=$reopen
                    284:           swmenu.currentStale=1;
                    285:           if (swmenu.reloadURL!='' && swmenu.reloadURL!= null) { 
                    286:              swmenu.switchbutton
                    287:              (3,1,'reload.gif','return','location','go(reloadURL)','Return to the last known location in the course sequence');
                    288: 	  }
                    289:           swmenu.clearbut(7,1);
                    290:           swmenu.clearbut(7,2);
                    291:           swmenu.clearbut(7,3);
                    292:           swmenu.menucltim=swmenu.setTimeout(
                    293:  'clearbut(2,1);clearbut(2,3);clearbut(8,1);clearbut(8,2);clearbut(8,3);'+
                    294:  'clearbut(9,1);clearbut(9,2);clearbut(9,3);clearbut(6,3);clearbut(6,1)',
                    295: 			  2000);
                    296: 
                    297:       }
                    298: 
                    299: // END LON-CAPA Internal
                    300: </script>
                    301: ENDREGTHIS
1.41      www       302:         }
                    303: # =============================================================================
1.38      www       304:     } else {
1.41      www       305: # ========================================== This can or will not be registered
                    306:         if ($textual) {
                    307: # Not registered, textual
                    308: 	    $result= (<<ENDDONOTREGTEXT);
                    309: ENDDONOTREGTEXT
                    310:         } else {
                    311: # Not registered, graphical
                    312:            $result = (<<ENDDONOTREGTHIS);
1.38      www       313: 
                    314: <script language="JavaScript">
                    315: // BEGIN LON-CAPA Internal
1.42      www       316: var swmenu=null;
1.38      www       317: 
                    318:     function LONCAPAreg() {
                    319: 	  swmenu=$reopen
                    320:           $timesync
                    321:           swmenu.currentStale=1;
                    322:           swmenu.clearbut(2,1);
                    323:           swmenu.clearbut(2,3);
                    324:           swmenu.clearbut(8,1);
                    325:           swmenu.clearbut(8,2);
                    326:           swmenu.clearbut(8,3);
                    327:           if (swmenu.currentURL) {
                    328:              swmenu.switchbutton
                    329:               (3,1,'reload.gif','return','location','go(currentURL)');
                    330:  	  } else {
                    331: 	      swmenu.clearbut(3,1);
                    332:           }
                    333:     }
                    334: 
                    335:     function LONCAPAstale() {
                    336:     }
                    337: 
                    338: // END LON-CAPA Internal
                    339: </script>
                    340: ENDDONOTREGTHIS
1.41      www       341:        }
                    342: # =============================================================================
1.38      www       343:     }
                    344:     return $result;
                    345: }
                    346: 
                    347: sub loadevents() {
                    348:     return 'LONCAPAreg();';
                    349: }
                    350: 
                    351: sub unloadevents() {
                    352:     return 'LONCAPAstale();';
                    353: }
1.30      www       354: 
1.32      www       355: # ============================================================= Start up remote
                    356: 
                    357: sub startupremote {
                    358:     my ($lowerurl)=@_;
1.49    ! www       359:     if (($ENV{'browser.interface'} eq 'textual') ||
        !           360:         ($ENV{'environment.remote'} eq 'off')) {
1.34      www       361:      return ('<meta HTTP-EQUIV="Refresh" CONTENT="0.5; url='.$lowerurl.'" />');
                    362:     }
1.49    ! www       363: #
        !           364: # The Remote actually gets launched!
        !           365: #
1.32      www       366:     my $configmenu=&rawconfig();
                    367:     return(<<ENDREMOTESTARTUP);
                    368: <script>
                    369: 
1.35      www       370: function wheelswitch() {
                    371:    if (window.status=='|') { 
                    372:       window.status='/'; 
                    373:    } else {
                    374:       if (window.status=='/') {
                    375:          window.status='-';
                    376:       } else {
                    377:          if (window.status=='-') { 
                    378:             window.status='\\\\'; 
                    379:          } else {
                    380:             if (window.status=='\\\\') { window.status='|'; }
                    381:          }
                    382:       }
                    383:    } 
                    384: }
                    385: 
1.32      www       386: // ---------------------------------------------------------- The wait function
                    387: var canceltim;
                    388: function wait() {
                    389:    if ((menuloaded==1) || (tim==1)) {
1.35      www       390:       window.status='Done.';
1.32      www       391:       if (tim==0) {
                    392:          clearTimeout(canceltim);
                    393:          $configmenu
                    394:          window.location='$lowerurl';  
                    395:       } else {
1.35      www       396:          alert("Remote Control timed out. It is possible that it was blocked by pop-up window filters.");
1.32      www       397:       }
                    398:    } else {
1.35      www       399:       wheelswitch();
                    400:       setTimeout('wait();',200);
1.32      www       401:    }
                    402: }
                    403: 
                    404: function main() {
1.35      www       405:    canceltim=setTimeout('tim=1;',60000);
                    406:    window.status='-';
1.32      www       407:    wait();
                    408: }
                    409: 
                    410: </script>
                    411: ENDREMOTESTARTUP
                    412: }
                    413: 
                    414: sub setflags() {
                    415:     return(<<ENDSETFLAGS);
                    416: <script>
                    417:     menuloaded=0;
                    418:     tim=0;
                    419: </script>
                    420: ENDSETFLAGS
                    421: }
                    422: 
                    423: sub maincall() {
1.49    ! www       424:     if (($ENV{'browser.interface'} eq 'textual') ||
        !           425:         ($ENV{'environment.remote'} eq 'off')) { return ''; }
1.32      www       426:     return(<<ENDMAINCALL);
                    427: <script>
                    428:     main();
                    429: </script>
                    430: ENDMAINCALL
                    431: }
1.30      www       432: # ================================================================= Reopen menu
                    433: 
                    434: sub reopenmenu {
1.49    ! www       435:    if (($ENV{'browser.interface'} eq 'textual') ||
        !           436:        ($ENV{'environment.remote'} eq 'off')) { return ''; }
1.30      www       437:    my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
1.47      matthew   438:    my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
                    439:    return('window.open('.$nothing.',"'.$menuname.'","",false);');
1.30      www       440: } 
                    441: 
1.1       www       442: # =============================================================== Open the menu
                    443: 
                    444: sub open {
1.22      www       445:     my $returnval='';
1.49    ! www       446:     if (($ENV{'browser.interface'} eq 'textual') ||
        !           447:         ($ENV{'environment.remote'} eq 'off')) { return ''; }
1.30      www       448:     my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
1.22      www       449:     unless (shift eq 'unix') {
                    450: # resizing does not work on linux because of virtual desktop sizes
                    451:        $returnval.=(<<ENDRESIZE);
                    452: if (window.screen) {
1.28      www       453:     self.resizeTo(screen.availWidth-215,screen.availHeight-55);
1.22      www       454:     self.moveTo(190,15);
                    455: }
                    456: ENDRESIZE
                    457:     }
                    458:     $returnval.=(<<ENDOPEN);
1.35      www       459: window.status='Opening LON-CAPA Remote Control';
1.30      www       460: var menu=window.open("/res/adm/pages/menu.html","$menuname",
1.14      www       461: "height=350,width=150,scrollbars=no,menubar=no,top=5,left=5,screenX=5,screenY=5");
1.1       www       462: ENDOPEN
1.22      www       463:     return '<script>'.$returnval.'</script>';
1.1       www       464: }
                    465: 
1.2       www       466: 
                    467: # ================================================================== Raw Config
                    468: 
1.3       www       469: sub clear {
                    470:     my ($row,$col)=@_;
1.49    ! www       471:     unless (($ENV{'browser.interface'} eq 'textual') ||
        !           472:             ($ENV{'environment.remote'} eq 'off')) {
1.35      www       473:        return "\n".qq(window.status+='.';swmenu.clearbut($row,$col););
1.34      www       474:    } else { return ''; }
1.3       www       475: }
                    476: 
1.40      www       477: # ============================================ Switch a button or create a link
1.25      matthew   478: # Switch acts on the javascript that is executed when a button is clicked.  
                    479: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
1.40      www       480: 
1.2       www       481: sub switch {
1.40      www       482:     my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$nobreak)=@_;
1.2       www       483:     $act=~s/\$uname/$uname/g;
                    484:     $act=~s/\$udom/$udom/g;
1.49    ! www       485:     unless (($ENV{'browser.interface'} eq 'textual')  ||
        !           486:             ($ENV{'environment.remote'} eq 'off')) {
1.34      www       487:        return "\n".
1.35      www       488:  qq(window.status+='.';swmenu.switchbutton($row,$col,"$img","$top","$bot","$act","$desc"););
1.34      www       489:    } else {
1.41      www       490:        if ($nobreak==2) { return ''; }
1.34      www       491:        my $text=$top.' '.$bot;
                    492:        $text=~s/\- //;
1.42      www       493:        return "\n".($nobreak?' ':'<br />').
1.43      www       494:         '<a href="javascript:'.$act.';" target="_top">'.$text.'</a> '.
                    495:         ($nobreak?'':$desc);
1.34      www       496:    }
1.2       www       497: }
                    498: 
                    499: sub secondlevel {
                    500:     my $output='';
                    501:     my 
1.27      www       502:     ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc)=@_;
1.2       www       503:     if ($prt eq 'any') {
1.27      www       504: 	   $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
1.2       www       505:     } elsif ($prt=~/^r(\w+)/) {
                    506:         if ($rol eq $1) {
1.27      www       507:            $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
1.2       www       508:         }
                    509:     }
                    510:     return $output;
                    511: }
                    512: 
1.18      www       513: sub openmenu {
1.30      www       514:     my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
1.49    ! www       515:     if (($ENV{'browser.interface'} eq 'textual') ||
        !           516:         ($ENV{'environment.remote'} eq 'off')) { return ''; }
1.47      matthew   517:     my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
                    518:     return "window.open(".$nothing.",'".$menuname."');";
1.18      www       519: }
                    520: 
1.2       www       521: sub rawconfig {
1.34      www       522:     my $textualoverride=shift;
                    523:     my $output='';
1.49    ! www       524:     unless (($ENV{'browser.interface'} eq 'textual') ||
        !           525:             ($ENV{'environment.remote'} eq 'off')) {
1.35      www       526:        $output.=
                    527:  "window.status='Opening Remote Control';var swmenu=".&openmenu().
                    528: "\nwindow.status='Configuring Remote Control ';";
1.34      www       529:     } else {
                    530:        unless ($textualoverride) { return ''; }
                    531:     }
1.2       www       532:     my $uname=$ENV{'user.name'};
                    533:     my $udom=$ENV{'user.domain'};
                    534:     my $adv=$ENV{'user.adv'};
1.4       www       535:     my $author=$ENV{'user.author'};
1.5       www       536:     my $crs='';
                    537:     if ($ENV{'request.course.id'}) {
                    538:        $crs='/'.$ENV{'request.course.id'};
1.7       www       539:        if ($ENV{'request.course.sec'}) {
                    540: 	   $crs.='_'.$ENV{'request.course.sec'};
                    541:        }
1.8       www       542:        $crs=~s/\_/\//g;
1.5       www       543:     }
1.2       www       544:     my $pub=($ENV{'request.state'} eq 'published');
                    545:     my $con=($ENV{'request.state'} eq 'construct');
                    546:     my $rol=$ENV{'request.role'};
1.25      matthew   547:     my $requested_domain = $ENV{'request.role.domain'};
1.13      harris41  548:     foreach (@desklines) {
1.27      www       549:         my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc)=split(/\:/,$_);
1.3       www       550:         $prt=~s/\$uname/$uname/g;
                    551:         $prt=~s/\$udom/$udom/g;
1.5       www       552:         $prt=~s/\$crs/$crs/g; 
1.25      matthew   553:         $prt=~s/\$requested_domain/$requested_domain/g;
1.3       www       554:         if ($pro eq 'clear') {
1.4       www       555: 	    $output.=&clear($row,$col);
1.3       www       556:         } elsif ($pro eq 'any') {
1.2       www       557:                $output.=&secondlevel(
1.27      www       558: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
1.2       www       559: 	} elsif ($pro eq 'smp') {
                    560:             unless ($adv) {
                    561:                $output.=&secondlevel(
1.27      www       562:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
1.2       www       563:             }
                    564:         } elsif ($pro eq 'adv') {
                    565:             if ($adv) {
                    566:                $output.=&secondlevel(
1.27      www       567: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
1.2       www       568:             }
                    569:         } elsif (($pro=~/p(\w+)/) && ($prt)) {
                    570: 	    if (&Apache::lonnet::allowed($1,$prt)) {
1.27      www       571:                $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
1.4       www       572:             }
1.26      www       573:         } elsif ($pro eq 'course') {
                    574:             if ($ENV{'request.course.fn'}) {
1.27      www       575:                $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
1.26      www       576: 	    }
1.4       www       577:         } elsif ($pro eq 'author') {
                    578:             if ($author) {
1.29      matthew   579:                 if ((($prt eq 'rca') && ($ENV{'request.role'}=~/^ca/)) ||
                    580:                     (($prt eq 'rau') && ($ENV{'request.role'}=~/^au/))) {
1.19      matthew   581:                     # Check that we are on the correct machine
1.29      matthew   582:                     my $cadom=$requested_domain;
                    583:                     my $caname=$ENV{'user.name'};
                    584:                     if ($prt eq 'rca') {
                    585: 		       ($cadom,$caname)=
1.6       www       586:                                ($ENV{'request.role'}=~/(\w+)\/(\w+)$/);
1.29      matthew   587:                     }                       
                    588:                     $act =~ s/\$caname/$caname/g;
1.19      matthew   589:                     my $home = &Apache::lonnet::homeserver($caname,$cadom);
1.32      www       590:                     if ($home eq $Apache::lonnet::perlvar{'lonHostID'}) {
1.19      matthew   591:                         $output.=switch($caname,$cadom,
1.27      www       592:                                         $row,$col,$img,$top,$bot,$act,$desc);
1.19      matthew   593:                     }
1.6       www       594:                 }
1.2       www       595:             }
                    596:         }
1.13      harris41  597:     }
1.49    ! www       598:     unless (($ENV{'browser.interface'} eq 'textual') ||
        !           599:             ($ENV{'environment.remote'} eq 'off')) {
1.35      www       600:        $output.="\nwindow.status='Synchronizing Time';swmenu.syncclock(1000*".time.");\nwindow.status='Remote Control Configured.';";
1.34      www       601:     }
1.2       www       602:     return $output;
                    603: }
                    604: 
                    605: # ======================================================================= Close
1.1       www       606: 
                    607: sub close {
1.49    ! www       608:     if (($ENV{'browser.interface'} eq 'textual') ||
        !           609:         ($ENV{'environment.remote'} eq 'off')) { return ''; }
1.30      www       610:     my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
1.1       www       611:     return(<<ENDCLOSE);
                    612: <script>
1.35      www       613: window.status='Accessing Remote Control';
1.30      www       614: menu=window.open("/adm/rat/empty.html","$menuname",
1.1       www       615:                  "height=350,width=150,scrollbars=no,menubar=no");
1.35      www       616: window.status='Disabling Remote Control';
                    617: menu.active=0;
1.31      www       618: menu.autologout=0;
1.35      www       619: window.status='Closing Remote Control';
1.1       www       620: menu.close();
1.35      www       621: window.status='Done.';
1.1       www       622: </script>
                    623: ENDCLOSE
                    624: }
                    625: 
                    626: # ====================================================================== Footer
                    627: 
                    628: sub footer {
                    629: 
1.33      www       630: }
                    631: 
1.42      www       632: sub utilityfunctions {
                    633:     unless ($ENV{'browser.interface'} eq 'textual') { return ''; }
                    634:     my $currenturl=$ENV{'REQUEST_URI'};
                    635:     my $currentsymb=$ENV{'request.symb'};
                    636: return (<<ENDUTILITY)
                    637: 
                    638:     var currentURL="$currenturl";
                    639:     var reloadURL="$currenturl";
                    640:     var currentSymb="$currentsymb";
                    641: 
                    642: function go(url) {
                    643:    if (url!='' && url!= null) {
                    644:        currentURL = null;
                    645:        currentSymb= null;
                    646:        window.location.href=url;
                    647:    }
                    648: }
                    649: 
                    650: function gopost(url,postdata) {
                    651:    if (url!='') {
                    652:       this.document.server.action=url;
                    653:       this.document.server.postdata.value=postdata;
                    654:       this.document.server.command.value='';
                    655:       this.document.server.url.value='';
                    656:       this.document.server.symb.value='';
                    657:       this.document.server.submit();
                    658:    }
                    659: }
                    660: 
                    661: function gocmd(url,cmd) {
                    662:    if (url!='') {
                    663:       this.document.server.action=url;
                    664:       this.document.server.postdata.value='';
                    665:       this.document.server.command.value=cmd;
                    666:       this.document.server.url.value=currentURL;
                    667:       this.document.server.symb.value=currentSymb;
                    668:       this.document.server.submit();
                    669:    }
                    670: }
                    671: ENDUTILITY
                    672: }
                    673: 
                    674: sub serverform {
                    675:     return(<<ENDSERVERFORM);
                    676: 
                    677: <form name="server" action="/adm/logout" method="post">
                    678: <input type="hidden" name="postdata" value="none" />
                    679: <input type="hidden" name="command" value="none" />
                    680: <input type="hidden" name="url" value="none" />
                    681: <input type="hidden" name="symb" value="none" />
                    682: </form>
                    683: ENDSERVERFORM
                    684: }
1.33      www       685: # ================================================ Handler when called directly
                    686: 
                    687: 
                    688: sub handler {
                    689:     my $r = shift;
                    690:     $r->content_type('text/html');
                    691:     $r->send_http_header;
                    692:     return OK if $r->header_only;
                    693: 
1.42      www       694:     my $utility=&utilityfunctions();
                    695:     my $form=&serverform();
1.34      www       696:     my $bodytag=&Apache::loncommon::bodytag('Main Menu');
1.33      www       697: # ------------------------------------------------------------ Print the screen
1.36      www       698:     $r->print(<<ENDHEADER);
                    699: <html><head>
                    700: <title>LON-CAPA Main Menu</title>
                    701: <script>
1.42      www       702: $utility
1.36      www       703: </script>
                    704: </head>
                    705: $bodytag
                    706: ENDHEADER
1.42      www       707:     $r->print(&rawconfig(1).$form);
1.33      www       708:     $r->print('</body></html>');
                    709:     return OK;
1.1       www       710: }
                    711: 
1.2       www       712: # ================================================================ Main Program
                    713: 
1.16      harris41  714: BEGIN {
1.15      matthew   715:   if (! defined($readdesk)) {
1.14      www       716:    {
1.10      albertel  717:     my $config=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.
                    718: 				  '/mydesk.tab');
                    719:     while (my $configline=<$config>) {
1.14      www       720:        $configline=(split(/\#/,$configline))[0];
                    721:        $configline=~s/^\s+//;
1.10      albertel  722:        chomp($configline);
1.14      www       723:        if ($configline) {
                    724:           $desklines[$#desklines+1]=$configline;
                    725:        }
1.2       www       726:     }
1.14      www       727:    }
                    728:    $readdesk='done';
1.10      albertel  729:   }
1.2       www       730: }
1.30      www       731: 
1.1       www       732: 1;
                    733: __END__
                    734: 
                    735: 
                    736: 
                    737: 
                    738: 
                    739: 
                    740: 

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