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