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