File:  [LON-CAPA] / loncom / interface / lonmenu.pm
Revision 1.29: download - view: text, annotated - select for diffs
Fri Dec 6 17:49:49 2002 UTC (21 years, 6 months ago) by matthew
Branches: MAIN
CVS tags: version_0_6_2, version_0_6, HEAD
Fix bug 262.  lonxml.pm now checks to see if you have permissions to edit
the currently view resource.  mydesk.tab no longer calls cstrgo in menu.html
so cstrgo and is_editable_resource (javascript functions) have been
removed from menu.html.  lonmenu.pm was cleaned up.
This has been tested for authors and co-authors and across domains.

    1: # The LearningOnline Network with CAPA
    2: # Routines to control the menu
    3: #
    4: # $Id: lonmenu.pm,v 1.29 2002/12/06 17:49:49 matthew 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-55);
   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,$description)=@_;
   66:     my $openwin=&openmenu();
   67:     return(<<ENDSMENU);
   68: <script>
   69:    var swmenu=$openwin
   70:    swmenu.switchbutton($row,$col,"$imgsrc","$texttop","$textbot","$action","$description");
   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: # Switch acts on the javascript that is executed when a button is clicked.  
   83: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
   84: sub switch {
   85:     my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc)=@_;
   86:     $act=~s/\$uname/$uname/g;
   87:     $act=~s/\$udom/$udom/g;
   88:     return "\n".
   89:  qq(swmenu.switchbutton($row,$col,"$img","$top","$bot","$act","$desc"););
   90: }
   91: 
   92: sub secondlevel {
   93:     my $output='';
   94:     my 
   95:     ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc)=@_;
   96:     if ($prt eq 'any') {
   97: 	   $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
   98:     } elsif ($prt=~/^r(\w+)/) {
   99:         if ($rol eq $1) {
  100:            $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
  101:         }
  102:     }
  103:     return $output;
  104: }
  105: 
  106: sub openmenu {
  107:     if ($ENV{'browser.type'} eq 'explorer') {
  108:        return "window.open('javascript:void(0);','LONCAPAmenu');";
  109:    } else {
  110:        return "window.open('','LONCAPAmenu');";
  111:    }
  112: }
  113: 
  114: sub rawconfig {
  115:     my $r = shift;
  116:     my $output="var swmenu=".&openmenu();
  117:     my $uname=$ENV{'user.name'};
  118:     my $udom=$ENV{'user.domain'};
  119:     my $adv=$ENV{'user.adv'};
  120:     my $author=$ENV{'user.author'};
  121:     my $crs='';
  122:     if ($ENV{'request.course.id'}) {
  123:        $crs='/'.$ENV{'request.course.id'};
  124:        if ($ENV{'request.course.sec'}) {
  125: 	   $crs.='_'.$ENV{'request.course.sec'};
  126:        }
  127:        $crs=~s/\_/\//g;
  128:     }
  129:     my $pub=($ENV{'request.state'} eq 'published');
  130:     my $con=($ENV{'request.state'} eq 'construct');
  131:     my $rol=$ENV{'request.role'};
  132:     my $requested_domain = $ENV{'request.role.domain'};
  133:     foreach (@desklines) {
  134:         my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc)=split(/\:/,$_);
  135:         $prt=~s/\$uname/$uname/g;
  136:         $prt=~s/\$udom/$udom/g;
  137:         $prt=~s/\$crs/$crs/g; 
  138:         $prt=~s/\$requested_domain/$requested_domain/g;
  139:         if ($pro eq 'clear') {
  140: 	    $output.=&clear($row,$col);
  141:         } elsif ($pro eq 'any') {
  142:                $output.=&secondlevel(
  143: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
  144: 	} elsif ($pro eq 'smp') {
  145:             unless ($adv) {
  146:                $output.=&secondlevel(
  147:           $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
  148:             }
  149:         } elsif ($pro eq 'adv') {
  150:             if ($adv) {
  151:                $output.=&secondlevel(
  152: 	  $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
  153:             }
  154:         } elsif (($pro=~/p(\w+)/) && ($prt)) {
  155: 	    if (&Apache::lonnet::allowed($1,$prt)) {
  156:                $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
  157:             }
  158:         } elsif ($pro eq 'course') {
  159:             if ($ENV{'request.course.fn'}) {
  160:                $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
  161: 	    }
  162:         } elsif ($pro eq 'author') {
  163:             if ($author) {
  164:                 if ((($prt eq 'rca') && ($ENV{'request.role'}=~/^ca/)) ||
  165:                     (($prt eq 'rau') && ($ENV{'request.role'}=~/^au/))) {
  166:                     # Check that we are on the correct machine
  167:                     my $cadom=$requested_domain;
  168:                     my $caname=$ENV{'user.name'};
  169:                     if ($prt eq 'rca') {
  170: 		       ($cadom,$caname)=
  171:                                ($ENV{'request.role'}=~/(\w+)\/(\w+)$/);
  172:                     }                       
  173:                     $act =~ s/\$caname/$caname/g;
  174:                     my $home = &Apache::lonnet::homeserver($caname,$cadom);
  175:                     if ($home eq $r->dir_config('lonHostID')) {
  176:                         $output.=switch($caname,$cadom,
  177:                                         $row,$col,$img,$top,$bot,$act,$desc);
  178:                     }
  179:                 }
  180:             }
  181:         }
  182:     }
  183:     $output.="swmenu.syncclock(1000*".time.");";
  184:     return $output;
  185: }
  186: 
  187: # ======================================================================= Close
  188: 
  189: sub close {
  190:     return(<<ENDCLOSE);
  191: <script>
  192: menu=window.open("/adm/rat/empty.html","LONCAPAmenu",
  193:                  "height=350,width=150,scrollbars=no,menubar=no");
  194: menu.close();
  195: </script>
  196: ENDCLOSE
  197: }
  198: 
  199: # ====================================================================== Footer
  200: 
  201: sub footer {
  202: 
  203: }
  204: 
  205: # ================================================================ Main Program
  206: 
  207: BEGIN {
  208:   if (! defined($readdesk)) {
  209:    {
  210:     my $config=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.
  211: 				  '/mydesk.tab');
  212:     while (my $configline=<$config>) {
  213:        $configline=(split(/\#/,$configline))[0];
  214:        $configline=~s/^\s+//;
  215:        chomp($configline);
  216:        if ($configline) {
  217:           $desklines[$#desklines+1]=$configline;
  218:        }
  219:     }
  220:    }
  221:    $readdesk='done';
  222:   }
  223: }
  224: 1;
  225: __END__
  226: 
  227: 
  228: 
  229: 
  230: 
  231: 
  232: 

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