1: # The LearningOnline Network with CAPA
2: # Routines to control the menu
3: #
4: # $Id: lonmenu.pm,v 1.120 2004/10/29 18:40:40 raeburn Exp $
5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: #
29: # There are two parameters controlling the action of this module:
30: #
31: # browser.interface - if this is 'textual', it overrides the second parameter
32: # and goes to screen reader PDA mode
33: #
34: # environment.remote - if this is 'on', the routines controll the remote
35: # control, otherwise they render the main window controls; ignored it
36: # browser.interface is 'textual'
37: #
38:
39: package Apache::lonmenu;
40:
41: use strict;
42: use Apache::lonnet();
43: use Apache::Constants qw(:common);
44: use Apache::lonhtmlcommon();
45: use Apache::loncommon();
46: use Apache::lonnavmaps();
47: use Apache::lonlocal;
48:
49: use vars qw(@desklines $readdesk);
50:
51:
52: my @inlineremote;
53: my $font;
54: my $tabbg;
55: my $pgbg;
56:
57: # ================================================================ Little texts
58:
59: sub initlittle {
60: return &Apache::lonlocal::texthash('ret' => 'Return to Last Location',
61: 'nav' => 'Navigate Contents',
62: 'main' => 'Main Menu',
63: 'launch' => 'Launch Remote Control');
64: }
65:
66: # ============================= This gets called at the top of the body section
67:
68: sub menubuttons {
69: my $forcereg=shift;
70: my $target =shift;
71: my $registration=shift;
72: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
73: ['inhibitmenu']);
74: if ($ENV{'form.inhibitmenu'} eq 'yes') { return ''; }
75:
76: my $navmaps='';
77: my $reloadlink='';
78: my $escurl=&Apache::lonnet::escape($ENV{'request.noversionuri'});
79: my $escsymb=&Apache::lonnet::escape($ENV{'request.symb'});
80: if ($ENV{'browser.interface'} eq 'textual') {
81: # Textual display only
82: my %lt=&initlittle();
83: $pgbg='#FFFFFF';
84: $tabbg='#FFFFFF';
85: $font='#000000';
86: if ($ENV{'request.course.id'}) {
87: $navmaps=(<<ENDNAV);
88: <a href="/adm/navmaps?postdata=$escurl&postsymb=$escsymb" target="_top">$lt{'nav'}</a>
89: ENDNAV
90: if (($ENV{'request.noversionuri'}=~/^\/adm\//) &&
91: ($ENV{'request.noversionuri'}!~/^\/adm\/wrapper\//) &&
92: ($ENV{'request.noversionuri'}!~/^\/adm\/.*\/(smppg|bulletinboard|aboutme)(\?|$)/)) {
93: my $escreload=&Apache::lonnet::escape('return:');
94: $reloadlink=(<<ENDRELOAD);
95: <a href="/adm/flip?postdata=$escreload" target="_top"><font color="$font">$lt{'ret'}</font></a>
96: ENDRELOAD
97: }
98: }
99: my $utility=&utilityfunctions();
100: my $output=(<<ENDMAINMENU);
101: <script>
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>
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>
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>
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 = 0;
231: if ($ENV{'request.filename'} =~ /^\/home\/([^\/]+)\/public_html\/(.*)/) {
232: $const_space = 1;
233: $uname = $1;
234: $thisdisfn = $2;
235: }
236:
237: if ($ENV{'request.noversionuri'} eq '/res/adm/pages/menu.html') { return ''; }
238:
239: $Apache::lonxml::registered=1;
240:
241: my $textinter=($ENV{'browser.interface'} eq 'textual');
242: my $noremote=($ENV{'environment.remote'} eq 'off');
243:
244: my $textual=($textinter || $noremote);
245:
246: @inlineremote=();
247: undef @inlineremote;
248:
249: my $reopen=&Apache::lonmenu::reopenmenu();
250:
251: my $newmail='';
252: if ($noremote) {
253: $newmail='<font face="Arial,Helvetica,sans-serif"><table bgcolor="'.$pgbg.'" border="0" cellspacing="1" cellpadding="1" width="100%"><tr><td bgcolor="'.$tabbg.'">';
254: }
255: if ($textual && $const_space) {
256: my $formaction='/priv/'.$uname.'/'.$thisdisfn;
257: $formaction=~s/\/+/\//g;
258: $newmail .= ('<form name="dirs" method="post" action="'.$formaction
259: .'" target="_top">'.
260: &Apache::lonhtmlcommon::crumbs($uname.'/'.$thisdisfn,'_top','/priv','','-1').
261: &Apache::lonhtmlcommon::select_recent('construct','recent',
262: 'this.form.action=this.form.recent.value;this.form.submit()').
263: '</form>');
264: &Apache::lonhtmlcommon::store_recent('construct',$formaction,$formaction);
265: }
266: if (($textual) && ($ENV{'request.symb'}) && ($ENV{'request.course.id'})) {
267: my ($mapurl,$rid,$resurl)=&Apache::lonnet::decode_symb($ENV{'request.symb'});
268: $newmail.=$ENV{'course.'.$ENV{'request.course.id'}.'.description'};
269: my $maptitle=&Apache::lonnet::gettitle($mapurl);
270: my $restitle=&Apache::lonnet::gettitle($resurl);
271: if ($maptitle) {
272: $newmail.=', '.$maptitle;
273: }
274: if ($restitle) {
275: $newmail.=': '.$restitle;
276: }
277: $newmail.=' ';
278: }
279: if (&Apache::lonmsg::newmail()) {
280: $newmail=($textual?
281: '<b><a href="/adm/communicate" target="_top">You have new messages</a></b><br />':
282: 'swmenu.setstatus("you have","messages");');
283: }
284: if ($noremote) {
285: $newmail.='</td></tr></table></font>';
286: }
287: my $timesync=($textual?'':'swmenu.syncclock(1000*'.time.');');
288: 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 />':'');
289: my $tableend=($noremote?'</table></font>':'').($textinter?'<a name="content" />':'');
290: # =============================================================================
291: # ============================ This is for URLs that actually can be registered
292: if (($ENV{'request.noversionuri'}!~/^\/(res\/)*adm\//) || ($forcereg)) {
293: # -- This applies to homework problems for users with grading privileges
294: my $crs='/'.$ENV{'request.course.id'};
295: if ($ENV{'request.course.sec'}) {
296: $crs.='_'.$ENV{'request.course.sec'};
297: }
298: $crs=~s/\_/\//g;
299:
300: my $hwkadd='';
301: if ($ENV{'request.filename'}=~/\.(problem|exam|quiz|assess|survey|form)$/) {
302: if (&Apache::lonnet::allowed('vgr',$crs)) {
303: $hwkadd.=&switch('','',7,1,'subm.gif','view sub-[_1]','missions[_1]',
304: "gocmd('/adm/grades','submission')",
305: 'View user submissions for this assessment resource');
306: }
307: if (&Apache::lonnet::allowed('mgr',$crs)) {
308: $hwkadd.=&switch('','',7,2,'pgrd.gif','problem[_1]','grades[_3]',
309: "gocmd('/adm/grades','gradingmenu')",
310: 'Modify user grades for this assessment resource');
311: }
312: }
313: if (&Apache::lonnet::allowed('opa',$crs)) {
314: $hwkadd.=&switch('','',7,3,'pparm.gif','problem[_2]','parms[_2]',
315: "gocmd('/adm/parmset','set')",
316: 'Modify deadlines, etc, for this resource');
317: }
318: # -- End Homework
319: ###
320: ### Determine whether or not to display the 'cstr' button for this
321: ### resource
322: ###
323: my $editbutton = '';
324: if ($ENV{'user.author'}) {
325: if ($ENV{'request.role'}=~/^(ca|au)/) {
326: # Set defaults for authors
327: my ($top,$bottom) = ('con-','struct');
328: my $action = "go('/priv/".$ENV{'user.name'}."');";
329: my $cadom = $ENV{'request.role.domain'};
330: my $caname = $ENV{'user.name'};
331: my $desc = "Enter my resource construction space";
332: # Set defaults for co-authors
333: if ($ENV{'request.role'} =~ /^ca/) {
334: ($cadom,$caname)=($ENV{'request.role'}=~/(\w+)\/(\w+)$/);
335: ($top,$bottom) = ('co con-','struct');
336: $action = "go('/priv/".$caname."');";
337: $desc = "Enter construction space as co-author";
338: }
339: # Check that we are on the correct machine
340: my $home = &Apache::lonnet::homeserver($caname,$cadom);
341: my $allowed=0;
342: my @ids=&Apache::lonnet::current_machine_ids();
343: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
344: if (!$allowed) {
345: $editbutton=&switch('','',6,1,$top,,$bottom,$action,$desc);
346: }
347: }
348: ##
349: ## Determine if user can edit url.
350: ##
351: my $cfile='';
352: my $cfuname='';
353: my $cfudom='';
354: if ($ENV{'request.filename'}) {
355: my $file=&Apache::lonnet::declutter($ENV{'request.filename'});
356: $file=~s/^(\w+)\/(\w+)/\/priv\/$2/;
357: # Check that the user has permission to edit this resource
358: ($cfuname,$cfudom)=&Apache::loncacc::constructaccess($file,$1);
359: if (defined($cfudom)) {
360: my $home=&Apache::lonnet::homeserver($cfuname,$cfudom);
361: my $allowed=0;
362: my @ids=&Apache::lonnet::current_machine_ids();
363: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
364: if ($allowed) {
365: $cfile=$file;
366: }
367: }
368: }
369: # Finally, turn the button on or off
370: if ($cfile && !$const_space) {
371: $editbutton=&switch
372: ('','',6,1,'cstr.gif','edit[_1]','resource[_2]',
373: "go('".$cfile."');","Edit this resource");
374: } elsif ($editbutton eq '') {
375: $editbutton=&clear(6,1);
376: }
377: }
378: ###
379: ###
380: # Prepare the rest of the buttons
381: my $menuitems;
382: if ($const_space) {
383: my $dir_catalog = '/priv/'.$uname.'/'.$thisdisfn.'/default.meta';
384: $menuitems=(<<ENDMENUITEMS);
385: s&2&1&mcrs.gif&list[_1]&dir[_1]&gopost('/adm/pubdir',currentURL)&List current directory
386: s&2&3&mcrs.gif&retrieve[_1]&version[_1]&gopost('/adm/retrieve',currentURL)&Retreive old version
387: s&6&1&mcrs.gif&publish[_1]&resource[_1]&gopost('/adm/publish',currentURL)&Publish this resource
388: s&6&3&mcrs.gif&delete[_1]&resource[_2]&gopost('/adm/cfile?action=delete',currentURL)&Delete this resource
389: s&8&3&prt.gif&prepare[_1]&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
390: ENDMENUITEMS
391: } else {
392: $menuitems=(<<ENDMENUITEMS);
393: c&3&1
394: s&2&1&back.gif&backward[_1]&&gopost('/adm/flip','back:'+currentURL)&Go to the previous resource in the course sequence&1
395: s&2&3&forw.gif&forward[_1]&&gopost('/adm/flip','forward:'+currentURL)&Go to the next resource in the course sequence&3
396: c&6&3
397: c&8&1
398: c&8&2
399: s&8&3&prt.gif&prepare[_1]&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
400: s&9&1&sbkm.gif&set[_1]&bookmark[_2]&set_bookmark()&Set a bookmark for this resource&2
401: s&9&3&anot.gif&anno-[_1]&tations[_1]&annotate()&Make notes and annotations about this resource&2
402: ENDMENUITEMS
403: unless ($ENV{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme)(\?|$)/) {
404: $menuitems.=(<<ENDREALRES);
405: s&6&3&catalog.gif&catalog[_1]&info[_1]&catalog_info()&Show catalog information
406: s&8&1&eval.gif&evaluate[_1]&this[_1]&gopost('/adm/evaluate',currentURL,1)&Provide my evaluation of this resource
407: 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
408: ENDREALRES
409: }
410: }
411: my $buttons='';
412: foreach (split(/\n/,$menuitems)) {
413: my ($command,@rest)=split(/\&/,$_);
414: if ($command eq 's') {
415: $buttons.=&switch('','',@rest);
416: } else {
417: $buttons.=&clear(@rest);
418: }
419: }
420: if ($textual) {
421: # Registered, textual output
422: my $form=&serverform();
423: my $inlinebuttons='';
424:
425: if ($ENV{'browser.interface'} eq 'textual') {
426: $inlinebuttons=
427: join('',map { (defined($_)?$_:'') } @inlineremote);
428: } else {
429: $inlinebuttons=(<<ENDINLINE);
430: <tr><td>$inlineremote[21]</td><td> </td><td>$inlineremote[23]</td></tr>
431: <tr><td>$inlineremote[61]</td><td>$inlineremote[62]</td><td>$inlineremote[63]</td></tr>
432: <tr><td>$inlineremote[71]</td><td>$inlineremote[72]</td><td>$inlineremote[73]</td></tr>
433: <tr><td>$inlineremote[81]</td><td>$inlineremote[82]</td><td>$inlineremote[83]</td></tr>
434: <tr><td>$inlineremote[91]</td><td>$inlineremote[92]</td><td>$inlineremote[93]</td></tr>
435: ENDINLINE
436: }
437: $result =(<<ENDREGTEXT);
438: <script>
439: // BEGIN LON-CAPA Internal
440: </script>
441: $timesync
442: $newmail
443: $tablestart
444: $inlinebuttons
445: $tableend
446: $form
447: <script>
448: // END LON-CAPA Internal
449: </script>
450:
451: ENDREGTEXT
452: # Registered, graphical output
453: } else {
454: my $requri=(split(/\?/,$ENV{'request.noversionuri'}))[0];
455: $requri=&Apache::lonnet::unescape($requri);
456: my $navstatus=&get_nav_status();
457: $result = (<<ENDREGTHIS);
458:
459: <script language="JavaScript">
460: // BEGIN LON-CAPA Internal
461: var swmenu=null;
462:
463: function LONCAPAreg() {
464: swmenu=$reopen;
465: swmenu.clearTimeout(swmenu.menucltim);
466: $timesync
467: $newmail
468: $buttons
469: swmenu.currentURL="$requri";
470: swmenu.reloadURL=swmenu.currentURL+window.location.search;
471: swmenu.currentSymb="$ENV{'request.symb'}";
472: swmenu.reloadSymb="$ENV{'request.symb'}";
473: swmenu.currentStale=0;
474: $navstatus
475: $hwkadd
476: $editbutton
477: }
478:
479: function LONCAPAstale() {
480: swmenu=$reopen
481: swmenu.currentStale=1;
482: if (swmenu.reloadURL!='' && swmenu.reloadURL!= null) {
483: swmenu.switchbutton
484: (3,1,'reload.gif','return','location','go(reloadURL)','Return to the last known location in the course sequence');
485: }
486: swmenu.clearbut(7,1);
487: swmenu.clearbut(7,2);
488: swmenu.clearbut(7,3);
489: swmenu.menucltim=swmenu.setTimeout(
490: 'clearbut(2,1);clearbut(2,3);clearbut(8,1);clearbut(8,2);clearbut(8,3);'+
491: 'clearbut(9,1);clearbut(9,3);clearbut(6,3);clearbut(6,1)',
492: 2000);
493: }
494:
495: // END LON-CAPA Internal
496: </script>
497: ENDREGTHIS
498: }
499: # =============================================================================
500: } else {
501: # ========================================== This can or will not be registered
502: if ($textual) {
503: # Not registered, textual
504: $result= (<<ENDDONOTREGTEXT);
505: ENDDONOTREGTEXT
506: } else {
507: # Not registered, graphical
508: $result = (<<ENDDONOTREGTHIS);
509:
510: <script language="JavaScript">
511: // BEGIN LON-CAPA Internal
512: var swmenu=null;
513:
514: function LONCAPAreg() {
515: swmenu=$reopen
516: $timesync
517: swmenu.currentStale=1;
518: swmenu.clearbut(2,1);
519: swmenu.clearbut(2,3);
520: swmenu.clearbut(8,1);
521: swmenu.clearbut(8,2);
522: swmenu.clearbut(8,3);
523: if (swmenu.currentURL) {
524: swmenu.switchbutton
525: (3,1,'reload.gif','return','location','go(currentURL)');
526: } else {
527: swmenu.clearbut(3,1);
528: }
529: }
530:
531: function LONCAPAstale() {
532: }
533:
534: // END LON-CAPA Internal
535: </script>
536: ENDDONOTREGTHIS
537: }
538: # =============================================================================
539: }
540: return $result;
541: }
542:
543: sub loadevents() {
544: if ($ENV{'request.noversionuri'} eq '/res/adm/pages/menu.html') { return ''; }
545: return 'LONCAPAreg();';
546: }
547:
548: sub unloadevents() {
549: if ($ENV{'request.noversionuri'} eq '/res/adm/pages/menu.html') { return ''; }
550: return 'LONCAPAstale();';
551: }
552:
553: # ============================================================= Start up remote
554:
555: sub startupremote {
556: my ($lowerurl)=@_;
557: if (($ENV{'browser.interface'} eq 'textual') ||
558: ($ENV{'environment.remote'} eq 'off')) {
559: return ('<meta HTTP-EQUIV="Refresh" CONTENT="0.5; url='.$lowerurl.'" />');
560: }
561: #
562: # The Remote actually gets launched!
563: #
564: my $configmenu=&rawconfig();
565: my $esclowerurl=&Apache::lonnet::escape($lowerurl);
566: my $message=&mt('"Waiting for Remote Control window to load: "+[_1]','waited');
567: return(<<ENDREMOTESTARTUP);
568: <script>
569: var timestart;
570: function wheelswitch() {
571: if (typeof(document.wheel) != 'undefined') {
572: if (typeof(document.wheel.spin) != 'undefined') {
573: var date=new Date();
574: var waited=Math.round(30-((date.getTime()-timestart)/1000));
575: document.wheel.spin.value=$message;
576: }
577: }
578: if (window.status=='|') {
579: window.status='/';
580: } else {
581: if (window.status=='/') {
582: window.status='-';
583: } else {
584: if (window.status=='-') {
585: window.status='\\\\';
586: } else {
587: if (window.status=='\\\\') { window.status='|'; }
588: }
589: }
590: }
591: }
592:
593: // ---------------------------------------------------------- The wait function
594: var canceltim;
595: function wait() {
596: if ((menuloaded==1) || (tim==1)) {
597: window.status='Done.';
598: if (tim==0) {
599: clearTimeout(canceltim);
600: $configmenu
601: window.location='$lowerurl';
602: } else {
603: window.location='/adm/remote?action=collapse&url=$esclowerurl';
604: }
605: } else {
606: wheelswitch();
607: setTimeout('wait();',200);
608: }
609: }
610:
611: function main() {
612: canceltim=setTimeout('tim=1;',30000);
613: window.status='-';
614: var date=new Date();
615: timestart=date.getTime();
616: wait();
617: }
618:
619: </script>
620: ENDREMOTESTARTUP
621: }
622:
623: sub setflags() {
624: return(<<ENDSETFLAGS);
625: <script>
626: menuloaded=0;
627: tim=0;
628: </script>
629: ENDSETFLAGS
630: }
631:
632: sub maincall() {
633: if (($ENV{'browser.interface'} eq 'textual') ||
634: ($ENV{'environment.remote'} eq 'off')) { return ''; }
635: return(<<ENDMAINCALL);
636: <script>
637: main();
638: </script>
639: ENDMAINCALL
640: }
641:
642: sub load_remote_msg {
643: my ($lowerurl)=@_;
644:
645: if (($ENV{'browser.interface'} eq 'textual') ||
646: ($ENV{'environment.remote'} eq 'off')) { return ''; }
647:
648: my $esclowerurl=&Apache::lonnet::escape($lowerurl);
649: my $link=&mt('<a href="[_1]">Continue</a> on in Inline Menu mode',
650: "/adm/remote?action=collapse?url=$esclowerurl");
651: return(<<ENDREMOTEFORM);
652: <p>
653: <form name="wheel">
654: <input name="spin" type="text" size="60" />
655: </form>
656: </p>
657: <p>$link</p>
658: ENDREMOTEFORM
659: }
660: # ================================================================= Reopen menu
661:
662: sub reopenmenu {
663: if (($ENV{'browser.interface'} eq 'textual') ||
664: ($ENV{'environment.remote'} eq 'off')) { return ''; }
665: my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
666: my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
667: return('window.open('.$nothing.',"'.$menuname.'","",false);');
668: }
669:
670: # =============================================================== Open the menu
671:
672: sub open {
673: my $returnval='';
674: if (($ENV{'browser.interface'} eq 'textual') ||
675: ($ENV{'environment.remote'} eq 'off')) {
676: return '<script type="text/javascript">self.name="loncapaclient";</script>';
677: }
678: my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
679: unless (shift eq 'unix') {
680: # resizing does not work on linux because of virtual desktop sizes
681: $returnval.=(<<ENDRESIZE);
682: if (window.screen) {
683: self.resizeTo(screen.availWidth-215,screen.availHeight-55);
684: self.moveTo(190,15);
685: }
686: ENDRESIZE
687: }
688: $returnval.=(<<ENDOPEN);
689: window.status='Opening LON-CAPA Remote Control';
690: var menu=window.open("/res/adm/pages/menu.html","$menuname",
691: "height=350,width=150,scrollbars=no,menubar=no,top=5,left=5,screenX=5,screenY=5");
692: self.name='loncapaclient';
693: ENDOPEN
694: return '<script>'.$returnval.'</script>';
695: }
696:
697:
698: # ================================================================== Raw Config
699:
700: sub clear {
701: my ($row,$col)=@_;
702: unless (($ENV{'browser.interface'} eq 'textual') ||
703: ($ENV{'environment.remote'} eq 'off')) {
704: return "\n".qq(window.status+='.';swmenu.clearbut($row,$col););
705: } else {
706: $inlineremote[10*$row+$col]='';
707: return '';
708: }
709: }
710:
711: # ============================================ Switch a button or create a link
712: # Switch acts on the javascript that is executed when a button is clicked.
713: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
714:
715: sub switch {
716: my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$nobreak)=@_;
717: $act=~s/\$uname/$uname/g;
718: $act=~s/\$udom/$udom/g;
719: $top=&mt($top);
720: $bot=&mt($bot);
721: $desc=&mt($desc);
722: $img=&mt($img);
723: unless (($ENV{'browser.interface'} eq 'textual') ||
724: ($ENV{'environment.remote'} eq 'off')) {
725: # Remote
726: return "\n".
727: qq(window.status+='.';swmenu.switchbutton($row,$col,"$img","$top","$bot","$act","$desc"););
728: } elsif ($ENV{'browser.interface'} eq 'textual') {
729: # Accessibility
730: if ($nobreak==2) { return ''; }
731: my $text=$top.' '.$bot;
732: $text=~s/\s*\-\s*//gs;
733: if ($nobreak) {
734: $inlineremote[10*$row+$col]=
735: '<a href="javascript:'.$act.';">'.$text.'</a>';
736: } else {
737: $inlineremote[10*$row+$col]="\n<br />".
738: $desc.' <a href="javascript:'.$act.';">'.$text.'</a>';
739: }
740: } else {
741: # Inline Remote
742: if ($nobreak==2) { return ''; }
743: my $text=$top.' '.$bot;
744: $text=~s/\s*\-\s*//gs;
745:
746: my $lonhttpdPort=$Apache::lonnet::perlvar{'lonhttpdPort'};
747: if (!defined($lonhttpdPort)) { $lonhttpdPort='8080'; }
748: my $pic=
749: '<img border="0" alt="'.$text.'" src="http://'.$ENV{'HTTP_HOST'}.
750: ':'.$lonhttpdPort.'/res/adm/pages/'.$img.'" align="'.
751: ($nobreak==3?'right':'left').'" />';
752: if (($ENV{'browser.interface'} eq 'textual') || ($ENV{'browser.interface'} eq 'faketextual')) {
753: # Accessibility
754: if ($nobreak==3) {
755: $inlineremote[10*$row+$col]="\n".
756: '<td width="40%" align="right"><font color="'.$font.'" size="+1">'.$text.
757: '</font></td><td width="10%" align="right" bgcolor="'.$tabbg.'">'.
758: '<a href="javascript:'.$act.';">'.$pic.'</a></td></tr>';
759: } elsif ($nobreak) {
760: $inlineremote[10*$row+$col]="\n<tr>".
761: '<td width="10%" align="left" bgcolor="'.$tabbg.'">'.
762: '<a href="javascript:'.$act.';">'.$pic.
763: '</a></td><td width="40%" align="left"><font color="'.$font.'" size="+1">'.$text.'</font></td>';
764: } else {
765: $inlineremote[10*$row+$col]="\n<tr>".
766: '<td width="10%" align="left" bgcolor="'.$tabbg.'">'.
767: '<a href="javascript:'.$act.';">'.$pic.
768: '</a></td><td colspan="3"><font color="'.$font.'">'.$desc.
769: '</font></td></tr>';
770: }
771: } else {
772: # Inline Menu
773: $inlineremote[10*$row+$col]=
774: '<a href="javascript:'.$act.';">'.$pic.
775: '</a><font color="'.$font.'" size="2">'.$desc.
776: '</font>';
777: }
778: }
779: return '';
780: }
781:
782: sub secondlevel {
783: my $output='';
784: my
785: ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc)=@_;
786: if ($prt eq 'any') {
787: $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
788: } elsif ($prt=~/^r(\w+)/) {
789: if ($rol eq $1) {
790: $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
791: }
792: }
793: return $output;
794: }
795:
796: sub openmenu {
797: my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
798: if (($ENV{'browser.interface'} eq 'textual') ||
799: ($ENV{'environment.remote'} eq 'off')) { return ''; }
800: my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
801: return "window.open(".$nothing.",'".$menuname."');";
802: }
803:
804: sub inlinemenu {
805: @inlineremote=();
806: undef @inlineremote;
807: &rawconfig(1);
808: return join('',map { (defined($_)?$_:'') } @inlineremote);
809: }
810:
811: sub rawconfig {
812: my $textualoverride=shift;
813: my $output='';
814: unless (($ENV{'browser.interface'} eq 'textual') ||
815: ($ENV{'environment.remote'} eq 'off')) {
816: $output.=
817: "window.status='Opening Remote Control';var swmenu=".&openmenu().
818: "\nwindow.status='Configuring Remote Control ';";
819: } else {
820: unless ($textualoverride) { return ''; }
821: }
822: my $uname=$ENV{'user.name'};
823: my $udom=$ENV{'user.domain'};
824: my $adv=$ENV{'user.adv'};
825: my $author=$ENV{'user.author'};
826: my $crs='';
827: if ($ENV{'request.course.id'}) {
828: $crs='/'.$ENV{'request.course.id'};
829: if ($ENV{'request.course.sec'}) {
830: $crs.='_'.$ENV{'request.course.sec'};
831: }
832: $crs=~s/\_/\//g;
833: }
834: my $pub=($ENV{'request.state'} eq 'published');
835: my $con=($ENV{'request.state'} eq 'construct');
836: my $rol=$ENV{'request.role'};
837: my $requested_domain = $ENV{'request.role.domain'};
838: foreach (@desklines) {
839: my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc)=split(/\:/,$_);
840: $prt=~s/\$uname/$uname/g;
841: $prt=~s/\$udom/$udom/g;
842: $prt=~s/\$crs/$crs/g;
843: $prt=~s/\$requested_domain/$requested_domain/g;
844: if ($pro eq 'clear') {
845: $output.=&clear($row,$col);
846: } elsif ($pro eq 'any') {
847: $output.=&secondlevel(
848: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
849: } elsif ($pro eq 'smp') {
850: unless ($adv) {
851: $output.=&secondlevel(
852: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
853: }
854: } elsif ($pro eq 'adv') {
855: if ($adv) {
856: $output.=&secondlevel(
857: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
858: }
859: } elsif (($pro=~/^p(\w+)/) && ($prt)) {
860: if (&Apache::lonnet::allowed($1,$prt)) {
861: $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
862: }
863: } elsif ($pro eq 'course') {
864: if ($ENV{'request.course.fn'}) {
865: $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
866: }
867: } elsif ($pro =~ /^course_(.*)$/) {
868: # Check for permissions inside of a course
869: if (($ENV{'request.course.id'}) &&
870: (&Apache::lonnet::allowed($1,$ENV{'request.course.id'}.
871: ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))
872: )) {
873: $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
874: }
875: } elsif ($pro eq 'author') {
876: if ($author) {
877: if ((($prt eq 'rca') && ($ENV{'request.role'}=~/^ca/)) ||
878: (($prt eq 'rau') && ($ENV{'request.role'}=~/^au/))) {
879: # Check that we are on the correct machine
880: my $cadom=$requested_domain;
881: my $caname=$ENV{'user.name'};
882: if ($prt eq 'rca') {
883: ($cadom,$caname)=
884: ($ENV{'request.role'}=~/(\w+)\/(\w+)$/);
885: }
886: $act =~ s/\$caname/$caname/g;
887: my $home = &Apache::lonnet::homeserver($caname,$cadom);
888: my $allowed=0;
889: my @ids=&Apache::lonnet::current_machine_ids();
890: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
891: if ($allowed) {
892: $output.=switch($caname,$cadom,
893: $row,$col,$img,$top,$bot,$act,$desc);
894: }
895: }
896: }
897: }
898: }
899: unless (($ENV{'browser.interface'} eq 'textual') ||
900: ($ENV{'environment.remote'} eq 'off')) {
901: $output.="\nwindow.status='Synchronizing Time';swmenu.syncclock(1000*".time.");\nwindow.status='Remote Control Configured.';";
902: }
903: return $output;
904: }
905:
906: # ======================================================================= Close
907:
908: sub close {
909: if (($ENV{'browser.interface'} eq 'textual') ||
910: ($ENV{'environment.remote'} eq 'off')) { return ''; }
911: my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
912: return(<<ENDCLOSE);
913: <script>
914: window.status='Accessing Remote Control';
915: menu=window.open("/adm/rat/empty.html","$menuname",
916: "height=350,width=150,scrollbars=no,menubar=no");
917: window.status='Disabling Remote Control';
918: menu.active=0;
919: menu.autologout=0;
920: window.status='Closing Remote Control';
921: menu.close();
922: window.status='Done.';
923: </script>
924: ENDCLOSE
925: }
926:
927: # ====================================================================== Footer
928:
929: sub footer {
930:
931: }
932:
933: sub utilityfunctions {
934: unless (($ENV{'browser.interface'} eq 'textual') ||
935: ($ENV{'environment.remote'} eq 'off')) { return ''; }
936: my $currenturl=$ENV{'request.noversionuri'};
937: my $currentsymb=$ENV{'request.symb'};
938: my $nav_control=&Apache::lonnavmaps::nav_control_js();
939: return (<<ENDUTILITY)
940:
941: var currentURL="$currenturl";
942: var reloadURL="$currenturl";
943: var currentSymb="$currentsymb";
944:
945: $nav_control
946:
947: function go(url) {
948: if (url!='' && url!= null) {
949: currentURL = null;
950: currentSymb= null;
951: window.location.href=url;
952: }
953: }
954:
955: function gopost(url,postdata) {
956: if (url!='') {
957: this.document.server.action=url;
958: this.document.server.postdata.value=postdata;
959: this.document.server.command.value='';
960: this.document.server.url.value='';
961: this.document.server.symb.value='';
962: this.document.server.submit();
963: }
964: }
965:
966: function gocmd(url,cmd) {
967: if (url!='') {
968: this.document.server.action=url;
969: this.document.server.postdata.value='';
970: this.document.server.command.value=cmd;
971: this.document.server.url.value=currentURL;
972: this.document.server.symb.value=currentSymb;
973: this.document.server.submit();
974: }
975: }
976:
977: function catalog_info() {
978: loncatinfo=window.open(window.location.pathname+'.meta',"LONcatInfo",'height=320,width=280,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
979: }
980:
981: function chat_win() {
982: lonchat=window.open('/res/adm/pages/chatroom.html',"LONchat",'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
983: }
984: ENDUTILITY
985: }
986:
987: sub serverform {
988: return(<<ENDSERVERFORM);
989:
990: <form name="server" action="/adm/logout" method="post" target="_top">
991: <input type="hidden" name="postdata" value="none" />
992: <input type="hidden" name="command" value="none" />
993: <input type="hidden" name="url" value="none" />
994: <input type="hidden" name="symb" value="none" />
995: </form>
996: ENDSERVERFORM
997: }
998:
999: sub get_nav_status {
1000: my $navstatus="swmenu.w_loncapanav_flag=";
1001: if ($ENV{'environment.remotenavmap'} eq 'on') {
1002: $navstatus.="1";
1003: } else {
1004: $navstatus.="-1";
1005: }
1006: return $navstatus;
1007: }
1008:
1009: # ================================================ Handler when called directly
1010:
1011:
1012: sub handler {
1013: my $r = shift;
1014: &Apache::loncommon::content_type($r,'text/html');
1015: $r->send_http_header;
1016: return OK if $r->header_only;
1017:
1018: my $form=&serverform();
1019: my $bodytag=&Apache::loncommon::bodytag('Main Menu');
1020: my $function='student';
1021: if ($ENV{'request.role'}=~/^(cc|in|ta|ep)/) {
1022: $function='coordinator';
1023: }
1024: if ($ENV{'request.role'}=~/^(su|dc|ad|li)/) {
1025: $function='admin';
1026: }
1027: if (($ENV{'request.role'}=~/^(au|ca)/) ||
1028: ($ENV{'request.noversionuri'}=~/^(\/priv|\~)/)) {
1029: $function='author';
1030: }
1031: my $domain=&Apache::loncommon::determinedomain();
1032: $pgbg=&Apache::loncommon::designparm($function.'.pgbg',$domain);
1033: $tabbg=&Apache::loncommon::designparm($function.'.tabbg',$domain);
1034: $font=&Apache::loncommon::designparm($function.'.font',$domain);
1035: # ---- Print the screen, pretent to be in text mode to generate text-based menu
1036: unless ($ENV{'browser.interface'} eq 'textual') {
1037: $ENV{'browser.interface'}='faketextual';
1038: $ENV{'environment.remote'}='off';
1039: }
1040: $r->print(<<ENDHEADER);
1041: <html><head>
1042: <title>LON-CAPA Main Menu</title>
1043: </head>
1044: $bodytag
1045: ENDHEADER
1046: $r->print('<table>'.&inlinemenu().'</table>'.$form);
1047: $r->print('</body></html>');
1048: return OK;
1049: }
1050:
1051: # ================================================================ Main Program
1052:
1053: BEGIN {
1054: if (! defined($readdesk)) {
1055: {
1056: my $tabfile = $Apache::lonnet::perlvar{'lonTabDir'}.'/mydesk.tab';
1057: if ( CORE::open( my $config,"<$tabfile") ) {
1058: while (my $configline=<$config>) {
1059: $configline=(split(/\#/,$configline))[0];
1060: $configline=~s/^\s+//;
1061: chomp($configline);
1062: if ($configline) {
1063: $desklines[$#desklines+1]=$configline;
1064: }
1065: }
1066: CORE::close($config);
1067: }
1068: }
1069: $readdesk='done';
1070: }
1071: }
1072:
1073: 1;
1074: __END__
1075:
1076:
1077:
1078:
1079:
1080:
1081:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>