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