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

1.1       www         1: # The LearningOnline Network with CAPA
                      2: # Routines to control the menu
                      3: #
1.37    ! www         4: # $Id: lonmenu.pm,v 1.36 2003/02/14 14:30:09 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: # (TeX Conversion Module
                     29: #
                     30: # 05/29/00,05/30 Gerd Kortemeyer)
                     31: #
1.8       www        32: # 10/05,05/28,05/30,06/01,06/08,06/09,07/04,08/07 Gerd Kortemeyer
1.17      matthew    33: # 02/15/02 Matthew Hall
1.1       www        34: 
                     35: package Apache::lonmenu;
                     36: 
                     37: use strict;
1.2       www        38: use Apache::lonnet;
1.33      www        39: use Apache::Constants qw(:common);
                     40: use Apache::loncommon;
1.2       www        41: use Apache::File;
                     42: use vars qw(@desklines $readdesk);
1.30      www        43: 
1.32      www        44: # ============================================================= Start up remote
                     45: 
                     46: sub startupremote {
                     47:     my ($lowerurl)=@_;
1.34      www        48:     if ($ENV{'browser.interface'} eq 'textual') {
                     49:      return ('<meta HTTP-EQUIV="Refresh" CONTENT="0.5; url='.$lowerurl.'" />');
                     50:     }
1.32      www        51:     my $configmenu=&rawconfig();
                     52:     return(<<ENDREMOTESTARTUP);
                     53: <script>
                     54: 
1.35      www        55: function wheelswitch() {
                     56:    if (window.status=='|') { 
                     57:       window.status='/'; 
                     58:    } else {
                     59:       if (window.status=='/') {
                     60:          window.status='-';
                     61:       } else {
                     62:          if (window.status=='-') { 
                     63:             window.status='\\\\'; 
                     64:          } else {
                     65:             if (window.status=='\\\\') { window.status='|'; }
                     66:          }
                     67:       }
                     68:    } 
                     69: }
                     70: 
1.32      www        71: // ---------------------------------------------------------- The wait function
                     72: var canceltim;
                     73: function wait() {
                     74:    if ((menuloaded==1) || (tim==1)) {
1.35      www        75:       window.status='Done.';
1.32      www        76:       if (tim==0) {
                     77:          clearTimeout(canceltim);
                     78:          $configmenu
                     79:          window.location='$lowerurl';  
                     80:       } else {
1.35      www        81:          alert("Remote Control timed out. It is possible that it was blocked by pop-up window filters.");
1.32      www        82:       }
                     83:    } else {
1.35      www        84:       wheelswitch();
                     85:       setTimeout('wait();',200);
1.32      www        86:    }
                     87: }
                     88: 
                     89: function main() {
1.35      www        90:    canceltim=setTimeout('tim=1;',60000);
                     91:    window.status='-';
1.32      www        92:    wait();
                     93: }
                     94: 
                     95: </script>
                     96: ENDREMOTESTARTUP
                     97: }
                     98: 
                     99: sub setflags() {
                    100:     return(<<ENDSETFLAGS);
                    101: <script>
                    102:     menuloaded=0;
                    103:     tim=0;
                    104: </script>
                    105: ENDSETFLAGS
                    106: }
                    107: 
                    108: sub maincall() {
1.34      www       109:     if ($ENV{'browser.interface'} eq 'textual') { return ''; }
1.32      www       110:     return(<<ENDMAINCALL);
                    111: <script>
                    112:     main();
                    113: </script>
                    114: ENDMAINCALL
                    115: }
1.30      www       116: # ================================================================= Reopen menu
                    117: 
                    118: sub reopenmenu {
                    119:    my $nothing='';
1.34      www       120:    if ($ENV{'browser.interface'} eq 'textual') { return ''; }
1.30      www       121:    my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
                    122:    if ($ENV{'browser.type'} eq 'explorer') { $nothing='javascript:void(0);'; }
                    123:    return('window.open("'.$nothing.'","'.$menuname.'","",false);');
                    124: } 
                    125: 
1.1       www       126: # =============================================================== Open the menu
                    127: 
                    128: sub open {
1.22      www       129:     my $returnval='';
1.34      www       130:     if ($ENV{'browser.interface'} eq 'textual') { return ''; }
1.30      www       131:     my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
1.22      www       132:     unless (shift eq 'unix') {
                    133: # resizing does not work on linux because of virtual desktop sizes
                    134:        $returnval.=(<<ENDRESIZE);
                    135: if (window.screen) {
1.28      www       136:     self.resizeTo(screen.availWidth-215,screen.availHeight-55);
1.22      www       137:     self.moveTo(190,15);
                    138: }
                    139: ENDRESIZE
                    140:     }
                    141:     $returnval.=(<<ENDOPEN);
1.35      www       142: window.status='Opening LON-CAPA Remote Control';
1.30      www       143: var menu=window.open("/res/adm/pages/menu.html","$menuname",
1.14      www       144: "height=350,width=150,scrollbars=no,menubar=no,top=5,left=5,screenX=5,screenY=5");
1.1       www       145: ENDOPEN
1.22      www       146:     return '<script>'.$returnval.'</script>';
1.1       www       147: }
                    148: 
