File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.33: download - view: text, annotated - select for diffs
Thu Feb 13 15:52:53 2003 UTC (21 years, 3 months ago) by www
Branches: MAIN
CVS tags: HEAD
Start work on server-side menu

    1: # The LearningOnline Network with CAPA
    2: # Routines to control the menu
    3: #
    4: # $Id: lonmenu.pm,v 1.33 2003/02/13 15:52:53 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:     my $configmenu=&rawconfig();
   49:     return(<<ENDREMOTESTARTUP);
   50: <script>
   51: 
   52: // ---------------------------------------------------------- The wait function
   53: var canceltim;
   54: function wait() {
   55:    if ((menuloaded==1) || (tim==1)) {
   56:       if (tim==0) {
   57:          clearTimeout(canceltim);
   58:          $configmenu
   59:          window.location='$lowerurl';  
   60:       } else {
   61:          alert("Remote Control Timed Out.");
   62:       }
   63:    } else {
   64:       setTimeout('wait();',100);
   65:    }
   66: }
   67: 
   68: function main() {
   69:    canceltim=setTimeout('tim=1;',80000);
   70:    wait();
   71: }
   72: 
   73: </script>
   74: ENDREMOTESTARTUP
   75: }
   76: 
   77: sub setflags() {
   78:     return(<<ENDSETFLAGS);
   79: <script>
   80:     menuloaded=0;
   81:     tim=0;
   82: </script>
   83: ENDSETFLAGS
   84: }
   85: 
   86: sub maincall() {
   87:     return(<<ENDMAINCALL);
   88: <script>
   89:     main();
   90: </script>
   91: ENDMAINCALL
   92: }
   93: # ================================================================= Reopen menu
   94: 
   95: sub reopenmenu {
   96:    my $nothing='';
   97:    my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
   98:    if ($ENV{'browser.type'} eq 'explorer') { $nothing='javascript:void(0);'; }
   99:    return('window.open("'.$nothing.'","'.$menuname.'","",false);');
  100: } 
  101: 
  102: # =============================================================== Open the menu
  103: 
  104: sub open {
  105:     my $returnval='';
  106:     my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
  107:     unless (shift eq 'unix') {
  108: # resizing does not work on linux because of virtual desktop sizes
  109:        $returnval.=(<<ENDRESIZE);
  110: if (window.screen) {
  111:     self.resizeTo(screen.availWidth-215,screen.availHeight-55);
  112:     self.moveTo(190,15);
  113: }
  114: ENDRESIZE
  115:     }
  116:     $returnval.=(<<ENDOPEN);
  117: var menu=window.open("/res/adm/pages/menu.html","$menuname",
  118: "height=350,width=150,scrollbars=no,menubar=no,top=5,left=5,screenX=5,screenY=5");
  119: ENDOPEN
  120:     return '<script>'.$returnval.'</script>';
  121: }
  122: 
  123: # ============================================================ Switch Menu Item
  124: 
  125: sub switchmenu {
  126:     my ($row,$col,$imgsrc,$texttop,$textbot,$action,$description)=@_;
  127:     my $openwin=&openmenu();
  128:     return(<<ENDSMENU);
  129: <script>
  130:    var swmenu=$openwin
  131:    swmenu.switchbutton($row,$col,"$imgsrc","$texttop","$textbot","$action","$description");
  132: </script>
  133: ENDSMENU
  134: }
  135: 
  136: # ================================================================== Raw Config
  137: 
  138: sub clear {
  139:     my ($row,$col)=@_;
  140:     return qq(swmenu.clearbut($row,$col););
  141: }
  142: 
  143: # Switch acts on the javascript that is executed when a button is clicked.  
  144: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
  145: sub switch {
  146:     my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc)=@_;
  147:     $act=~s/\$uname/$uname/g;
  148:     $act=~s/\$udom/$udom/g;
  149:     return "\n".
  150:  qq(swmenu.switchbutton($row,$col,"$img","$top","$bot","$act","$desc"););
  151: }
  152: 
  153: sub secondlevel {
  154:     my $output='';
  155:     my 
  156:     ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc)=@_;
  157:     if ($prt eq 'any') {
  158: 	   $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
  159:     } elsif ($prt=~/^r(\w+)/) {
  160:         if ($rol eq $1) {
  161:            $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
  162:         }
  163:     }
  164:     return $output;
  165: }
  166: 
  167: sub openmenu {
  168:     my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
  169:     if ($ENV{'browser.type'} eq 'explorer') {
  170:        return "window.open('javascript:void(0);','".$menuname."');";
  171:    } else {
  172:        return "window.open('','".$menuname."');";
  173:    }
  174: }
  175: 
  176: sub rawconfig {
  177:     my $output="var swmenu=".&openmenu();
  178:     my $uname=$ENV{'user.name'};
  179:     my $udom=$ENV{'user.domain'};
  180:     my $adv=$ENV{'user.adv'};
  181:     my $author=$ENV{'user.author'};
  182:     my $crs='';
  183:     if ($ENV{'request.course.id'}) {
  184:        $crs='/'.$ENV{'request.course.id'};
  185:        if ($ENV{'request.course.sec'}) {
  186: 	   $crs.='_'.$ENV{'request.course.sec'};
  187:        }
  188:        $crs=~s/\_/\//g;
  189:     }
  190:     my $pub=($ENV{'request.state'} eq 'published');
  191:     my $con=($ENV{'request.state'} eq 'construct');
  192:     my $rol=$ENV{'request.role'};
  193:     my $requested_domain = $ENV{'request.role.domain'};
  194:     foreach (@desklines) {
  195:         my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc)=split(/\:/,$_);
  196:         $prt=~s/\$uname/$uname/g;
  197:         $prt=~s/\$udom/$udom/g;
  198:         $prt=~s/\$crs/$crs/g; 
  199:         $prt=~s/\$requested_domain/$requested_domain/g;
  200:         if ($pro eq 'clear') {
  201: 	    $output.=&clear($row,$col);
  202:         } elsif ($pro eq 'any') {
  203:                $output.=&secondlevel(
  204: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
  205: 	} elsif ($pro eq 'smp') {
  206:             unless ($adv) {
  207:                $output.=&secondlevel(
  208:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
  209:             }
  210:         } elsif ($pro eq 'adv') {
  211:             if ($adv) {
  212:                $output.=&secondlevel(
  213: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
  214:             }
  215:         } elsif (($pro=~/p(\w+)/) && ($prt)) {
  216: 	    if (&Apache::lonnet::allowed($1,$prt)) {
  217:                $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
  218:             }
  219:         } elsif ($pro eq 'course') {
  220:             if ($ENV{'request.course.fn'}) {
  221:                $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
  222: 	    }
  223:         } elsif ($pro eq 'author') {
  224:             if ($author) {
  225:                 if ((($prt eq 'rca') && ($ENV{'request.role'}=~/^ca/)) ||
  226:                     (($prt eq 'rau') && ($ENV{'request.role'}=~/^au/))) {
  227:                     # Check that we are on the correct machine
  228:                     my $cadom=$requested_domain;
  229:                     my $caname=$ENV{'user.name'};
  230:                     if ($prt eq 'rca') {
  231: 		       ($cadom,$caname)=
  232:                                ($ENV{'request.role'}=~/(\w+)\/(\w+)$/);
  233:                     }                       
  234:                     $act =~ s/\$caname/$caname/g;
  235:                     my $home = &Apache::lonnet::homeserver($caname,$cadom);
  236:                     if ($home eq $Apache::lonnet::perlvar{'lonHostID'}) {
  237:                         $output.=switch($caname,$cadom,
  238:                                         $row,$col,$img,$top,$bot,$act,$desc);
  239:                     }
  240:                 }
  241:             }
  242:         }
  243:     }
  244:     $output.="swmenu.syncclock(1000*".time.");";
  245:     return $output;
  246: }
  247: 
  248: # ======================================================================= Close
  249: 
  250: sub close {
  251:     my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
  252:     return(<<ENDCLOSE);
  253: <script>
  254: menu=window.open("/adm/rat/empty.html","$menuname",
  255:                  "height=350,width=150,scrollbars=no,menubar=no");
  256: menu.autologout=0;
  257: menu.close();
  258: </script>
  259: ENDCLOSE
  260: }
  261: 
  262: # ====================================================================== Footer
  263: 
  264: sub footer {
  265: 
  266: }
  267: 
  268: # ================================================ Handler when called directly
  269: 
  270: 
  271: sub handler {
  272:     my $r = shift;
  273:     $r->content_type('text/html');
  274:     $r->send_http_header;
  275:     return OK if $r->header_only;
  276: 
  277: # ------------------------------------------------------------ Print the screen
  278:     $r->print('<html><head><title>LON-CAPA Main Menu</title></head>');
  279:     $r->print('<body bgcolor="#FFFFFF">');
  280:     $r->print('<h1>LON-CAPA Main Menu</h1>');
  281:     $r->print('</body></html>');
  282:     return OK;
  283: }
  284: 
  285: # ================================================================ Main Program
  286: 
  287: BEGIN {
  288:   if (! defined($readdesk)) {
  289:    {
  290:     my $config=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.
  291: 				  '/mydesk.tab');
  292:     while (my $configline=<$config>) {
  293:        $configline=(split(/\#/,$configline))[0];
  294:        $configline=~s/^\s+//;
  295:        chomp($configline);
  296:        if ($configline) {
  297:           $desklines[$#desklines+1]=$configline;
  298:        }
  299:     }
  300:    }
  301:    $readdesk='done';
  302:   }
  303: }
  304: 
  305: 1;
  306: __END__
  307: 
  308: 
  309: 
  310: 
  311: 
  312: 
  313: 

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