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