1: # The LearningOnline Network with CAPA
2: # Routines to control the menu
3: #
4: # $Id: lonmenu.pm,v 1.82 2003/08/06 17:23:49 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" target="_top">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&3&anot.gif&anno-&tations&annotate()&Make notes and annotations about this resource&2
338: ENDMENUITEMS
339: unless ($ENV{'REQUEST_URI'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme)(\?|$)/) {
340: $menuitems.=(<<ENDREALRES);
341: s&6&3&catalog.gif&catalog&info&catalog_info()&Show catalog information
342: s&8&1&eval.gif&evaluate&this&gopost('/adm/evaluate',currentURL,1)&Provide my evaluation of this resource
343: s&8&2&fdbk.gif&feedback&discuss&gopost('/adm/feedback',currentURL,1)&Provide feedback messages or contribute to the course discussion about this resource
344: ENDREALRES
345: }
346: my $buttons='';
347: foreach (split(/\n/,$menuitems)) {
348: my ($command,@rest)=split(/\&/,$_);
349: if ($command eq 's') {
350: $buttons.=&switch('','',@rest);
351: } else {
352: $buttons.=&clear(@rest);
353: }
354: }
355: if ($textual) {
356: # Registered, textual output
357: my $utility=&utilityfunctions();
358: my $form=&serverform();
359: my $inlinebuttons=
360: join('',map { (defined($_)?$_:'') } @inlineremote);
361: $result =(<<ENDREGTEXT);
362: <script>
363: // BEGIN LON-CAPA Internal
364: $utility
365: </script>
366: $timesync
367: $newmail
368: $tablestart
369: $inlinebuttons
370: $tableend
371: $form
372: <script>
373: // END LON-CAPA Internal
374: </script>
375:
376: ENDREGTEXT
377: # Registered, graphical output
378: } else {
379: $result = (<<ENDREGTHIS);
380:
381: <script language="JavaScript">
382: // BEGIN LON-CAPA Internal
383: var swmenu=null;
384:
385: function LONCAPAreg() {
386: swmenu=$reopen;
387: swmenu.clearTimeout(swmenu.menucltim);
388: $timesync
389: $newmail
390: $buttons
391: swmenu.currentURL=window.location.pathname;
392: swmenu.reloadURL=window.location.pathname+window.location.search;
393: swmenu.currentSymb="$ENV{'request.symb'}";
394: swmenu.reloadSymb="$ENV{'request.symb'}";
395: swmenu.currentStale=0;
396: $hwkadd
397: $editbutton
398: }
399:
400: function LONCAPAstale() {
401: swmenu=$reopen
402: swmenu.currentStale=1;
403: if (swmenu.reloadURL!='' && swmenu.reloadURL!= null) {
404: swmenu.switchbutton
405: (3,1,'reload.gif','return','location','go(reloadURL)','Return to the last known location in the course sequence');
406: }
407: swmenu.clearbut(7,1);
408: swmenu.clearbut(7,2);
409: swmenu.clearbut(7,3);
410: swmenu.menucltim=swmenu.setTimeout(
411: 'clearbut(2,1);clearbut(2,3);clearbut(8,1);clearbut(8,2);clearbut(8,3);'+
412: 'clearbut(9,1);clearbut(9,2);clearbut(9,3);clearbut(6,3);clearbut(6,1)',
413: 2000);
414: }
415:
416: // END LON-CAPA Internal
417: </script>
418: ENDREGTHIS
419: }
420: # =============================================================================
421: } else {
422: # ========================================== This can or will not be registered
423: if ($textual) {
424: # Not registered, textual
425: $result= (<<ENDDONOTREGTEXT);
426: ENDDONOTREGTEXT
427: } else {
428: # Not registered, graphical
429: $result = (<<ENDDONOTREGTHIS);
430:
431: <script language="JavaScript">
432: // BEGIN LON-CAPA Internal
433: var swmenu=null;
434:
435: function LONCAPAreg() {
436: swmenu=$reopen
437: $timesync
438: swmenu.currentStale=1;
439: swmenu.clearbut(2,1);
440: swmenu.clearbut(2,3);
441: swmenu.clearbut(8,1);
442: swmenu.clearbut(8,2);
443: swmenu.clearbut(8,3);
444: if (swmenu.currentURL) {
445: swmenu.switchbutton
446: (3,1,'reload.gif','return','location','go(currentURL)');
447: } else {
448: swmenu.clearbut(3,1);
449: }
450: }
451:
452: function LONCAPAstale() {
453: }
454:
455: // END LON-CAPA Internal
456: </script>
457: ENDDONOTREGTHIS
458: }
459: # =============================================================================
460: }
461: return $result;
462: }
463:
464: sub loadevents() {
465: if ($ENV{'REQUEST_URI'} eq '/res/adm/pages/menu.html') { return ''; }
466: return 'LONCAPAreg();';
467: }
468:
469: sub unloadevents() {
470: if ($ENV{'REQUEST_URI'} eq '/res/adm/pages/menu.html') { return ''; }
471: return 'LONCAPAstale();';
472: }
473:
474: # ============================================================= Start up remote
475:
476: sub startupremote {
477: my ($lowerurl)=@_;
478: if (($ENV{'browser.interface'} eq 'textual') ||
479: ($ENV{'environment.remote'} eq 'off')) {
480: return ('<meta HTTP-EQUIV="Refresh" CONTENT="0.5; url='.$lowerurl.'" />');
481: }
482: #
483: # The Remote actually gets launched!
484: #
485: my $configmenu=&rawconfig();
486: my $esclowerurl=&Apache::lonnet::escape($lowerurl);
487:
488: return(<<ENDREMOTESTARTUP);
489: <script>
490:
491: function wheelswitch() {
492: if (window.status=='|') {
493: window.status='/';
494: } else {
495: if (window.status=='/') {
496: window.status='-';
497: } else {
498: if (window.status=='-') {
499: window.status='\\\\';
500: } else {
501: if (window.status=='\\\\') { window.status='|'; }
502: }
503: }
504: }
505: }
506:
507: // ---------------------------------------------------------- The wait function
508: var canceltim;
509: function wait() {
510: if ((menuloaded==1) || (tim==1)) {
511: window.status='Done.';
512: if (tim==0) {
513: clearTimeout(canceltim);
514: $configmenu
515: window.location='$lowerurl';
516: } else {
517: window.location='/adm/remote?action=collapse&url=$esclowerurl';
518: }
519: } else {
520: wheelswitch();
521: setTimeout('wait();',200);
522: }
523: }
524:
525: function main() {
526: canceltim=setTimeout('tim=1;',30000);
527: window.status='-';
528: wait();
529: }
530:
531: </script>
532: ENDREMOTESTARTUP
533: }
534:
535: sub setflags() {
536: return(<<ENDSETFLAGS);
537: <script>
538: menuloaded=0;
539: tim=0;
540: </script>
541: ENDSETFLAGS
542: }
543:
544: sub maincall() {
545: if (($ENV{'browser.interface'} eq 'textual') ||
546: ($ENV{'environment.remote'} eq 'off')) { return ''; }
547: return(<<ENDMAINCALL);
548: <script>
549: main();
550: </script>
551: ENDMAINCALL
552: }
553: # ================================================================= Reopen menu
554:
555: sub reopenmenu {
556: if (($ENV{'browser.interface'} eq 'textual') ||
557: ($ENV{'environment.remote'} eq 'off')) { return ''; }
558: my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
559: my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
560: return('window.open('.$nothing.',"'.$menuname.'","",false);');
561: }
562:
563: # =============================================================== Open the menu
564:
565: sub open {
566: my $returnval='';
567: if (($ENV{'browser.interface'} eq 'textual') ||
568: ($ENV{'environment.remote'} eq 'off')) { return ''; }
569: my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
570: unless (shift eq 'unix') {
571: # resizing does not work on linux because of virtual desktop sizes
572: $returnval.=(<<ENDRESIZE);
573: if (window.screen) {
574: self.resizeTo(screen.availWidth-215,screen.availHeight-55);
575: self.moveTo(190,15);
576: }
577: ENDRESIZE
578: }
579: $returnval.=(<<ENDOPEN);
580: window.status='Opening LON-CAPA Remote Control';
581: var menu=window.open("/res/adm/pages/menu.html","$menuname",
582: "height=350,width=150,scrollbars=no,menubar=no,top=5,left=5,screenX=5,screenY=5");
583: self.name='loncapaclient';
584: ENDOPEN
585: return '<script>'.$returnval.'</script>';
586: }
587:
588:
589: # ================================================================== Raw Config
590:
591: sub clear {
592: my ($row,$col)=@_;
593: unless (($ENV{'browser.interface'} eq 'textual') ||
594: ($ENV{'environment.remote'} eq 'off')) {
595: return "\n".qq(window.status+='.';swmenu.clearbut($row,$col););
596: } else {
597: $inlineremote[10*$row+$col]='';
598: return '';
599: }
600: }
601:
602: # ============================================ Switch a button or create a link
603: # Switch acts on the javascript that is executed when a button is clicked.
604: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
605:
606: sub switch {
607: my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$nobreak)=@_;
608: $act=~s/\$uname/$uname/g;
609: $act=~s/\$udom/$udom/g;
610: unless (($ENV{'browser.interface'} eq 'textual') ||
611: ($ENV{'environment.remote'} eq 'off')) {
612: # Remote
613: return "\n".
614: qq(window.status+='.';swmenu.switchbutton($row,$col,"$img","$top","$bot","$act","$desc"););
615: } elsif ($ENV{'browser.interface'} eq 'textual') {
616: # Accessibility
617: if ($nobreak==2) { return ''; }
618: my $text=$top.' '.$bot;
619: $text=~s/\s*\-\s*//gs;
620: $inlineremote[10*$row+$col]="\n".($nobreak?' ':'<br />').
621: '<a href="javascript:'.$act.';">'.$text.'</a> '.
622: ($nobreak?'':$desc);
623: } else {
624: # Inline Remote
625: if ($nobreak==2) { return ''; }
626: my $text=$top.' '.$bot;
627: $text=~s/\s*\-\s*//gs;
628: $inlineremote[10*$row+$col]="\n".
629: ($nobreak==3?'<td width="50%" colspan="2" align="right"':'<tr><td').
630: ' bgcolor="'.$tabbg.'"'.($nobreak==1?' width="50%" colspan="2"':'').
631: '"><a href="javascript:'.$act.';"><font color="'.$font.'"'.
632: ($nobreak?' size="+1"':'').
633: '>'.$text.'</font></a></td>'.
634: ($nobreak?'':'<td colspan="3" width="80%"><font color="'.$font.'" size="-1">'.$desc.'</font>').($nobreak!=1?'</tr>':'');
635: }
636: return '';
637: }
638:
639: sub secondlevel {
640: my $output='';
641: my
642: ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc)=@_;
643: if ($prt eq 'any') {
644: $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
645: } elsif ($prt=~/^r(\w+)/) {
646: if ($rol eq $1) {
647: $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
648: }
649: }
650: return $output;
651: }
652:
653: sub openmenu {
654: my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
655: if (($ENV{'browser.interface'} eq 'textual') ||
656: ($ENV{'environment.remote'} eq 'off')) { return ''; }
657: my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
658: return "window.open(".$nothing.",'".$menuname."');";
659: }
660:
661: sub inlinemenu {
662: @inlineremote=();
663: undef @inlineremote;
664: &rawconfig(1);
665: return join('',map { (defined($_)?$_:'') } @inlineremote);
666: }
667:
668: sub rawconfig {
669: my $textualoverride=shift;
670: my $output='';
671: unless (($ENV{'browser.interface'} eq 'textual') ||
672: ($ENV{'environment.remote'} eq 'off')) {
673: $output.=
674: "window.status='Opening Remote Control';var swmenu=".&openmenu().
675: "\nwindow.status='Configuring Remote Control ';";
676: } else {
677: unless ($textualoverride) { return ''; }
678: }
679: my $uname=$ENV{'user.name'};
680: my $udom=$ENV{'user.domain'};
681: my $adv=$ENV{'user.adv'};
682: my $author=$ENV{'user.author'};
683: my $crs='';
684: if ($ENV{'request.course.id'}) {
685: $crs='/'.$ENV{'request.course.id'};
686: if ($ENV{'request.course.sec'}) {
687: $crs.='_'.$ENV{'request.course.sec'};
688: }
689: $crs=~s/\_/\//g;
690: }
691: my $pub=($ENV{'request.state'} eq 'published');
692: my $con=($ENV{'request.state'} eq 'construct');
693: my $rol=$ENV{'request.role'};
694: my $requested_domain = $ENV{'request.role.domain'};
695: foreach (@desklines) {
696: my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc)=split(/\:/,$_);
697: $prt=~s/\$uname/$uname/g;
698: $prt=~s/\$udom/$udom/g;
699: $prt=~s/\$crs/$crs/g;
700: $prt=~s/\$requested_domain/$requested_domain/g;
701: if ($pro eq 'clear') {
702: $output.=&clear($row,$col);
703: } elsif ($pro eq 'any') {
704: $output.=&secondlevel(
705: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
706: } elsif ($pro eq 'smp') {
707: unless ($adv) {
708: $output.=&secondlevel(
709: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
710: }
711: } elsif ($pro eq 'adv') {
712: if ($adv) {
713: $output.=&secondlevel(
714: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
715: }
716: } elsif (($pro=~/^p(\w+)/) && ($prt)) {
717: if (&Apache::lonnet::allowed($1,$prt)) {
718: $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
719: }
720: } elsif ($pro eq 'course') {
721: if ($ENV{'request.course.fn'}) {
722: $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
723: }
724: } elsif ($pro =~ /^course_(.*)$/) {
725: # Check for permissions inside of a course
726: if (($ENV{'request.course.id'}) &&
727: (&Apache::lonnet::allowed($1,$ENV{'request.course.id'}.
728: ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))
729: )) {
730: $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
731: }
732: } elsif ($pro eq 'author') {
733: if ($author) {
734: if ((($prt eq 'rca') && ($ENV{'request.role'}=~/^ca/)) ||
735: (($prt eq 'rau') && ($ENV{'request.role'}=~/^au/))) {
736: # Check that we are on the correct machine
737: my $cadom=$requested_domain;
738: my $caname=$ENV{'user.name'};
739: if ($prt eq 'rca') {
740: ($cadom,$caname)=
741: ($ENV{'request.role'}=~/(\w+)\/(\w+)$/);
742: }
743: $act =~ s/\$caname/$caname/g;
744: my $home = &Apache::lonnet::homeserver($caname,$cadom);
745: if ($home eq $Apache::lonnet::perlvar{'lonHostID'}) {
746: $output.=switch($caname,$cadom,
747: $row,$col,$img,$top,$bot,$act,$desc);
748: }
749: }
750: }
751: }
752: }
753: unless (($ENV{'browser.interface'} eq 'textual') ||
754: ($ENV{'environment.remote'} eq 'off')) {
755: $output.="\nwindow.status='Synchronizing Time';swmenu.syncclock(1000*".time.");\nwindow.status='Remote Control Configured.';";
756: }
757: return $output;
758: }
759:
760: # ======================================================================= Close
761:
762: sub close {
763: if (($ENV{'browser.interface'} eq 'textual') ||
764: ($ENV{'environment.remote'} eq 'off')) { return ''; }
765: my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
766: return(<<ENDCLOSE);
767: <script>
768: window.status='Accessing Remote Control';
769: menu=window.open("/adm/rat/empty.html","$menuname",
770: "height=350,width=150,scrollbars=no,menubar=no");
771: window.status='Disabling Remote Control';
772: menu.active=0;
773: menu.autologout=0;
774: window.status='Closing Remote Control';
775: menu.close();
776: window.status='Done.';
777: </script>
778: ENDCLOSE
779: }
780:
781: # ====================================================================== Footer
782:
783: sub footer {
784:
785: }
786:
787: sub utilityfunctions {
788: unless (($ENV{'browser.interface'} eq 'textual') ||
789: ($ENV{'environment.remote'} eq 'off')) { return ''; }
790: my $currenturl=$ENV{'REQUEST_URI'};
791: my $currentsymb=$ENV{'request.symb'};
792: return (<<ENDUTILITY)
793:
794: var currentURL="$currenturl";
795: var reloadURL="$currenturl";
796: var currentSymb="$currentsymb";
797:
798: function go(url) {
799: if (url!='' && url!= null) {
800: currentURL = null;
801: currentSymb= null;
802: window.location.href=url;
803: }
804: }
805:
806: function gopost(url,postdata) {
807: if (url!='') {
808: this.document.server.action=url;
809: this.document.server.postdata.value=postdata;
810: this.document.server.command.value='';
811: this.document.server.url.value='';
812: this.document.server.symb.value='';
813: this.document.server.submit();
814: }
815: }
816:
817: function gocmd(url,cmd) {
818: if (url!='') {
819: this.document.server.action=url;
820: this.document.server.postdata.value='';
821: this.document.server.command.value=cmd;
822: this.document.server.url.value=currentURL;
823: this.document.server.symb.value=currentSymb;
824: this.document.server.submit();
825: }
826: }
827:
828: function catalog_info() {
829: loncatinfo=window.open(window.location.pathname+'.meta',"LONcatInfo",'height=320,width=280,resizeable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
830: }
831:
832: function chat_win() {
833: lonchat=window.open('/res/adm/pages/chatroom.html',"LONchat",'height=320,width=280,resizeable=yes,location=no,menubar=no,toolbar=no');
834: }
835: ENDUTILITY
836: }
837:
838: sub serverform {
839: return(<<ENDSERVERFORM);
840:
841: <form name="server" action="/adm/logout" method="post" target="_top">
842: <input type="hidden" name="postdata" value="none" />
843: <input type="hidden" name="command" value="none" />
844: <input type="hidden" name="url" value="none" />
845: <input type="hidden" name="symb" value="none" />
846: </form>
847: ENDSERVERFORM
848: }
849: # ================================================ Handler when called directly
850:
851:
852: sub handler {
853: my $r = shift;
854: $r->content_type('text/html');
855: $r->send_http_header;
856: return OK if $r->header_only;
857:
858: my $form=&serverform();
859: my $bodytag=&Apache::loncommon::bodytag('Main Menu');
860: my $function='student';
861: if ($ENV{'request.role'}=~/^(cc|in|ta|ep)/) {
862: $function='coordinator';
863: }
864: if ($ENV{'request.role'}=~/^(su|dc|ad|li)/) {
865: $function='admin';
866: }
867: if (($ENV{'request.role'}=~/^(au|ca)/) ||
868: ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
869: $function='author';
870: }
871: my $domain=&Apache::loncommon::determinedomain();
872: $pgbg=&Apache::loncommon::designparm($function.'.pgbg',$domain);
873: $tabbg=&Apache::loncommon::designparm($function.'.tabbg',$domain);
874: $font=&Apache::loncommon::designparm($function.'.font',$domain);
875: # ---- Print the screen, pretent to be in text mode to generate text-based menu
876: unless ($ENV{'brower.interface'} eq 'textual') {
877: $ENV{'environment.remote'}='off';
878: }
879: my $utility=&utilityfunctions();
880: $r->print(<<ENDHEADER);
881: <html><head>
882: <title>LON-CAPA Main Menu</title>
883: <script>
884: $utility
885: </script>
886: </head>
887: $bodytag
888: ENDHEADER
889: $r->print('<table>'.&inlinemenu().'</table>'.$form);
890: $r->print('</body></html>');
891: return OK;
892: }
893:
894: # ================================================================ Main Program
895:
896: BEGIN {
897: if (! defined($readdesk)) {
898: {
899: my $config=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.
900: '/mydesk.tab');
901: while (my $configline=<$config>) {
902: $configline=(split(/\#/,$configline))[0];
903: $configline=~s/^\s+//;
904: chomp($configline);
905: if ($configline) {
906: $desklines[$#desklines+1]=$configline;
907: }
908: }
909: }
910: $readdesk='done';
911: }
912: }
913:
914: 1;
915: __END__
916:
917:
918:
919:
920:
921:
922:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>