1.2       www       149: 
                    150: # ================================================================== Raw Config
                    151: 
1.3       www       152: sub clear {
                    153:     my ($row,$col)=@_;
1.34      www       154:     unless ($ENV{'browser.interface'} eq 'textual') {
1.35      www       155:        return "\n".qq(window.status+='.';swmenu.clearbut($row,$col););
1.34      www       156:    } else { return ''; }
1.3       www       157: }
                    158: 
1.25      matthew   159: # Switch acts on the javascript that is executed when a button is clicked.  
                    160: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
1.2       www       161: sub switch {
1.27      www       162:     my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc)=@_;
1.2       www       163:     $act=~s/\$uname/$uname/g;
                    164:     $act=~s/\$udom/$udom/g;
1.34      www       165:     unless ($ENV{'browser.interface'} eq 'textual') {
                    166:        return "\n".
1.35      www       167:  qq(window.status+='.';swmenu.switchbutton($row,$col,"$img","$top","$bot","$act","$desc"););
1.34      www       168:    } else {
                    169:        my $text=$top.' '.$bot;
                    170:        $text=~s/\- //;
1.36      www       171:        return '<br /><a href="javascript:'.$act.';">'.$text.'</a> '.$desc;
1.34      www       172:    }
1.2       www       173: }
                    174: 
                    175: sub secondlevel {
                    176:     my $output='';
                    177:     my 
1.27      www       178:     ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc)=@_;
1.2       www       179:     if ($prt eq 'any') {
1.27      www       180: 	   $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
1.2       www       181:     } elsif ($prt=~/^r(\w+)/) {
                    182:         if ($rol eq $1) {
1.27      www       183:            $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
1.2       www       184:         }
                    185:     }
                    186:     return $output;
                    187: }
                    188: 
1.18      www       189: sub openmenu {
1.30      www       190:     my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
1.34      www       191:     if ($ENV{'browser.interface'} eq 'textual') { return ''; }
1.18      www       192:     if ($ENV{'browser.type'} eq 'explorer') {
1.30      www       193:        return "window.open('javascript:void(0);','".$menuname."');";
1.18      www       194:    } else {
1.30      www       195:        return "window.open('','".$menuname."');";
1.18      www       196:    }
                    197: }
                    198: 
