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