File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.30: download - view: text, annotated - select for diffs
Wed Jan 15 23:59:26 2003 UTC (21 years, 4 months ago) by www
Branches: MAIN
CVS tags: HEAD
Remote control has "tool hint" bubbles.

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

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