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