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