1: # The LearningOnline Network with CAPA
2: # Routines to control the menu
3: #
4: # $Id: lonmenu.pm,v 1.37 2003/02/14 15:14:37 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::Constants qw(:common);
40: use Apache::loncommon;
41: use Apache::File;
42: use vars qw(@desklines $readdesk);
43:
44: # ============================================================= Start up remote
45:
46: sub startupremote {
47: my ($lowerurl)=@_;
48: if ($ENV{'browser.interface'} eq 'textual') {
49: return ('<meta HTTP-EQUIV="Refresh" CONTENT="0.5; url='.$lowerurl.'" />');
50: }
51: my $configmenu=&rawconfig();
52: return(<<ENDREMOTESTARTUP);
53: <script>
54:
55: function wheelswitch() {
56: if (window.status=='|') {
57: window.status='/';
58: } else {
59: if (window.status=='/') {
60: window.status='-';
61: } else {
62: if (window.status=='-') {
63: window.status='\\\\';
64: } else {
65: if (window.status=='\\\\') { window.status='|'; }
66: }
67: }
68: }
69: }
70:
71: // ---------------------------------------------------------- The wait function
72: var canceltim;
73: function wait() {
74: if ((menuloaded==1) || (tim==1)) {
75: window.status='Done.';
76: if (tim==0) {
77: clearTimeout(canceltim);
78: $configmenu
79: window.location='$lowerurl';
80: } else {
81: alert("Remote Control timed out. It is possible that it was blocked by pop-up window filters.");
82: }
83: } else {
84: wheelswitch();
85: setTimeout('wait();',200);
86: }
87: }
88:
89: function main() {
90: canceltim=setTimeout('tim=1;',60000);
91: window.status='-';
92: wait();
93: }
94:
95: </script>
96: ENDREMOTESTARTUP
97: }
98:
99: sub setflags() {
100: return(<<ENDSETFLAGS);
101: <script>
102: menuloaded=0;
103: tim=0;
104: </script>
105: ENDSETFLAGS
106: }
107:
108: sub maincall() {
109: if ($ENV{'browser.interface'} eq 'textual') { return ''; }
110: return(<<ENDMAINCALL);
111: <script>
112: main();
113: </script>
114: ENDMAINCALL
115: }
116: # ================================================================= Reopen menu
117:
118: sub reopenmenu {
119: my $nothing='';
120: if ($ENV{'browser.interface'} eq 'textual') { return ''; }
121: my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
122: if ($ENV{'browser.type'} eq 'explorer') { $nothing='javascript:void(0);'; }
123: return('window.open("'.$nothing.'","'.$menuname.'","",false);');
124: }
125:
126: # =============================================================== Open the menu
127:
128: sub open {
129: my $returnval='';
130: if ($ENV{'browser.interface'} eq 'textual') { return ''; }
131: my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
132: unless (shift eq 'unix') {
133: # resizing does not work on linux because of virtual desktop sizes
134: $returnval.=(<<ENDRESIZE);
135: if (window.screen) {
136: self.resizeTo(screen.availWidth-215,screen.availHeight-55);
137: self.moveTo(190,15);
138: }
139: ENDRESIZE
140: }
141: $returnval.=(<<ENDOPEN);
142: window.status='Opening LON-CAPA Remote Control';
143: var menu=window.open("/res/adm/pages/menu.html","$menuname",
144: "height=350,width=150,scrollbars=no,menubar=no,top=5,left=5,screenX=5,screenY=5");
145: ENDOPEN
146: return '<script>'.$returnval.'</script>';
147: }
148:
149:
150: # ================================================================== Raw Config
151:
152: sub clear {
153: my ($row,$col)=@_;
154: unless ($ENV{'browser.interface'} eq 'textual') {
155: return "\n".qq(window.status+='.';swmenu.clearbut($row,$col););
156: } else { return ''; }
157: }
158:
159: # Switch acts on the javascript that is executed when a button is clicked.
160: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
161: sub switch {
162: my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc)=@_;
163: $act=~s/\$uname/$uname/g;
164: $act=~s/\$udom/$udom/g;
165: unless ($ENV{'browser.interface'} eq 'textual') {
166: return "\n".
167: qq(window.status+='.';swmenu.switchbutton($row,$col,"$img","$top","$bot","$act","$desc"););
168: } else {
169: my $text=$top.' '.$bot;
170: $text=~s/\- //;
171: return '<br /><a href="javascript:'.$act.';">'.$text.'</a> '.$desc;
172: }
173: }
174:
175: sub secondlevel {
176: my $output='';
177: my
178: ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc)=@_;
179: if ($prt eq 'any') {
180: $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
181: } elsif ($prt=~/^r(\w+)/) {
182: if ($rol eq $1) {
183: $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
184: }
185: }
186: return $output;
187: }
188:
189: sub openmenu {
190: my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
191: if ($ENV{'browser.interface'} eq 'textual') { return ''; }
192: if ($ENV{'browser.type'} eq 'explorer') {
193: return "window.open('javascript:void(0);','".$menuname."');";
194: } else {
195: return "window.open('','".$menuname."');";
196: }
197: }
198:
199: sub rawconfig {
200: my $textualoverride=shift;
201: my $output='';
202: unless ($ENV{'browser.interface'} eq 'textual') {
203: $output.=
204: "window.status='Opening Remote Control';var swmenu=".&openmenu().
205: "\nwindow.status='Configuring Remote Control ';";
206: } else {
207: unless ($textualoverride) { return ''; }
208: }
209: my $uname=$ENV{'user.name'};
210: my $udom=$ENV{'user.domain'};
211: my $adv=$ENV{'user.adv'};
212: my $author=$ENV{'user.author'};
213: my $crs='';
214: if ($ENV{'request.course.id'}) {
215: $crs='/'.$ENV{'request.course.id'};
216: if ($ENV{'request.course.sec'}) {
217: $crs.='_'.$ENV{'request.course.sec'};
218: }
219: $crs=~s/\_/\//g;
220: }
221: my $pub=($ENV{'request.state'} eq 'published');
222: my $con=($ENV{'request.state'} eq 'construct');
223: my $rol=$ENV{'request.role'};
224: my $requested_domain = $ENV{'request.role.domain'};
225: foreach (@desklines) {
226: my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc)=split(/\:/,$_);
227: $prt=~s/\$uname/$uname/g;
228: $prt=~s/\$udom/$udom/g;
229: $prt=~s/\$crs/$crs/g;
230: $prt=~s/\$requested_domain/$requested_domain/g;
231: if ($pro eq 'clear') {
232: $output.=&clear($row,$col);
233: } elsif ($pro eq 'any') {
234: $output.=&secondlevel(
235: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
236: } elsif ($pro eq 'smp') {
237: unless ($adv) {
238: $output.=&secondlevel(
239: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
240: }
241: } elsif ($pro eq 'adv') {
242: if ($adv) {
243: $output.=&secondlevel(
244: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
245: }
246: } elsif (($pro=~/p(\w+)/) && ($prt)) {
247: if (&Apache::lonnet::allowed($1,$prt)) {
248: $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
249: }
250: } elsif ($pro eq 'course') {
251: if ($ENV{'request.course.fn'}) {
252: $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
253: }
254: } elsif ($pro eq 'author') {
255: if ($author) {
256: if ((($prt eq 'rca') && ($ENV{'request.role'}=~/^ca/)) ||
257: (($prt eq 'rau') && ($ENV{'request.role'}=~/^au/))) {
258: # Check that we are on the correct machine
259: my $cadom=$requested_domain;
260: my $caname=$ENV{'user.name'};
261: if ($prt eq 'rca') {
262: ($cadom,$caname)=
263: ($ENV{'request.role'}=~/(\w+)\/(\w+)$/);
264: }
265: $act =~ s/\$caname/$caname/g;
266: my $home = &Apache::lonnet::homeserver($caname,$cadom);
267: if ($home eq $Apache::lonnet::perlvar{'lonHostID'}) {
268: $output.=switch($caname,$cadom,
269: $row,$col,$img,$top,$bot,$act,$desc);
270: }
271: }
272: }
273: }
274: }
275: unless ($ENV{'browser.interface'} eq 'textual') {
276: $output.="\nwindow.status='Synchronizing Time';swmenu.syncclock(1000*".time.");\nwindow.status='Remote Control Configured.';";
277: }
278: return $output;
279: }
280:
281: # ======================================================================= Close
282:
283: sub close {
284: if ($ENV{'browser.interface'} eq 'textual') { return ''; }
285: my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
286: return(<<ENDCLOSE);
287: <script>
288: window.status='Accessing Remote Control';
289: menu=window.open("/adm/rat/empty.html","$menuname",
290: "height=350,width=150,scrollbars=no,menubar=no");
291: window.status='Disabling Remote Control';
292: menu.active=0;
293: menu.autologout=0;
294: window.status='Closing Remote Control';
295: menu.close();
296: window.status='Done.';
297: </script>
298: ENDCLOSE
299: }
300:
301: # ====================================================================== Footer
302:
303: sub footer {
304:
305: }
306:
307: # ================================================ Handler when called directly
308:
309:
310: sub handler {
311: my $r = shift;
312: $r->content_type('text/html');
313: $r->send_http_header;
314: return OK if $r->header_only;
315:
316: my $bodytag=&Apache::loncommon::bodytag('Main Menu');
317: # ------------------------------------------------------------ Print the screen
318: $r->print(<<ENDHEADER);
319: <html><head>
320: <title>LON-CAPA Main Menu</title>
321: <script>
322: function go(url) {
323: window.location=url;
324: }
325: function gopost(url) {
326: window.location=url;
327: }
328: </script>
329: </head>
330: $bodytag
331: ENDHEADER
332: $r->print(&rawconfig(1));
333: $r->print('</body></html>');
334: return OK;
335: }
336:
337: # ================================================================ Main Program
338:
339: BEGIN {
340: if (! defined($readdesk)) {
341: {
342: my $config=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.
343: '/mydesk.tab');
344: while (my $configline=<$config>) {
345: $configline=(split(/\#/,$configline))[0];
346: $configline=~s/^\s+//;
347: chomp($configline);
348: if ($configline) {
349: $desklines[$#desklines+1]=$configline;
350: }
351: }
352: }
353: $readdesk='done';
354: }
355: }
356:
357: 1;
358: __END__
359:
360:
361:
362:
363:
364:
365:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>