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