1.2       www       199: sub rawconfig {
1.34      www       200:     my $textualoverride=shift;
                    201:     my $output='';
                    202:     unless ($ENV{'browser.interface'} eq 'textual') {
1.35      www       203:        $output.=
                    204:  "window.status='Opening Remote Control';var swmenu=".&openmenu().
                    205: "\nwindow.status='Configuring Remote Control ';";
1.34      www       206:     } else {
                    207:        unless ($textualoverride) { return ''; }
                    208:     }
1.2       www       209:     my $uname=$ENV{'user.name'};
                    210:     my $udom=$ENV{'user.domain'};
                    211:     my $adv=$ENV{'user.adv'};
1.4       www       212:     my $author=$ENV{'user.author'};
1.5       www       213:     my $crs='';
                    214:     if ($ENV{'request.course.id'}) {
                    215:        $crs='/'.$ENV{'request.course.id'};
1.7       www       216:        if ($ENV{'request.course.sec'}) {
                    217: 	   $crs.='_'.$ENV{'request.course.sec'};
                    218:        }
1.8       www       219:        $crs=~s/\_/\//g;
1.5       www       220:     }
1.2       www       221:     my $pub=($ENV{'request.state'} eq 'published');
                    222:     my $con=($ENV{'request.state'} eq 'construct');
                    223:     my $rol=$ENV{'request.role'};
1.25      matthew   224:     my $requested_domain = $ENV{'request.role.domain'};
1.13      harris41  225:     foreach (@desklines) {
1.27      www       226:         my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc)=split(/\:/,$_);
1.3       www       227:         $prt=~s/\$uname/$uname/g;
                    228:         $prt=~s/\$udom/$udom/g;
1.5       www       229:         $prt=~s/\$crs/$crs/g; 
1.25      matthew   230:         $prt=~s/\$requested_domain/$requested_domain/g;
1.3       www       231:         if ($pro eq 'clear') {
1.4       www       232: 	    $output.=&clear($row,$col);
1.3       www       233:         } elsif ($pro eq 'any') {
1.2       www       234:                $output.=&secondlevel(
1.27      www       235: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
1.2       www       236: 	} elsif ($pro eq 'smp') {
                    237:             unless ($adv) {
                    238:                $output.=&secondlevel(
1.27      www       239:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
1.2       www       240:             }
                    241:         } elsif ($pro eq 'adv') {
                    242:             if ($adv) {
                    243:                $output.=&secondlevel(
1.27      www       244: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
1.2       www       245:             }
                    246:         } elsif (($pro=~/p(\w+)/) && ($prt)) {
                    247: 	    if (&Apache::lonnet::allowed($1,$prt)) {
1.27      www       248:                $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
1.4       www       249:             }
1.26      www       250:         } elsif ($pro eq 'course') {
                    251:             if ($ENV{'request.course.fn'}) {
1.27      www       252:                $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
1.26      www       253: 	    }
1.4       www       254:         } elsif ($pro eq 'author') {
                    255:             if ($author) {
1.29      matthew   256:                 if ((($prt eq 'rca') && ($ENV{'request.role'}=~/^ca/)) ||
                    257:                     (($prt eq 'rau') && ($ENV{'request.role'}=~/^au/))) {
1.19      matthew   258:                     # Check that we are on the correct machine
1.29      matthew   259:                     my $cadom=$requested_domain;
                    260:                     my $caname=$ENV{'user.name'};
                    261:                     if ($prt eq 'rca') {
                    262: 		       ($cadom,$caname)=
1.6       www       263:                                ($ENV{'request.role'}=~/(\w+)\/(\w+)$/);
1.29      matthew   264:                     }                       
                    265:                     $act =~ s/\$caname/$caname/g;
1.19      matthew   266:                     my $home = &Apache::lonnet::homeserver($caname,$cadom);
1.32      www       267:                     if ($home eq $Apache::lonnet::perlvar{'lonHostID'}) {
1.19      matthew   268:                         $output.=switch($caname,$cadom,
1.27      www       269:                                         $row,$col,$img,$top,$bot,$act,$desc);
1.19      matthew   270:                     }
1.6       www       271:                 }
1.2       www       272:             }
                    273:         }
1.13      harris41  274:     }
1.34      www       275:     unless ($ENV{'browser.interface'} eq 'textual') {
1.35      www       276:        $output.="\nwindow.status='Synchronizing Time';swmenu.syncclock(1000*".time.");\nwindow.status='Remote Control Configured.';";
1.34      www       277:     }
1.2       www       278:     return $output;
                    279: }
                    280: 
                    281: # ======================================================================= Close
1.1       www       282: 
                    283: sub close {
1.35      www       284:     if ($ENV{'browser.interface'} eq 'textual') { return ''; }
1.30      www       285:     my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
1.1       www       286:     return(<<ENDCLOSE);
                    287: <script>
1.35      www       288: window.status='Accessing Remote Control';
1.30      www       289: menu=window.open("/adm/rat/empty.html","$menuname",
1.1       www       290:                  "height=350,width=150,scrollbars=no,menubar=no");
1.35      www       291: window.status='Disabling Remote Control';
                    292: menu.active=0;
1.31      www       293: menu.autologout=0;
1.35      www       294: window.status='Closing Remote Control';
1.1       www       295: menu.close();
1.35      www       296: window.status='Done.';
1.1       www       297: </script>
                    298: ENDCLOSE
                    299: }
                    300: 
                    301: # ====================================================================== Footer
                    302: 
                    303: sub footer {
                    304: 
1.33      www       305: }
                    306: 
                    307: # ================================================ Handler when called directly
                    308: 
                    309: 
                    310: sub handler {
                    311:     my $r = shift;
                    312:     $r->content_type('text/html');
                    313:     $r->send_http_header;
                    314:     return OK if $r->header_only;
                    315: 
1.34      www       316:     my $bodytag=&Apache::loncommon::bodytag('Main Menu');
1.33      www       317: # ------------------------------------------------------------ Print the screen
1.36      www       318:     $r->print(<<ENDHEADER);
                    319: <html><head>
                    320: <title>LON-CAPA Main Menu</title>
                    321: <script>
                    322: function go(url) {
                    323:     window.location=url;
                    324: }
                    325: function gopost(url) {
                    326:     window.location=url;
                    327: }
                    328: </script>
                    329: </head>
                    330: $bodytag
                    331: ENDHEADER
1.34      www       332:     $r->print(&rawconfig(1));
1.33      www       333:     $r->print('</body></html>');
                    334:     return OK;
1.1       www       335: }
                    336: 
1.2       www       337: # ================================================================ Main Program
                    338: 
1.16      harris41  339: BEGIN {
1.15      matthew   340:   if (! defined($readdesk)) {
1.14      www       341:    {
1.10      albertel  342:     my $config=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.
                    343: 				  '/mydesk.tab');
                    344:     while (my $configline=<$config>) {
1.14      www       345:        $configline=(split(/\#/,$configline))[0];
                    346:        $configline=~s/^\s+//;
1.10      albertel  347:        chomp($configline);
1.14      www       348:        if ($configline) {
                    349:           $desklines[$#desklines+1]=$configline;
                    350:        }
1.2       www       351:     }
1.14      www       352:    }
                    353:    $readdesk='done';
1.10      albertel  354:   }
1.2       www       355: }
1.30      www       356: 
1.1       www       357: 1;
                    358: __END__
                    359: 
                    360: 
                    361: 
                    362: 
                    363: 
                    364: 
                    365: 

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