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