File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.24: download - view: text, annotated - select for diffs
Mon Jul 15 19:45:18 2002 UTC (21 years, 10 months ago) by www
Branches: MAIN
CVS tags: HEAD
Doing timeout is not precise enough to keep a clock going on many systems.
On sync, figure out time difference between client and server, use client
clock and apply delta instead.

    1: # The LearningOnline Network with CAPA
    2: # Routines to control the menu
    3: #
    4: # $Id: lonmenu.pm,v 1.24 2002/07/15 19:45:18 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::File;
   40: use vars qw(@desklines $readdesk);
   41:  
   42: # =============================================================== Open the menu
   43: 
   44: sub open {
   45:     my $returnval='';
   46:     unless (shift eq 'unix') {
   47: # resizing does not work on linux because of virtual desktop sizes
   48:        $returnval.=(<<ENDRESIZE);
   49: if (window.screen) {
   50:     self.resizeTo(screen.availWidth-215,screen.availHeight-40);
   51:     self.moveTo(190,15);
   52: }
   53: ENDRESIZE
   54:     }
   55:     $returnval.=(<<ENDOPEN);
   56: var menu=window.open("/res/adm/pages/menu.html","LONCAPAmenu",
   57: "height=350,width=150,scrollbars=no,menubar=no,top=5,left=5,screenX=5,screenY=5");
   58: ENDOPEN
   59:     return '<script>'.$returnval.'</script>';
   60: }
   61: 
   62: # ============================================================ Switch Menu Item
   63: 
   64: sub switchmenu {
   65:     my ($row,$col,$imgsrc,$texttop,$textbot,$action)=@_;
   66:     my $openwin=&openmenu();
   67:     return(<<ENDSMENU);
   68: <script>
   69:    var swmenu=$openwin
   70:    swmenu.switchbutton($row,$col,"$imgsrc","$texttop","$textbot","$action");
   71: </script>
   72: ENDSMENU
   73: }
   74: 
   75: # ================================================================== Raw Config
   76: 
   77: sub clear {
   78:     my ($row,$col)=@_;
   79:     return qq(swmenu.clearbut($row,$col););
   80: }
   81: 
   82: sub switch {
   83:     my ($uname,$udom,$row,$col,$img,$top,$bot,$act)=@_;
   84:     $act=~s/\$uname/$uname/g;
   85:     $act=~s/\$udom/$udom/g;
   86:     return "\n".
   87:  qq(swmenu.switchbutton($row,$col,"$img","$top","$bot","$act"););
   88: }
   89: 
   90: sub secondlevel {
   91:     my $output='';
   92:     my 
   93:     ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act)=@_;
   94:     if ($prt eq 'any') {
   95: 	   $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act);
   96:     } elsif ($prt=~/^r(\w+)/) {
   97:         if ($rol eq $1) {
   98:            $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act);
   99:         }
  100:     }
  101:     return $output;
  102: }
  103: 
  104: sub openmenu {
  105:     if ($ENV{'browser.type'} eq 'explorer') {
  106:        return "window.open('javascript:void(0);','LONCAPAmenu');";
  107:    } else {
  108:        return "window.open('','LONCAPAmenu');";
  109:    }
  110: }
  111: 
  112: sub rawconfig {
  113:     my $r = shift;
  114:     my $output="var swmenu=".&openmenu();
  115:     my $uname=$ENV{'user.name'};
  116:     my $udom=$ENV{'user.domain'};
  117:     my $adv=$ENV{'user.adv'};
  118:     my $author=$ENV{'user.author'};
  119:     my $crs='';
  120:     if ($ENV{'request.course.id'}) {
  121:        $crs='/'.$ENV{'request.course.id'};
  122:        if ($ENV{'request.course.sec'}) {
  123: 	   $crs.='_'.$ENV{'request.course.sec'};
  124:        }
  125:        $crs=~s/\_/\//g;
  126:     }
  127:     my $pub=($ENV{'request.state'} eq 'published');
  128:     my $con=($ENV{'request.state'} eq 'construct');
  129:     my $rol=$ENV{'request.role'};
  130:     foreach (@desklines) {
  131:         my ($row,$col,$pro,$prt,$img,$top,$bot,$act)=split(/\:/,$_);
  132:         $prt=~s/\$uname/$uname/g;
  133:         $prt=~s/\$udom/$udom/g;
  134:         $prt=~s/\$crs/$crs/g; 
  135:         if ($pro eq 'clear') {
  136: 	    $output.=&clear($row,$col);
  137:         } elsif ($pro eq 'any') {
  138:                $output.=&secondlevel(
  139: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act);
  140: 	} elsif ($pro eq 'smp') {
  141:             unless ($adv) {
  142:                $output.=&secondlevel(
  143:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act);
  144:             }
  145:         } elsif ($pro eq 'adv') {
  146:             if ($adv) {
  147:                $output.=&secondlevel(
  148: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act);
  149:             }
  150:         } elsif (($pro=~/p(\w+)/) && ($prt)) {
  151: 	    if (&Apache::lonnet::allowed($1,$prt)) {
  152:                $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act);
  153:             }
  154:         } elsif ($pro eq 'author') {
  155:             if ($author) {
  156:                 if (($prt eq 'rca') && ($ENV{'request.role'}=~/^ca/)) {
  157:                     # Check that we are on the correct machine
  158: 		    my ($cadom,$caname)=
  159:                                ($ENV{'request.role'}=~/(\w+)\/(\w+)$/);
  160:                     my $home = &Apache::lonnet::homeserver($caname,$cadom);
  161:                     if ($home eq $r->dir_config('lonHostID')) {
  162:                         $output.=switch($caname,$cadom,
  163:                                         $row,$col,$img,$top,$bot,$act);
  164:                     }
  165:                 } elsif ($prt eq 'any') {
  166:                     my $home = &Apache::lonnet::homeserver
  167:                         ($ENV{'user.name'},$ENV{'user.domain'});
  168:                     if ($home eq $r->dir_config('lonHostID')) {
  169:                         $output.=switch
  170:                             ($ENV{'user.name'},$ENV{'user.domain'},
  171:                              $row,$col,$img,$top,$bot,$act);
  172:                     }
  173:                 }
  174:             }
  175:         }
  176:     }
  177:     $output.="swmenu.syncclock(1000*".time.");";
  178:     return $output;
  179: }
  180: 
  181: # ======================================================================= Close
  182: 
  183: sub close {
  184:     return(<<ENDCLOSE);
  185: <script>
  186: menu=window.open("/adm/rat/empty.html","LONCAPAmenu",
  187:                  "height=350,width=150,scrollbars=no,menubar=no");
  188: menu.close();
  189: </script>
  190: ENDCLOSE
  191: }
  192: 
  193: # ====================================================================== Footer
  194: 
  195: sub footer {
  196: 
  197: }
  198: 
  199: # ================================================================ Main Program
  200: 
  201: BEGIN {
  202:   if (! defined($readdesk)) {
  203:    {
  204:     my $config=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.
  205: 				  '/mydesk.tab');
  206:     while (my $configline=<$config>) {
  207:        $configline=(split(/\#/,$configline))[0];
  208:        $configline=~s/^\s+//;
  209:        chomp($configline);
  210:        if ($configline) {
  211:           $desklines[$#desklines+1]=$configline;
  212:        }
  213:     }
  214:    }
  215:    $readdesk='done';
  216:   }
  217: }
  218: 1;
  219: __END__
  220: 
  221: 
  222: 
  223: 
  224: 
  225: 
  226: 

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