Annotation of loncom/interface/lonmenu.pm, revision 1.39
1.1 www 1: # The LearningOnline Network with CAPA
2: # Routines to control the menu
3: #
1.39 ! www 4: # $Id: lonmenu.pm,v 1.38 2003/02/14 19:35:54 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.38 www 43:
44: # ======================================================= Make the menu buttons
45:
46: sub menubuttons {
47: my $forcereg=shift;
48: my $target =shift;
49: unless ($ENV{'browser.interface'} eq 'textual') { return ''; }
1.39 ! www 50: my $output='<a href="/adm/menu">Main Menu</a><br />';
! 51: return $output."<hr />";
1.38 www 52: }
53:
54: # ============================================== Register a URL with the remote
55:
56:
57: sub registerurl {
58: my $forcereg=shift;
59: my $target = shift;
60: my $result = '';
61:
62: if ($target eq 'edit') {
63: $result .="<script type=\"text/javascrtipt\">\n".
64: "if (typeof swmenu != 'undefined') {swmenu.currentURL=null;}\n".
65: &Apache::loncommon::browser_and_searcher_javascript().
66: "\n</script>\n";
67: }
68: if (($ENV{'browser.interface'} eq 'textual') ||
69: ((($ENV{'request.publicaccess'}) ||
70: (!&Apache::lonnet::is_on_map($ENV{'REQUEST_URI'}))) &&
71: (!$forcereg))) {
72: return $result.
73: '<script type="text/javascript">function LONCAPAreg(){;} function LONCAPAstale(){}</script>';
74: }
75: if ($Apache::lonxml::registered && !$forcereg) { return ''; }
76: $Apache::lonxml::registered=1;
77: my $reopen=&Apache::lonmenu::reopenmenu();
78: my $newmail='';
79: if (&Apache::lonmsg::newmail()) {
80: $newmail='swmenu.setstatus("you have","messages");';
81: }
82: my $timesync='swmenu.syncclock(1000*'.time.');';
83: if (($ENV{'REQUEST_URI'}!~/^\/(res\/)*adm\//) || ($forcereg)) {
84: my $hwkadd='';
85: if ($ENV{'request.filename'}=~/\.(problem|exam|quiz|assess|survey|form)$/) {
86: if (&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'})) {
87: $hwkadd.=(<<ENDSUBM);
88: swmenu.switchbutton(7,1,'subm.gif','view sub','missions','gocmd("/adm/grades","submission")',
89: 'View user submissions for this assessment resource');
90: ENDSUBM
91: }
92: if (&Apache::lonnet::allowed('mgr',$ENV{'request.course.id'})) {
93: $hwkadd.=(<<ENDGRDS);
94: swmenu.switchbutton(7,2,'pgrd.gif','problem','grades','gocmd("/adm/grades","gradingmenu")',
95: 'Modify user grades for this assessment resource');
96: ENDGRDS
97: }
98: if (&Apache::lonnet::allowed('opa',$ENV{'request.course.id'})) {
99: $hwkadd.=(<<ENDPARM);
100: swmenu.switchbutton(7,3,'pparm.gif','problem','parms','gocmd("/adm/parmset","set")',
101: 'Modify deadlines, etc, for this assessment resource');
102: ENDPARM
103: }
104: }
105: ###
106: ### Determine whether or not to display the 'cstr' button for this
107: ### resource
108: ###
109: my $editbutton = '';
110: if ($ENV{'user.author'}) {
111: if ($ENV{'request.role'}=~/^(ca|au)/) {
112: # Set defaults for authors
113: my ($top,$bottom) = ('con-','struct');
114: my $action = "go('/priv/".$ENV{'user.name'}."');";
115: my $cadom = $ENV{'request.role.domain'};
116: my $caname = $ENV{'user.name'};
117: my $desc = "Enter my resource construction space";
118: # Set defaults for co-authors
119: if ($ENV{'request.role'} =~ /^ca/) {
120: ($cadom,$caname)=($ENV{'request.role'}=~/(\w+)\/(\w+)$/);
121: ($top,$bottom) = ('co con-','struct');
122: $action = "go('/priv/".$caname."');";
123: $desc = "Enter construction space as co-author";
124: }
125: # Check that we are on the correct machine
126: my $home = &Apache::lonnet::homeserver($caname,$cadom);
127: if ($home eq $Apache::lonnet::perlvar{'lonHostID'}) {
128: $editbutton=&Apache::lonmenu::switch
129: ('','',6,1,$top,,$bottom,$action,$desc);
130: }
131: }
132: ##
133: ## Determine if user can edit url.
134: ##
135: my $cfile='';
136: my $cfuname='';
137: my $cfudom='';
138: if ($ENV{'request.filename'}) {
139: my $file=&Apache::lonnet::declutter($ENV{'request.filename'});
140: $file=~s/^(\w+)\/(\w+)/\/priv\/$2/;
141: # Chech that the user has permission to edit this resource
142: ($cfuname,$cfudom)=&Apache::loncacc::constructaccess($file,$1);
143: if (defined($cfudom)) {
144: if (&Apache::lonnet::homeserver($cfuname,$cfudom)
145: eq $Apache::lonnet::perlvar{'lonHostID'}) {
146: $cfile=$file;
147: }
148: }
149: }
150: # Finally, turn the button on or off
151: if ($cfile) {
152: $editbutton=&Apache::lonmenu::switch
153: ('','',6,1,'cstr.gif','edit','resource',
154: "go('".$cfile."');","Edit this resource");
155: } elsif ($editbutton eq '') {
156: $editbutton = ' swmenu.clearbut(6,1);';
157: }
158: }
159: ###
160: ###
161: $result = (<<ENDREGTHIS);
162:
163: <script language="JavaScript">
164: // BEGIN LON-CAPA Internal
165:
166: function LONCAPAreg() {
167: swmenu=$reopen;
168: swmenu.clearTimeout(swmenu.menucltim);
169: $timesync
170: $newmail
171: swmenu.currentURL=window.location.pathname;
172: swmenu.reloadURL=window.location.pathname;
173: swmenu.currentSymb="$ENV{'request.symb'}";
174: swmenu.reloadSymb="$ENV{'request.symb'}";
175: swmenu.currentStale=0;
176: swmenu.clearbut(3,1);
177: swmenu.switchbutton
178: (6,3,'catalog.gif','catalog','info','catalog_info()','Show catalog information');
179: swmenu.switchbutton
180: (8,1,'eval.gif','evaluate','this','gopost("/adm/evaluate",currentURL)','Provide my evaluation of this resource');
181: swmenu.switchbutton
182: (8,2,'fdbk.gif','feedback','discuss','gopost("/adm/feedback",currentURL)','Provide feedback messages or contribute to the course discussion about this resource');
183: swmenu.switchbutton
184: (8,3,'prt.gif','prepare','printout','gopost("/adm/printout",currentURL)','Prepare a printable document');
185: swmenu.switchbutton
186: (2,1,'back.gif','backward','','gopost("/adm/flip","back:"+currentURL)','Go to the previous resource in the course sequence');
187: swmenu.switchbutton
188: (2,3,'forw.gif','forward','','gopost("/adm/flip","forward:"+currentURL)','Go to the next resource in the course sequence');
189: swmenu.switchbutton
190: (9,1,'sbkm.gif','set','bookmark','set_bookmark()','Set a bookmark for this resource');
191: swmenu.switchbutton
192: (9,2,'vbkm.gif','view','bookmark','edit_bookmarks()','Use or edit my bookmark collection');
193: swmenu.switchbutton
194: (9,3,'anot.gif','anno-','tations','annotate()','Make notes and annotations about this resource');
195: $hwkadd
196: $editbutton
197: }
198:
199: function LONCAPAstale() {
200: swmenu=$reopen
201: swmenu.currentStale=1;
202: if (swmenu.reloadURL!='' && swmenu.reloadURL!= null) {
203: swmenu.switchbutton
204: (3,1,'reload.gif','return','location','go(reloadURL)','Return to the last known location in the course sequence');
205: }
206: swmenu.clearbut(7,1);
207: swmenu.clearbut(7,2);
208: swmenu.clearbut(7,3);
209: swmenu.menucltim=swmenu.setTimeout(
210: 'clearbut(2,1);clearbut(2,3);clearbut(8,1);clearbut(8,2);clearbut(8,3);'+
211: 'clearbut(9,1);clearbut(9,2);clearbut(9,3);clearbut(6,3);clearbut(6,1)',
212: 2000);
213:
214: }
215:
216: // END LON-CAPA Internal
217: </script>
218: ENDREGTHIS
219:
220: } else {
221: $result = (<<ENDDONOTREGTHIS);
222:
223: <script language="JavaScript">
224: // BEGIN LON-CAPA Internal
225:
226: function LONCAPAreg() {
227: swmenu=$reopen
228: $timesync
229: swmenu.currentStale=1;
230: swmenu.clearbut(2,1);
231: swmenu.clearbut(2,3);
232: swmenu.clearbut(8,1);
233: swmenu.clearbut(8,2);
234: swmenu.clearbut(8,3);
235: if (swmenu.currentURL) {
236: swmenu.switchbutton
237: (3,1,'reload.gif','return','location','go(currentURL)');
238: } else {
239: swmenu.clearbut(3,1);
240: }
241: }
242:
243: function LONCAPAstale() {
244: }
245:
246: // END LON-CAPA Internal
247: </script>
248: ENDDONOTREGTHIS
249: }
250: return $result;
251: }
252:
253: sub loadevents() {
254: return 'LONCAPAreg();';
255: }
256:
257: sub unloadevents() {
258: return 'LONCAPAstale();';
259: }
1.30 www 260:
1.32 www 261: # ============================================================= Start up remote
262:
263: sub startupremote {
264: my ($lowerurl)=@_;
1.34 www 265: if ($ENV{'browser.interface'} eq 'textual') {
266: return ('<meta HTTP-EQUIV="Refresh" CONTENT="0.5; url='.$lowerurl.'" />');
267: }
1.32 www 268: my $configmenu=&rawconfig();
269: return(<<ENDREMOTESTARTUP);
270: <script>
271:
1.35 www 272: function wheelswitch() {
273: if (window.status=='|') {
274: window.status='/';
275: } else {
276: if (window.status=='/') {
277: window.status='-';
278: } else {
279: if (window.status=='-') {
280: window.status='\\\\';
281: } else {
282: if (window.status=='\\\\') { window.status='|'; }
283: }
284: }
285: }
286: }
287:
1.32 www 288: // ---------------------------------------------------------- The wait function
289: var canceltim;
290: function wait() {
291: if ((menuloaded==1) || (tim==1)) {
1.35 www 292: window.status='Done.';
1.32 www 293: if (tim==0) {
294: clearTimeout(canceltim);
295: $configmenu
296: window.location='$lowerurl';
297: } else {
1.35 www 298: alert("Remote Control timed out. It is possible that it was blocked by pop-up window filters.");
1.32 www 299: }
300: } else {
1.35 www 301: wheelswitch();
302: setTimeout('wait();',200);
1.32 www 303: }
304: }
305:
306: function main() {
1.35 www 307: canceltim=setTimeout('tim=1;',60000);
308: window.status='-';
1.32 www 309: wait();
310: }
311:
312: </script>
313: ENDREMOTESTARTUP
314: }
315:
316: sub setflags() {
317: return(<<ENDSETFLAGS);
318: <script>
319: menuloaded=0;
320: tim=0;
321: </script>
322: ENDSETFLAGS
323: }
324:
325: sub maincall() {
1.34 www 326: if ($ENV{'browser.interface'} eq 'textual') { return ''; }
1.32 www 327: return(<<ENDMAINCALL);
328: <script>
329: main();
330: </script>
331: ENDMAINCALL
332: }
1.30 www 333: # ================================================================= Reopen menu
334:
335: sub reopenmenu {
336: my $nothing='';
1.34 www 337: if ($ENV{'browser.interface'} eq 'textual') { return ''; }
1.30 www 338: my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
339: if ($ENV{'browser.type'} eq 'explorer') { $nothing='javascript:void(0);'; }
340: return('window.open("'.$nothing.'","'.$menuname.'","",false);');
341: }
342:
1.1 www 343: # =============================================================== Open the menu
344:
345: sub open {
1.22 www 346: my $returnval='';
1.34 www 347: if ($ENV{'browser.interface'} eq 'textual') { return ''; }
1.30 www 348: my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
1.22 www 349: unless (shift eq 'unix') {
350: # resizing does not work on linux because of virtual desktop sizes
351: $returnval.=(<<ENDRESIZE);
352: if (window.screen) {
1.28 www 353: self.resizeTo(screen.availWidth-215,screen.availHeight-55);
1.22 www 354: self.moveTo(190,15);
355: }
356: ENDRESIZE
357: }
358: $returnval.=(<<ENDOPEN);
1.35 www 359: window.status='Opening LON-CAPA Remote Control';
1.30 www 360: var menu=window.open("/res/adm/pages/menu.html","$menuname",
1.14 www 361: "height=350,width=150,scrollbars=no,menubar=no,top=5,left=5,screenX=5,screenY=5");
1.1 www 362: ENDOPEN
1.22 www 363: return '<script>'.$returnval.'</script>';
1.1 www 364: }
365:
1.2 www 366:
367: # ================================================================== Raw Config
368:
1.3 www 369: sub clear {
370: my ($row,$col)=@_;
1.34 www 371: unless ($ENV{'browser.interface'} eq 'textual') {
1.35 www 372: return "\n".qq(window.status+='.';swmenu.clearbut($row,$col););
1.34 www 373: } else { return ''; }
1.3 www 374: }
375:
1.25 matthew 376: # Switch acts on the javascript that is executed when a button is clicked.
377: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
1.2 www 378: sub switch {
1.27 www 379: my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc)=@_;
1.2 www 380: $act=~s/\$uname/$uname/g;
381: $act=~s/\$udom/$udom/g;
1.34 www 382: unless ($ENV{'browser.interface'} eq 'textual') {
383: return "\n".
1.35 www 384: qq(window.status+='.';swmenu.switchbutton($row,$col,"$img","$top","$bot","$act","$desc"););
1.34 www 385: } else {
386: my $text=$top.' '.$bot;
387: $text=~s/\- //;
1.36 www 388: return '<br /><a href="javascript:'.$act.';">'.$text.'</a> '.$desc;
1.34 www 389: }
1.2 www 390: }
391:
392: sub secondlevel {
393: my $output='';
394: my
1.27 www 395: ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc)=@_;
1.2 www 396: if ($prt eq 'any') {
1.27 www 397: $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
1.2 www 398: } elsif ($prt=~/^r(\w+)/) {
399: if ($rol eq $1) {
1.27 www 400: $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
1.2 www 401: }
402: }
403: return $output;
404: }
405:
1.18 www 406: sub openmenu {
1.30 www 407: my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
1.34 www 408: if ($ENV{'browser.interface'} eq 'textual') { return ''; }
1.18 www 409: if ($ENV{'browser.type'} eq 'explorer') {
1.30 www 410: return "window.open('javascript:void(0);','".$menuname."');";
1.18 www 411: } else {
1.30 www 412: return "window.open('','".$menuname."');";
1.18 www 413: }
414: }
415:
1.2 www 416: sub rawconfig {
1.34 www 417: my $textualoverride=shift;
418: my $output='';
419: unless ($ENV{'browser.interface'} eq 'textual') {
1.35 www 420: $output.=
421: "window.status='Opening Remote Control';var swmenu=".&openmenu().
422: "\nwindow.status='Configuring Remote Control ';";
1.34 www 423: } else {
424: unless ($textualoverride) { return ''; }
425: }
1.2 www 426: my $uname=$ENV{'user.name'};
427: my $udom=$ENV{'user.domain'};
428: my $adv=$ENV{'user.adv'};
1.4 www 429: my $author=$ENV{'user.author'};
1.5 www 430: my $crs='';
431: if ($ENV{'request.course.id'}) {
432: $crs='/'.$ENV{'request.course.id'};
1.7 www 433: if ($ENV{'request.course.sec'}) {
434: $crs.='_'.$ENV{'request.course.sec'};
435: }
1.8 www 436: $crs=~s/\_/\//g;
1.5 www 437: }
1.2 www 438: my $pub=($ENV{'request.state'} eq 'published');
439: my $con=($ENV{'request.state'} eq 'construct');
440: my $rol=$ENV{'request.role'};
1.25 matthew 441: my $requested_domain = $ENV{'request.role.domain'};
1.13 harris41 442: foreach (@desklines) {
1.27 www 443: my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc)=split(/\:/,$_);
1.3 www 444: $prt=~s/\$uname/$uname/g;
445: $prt=~s/\$udom/$udom/g;
1.5 www 446: $prt=~s/\$crs/$crs/g;
1.25 matthew 447: $prt=~s/\$requested_domain/$requested_domain/g;
1.3 www 448: if ($pro eq 'clear') {
1.4 www 449: $output.=&clear($row,$col);
1.3 www 450: } elsif ($pro eq 'any') {
1.2 www 451: $output.=&secondlevel(
1.27 www 452: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
1.2 www 453: } elsif ($pro eq 'smp') {
454: unless ($adv) {
455: $output.=&secondlevel(
1.27 www 456: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
1.2 www 457: }
458: } elsif ($pro eq 'adv') {
459: if ($adv) {
460: $output.=&secondlevel(
1.27 www 461: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
1.2 www 462: }
463: } elsif (($pro=~/p(\w+)/) && ($prt)) {
464: if (&Apache::lonnet::allowed($1,$prt)) {
1.27 www 465: $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
1.4 www 466: }
1.26 www 467: } elsif ($pro eq 'course') {
468: if ($ENV{'request.course.fn'}) {
1.27 www 469: $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
1.26 www 470: }
1.4 www 471: } elsif ($pro eq 'author') {
472: if ($author) {
1.29 matthew 473: if ((($prt eq 'rca') && ($ENV{'request.role'}=~/^ca/)) ||
474: (($prt eq 'rau') && ($ENV{'request.role'}=~/^au/))) {
1.19 matthew 475: # Check that we are on the correct machine
1.29 matthew 476: my $cadom=$requested_domain;
477: my $caname=$ENV{'user.name'};
478: if ($prt eq 'rca') {
479: ($cadom,$caname)=
1.6 www 480: ($ENV{'request.role'}=~/(\w+)\/(\w+)$/);
1.29 matthew 481: }
482: $act =~ s/\$caname/$caname/g;
1.19 matthew 483: my $home = &Apache::lonnet::homeserver($caname,$cadom);
1.32 www 484: if ($home eq $Apache::lonnet::perlvar{'lonHostID'}) {
1.19 matthew 485: $output.=switch($caname,$cadom,
1.27 www 486: $row,$col,$img,$top,$bot,$act,$desc);
1.19 matthew 487: }
1.6 www 488: }
1.2 www 489: }
490: }
1.13 harris41 491: }
1.34 www 492: unless ($ENV{'browser.interface'} eq 'textual') {
1.35 www 493: $output.="\nwindow.status='Synchronizing Time';swmenu.syncclock(1000*".time.");\nwindow.status='Remote Control Configured.';";
1.34 www 494: }
1.2 www 495: return $output;
496: }
497:
498: # ======================================================================= Close
1.1 www 499:
500: sub close {
1.35 www 501: if ($ENV{'browser.interface'} eq 'textual') { return ''; }
1.30 www 502: my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
1.1 www 503: return(<<ENDCLOSE);
504: <script>
1.35 www 505: window.status='Accessing Remote Control';
1.30 www 506: menu=window.open("/adm/rat/empty.html","$menuname",
1.1 www 507: "height=350,width=150,scrollbars=no,menubar=no");
1.35 www 508: window.status='Disabling Remote Control';
509: menu.active=0;
1.31 www 510: menu.autologout=0;
1.35 www 511: window.status='Closing Remote Control';
1.1 www 512: menu.close();
1.35 www 513: window.status='Done.';
1.1 www 514: </script>
515: ENDCLOSE
516: }
517:
518: # ====================================================================== Footer
519:
520: sub footer {
521:
1.33 www 522: }
523:
524: # ================================================ Handler when called directly
525:
526:
527: sub handler {
528: my $r = shift;
529: $r->content_type('text/html');
530: $r->send_http_header;
531: return OK if $r->header_only;
532:
1.34 www 533: my $bodytag=&Apache::loncommon::bodytag('Main Menu');
1.33 www 534: # ------------------------------------------------------------ Print the screen
1.36 www 535: $r->print(<<ENDHEADER);
536: <html><head>
537: <title>LON-CAPA Main Menu</title>
538: <script>
539: function go(url) {
540: window.location=url;
541: }
542: function gopost(url) {
543: window.location=url;
544: }
545: </script>
546: </head>
547: $bodytag
548: ENDHEADER
1.34 www 549: $r->print(&rawconfig(1));
1.33 www 550: $r->print('</body></html>');
551: return OK;
1.1 www 552: }
553:
1.2 www 554: # ================================================================ Main Program
555:
1.16 harris41 556: BEGIN {
1.15 matthew 557: if (! defined($readdesk)) {
1.14 www 558: {
1.10 albertel 559: my $config=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.
560: '/mydesk.tab');
561: while (my $configline=<$config>) {
1.14 www 562: $configline=(split(/\#/,$configline))[0];
563: $configline=~s/^\s+//;
1.10 albertel 564: chomp($configline);
1.14 www 565: if ($configline) {
566: $desklines[$#desklines+1]=$configline;
567: }
1.2 www 568: }
1.14 www 569: }
570: $readdesk='done';
1.10 albertel 571: }
1.2 www 572: }
1.30 www 573:
1.1 www 574: 1;
575: __END__
576:
577:
578:
579:
580:
581:
582:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>