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

1.1       www         1: # The LearningOnline Network with CAPA
                      2: # Routines to control the menu
                      3: #
1.35    ! www         4: # $Id: lonmenu.pm,v 1.34 2003/02/13 18:11:26 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: # ============================================================ Switch Menu Item
                    150: 
                    151: sub switchmenu {
1.27      www       152:     my ($row,$col,$imgsrc,$texttop,$textbot,$action,$description)=@_;
1.34      www       153:     if ($ENV{'browser.interface'} eq 'textual') { return ''; }
1.18      www       154:     my $openwin=&openmenu();
1.2       www       155:     return(<<ENDSMENU);
                    156: <script>
1.20      matthew   157:    var swmenu=$openwin
1.27      www       158:    swmenu.switchbutton($row,$col,"$imgsrc","$texttop","$textbot","$action","$description");
1.2       www       159: </script>
                    160: ENDSMENU
                    161: }
                    162: 
                    163: # ================================================================== Raw Config
                    164: 
1.3       www       165: sub clear {
                    166:     my ($row,$col)=@_;
1.34      www       167:     unless ($ENV{'browser.interface'} eq 'textual') {
1.35    ! www       168:        return "\n".qq(window.status+='.';swmenu.clearbut($row,$col););
1.34      www       169:    } else { return ''; }
1.3       www       170: }
                    171: 
1.25      matthew   172: # Switch acts on the javascript that is executed when a button is clicked.  
                    173: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
1.2       www       174: sub switch {
1.27      www       175:     my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc)=@_;
1.2       www       176:     $act=~s/\$uname/$uname/g;
                    177:     $act=~s/\$udom/$udom/g;
1.34      www       178:     unless ($ENV{'browser.interface'} eq 'textual') {
                    179:        return "\n".
1.35    ! www       180:  qq(window.status+='.';swmenu.switchbutton($row,$col,"$img","$top","$bot","$act","$desc"););
1.34      www       181:    } else {
                    182:        my $text=$top.' '.$bot;
                    183:        $text=~s/\- //;
                    184:        return '<br /><a href="'.$act.'">'.$text.'</a> '.$desc;
                    185:    }
1.2       www       186: }
                    187: 
                    188: sub secondlevel {
                    189:     my $output='';
                    190:     my 
1.27      www       191:     ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc)=@_;
1.2       www       192:     if ($prt eq 'any') {
1.27      www       193: 	   $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
1.2       www       194:     } elsif ($prt=~/^r(\w+)/) {
                    195:         if ($rol eq $1) {
1.27      www       196:            $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
1.2       www       197:         }
                    198:     }
                    199:     return $output;
                    200: }
                    201: 
1.18      www       202: sub openmenu {
1.30      www       203:     my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
1.34      www       204:     if ($ENV{'browser.interface'} eq 'textual') { return ''; }
1.18      www       205:     if ($ENV{'browser.type'} eq 'explorer') {
1.30      www       206:        return "window.open('javascript:void(0);','".$menuname."');";
1.18      www       207:    } else {
1.30      www       208:        return "window.open('','".$menuname."');";
1.18      www       209:    }
                    210: }
                    211: 
