File:
[LON-CAPA] /
loncom /
interface /
lonmenu.pm
Revision
1.32:
download - view:
text,
annotated -
select for diffs
Fri Jan 31 21:46:36 2003 UTC (21 years, 6 months ago) by
www
Branches:
MAIN
CVS tags:
HEAD
Attempt to work on bug #1205 by changing the timing of events at login for the
remote. Also, trying to isolate remote-related code into lonmenu.pm so that
alternative remotes/navigation become easier to implement later.
1: # The LearningOnline Network with CAPA
2: # Routines to control the menu
3: #
4: # $Id: lonmenu.pm,v 1.32 2003/01/31 21:46:36 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: # ============================================================= 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: }
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:
100: # =============================================================== Open the menu
101:
102: sub open {
103: my $returnval='';
104: my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
105: unless (shift eq 'unix') {
106: # resizing does not work on linux because of virtual desktop sizes
107: $returnval.=(<<ENDRESIZE);
108: if (window.screen) {
109: self.resizeTo(screen.availWidth-215,screen.availHeight-55);
110: self.moveTo(190,15);
111: }
112: ENDRESIZE
113: }
114: $returnval.=(<<ENDOPEN);
115: var menu=window.open("/res/adm/pages/menu.html","$menuname",
116: "height=350,width=150,scrollbars=no,menubar=no,top=5,left=5,screenX=5,screenY=5");
117: ENDOPEN
118: return '<script>'.$returnval.'</script>';
119: }
120:
121: # ============================================================ Switch Menu Item
122:
123: sub switchmenu {
124: my ($row,$col,$imgsrc,$texttop,$textbot,$action,$description)=@_;
125: my $openwin=&openmenu();
126: return(<<ENDSMENU);
127: <script>
128: var swmenu=$openwin
129: swmenu.switchbutton($row,$col,"$imgsrc","$texttop","$textbot","$action","$description");
130: </script>
131: ENDSMENU
132: }
133:
134: # ================================================================== Raw Config
135:
136: sub clear {
137: my ($row,$col)=@_;
138: return qq(swmenu.clearbut($row,$col););
139: }
140:
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(..)".
143: sub switch {
144: my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc)=@_;
145: $act=~s/\$uname/$uname/g;
146: $act=~s/\$udom/$udom/g;
147: return "\n".
148: qq(swmenu.switchbutton($row,$col,"$img","$top","$bot","$act","$desc"););
149: }
150:
151: sub secondlevel {
152: my $output='';
153: my
154: ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc)=@_;
155: if ($prt eq 'any') {
156: $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
157: } elsif ($prt=~/^r(\w+)/) {
158: if ($rol eq $1) {
159: $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
160: }
161: }
162: return $output;
163: }
164:
165: sub openmenu {
166: my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
167: if ($ENV{'browser.type'} eq 'explorer') {
168: return "window.open('javascript:void(0);','".$menuname."');";
169: } else {
170: return "window.open('','".$menuname."');";
171: }
172: }
173:
174: sub rawconfig {
175: my $output="var swmenu=".&openmenu();
176: my $uname=$ENV{'user.name'};
177: my $udom=$ENV{'user.domain'};
178: my $adv=$ENV{'user.adv'};
179: my $author=$ENV{'user.author'};
180: my $crs='';
181: if ($ENV{'request.course.id'}) {
182: $crs='/'.$ENV{'request.course.id'};
183: if ($ENV{'request.course.sec'}) {
184: $crs.='_'.$ENV{'request.course.sec'};
185: }
186: $crs=~s/\_/\//g;
187: }
188: my $pub=($ENV{'request.state'} eq 'published');
189: my $con=($ENV{'request.state'} eq 'construct');
190: my $rol=$ENV{'request.role'};
191: my $requested_domain = $ENV{'request.role.domain'};
192: foreach (@desklines) {
193: my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc)=split(/\:/,$_);
194: $prt=~s/\$uname/$uname/g;
195: $prt=~s/\$udom/$udom/g;
196: $prt=~s/\$crs/$crs/g;
197: $prt=~s/\$requested_domain/$requested_domain/g;
198: if ($pro eq 'clear') {
199: $output.=&clear($row,$col);
200: } elsif ($pro eq 'any') {
201: $output.=&secondlevel(
202: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
203: } elsif ($pro eq 'smp') {
204: unless ($adv) {
205: $output.=&secondlevel(
206: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
207: }
208: } elsif ($pro eq 'adv') {
209: if ($adv) {
210: $output.=&secondlevel(
211: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
212: }
213: } elsif (($pro=~/p(\w+)/) && ($prt)) {
214: if (&Apache::lonnet::allowed($1,$prt)) {
215: $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
216: }
217: } elsif ($pro eq 'course') {
218: if ($ENV{'request.course.fn'}) {
219: $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
220: }
221: } elsif ($pro eq 'author') {
222: if ($author) {
223: if ((($prt eq 'rca') && ($ENV{'request.role'}=~/^ca/)) ||
224: (($prt eq 'rau') && ($ENV{'request.role'}=~/^au/))) {
225: # Check that we are on the correct machine
226: my $cadom=$requested_domain;
227: my $caname=$ENV{'user.name'};
228: if ($prt eq 'rca') {
229: ($cadom,$caname)=
230: ($ENV{'request.role'}=~/(\w+)\/(\w+)$/);
231: }
232: $act =~ s/\$caname/$caname/g;
233: my $home = &Apache::lonnet::homeserver($caname,$cadom);
234: if ($home eq $Apache::lonnet::perlvar{'lonHostID'}) {
235: $output.=switch($caname,$cadom,
236: $row,$col,$img,$top,$bot,$act,$desc);
237: }
238: }
239: }
240: }
241: }
242: $output.="swmenu.syncclock(1000*".time.");";
243: return $output;
244: }
245:
246: # ======================================================================= Close
247:
248: sub close {
249: my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
250: return(<<ENDCLOSE);
251: <script>
252: menu=window.open("/adm/rat/empty.html","$menuname",
253: "height=350,width=150,scrollbars=no,menubar=no");
254: menu.autologout=0;
255: menu.close();
256: </script>
257: ENDCLOSE
258: }
259:
260: # ====================================================================== Footer
261:
262: sub footer {
263:
264: }
265:
266: # ================================================================ Main Program
267:
268: BEGIN {
269: if (! defined($readdesk)) {
270: {
271: my $config=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.
272: '/mydesk.tab');
273: while (my $configline=<$config>) {
274: $configline=(split(/\#/,$configline))[0];
275: $configline=~s/^\s+//;
276: chomp($configline);
277: if ($configline) {
278: $desklines[$#desklines+1]=$configline;
279: }
280: }
281: }
282: $readdesk='done';
283: }
284: }
285:
286: 1;
287: __END__
288:
289:
290:
291:
292:
293:
294:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>