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