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