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