File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.35: download - view: text, annotated - select for diffs
Thu Feb 13 20:35:39 2003 UTC (21 years, 3 months ago) by www
Branches: MAIN
CVS tags: HEAD
Slightly ridiculous over use of window.status, but apparently the only way
to nail down where "Unspecified Errors" happen in Internet Explorer.

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

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