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