1.2       www       212: sub rawconfig {
1.34      www       213:     my $textualoverride=shift;
                    214:     my $output='';
                    215:     unless ($ENV{'browser.interface'} eq 'textual') {
1.35    ! www       216:        $output.=
        !           217:  "window.status='Opening Remote Control';var swmenu=".&openmenu().
        !           218: "\nwindow.status='Configuring Remote Control ';";
1.34      www       219:     } else {
                    220:        unless ($textualoverride) { return ''; }
                    221:     }
1.2       www       222:     my $uname=$ENV{'user.name'};
                    223:     my $udom=$ENV{'user.domain'};
                    224:     my $adv=$ENV{'user.adv'};
1.4       www       225:     my $author=$ENV{'user.author'};
1.5       www       226:     my $crs='';
                    227:     if ($ENV{'request.course.id'}) {
                    228:        $crs='/'.$ENV{'request.course.id'};
1.7       www       229:        if ($ENV{'request.course.sec'}) {
                    230: 	   $crs.='_'.$ENV{'request.course.sec'};
                    231:        }
1.8       www       232:        $crs=~s/\_/\//g;
1.5       www       233:     }
1.2       www       234:     my $pub=($ENV{'request.state'} eq 'published');
                    235:     my $con=($ENV{'request.state'} eq 'construct');
                    236:     my $rol=$ENV{'request.role'};
1.25      matthew   237:     my $requested_domain = $ENV{'request.role.domain'};
1.13      harris41  238:     foreach (@desklines) {
1.27      www       239:         my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc)=split(/\:/,$_);
1.3       www       240:         $prt=~s/\$uname/$uname/g;
                    241:         $prt=~s/\$udom/$udom/g;
1.5       www       242:         $prt=~s/\$crs/$crs/g; 
1.25      matthew   243:         $prt=~s/\$requested_domain/$requested_domain/g;
1.3       www       244:         if ($pro eq 'clear') {
1.4       www       245: 	    $output.=&clear($row,$col);
1.3       www       246:         } elsif ($pro eq 'any') {
1.2       www       247:                $output.=&secondlevel(
1.27      www       248: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
1.2       www       249: 	} elsif ($pro eq 'smp') {
                    250:             unless ($adv) {
                    251:                $output.=&secondlevel(
1.27      www       252:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
1.2       www       253:             }
                    254:         } elsif ($pro eq 'adv') {
                    255:             if ($adv) {
                    256:                $output.=&secondlevel(
1.27      www       257: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
1.2       www       258:             }
                    259:         } elsif (($pro=~/p(\w+)/) && ($prt)) {
                    260: 	    if (&Apache::lonnet::allowed($1,$prt)) {
1.27      www       261:                $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
1.4       www       262:             }
1.26      www       263:         } elsif ($pro eq 'course') {
                    264:             if ($ENV{'request.course.fn'}) {
1.27      www       265:                $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
1.26      www       266: 	    }
1.4       www       267:         } elsif ($pro eq 'author') {
                    268:             if ($author) {
1.29      matthew   269:                 if ((($prt eq 'rca') && ($ENV{'request.role'}=~/^ca/)) ||
                    270:                     (($prt eq 'rau') && ($ENV{'request.role'}=~/^au/))) {
1.19      matthew   271:                     # Check that we are on the correct machine
1.29      matthew   272:                     my $cadom=$requested_domain;
                    273:                     my $caname=$ENV{'user.name'};
                    274:                     if ($prt eq 'rca') {
                    275: 		       ($cadom,$caname)=
1.6       www       276:                                ($ENV{'request.role'}=~/(\w+)\/(\w+)$/);
1.29      matthew   277:                     }                       
                    278:                     $act =~ s/\$caname/$caname/g;
1.19      matthew   279:                     my $home = &Apache::lonnet::homeserver($caname,$cadom);
1.32      www       280:                     if ($home eq $Apache::lonnet::perlvar{'lonHostID'}) {
1.19      matthew   281:                         $output.=switch($caname,$cadom,
1.27      www       282:                                         $row,$col,$img,$top,$bot,$act,$desc);
1.19      matthew   283:                     }
1.6       www       284:                 }
1.2       www       285:             }
                    286:         }
1.13      harris41  287:     }
1.34      www       288:     unless ($ENV{'browser.interface'} eq 'textual') {
1.35    ! www       289:        $output.="\nwindow.status='Synchronizing Time';swmenu.syncclock(1000*".time.");\nwindow.status='Remote Control Configured.';";
1.34      www       290:     }
1.2       www       291:     return $output;
                    292: }
                    293: 
                    294: # ======================================================================= Close
1.1       www       295: 
                    296: sub close {
1.35    ! www       297:     if ($ENV{'browser.interface'} eq 'textual') { return ''; }
1.30      www       298:     my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
1.1       www       299:     return(<<ENDCLOSE);
                    300: <script>
1.35    ! www       301: window.status='Accessing Remote Control';
1.30      www       302: menu=window.open("/adm/rat/empty.html","$menuname",
1.1       www       303:                  "height=350,width=150,scrollbars=no,menubar=no");
1.35    ! www       304: window.status='Disabling Remote Control';
        !           305: menu.active=0;
1.31      www       306: menu.autologout=0;
1.35    ! www       307: window.status='Closing Remote Control';
1.1       www       308: menu.close();
1.35    ! www       309: window.status='Done.';
1.1       www       310: </script>
                    311: ENDCLOSE
                    312: }
                    313: 
                    314: # ====================================================================== Footer
                    315: 
                    316: sub footer {
                    317: 
1.33      www       318: }
                    319: 
                    320: # ================================================ Handler when called directly
                    321: 
                    322: 
                    323: sub handler {
                    324:     my $r = shift;
                    325:     $r->content_type('text/html');
                    326:     $r->send_http_header;
                    327:     return OK if $r->header_only;
                    328: 
1.34      www       329:     my $bodytag=&Apache::loncommon::bodytag('Main Menu');
1.33      www       330: # ------------------------------------------------------------ Print the screen
1.34      www       331:     $r->print('<html><head><title>LON-CAPA Main Menu</title></head>'.$bodytag);
                    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>