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