Annotation of loncom/interface/lonmenu.pm, revision 1.32
1.1 www 1: # The LearningOnline Network with CAPA
2: # Routines to control the menu
3: #
1.32 ! www 4: # $Id: lonmenu.pm,v 1.31 2003/01/29 15:22:06 www Exp $
1.11 albertel 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: #
1.1 www 28: # (TeX Conversion Module
29: #
30: # 05/29/00,05/30 Gerd Kortemeyer)
31: #
1.8 www 32: # 10/05,05/28,05/30,06/01,06/08,06/09,07/04,08/07 Gerd Kortemeyer
1.17 matthew 33: # 02/15/02 Matthew Hall
1.1 www 34:
35: package Apache::lonmenu;
36:
37: use strict;
1.2 www 38: use Apache::lonnet;
39: use Apache::File;
40: use vars qw(@desklines $readdesk);
1.30 www 41:
1.32 ! www 42: # ============================================================= Start up remote
! 43:
! 44: sub startupremote {
! 45: my ($lowerurl)=@_;
! 46: my $configmenu=&rawconfig();
! 47: return(<<ENDREMOTESTARTUP);
! 48: <script>
! 49:
! 50: // ---------------------------------------------------------- The wait function
! 51: var canceltim;
! 52: function wait() {
! 53: if ((menuloaded==1) || (tim==1)) {
! 54: if (tim==0) {
! 55: clearTimeout(canceltim);
! 56: $configmenu
! 57: window.location='$lowerurl';
! 58: } else {
! 59: alert("Remote Control Timed Out.");
! 60: }
! 61: } else {
! 62: setTimeout('wait();',100);
! 63: }
! 64: }
! 65:
! 66: function main() {
! 67: canceltim=setTimeout('tim=1;',80000);
! 68: wait();
! 69: }
! 70:
! 71: </script>
! 72: ENDREMOTESTARTUP
! 73: }
! 74:
! 75: sub setflags() {
! 76: return(<<ENDSETFLAGS);
! 77: <script>
! 78: menuloaded=0;
! 79: tim=0;
! 80: </script>
! 81: ENDSETFLAGS
! 82: }
! 83:
! 84: sub maincall() {
! 85: return(<<ENDMAINCALL);
! 86: <script>
! 87: main();
! 88: </script>
! 89: ENDMAINCALL
! 90: }
1.30 www 91: # ================================================================= Reopen menu
92:
93: sub reopenmenu {
94: my $nothing='';
95: my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
96: if ($ENV{'browser.type'} eq 'explorer') { $nothing='javascript:void(0);'; }
97: return('window.open("'.$nothing.'","'.$menuname.'","",false);');
98: }
99:
1.1 www 100: # =============================================================== Open the menu
101:
102: sub open {
1.22 www 103: my $returnval='';
1.30 www 104: my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
1.22 www 105: unless (shift eq 'unix') {
106: # resizing does not work on linux because of virtual desktop sizes
107: $returnval.=(<<ENDRESIZE);
108: if (window.screen) {
1.28 www 109: self.resizeTo(screen.availWidth-215,screen.availHeight-55);
1.22 www 110: self.moveTo(190,15);
111: }
112: ENDRESIZE
113: }
114: $returnval.=(<<ENDOPEN);
1.30 www 115: var menu=window.open("/res/adm/pages/menu.html","$menuname",
1.14 www 116: "height=350,width=150,scrollbars=no,menubar=no,top=5,left=5,screenX=5,screenY=5");
1.1 www 117: ENDOPEN
1.22 www 118: return '<script>'.$returnval.'</script>';
1.1 www 119: }
120:
1.2 www 121: # ============================================================ Switch Menu Item
122:
123: sub switchmenu {
1.27 www 124: my ($row,$col,$imgsrc,$texttop,$textbot,$action,$description)=@_;
1.18 www 125: my $openwin=&openmenu();
1.2 www 126: return(<<ENDSMENU);
127: <script>
1.20 matthew 128: var swmenu=$openwin
1.27 www 129: swmenu.switchbutton($row,$col,"$imgsrc","$texttop","$textbot","$action","$description");
1.2 www 130: </script>
131: ENDSMENU
132: }
133:
134: # ================================================================== Raw Config
135:
1.3 www 136: sub clear {
137: my ($row,$col)=@_;
138: return qq(swmenu.clearbut($row,$col););
139: }
140:
1.25 matthew 141: # Switch acts on the javascript that is executed when a button is clicked.
142: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
1.2 www 143: sub switch {
1.27 www 144: my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc)=@_;
1.2 www 145: $act=~s/\$uname/$uname/g;
146: $act=~s/\$udom/$udom/g;
147: return "\n".
1.27 www 148: qq(swmenu.switchbutton($row,$col,"$img","$top","$bot","$act","$desc"););
1.2 www 149: }
150:
151: sub secondlevel {
152: my $output='';
153: my
1.27 www 154: ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc)=@_;
1.2 www 155: if ($prt eq 'any') {
1.27 www 156: $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
1.2 www 157: } elsif ($prt=~/^r(\w+)/) {
158: if ($rol eq $1) {
1.27 www 159: $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
1.2 www 160: }
161: }
162: return $output;
163: }
164:
1.18 www 165: sub openmenu {
1.30 www 166: my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
1.18 www 167: if ($ENV{'browser.type'} eq 'explorer') {
1.30 www 168: return "window.open('javascript:void(0);','".$menuname."');";
1.18 www 169: } else {
1.30 www 170: return "window.open('','".$menuname."');";
1.18 www 171: }
172: }
173:
1.2 www 174: sub rawconfig {
1.20 matthew 175: my $output="var swmenu=".&openmenu();
1.2 www 176: my $uname=$ENV{'user.name'};
177: my $udom=$ENV{'user.domain'};
178: my $adv=$ENV{'user.adv'};
1.4 www 179: my $author=$ENV{'user.author'};
1.5 www 180: my $crs='';
181: if ($ENV{'request.course.id'}) {
182: $crs='/'.$ENV{'request.course.id'};
1.7 www 183: if ($ENV{'request.course.sec'}) {
184: $crs.='_'.$ENV{'request.course.sec'};
185: }
1.8 www 186: $crs=~s/\_/\//g;
1.5 www 187: }
1.2 www 188: my $pub=($ENV{'request.state'} eq 'published');
189: my $con=($ENV{'request.state'} eq 'construct');
190: my $rol=$ENV{'request.role'};
1.25 matthew 191: my $requested_domain = $ENV{'request.role.domain'};
1.13 harris41 192: foreach (@desklines) {
1.27 www 193: my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc)=split(/\:/,$_);
1.3 www 194: $prt=~s/\$uname/$uname/g;
195: $prt=~s/\$udom/$udom/g;
1.5 www 196: $prt=~s/\$crs/$crs/g;
1.25 matthew 197: $prt=~s/\$requested_domain/$requested_domain/g;
1.3 www 198: if ($pro eq 'clear') {
1.4 www 199: $output.=&clear($row,$col);
1.3 www 200: } elsif ($pro eq 'any') {
1.2 www 201: $output.=&secondlevel(
1.27 www 202: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
1.2 www 203: } elsif ($pro eq 'smp') {
204: unless ($adv) {
205: $output.=&secondlevel(
1.27 www 206: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
1.2 www 207: }
208: } elsif ($pro eq 'adv') {
209: if ($adv) {
210: $output.=&secondlevel(
1.27 www 211: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
1.2 www 212: }
213: } elsif (($pro=~/p(\w+)/) && ($prt)) {
214: if (&Apache::lonnet::allowed($1,$prt)) {
1.27 www 215: $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
1.4 www 216: }
1.26 www 217: } elsif ($pro eq 'course') {
218: if ($ENV{'request.course.fn'}) {
1.27 www 219: $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
1.26 www 220: }
1.4 www 221: } elsif ($pro eq 'author') {
222: if ($author) {
1.29 matthew 223: if ((($prt eq 'rca') && ($ENV{'request.role'}=~/^ca/)) ||
224: (($prt eq 'rau') && ($ENV{'request.role'}=~/^au/))) {
1.19 matthew 225: # Check that we are on the correct machine
1.29 matthew 226: my $cadom=$requested_domain;
227: my $caname=$ENV{'user.name'};
228: if ($prt eq 'rca') {
229: ($cadom,$caname)=
1.6 www 230: ($ENV{'request.role'}=~/(\w+)\/(\w+)$/);
1.29 matthew 231: }
232: $act =~ s/\$caname/$caname/g;
1.19 matthew 233: my $home = &Apache::lonnet::homeserver($caname,$cadom);
1.32 ! www 234: if ($home eq $Apache::lonnet::perlvar{'lonHostID'}) {
1.19 matthew 235: $output.=switch($caname,$cadom,
1.27 www 236: $row,$col,$img,$top,$bot,$act,$desc);
1.19 matthew 237: }
1.6 www 238: }
1.2 www 239: }
240: }
1.13 harris41 241: }
1.24 www 242: $output.="swmenu.syncclock(1000*".time.");";
1.2 www 243: return $output;
244: }
245:
246: # ======================================================================= Close
1.1 www 247:
248: sub close {
1.30 www 249: my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
1.1 www 250: return(<<ENDCLOSE);
251: <script>
1.30 www 252: menu=window.open("/adm/rat/empty.html","$menuname",
1.1 www 253: "height=350,width=150,scrollbars=no,menubar=no");
1.31 www 254: menu.autologout=0;
1.1 www 255: menu.close();
256: </script>
257: ENDCLOSE
258: }
259:
260: # ====================================================================== Footer
261:
262: sub footer {
263:
264: }
265:
1.2 www 266: # ================================================================ Main Program
267:
1.16 harris41 268: BEGIN {
1.15 matthew 269: if (! defined($readdesk)) {
1.14 www 270: {
1.10 albertel 271: my $config=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.
272: '/mydesk.tab');
273: while (my $configline=<$config>) {
1.14 www 274: $configline=(split(/\#/,$configline))[0];
275: $configline=~s/^\s+//;
1.10 albertel 276: chomp($configline);
1.14 www 277: if ($configline) {
278: $desklines[$#desklines+1]=$configline;
279: }
1.2 www 280: }
1.14 www 281: }
282: $readdesk='done';
1.10 albertel 283: }
1.2 www 284: }
1.30 www 285:
1.1 www 286: 1;
287: __END__
288:
289:
290:
291:
292:
293:
294:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>