1: # The LearningOnline Network with CAPA
2: # Routines to control the menu
3: #
4: # $Id: lonmenu.pm,v 1.75 2003/06/05 00:01:45 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: #
29: # There are two parameters controlling the action of this module:
30: #
31: # browser.interface - if this is 'textual', it overrides the second parameter
32: # and goes to screen reader PDA mode
33: #
34: # environment.remote - if this is 'on', the routines controll the remote
35: # control, otherwise they render the main window controls; ignored it
36: # browser.interface is 'textual'
37: #
38:
39: package Apache::lonmenu;
40:
41: use strict;
42: use Apache::lonnet;
43: use Apache::Constants qw(:common);
44: use Apache::lonhtmlcommon();
45: use Apache::loncommon;
46: use Apache::File;
47: use vars qw(@desklines $readdesk);
48: my @inlineremote;
49: my $font;
50: my $tabbg;
51: my $pgbg;
52:
53: # ============================= This gets called at the top of the body section
54:
55: sub menubuttons {
56: my $forcereg=shift;
57: my $target =shift;
58: my $registration=shift;
59: my $navmaps='';
60: my $reloadlink='';
61: my $escurl=&Apache::lonnet::escape($ENV{'REQUEST_URI'});
62: my $escsymb=&Apache::lonnet::escape($ENV{'request.symb'});
63: if ($ENV{'browser.interface'} eq 'textual') {
64: # Textual display only
65: if ($ENV{'request.course.id'}) {
66: $navmaps=(<<ENDNAV);
67: <a href="/adm/navmaps?postdata=$escurl&postsymb=$escsymb" target="_top">Navigate Contents</a>
68: ENDNAV
69: if (($ENV{'REQUEST_URI'}=~/^\/adm\//) &&
70: ($ENV{'REQUEST_URI'}!~/^\/adm\/wrapper\//) &&
71: ($ENV{'REQUEST_URI'}!~/^\/adm\/.*\/(smppg|bulletinboard|aboutme)(\?|$)/)) {
72: my $escreload=&Apache::lonnet::escape('return:');
73: $reloadlink=(<<ENDRELOAD);
74: <a href="/adm/flip?postdata=$escreload" target="_top"><font color="$font">Return to Last Location</font></a>
75: ENDRELOAD
76: }
77: }
78: my $output=(<<ENDMAINMENU);
79: <script>
80: // BEGIN LON-CAPA Internal
81: </script>
82: <a href="/adm/menu" target="_top">Main Menu</a>
83: $reloadlink $navmaps<br />
84: <script>
85: // END LON-CAPA Internal
86: </script>
87: ENDMAINMENU
88: if ($registration) { $output.=&innerregister($forcereg,$target); }
89: return $output."<hr />";
90: } elsif ($ENV{'environment.remote'} eq 'off') {
91: # Remote Control is switched off
92: # figure out colors
93: my $function='student';
94: if ($ENV{'request.role'}=~/^(cc|in|ta|ep)/) {
95: $function='coordinator';
96: }
97: if ($ENV{'request.role'}=~/^(su|dc|ad|li)/) {
98: $function='admin';
99: }
100: if (($ENV{'request.role'}=~/^(au|ca)/) ||
101: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
102: $function='author';
103: }
104: my $domain=&Apache::loncommon::determinedomain();
105: $pgbg=&Apache::loncommon::designparm($function.'.pgbg',$domain);
106: $tabbg=&Apache::loncommon::designparm($function.'.tabbg',$domain);
107: $font=&Apache::loncommon::designparm($function.'.font',$domain);
108: my $link=&Apache::loncommon::designparm($function.'.link',$domain);
109: my $alink=&Apache::loncommon::designparm($function.'.alink',$domain);
110: my $vlink=&Apache::loncommon::designparm($function.'.vlink',$domain);
111: my $sidebg=&Apache::loncommon::designparm($function.'.sidebg',$domain);
112: # Do we have a NAV link?
113: if ($ENV{'request.course.id'}) {
114: $navmaps=(<<ENDNAVREM);
115: <td bgcolor="$tabbg">
116: <a href="/adm/navmaps?postdata=$escurl&postsymb=$escsymb" target="_top"><font color="$font">Navigate Contents</font></a></td>
117: ENDNAVREM
118: if (($ENV{'REQUEST_URI'}=~/^\/adm\//) &&
119: ($ENV{'REQUEST_URI'}!~/^\/adm\/wrapper\//) &&
120: ($ENV{'REQUEST_URI'}!~/^\/adm\/.*\/(smppg|bulletinboard|aboutme)(\?|$)/)) {
121: my $escreload=&Apache::lonnet::escape('return:');
122: $reloadlink=(<<ENDRELOAD);
123: <td bgcolor="$tabbg">
124: <a href="/adm/flip?postdata=$escreload" target="_top"><font color="$font">Return to Last Location</font></a></td>
125: ENDRELOAD
126: }
127: }
128: my $reg='';
129: if ($registration) {
130: $reg=&innerregister($forcereg,$target);
131: }
132: return (<<ENDINLINEMENU);
133: <script>
134: // BEGIN LON-CAPA Internal
135: </script>
136: <table bgcolor="$pgbg" width="100%" border="0" cellpadding="3" cellspacing="3">
137: <tr>
138: <td bgcolor="$tabbg">
139: <a href="/adm/menu" target="_top"><font color="$font">Main Menu</font></a>
140: </td>
141: $reloadlink
142: $navmaps
143: <td bgcolor="$tabbg">
144: <a href="/adm/remote?action=launch&url=$escurl" target="_top">
145: <font color="$font">Launch Remote Control</font></a></td>
146: <td bgcolor="$tabbg">
147: <img align="right" src="/adm/lonIcons/minilogo.gif" />
148: <b>LON-CAPA</b></td>
149: </tr>
150: </table>
151: <script>
152: // END LON-CAPA Internal
153: </script>
154: $reg
155: ENDINLINEMENU
156: } else {
157: return '';
158: }
159: }
160:
161: # ===== Early call to LONCAPAreg for long-running pages, preferably used right
162: # ===== before $r->rflush()
163:
164: sub regflush {
165: return '<script type="text/javascript">'.&loadevents.'</script>';
166: }
167:
168: # ====================================== This gets called in the header section
169:
170: sub registerurl {
171: my $forcereg=shift;
172: my $target = shift;
173: my $result = '';
174: if ($ENV{'REQUEST_URI'} eq '/res/adm/pages/menu.html') { return ''; }
175: my $force_title='';
176: if ($ENV{'request.state'} eq 'construct') {
177: $force_title=&Apache::lonxml::display_title();
178: }
179: if ($target eq 'edit') {
180: $result .="<script type=\"text/javascript\">\n".
181: "if (typeof swmenu != 'undefined') {swmenu.currentURL=null;}\n".
182: &Apache::loncommon::browser_and_searcher_javascript().
183: "\n</script>\n";
184: }
185: if (($ENV{'browser.interface'} eq 'textual') ||
186: ($ENV{'environment.remote'} eq 'off') ||
187: ((($ENV{'request.publicaccess'}) ||
188: (!&Apache::lonnet::is_on_map($ENV{'REQUEST_URI'}))) &&
189: (!$forcereg))) {
190: my $loadfunction='';
191: my $inlineloadfunction='';
192: my $unloadfunction='';
193: unless (($ENV{'browser.interface'} eq 'textual') ||
194: ($ENV{'environment.remote'} eq 'off') ||
195: ($ENV{'request.publicaccess'})) {
196: my $reopen=&Apache::lonmenu::reopenmenu();
197: $loadfunction='swmenu='.$reopen.'swmenu.windowloaded(self.name);window.focus();';
198: $inlineloadfunction=®flush();
199: $unloadfunction='swmenu='.$reopen.'swmenu.windowunloaded(self.name);';
200: }
201: return $result.(<<ENDFUNCTIONS);
202: <script type="text/javascript">
203: function LONCAPAreg() {
204: $loadfunction
205: }
206:
207: function LONCAPAstale() {
208: $unloadfunction
209: }
210: </script>
211: $inlineloadfunction
212: $force_title
213: ENDFUNCTIONS
214: }
215: # Graphical display after login only
216: if ($Apache::lonxml::registered && !$forcereg) { return ''; }
217: $result.=&innerregister($forcereg,$target);
218: return $result.$force_title;
219: }
220:
221: # =========== This gets called in order to register a URL, both with the Remote
222: # =========== and in the body of the document
223:
224: sub innerregister {
225: my $forcereg=shift;
226: my $target = shift;
227: my $result = '';
228: if ($ENV{'REQUEST_URI'} eq '/res/adm/pages/menu.html') { return ''; }
229:
230: $Apache::lonxml::registered=1;
231:
232: my $textinter=($ENV{'browser.interface'} eq 'textual');
233: my $noremote=($ENV{'environment.remote'} eq 'off');
234:
235: my $textual=($textinter || $noremote);
236:
237: @inlineremote=();
238: undef @inlineremote;
239:
240: my $reopen=&Apache::lonmenu::reopenmenu();
241:
242: my $newmail='';
243: if ($noremote) {
244: $newmail='<table bgcolor="'.$pgbg.'" border="0" cellspacing="3" cellpadding="3" width="100%"><tr><td bgcolor="'.$tabbg.'">';
245: }
246: if (($textual) && ($ENV{'request.symb'}) && ($ENV{'request.course.id'})) {
247: my ($mapurl,$rid,$resurl)=split(/\_\_\_/,$ENV{'request.symb'});
248: $newmail.=$ENV{'course.'.$ENV{'request.course.id'}.'.description'};
249: my $maptitle=&Apache::lonnet::gettitle($mapurl);
250: my $restitle=&Apache::lonnet::gettitle($resurl);
251: if ($maptitle) {
252: $newmail.=', '.$maptitle;
253: }
254: if ($restitle) {
255: $newmail.=': '.$restitle;
256: }
257: $newmail.=' ';
258: }
259: if (&Apache::lonmsg::newmail()) {
260: $newmail=($textual?
261: '<b><a href="/adm/communicate">You have new messages</a></b><br />':
262: 'swmenu.setstatus("you have","messages");');
263: }
264: if ($noremote) {
265: $newmail.='</td></tr></table>';
266: }
267: my $timesync=($textual?'':'swmenu.syncclock(1000*'.time.');');
268: my $tablestart=($noremote?'<table bgcolor="'.$pgbg.'" border="0" cellspacing="3" cellpadding="3" width="100%">':'');
269: my $tableend=($noremote?'</table>':'');
270: # =============================================================================
271: # ============================ This is for URLs that actually can be registered
272: if (($ENV{'REQUEST_URI'}!~/^\/(res\/)*adm\//) || ($forcereg)) {
273: # -- This applies to homework problems for users with grading privileges
274: my $hwkadd='';
275: if
276: ($ENV{'request.filename'}=~/\.(problem|exam|quiz|assess|survey|form)$/) {
277: if (&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'})) {
278: $hwkadd.=&switch('','',7,1,'subm.gif','view sub','missions',
279: "gocmd('/adm/grades','submission')",
280: 'View user submissions for this assessment resource');
281: }
282: if (&Apache::lonnet::allowed('mgr',$ENV{'request.course.id'})) {
283: $hwkadd.=&switch('','',7,2,'pgrd.gif','problem','grades',
284: "gocmd('/adm/grades','gradingmenu')",
285: 'Modify user grades for this assessment resource');
286: }
287: if (&Apache::lonnet::allowed('opa',$ENV{'request.course.id'})) {
288: $hwkadd.=&switch('','',7,3,'pparm.gif','problem','parms',
289: "gocmd('/adm/parmset','set')",
290: 'Modify deadlines, etc, for this assessment resource');
291: }
292: }
293: # -- End Homework
294: ###
295: ### Determine whether or not to display the 'cstr' button for this
296: ### resource
297: ###
298: my $editbutton = '';
299: if ($ENV{'user.author'}) {
300: if ($ENV{'request.role'}=~/^(ca|au)/) {
301: # Set defaults for authors
302: my ($top,$bottom) = ('con-','struct');
303: my $action = "go('/priv/".$ENV{'user.name'}."');";
304: my $cadom = $ENV{'request.role.domain'};
305: my $caname = $ENV{'user.name'};
306: my $desc = "Enter my resource construction space";
307: # Set defaults for co-authors
308: if ($ENV{'request.role'} =~ /^ca/) {
309: ($cadom,$caname)=($ENV{'request.role'}=~/(\w+)\/(\w+)$/);
310: ($top,$bottom) = ('co con-','struct');
311: $action = "go('/priv/".$caname."');";
312: $desc = "Enter construction space as co-author";
313: }
314: # Check that we are on the correct machine
315: my $home = &Apache::lonnet::homeserver($caname,$cadom);
316: if ($home eq $Apache::lonnet::perlvar{'lonHostID'}) {
317: $editbutton=&switch
318: ('','',6,1,$top,,$bottom,$action,$desc);
319: }
320: }
321: ##
322: ## Determine if user can edit url.
323: ##
324: my $cfile='';
325: my $cfuname='';
326: my $cfudom='';
327: if ($ENV{'request.filename'}) {
328: my $file=&Apache::lonnet::declutter($ENV{'request.filename'});
329: $file=~s/^(\w+)\/(\w+)/\/priv\/$2/;
330: # Chech that the user has permission to edit this resource
331: ($cfuname,$cfudom)=&Apache::loncacc::constructaccess($file,$1);
332: if (defined($cfudom)) {
333: if (&Apache::lonnet::homeserver($cfuname,$cfudom)
334: eq $Apache::lonnet::perlvar{'lonHostID'}) {
335: $cfile=$file;
336: }
337: }
338: }
339: # Finally, turn the button on or off
340: if ($cfile) {
341: $editbutton=&switch
342: ('','',6,1,'cstr.gif','edit','resource',
343: "go('".$cfile."');","Edit this resource");
344: } elsif ($editbutton eq '') {
345: $editbutton=&clear(6,1);
346: }
347: }
348: ###
349: ###
350: # Prepare the rest of the buttons
351: my $menuitems=(<<ENDMENUITEMS);
352: c&3&1
353: s&2&1&back.gif&backward&&gopost('/adm/flip','back:'+currentURL)&Go to the previous resource in the course sequence&1
354: s&2&3&forw.gif&forward&&gopost('/adm/flip','forward:'+currentURL)&Go to the next resource in the course sequence&3
355: s&6&3&catalog.gif&catalog&info&catalog_info()&Show catalog information
356: s&8&1&eval.gif&evaluate&this&gopost('/adm/evaluate',currentURL)&Provide my evaluation of this resource
357: s&8&2&fdbk.gif&feedback&discuss&gopost('/adm/feedback',currentURL)&Provide feedback messages or contribute to the course discussion about this resource
358: s&8&3&prt.gif&prepare&printout&gopost('/adm/printout',currentURL)&Prepare a printable document
359: s&9&1&sbkm.gif&set&bookmark&set_bookmark()&Set a bookmark for this resource&2
360: s&9&2&vbkm.gif&view&bookmark&edit_bookmarks()&Use or edit my bookmark collection&2
361: s&9&3&anot.gif&anno-&tations&annotate()&Make notes and annotations about this resource&2
362: ENDMENUITEMS
363: my $buttons='';
364: foreach (split(/\n/,$menuitems)) {
365: my ($command,@rest)=split(/\&/,$_);
366: if ($command eq 's') {
367: $buttons.=&switch('','',@rest);
368: } else {
369: $buttons.=&clear(@rest);
370: }
371: }
372: if ($textual) {
373: # Registered, textual output
374: my $utility=&utilityfunctions();
375: my $form=&serverform();
376: my $inlinebuttons=
377: join('',map { (defined($_)?$_:'') } @inlineremote);
378: $result =(<<ENDREGTEXT);
379: <script>
380: // BEGIN LON-CAPA Internal
381: $utility
382: </script>
383: $timesync
384: $newmail
385: $tablestart
386: $inlinebuttons
387: $tableend
388: $form
389: <script>
390: // END LON-CAPA Internal
391: </script>
392:
393: ENDREGTEXT
394: # Registered, graphical output
395: } else {
396: $result = (<<ENDREGTHIS);
397:
398: <script language="JavaScript">
399: // BEGIN LON-CAPA Internal
400: var swmenu=null;
401: swmenu=$reopen;
402: swmenu.windowloaded(self.name);
403:
404: function LONCAPAreg() {
405: swmenu=$reopen;
406: swmenu.windowloaded(self.name);
407: swmenu.clearTimeout(swmenu.menucltim);
408: $timesync
409: $newmail
410: $buttons
411: swmenu.currentURL=window.location.pathname;
412: swmenu.reloadURL=window.location.pathname+window.location.search;
413: swmenu.currentSymb="$ENV{'request.symb'}";
414: swmenu.reloadSymb="$ENV{'request.symb'}";
415: swmenu.currentStale=0;
416: $hwkadd
417: $editbutton
418: }
419:
420: function LONCAPAstale() {
421: swmenu=$reopen
422: swmenu.currentStale=1;
423: if (swmenu.reloadURL!='' && swmenu.reloadURL!= null) {
424: swmenu.switchbutton
425: (3,1,'reload.gif','return','location','go(reloadURL)','Return to the last known location in the course sequence');
426: }
427: swmenu.clearbut(7,1);
428: swmenu.clearbut(7,2);
429: swmenu.clearbut(7,3);
430: swmenu.menucltim=swmenu.setTimeout(
431: 'clearbut(2,1);clearbut(2,3);clearbut(8,1);clearbut(8,2);clearbut(8,3);'+
432: 'clearbut(9,1);clearbut(9,2);clearbut(9,3);clearbut(6,3);clearbut(6,1)',
433: 2000);
434: swmenu.windowunloaded(self.name);
435: }
436:
437: // END LON-CAPA Internal
438: </script>
439: ENDREGTHIS
440: }
441: # =============================================================================
442: } else {
443: # ========================================== This can or will not be registered
444: if ($textual) {
445: # Not registered, textual
446: $result= (<<ENDDONOTREGTEXT);
447: ENDDONOTREGTEXT
448: } else {
449: # Not registered, graphical
450: $result = (<<ENDDONOTREGTHIS);
451:
452: <script language="JavaScript">
453: // BEGIN LON-CAPA Internal
454: var swmenu=null;
455:
456: function LONCAPAreg() {
457: swmenu=$reopen
458: swmenu.windowloaded(self.name);
459: $timesync
460: swmenu.currentStale=1;
461: swmenu.clearbut(2,1);
462: swmenu.clearbut(2,3);
463: swmenu.clearbut(8,1);
464: swmenu.clearbut(8,2);
465: swmenu.clearbut(8,3);
466: if (swmenu.currentURL) {
467: swmenu.switchbutton
468: (3,1,'reload.gif','return','location','go(currentURL)');
469: } else {
470: swmenu.clearbut(3,1);
471: }
472: }
473:
474: function LONCAPAstale() {
475: swmenu=$reopen
476: swmenu.windowunloaded(self.name);
477: }
478:
479: // END LON-CAPA Internal
480: </script>
481: ENDDONOTREGTHIS
482: }
483: # =============================================================================
484: }
485: return $result;
486: }
487:
488: sub loadevents() {
489: if ($ENV{'REQUEST_URI'} eq '/res/adm/pages/menu.html') { return ''; }
490: return 'LONCAPAreg();';
491: }
492:
493: sub unloadevents() {
494: if ($ENV{'REQUEST_URI'} eq '/res/adm/pages/menu.html') { return ''; }
495: return 'LONCAPAstale();';
496: }
497:
498: # ============================================================= Start up remote
499:
500: sub startupremote {
501: my ($lowerurl)=@_;
502: if (($ENV{'browser.interface'} eq 'textual') ||
503: ($ENV{'environment.remote'} eq 'off')) {
504: return ('<meta HTTP-EQUIV="Refresh" CONTENT="0.5; url='.$lowerurl.'" />');
505: }
506: #
507: # The Remote actually gets launched!
508: #
509: my $configmenu=&rawconfig();
510: my $esclowerurl=&Apache::lonnet::escape($lowerurl);
511:
512: return(<<ENDREMOTESTARTUP);
513: <script>
514:
515: function wheelswitch() {
516: if (window.status=='|') {
517: window.status='/';
518: } else {
519: if (window.status=='/') {
520: window.status='-';
521: } else {
522: if (window.status=='-') {
523: window.status='\\\\';
524: } else {
525: if (window.status=='\\\\') { window.status='|'; }
526: }
527: }
528: }
529: }
530:
531: // ---------------------------------------------------------- The wait function
532: var canceltim;
533: function wait() {
534: if ((menuloaded==1) || (tim==1)) {
535: window.status='Done.';
536: if (tim==0) {
537: clearTimeout(canceltim);
538: $configmenu
539: window.location='$lowerurl';
540: } else {
541: window.location='/adm/remote?action=collapse&url=$esclowerurl';
542: }
543: } else {
544: wheelswitch();
545: setTimeout('wait();',200);
546: }
547: }
548:
549: function main() {
550: canceltim=setTimeout('tim=1;',30000);
551: window.status='-';
552: wait();
553: }
554:
555: </script>
556: ENDREMOTESTARTUP
557: }
558:
559: sub setflags() {
560: return(<<ENDSETFLAGS);
561: <script>
562: menuloaded=0;
563: tim=0;
564: </script>
565: ENDSETFLAGS
566: }
567:
568: sub maincall() {
569: if (($ENV{'browser.interface'} eq 'textual') ||
570: ($ENV{'environment.remote'} eq 'off')) { return ''; }
571: return(<<ENDMAINCALL);
572: <script>
573: main();
574: </script>
575: ENDMAINCALL
576: }
577: # ================================================================= Reopen menu
578:
579: sub reopenmenu {
580: if (($ENV{'browser.interface'} eq 'textual') ||
581: ($ENV{'environment.remote'} eq 'off')) { return ''; }
582: my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
583: my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
584: return('window.open('.$nothing.',"'.$menuname.'","",false);');
585: }
586:
587: # =============================================================== Open the menu
588:
589: sub open {
590: my $returnval='';
591: if (($ENV{'browser.interface'} eq 'textual') ||
592: ($ENV{'environment.remote'} eq 'off')) { return ''; }
593: my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
594: unless (shift eq 'unix') {
595: # resizing does not work on linux because of virtual desktop sizes
596: $returnval.=(<<ENDRESIZE);
597: if (window.screen) {
598: self.resizeTo(screen.availWidth-215,screen.availHeight-55);
599: self.moveTo(190,15);
600: }
601: ENDRESIZE
602: }
603: $returnval.=(<<ENDOPEN);
604: window.status='Opening LON-CAPA Remote Control';
605: var menu=window.open("/res/adm/pages/menu.html","$menuname",
606: "height=350,width=150,scrollbars=no,menubar=no,top=5,left=5,screenX=5,screenY=5");
607: self.name='loncapaclient';
608: ENDOPEN
609: return '<script>'.$returnval.'</script>';
610: }
611:
612:
613: # ================================================================== Raw Config
614:
615: sub clear {
616: my ($row,$col)=@_;
617: unless (($ENV{'browser.interface'} eq 'textual') ||
618: ($ENV{'environment.remote'} eq 'off')) {
619: return "\n".qq(window.status+='.';swmenu.clearbut($row,$col););
620: } else {
621: $inlineremote[10*$row+$col]='';
622: return '';
623: }
624: }
625:
626: # ============================================ Switch a button or create a link
627: # Switch acts on the javascript that is executed when a button is clicked.
628: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
629:
630: sub switch {
631: my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$nobreak)=@_;
632: $act=~s/\$uname/$uname/g;
633: $act=~s/\$udom/$udom/g;
634: unless (($ENV{'browser.interface'} eq 'textual') ||
635: ($ENV{'environment.remote'} eq 'off')) {
636: # Remote
637: return "\n".
638: qq(window.status+='.';swmenu.switchbutton($row,$col,"$img","$top","$bot","$act","$desc"););
639: } elsif ($ENV{'browser.interface'} eq 'textual') {
640: # Accessibility
641: if ($nobreak==2) { return ''; }
642: my $text=$top.' '.$bot;
643: $text=~s/\- //;
644: $inlineremote[10*$row+$col]="\n".($nobreak?' ':'<br />').
645: '<a href="javascript:'.$act.';">'.$text.'</a> '.
646: ($nobreak?'':$desc);
647: } else {
648: # Inline Remote
649: if ($nobreak==2) { return ''; }
650: my $text=$top.' '.$bot;
651: $text=~s/\- //;
652: $inlineremote[10*$row+$col]="\n".
653: ($nobreak==3?'<td width="50%" colspan="2" align="right"':'<tr><td').
654: ' bgcolor="'.$tabbg.'"'.($nobreak==1?' width="50%" colspan="2"':'').
655: '"><a href="javascript:'.$act.';"><font color="'.$font.'"'.
656: ($nobreak?' size="+1"':'').
657: '>'.$text.'</font></a></td>'.
658: ($nobreak?'':'<td colspan="3" width="80%"><font color="'.$font.'" size="-1">'.$desc.'</font>').($nobreak!=1?'</tr>':'');
659: }
660: return '';
661: }
662:
663: sub secondlevel {
664: my $output='';
665: my
666: ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc)=@_;
667: if ($prt eq 'any') {
668: $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
669: } elsif ($prt=~/^r(\w+)/) {
670: if ($rol eq $1) {
671: $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
672: }
673: }
674: return $output;
675: }
676:
677: sub openmenu {
678: my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
679: if (($ENV{'browser.interface'} eq 'textual') ||
680: ($ENV{'environment.remote'} eq 'off')) { return ''; }
681: my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
682: return "window.open(".$nothing.",'".$menuname."');";
683: }
684:
685: sub inlinemenu {
686: @inlineremote=();
687: undef @inlineremote;
688: &rawconfig(1);
689: return join('',map { (defined($_)?$_:'') } @inlineremote);
690: }
691:
692: sub rawconfig {
693: my $textualoverride=shift;
694: my $output='';
695: unless (($ENV{'browser.interface'} eq 'textual') ||
696: ($ENV{'environment.remote'} eq 'off')) {
697: $output.=
698: "window.status='Opening Remote Control';var swmenu=".&openmenu().
699: "\nwindow.status='Configuring Remote Control ';";
700: } else {
701: unless ($textualoverride) { return ''; }
702: }
703: my $uname=$ENV{'user.name'};
704: my $udom=$ENV{'user.domain'};
705: my $adv=$ENV{'user.adv'};
706: my $author=$ENV{'user.author'};
707: my $crs='';
708: if ($ENV{'request.course.id'}) {
709: $crs='/'.$ENV{'request.course.id'};
710: if ($ENV{'request.course.sec'}) {
711: $crs.='_'.$ENV{'request.course.sec'};
712: }
713: $crs=~s/\_/\//g;
714: }
715: my $pub=($ENV{'request.state'} eq 'published');
716: my $con=($ENV{'request.state'} eq 'construct');
717: my $rol=$ENV{'request.role'};
718: my $requested_domain = $ENV{'request.role.domain'};
719: foreach (@desklines) {
720: my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc)=split(/\:/,$_);
721: $prt=~s/\$uname/$uname/g;
722: $prt=~s/\$udom/$udom/g;
723: $prt=~s/\$crs/$crs/g;
724: $prt=~s/\$requested_domain/$requested_domain/g;
725: if ($pro eq 'clear') {
726: $output.=&clear($row,$col);
727: } elsif ($pro eq 'any') {
728: $output.=&secondlevel(
729: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
730: } elsif ($pro eq 'smp') {
731: unless ($adv) {
732: $output.=&secondlevel(
733: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
734: }
735: } elsif ($pro eq 'adv') {
736: if ($adv) {
737: $output.=&secondlevel(
738: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
739: }
740: } elsif (($pro=~/p(\w+)/) && ($prt)) {
741: if (&Apache::lonnet::allowed($1,$prt)) {
742: $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
743: }
744: } elsif ($pro eq 'course') {
745: if ($ENV{'request.course.fn'}) {
746: $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
747: }
748: } elsif ($pro eq 'author') {
749: if ($author) {
750: if ((($prt eq 'rca') && ($ENV{'request.role'}=~/^ca/)) ||
751: (($prt eq 'rau') && ($ENV{'request.role'}=~/^au/))) {
752: # Check that we are on the correct machine
753: my $cadom=$requested_domain;
754: my $caname=$ENV{'user.name'};
755: if ($prt eq 'rca') {
756: ($cadom,$caname)=
757: ($ENV{'request.role'}=~/(\w+)\/(\w+)$/);
758: }
759: $act =~ s/\$caname/$caname/g;
760: my $home = &Apache::lonnet::homeserver($caname,$cadom);
761: if ($home eq $Apache::lonnet::perlvar{'lonHostID'}) {
762: $output.=switch($caname,$cadom,
763: $row,$col,$img,$top,$bot,$act,$desc);
764: }
765: }
766: }
767: }
768: }
769: unless (($ENV{'browser.interface'} eq 'textual') ||
770: ($ENV{'environment.remote'} eq 'off')) {
771: $output.="\nwindow.status='Synchronizing Time';swmenu.syncclock(1000*".time.");\nwindow.status='Remote Control Configured.';";
772: }
773: return $output;
774: }
775:
776: # ======================================================================= Close
777:
778: sub close {
779: if (($ENV{'browser.interface'} eq 'textual') ||
780: ($ENV{'environment.remote'} eq 'off')) { return ''; }
781: my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
782: return(<<ENDCLOSE);
783: <script>
784: window.status='Accessing Remote Control';
785: menu=window.open("/adm/rat/empty.html","$menuname",
786: "height=350,width=150,scrollbars=no,menubar=no");
787: window.status='Disabling Remote Control';
788: menu.active=0;
789: menu.autologout=0;
790: window.status='Closing Remote Control';
791: menu.close();
792: window.status='Done.';
793: </script>
794: ENDCLOSE
795: }
796:
797: # ====================================================================== Footer
798:
799: sub footer {
800:
801: }
802:
803: sub utilityfunctions {
804: unless (($ENV{'browser.interface'} eq 'textual') ||
805: ($ENV{'environment.remote'} eq 'off')) { return ''; }
806: my $currenturl=$ENV{'REQUEST_URI'};
807: my $currentsymb=$ENV{'request.symb'};
808: return (<<ENDUTILITY)
809:
810: var currentURL="$currenturl";
811: var reloadURL="$currenturl";
812: var currentSymb="$currentsymb";
813:
814: function go(url) {
815: if (url!='' && url!= null) {
816: currentURL = null;
817: currentSymb= null;
818: window.location.href=url;
819: }
820: }
821:
822: function gopost(url,postdata) {
823: if (url!='') {
824: this.document.server.action=url;
825: this.document.server.postdata.value=postdata;
826: this.document.server.command.value='';
827: this.document.server.url.value='';
828: this.document.server.symb.value='';
829: this.document.server.submit();
830: }
831: }
832:
833: function gocmd(url,cmd) {
834: if (url!='') {
835: this.document.server.action=url;
836: this.document.server.postdata.value='';
837: this.document.server.command.value=cmd;
838: this.document.server.url.value=currentURL;
839: this.document.server.symb.value=currentSymb;
840: this.document.server.submit();
841: }
842: }
843:
844: function catalog_info() {
845: loncatinfo=window.open(window.location.pathname+'.meta',"LONcatInfo",'height=320,width=280,resizeable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
846: }
847:
848: function chat_win() {
849: lonchat=window.open('/res/adm/pages/chatroom.html',"LONchat",'height=320,width=280,resizeable=yes,location=no,menubar=no,toolbar=no');
850: }
851: ENDUTILITY
852: }
853:
854: sub serverform {
855: return(<<ENDSERVERFORM);
856:
857: <form name="server" action="/adm/logout" method="post" target="_top">
858: <input type="hidden" name="postdata" value="none" />
859: <input type="hidden" name="command" value="none" />
860: <input type="hidden" name="url" value="none" />
861: <input type="hidden" name="symb" value="none" />
862: </form>
863: ENDSERVERFORM
864: }
865: # ================================================ Handler when called directly
866:
867:
868: sub handler {
869: my $r = shift;
870: $r->content_type('text/html');
871: $r->send_http_header;
872: return OK if $r->header_only;
873:
874: my $form=&serverform();
875: my $bodytag=&Apache::loncommon::bodytag('Main Menu');
876: my $function='student';
877: if ($ENV{'request.role'}=~/^(cc|in|ta|ep)/) {
878: $function='coordinator';
879: }
880: if ($ENV{'request.role'}=~/^(su|dc|ad|li)/) {
881: $function='admin';
882: }
883: if (($ENV{'request.role'}=~/^(au|ca)/) ||
884: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
885: $function='author';
886: }
887: my $domain=&Apache::loncommon::determinedomain();
888: $pgbg=&Apache::loncommon::designparm($function.'.pgbg',$domain);
889: $tabbg=&Apache::loncommon::designparm($function.'.tabbg',$domain);
890: $font=&Apache::loncommon::designparm($function.'.font',$domain);
891: # ---- Print the screen, pretent to be in text mode to generate text-based menu
892: unless ($ENV{'brower.interface'} eq 'textual') {
893: $ENV{'environment.remote'}='off';
894: }
895: my $utility=&utilityfunctions();
896: $r->print(<<ENDHEADER);
897: <html><head>
898: <title>LON-CAPA Main Menu</title>
899: <script>
900: $utility
901: </script>
902: </head>
903: $bodytag
904: ENDHEADER
905: $r->print('<table>'.&inlinemenu().'</table>'.$form);
906: $r->print('</body></html>');
907: return OK;
908: }
909:
910: # ================================================================ Main Program
911:
912: BEGIN {
913: if (! defined($readdesk)) {
914: {
915: my $config=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.
916: '/mydesk.tab');
917: while (my $configline=<$config>) {
918: $configline=(split(/\#/,$configline))[0];
919: $configline=~s/^\s+//;
920: chomp($configline);
921: if ($configline) {
922: $desklines[$#desklines+1]=$configline;
923: }
924: }
925: }
926: $readdesk='done';
927: }
928: }
929:
930: 1;
931: __END__
932:
933:
934:
935:
936:
937:
938:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>