File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.16: download - view: text, annotated - select for diffs
Thu Feb 14 14:55:37 2002 UTC (22 years, 3 months ago) by harris41
Branches: MAIN
CVS tags: HEAD
sub BEGIN to BEGIN

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

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