Annotation of loncom/interface/lonmenu.pm, revision 1.112
1.1 www 1: # The LearningOnline Network with CAPA
2: # Routines to control the menu
3: #
1.112 ! albertel 4: # $Id: lonmenu.pm,v 1.111 2004/07/23 19:09:27 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.41 www 423: $result = (<<ENDREGTHIS);
1.38 www 424:
425: <script language="JavaScript">
426: // BEGIN LON-CAPA Internal
1.42 www 427: var swmenu=null;
1.38 www 428:
429: function LONCAPAreg() {
430: swmenu=$reopen;
431: swmenu.clearTimeout(swmenu.menucltim);
432: $timesync
433: $newmail
1.41 www 434: $buttons
1.84 www 435: swmenu.currentURL="$requri";
1.85 www 436: swmenu.reloadURL=swmenu.currentURL+window.location.search;
1.38 www 437: swmenu.currentSymb="$ENV{'request.symb'}";
438: swmenu.reloadSymb="$ENV{'request.symb'}";
439: swmenu.currentStale=0;
440: $hwkadd
441: $editbutton
442: }
443:
444: function LONCAPAstale() {
445: swmenu=$reopen
446: swmenu.currentStale=1;
447: if (swmenu.reloadURL!='' && swmenu.reloadURL!= null) {
448: swmenu.switchbutton
449: (3,1,'reload.gif','return','location','go(reloadURL)','Return to the last known location in the course sequence');
450: }
451: swmenu.clearbut(7,1);
452: swmenu.clearbut(7,2);
453: swmenu.clearbut(7,3);
454: swmenu.menucltim=swmenu.setTimeout(
455: 'clearbut(2,1);clearbut(2,3);clearbut(8,1);clearbut(8,2);clearbut(8,3);'+
1.108 www 456: 'clearbut(9,1);clearbut(9,3);clearbut(6,3);clearbut(6,1)',
1.38 www 457: 2000);
458: }
459:
460: // END LON-CAPA Internal
461: </script>
462: ENDREGTHIS
1.41 www 463: }
464: # =============================================================================
1.38 www 465: } else {
1.41 www 466: # ========================================== This can or will not be registered
467: if ($textual) {
468: # Not registered, textual
469: $result= (<<ENDDONOTREGTEXT);
470: ENDDONOTREGTEXT
471: } else {
472: # Not registered, graphical
473: $result = (<<ENDDONOTREGTHIS);
1.38 www 474:
475: <script language="JavaScript">
476: // BEGIN LON-CAPA Internal
1.42 www 477: var swmenu=null;
1.38 www 478:
479: function LONCAPAreg() {
480: swmenu=$reopen
481: $timesync
482: swmenu.currentStale=1;
483: swmenu.clearbut(2,1);
484: swmenu.clearbut(2,3);
485: swmenu.clearbut(8,1);
486: swmenu.clearbut(8,2);
487: swmenu.clearbut(8,3);
488: if (swmenu.currentURL) {
489: swmenu.switchbutton
490: (3,1,'reload.gif','return','location','go(currentURL)');
491: } else {
492: swmenu.clearbut(3,1);
493: }
494: }
495:
496: function LONCAPAstale() {
497: }
498:
499: // END LON-CAPA Internal
500: </script>
501: ENDDONOTREGTHIS
1.41 www 502: }
503: # =============================================================================
1.38 www 504: }
505: return $result;
506: }
507:
508: sub loadevents() {
1.97 www 509: if ($ENV{'request.noversionuri'} eq '/res/adm/pages/menu.html') { return ''; }
1.38 www 510: return 'LONCAPAreg();';
511: }
512:
513: sub unloadevents() {
1.97 www 514: if ($ENV{'request.noversionuri'} eq '/res/adm/pages/menu.html') { return ''; }
1.38 www 515: return 'LONCAPAstale();';
516: }
1.30 www 517:
1.32 www 518: # ============================================================= Start up remote
519:
520: sub startupremote {
521: my ($lowerurl)=@_;
1.49 www 522: if (($ENV{'browser.interface'} eq 'textual') ||
523: ($ENV{'environment.remote'} eq 'off')) {
1.34 www 524: return ('<meta HTTP-EQUIV="Refresh" CONTENT="0.5; url='.$lowerurl.'" />');
525: }
1.49 www 526: #
527: # The Remote actually gets launched!
528: #
1.32 www 529: my $configmenu=&rawconfig();
1.52 www 530: my $esclowerurl=&Apache::lonnet::escape($lowerurl);
531:
1.32 www 532: return(<<ENDREMOTESTARTUP);
533: <script>
534:
1.35 www 535: function wheelswitch() {
536: if (window.status=='|') {
537: window.status='/';
538: } else {
539: if (window.status=='/') {
540: window.status='-';
541: } else {
542: if (window.status=='-') {
543: window.status='\\\\';
544: } else {
545: if (window.status=='\\\\') { window.status='|'; }
546: }
547: }
548: }
549: }
550:
1.32 www 551: // ---------------------------------------------------------- The wait function
552: var canceltim;
553: function wait() {
554: if ((menuloaded==1) || (tim==1)) {
1.35 www 555: window.status='Done.';
1.32 www 556: if (tim==0) {
557: clearTimeout(canceltim);
558: $configmenu
559: window.location='$lowerurl';
560: } else {
1.52 www 561: window.location='/adm/remote?action=collapse&url=$esclowerurl';
1.32 www 562: }
563: } else {
1.35 www 564: wheelswitch();
565: setTimeout('wait();',200);
1.32 www 566: }
567: }
568:
569: function main() {
1.52 www 570: canceltim=setTimeout('tim=1;',30000);
1.35 www 571: window.status='-';
1.32 www 572: wait();
573: }
574:
575: </script>
576: ENDREMOTESTARTUP
577: }
578:
579: sub setflags() {
580: return(<<ENDSETFLAGS);
581: <script>
582: menuloaded=0;
583: tim=0;
584: </script>
585: ENDSETFLAGS
586: }
587:
588: sub maincall() {
1.49 www 589: if (($ENV{'browser.interface'} eq 'textual') ||
590: ($ENV{'environment.remote'} eq 'off')) { return ''; }
1.32 www 591: return(<<ENDMAINCALL);
592: <script>
593: main();
594: </script>
595: ENDMAINCALL
596: }
1.30 www 597: # ================================================================= Reopen menu
598:
599: sub reopenmenu {
1.49 www 600: if (($ENV{'browser.interface'} eq 'textual') ||
601: ($ENV{'environment.remote'} eq 'off')) { return ''; }
1.30 www 602: my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
1.47 matthew 603: my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
604: return('window.open('.$nothing.',"'.$menuname.'","",false);');
1.30 www 605: }
606:
1.1 www 607: # =============================================================== Open the menu
608:
609: sub open {
1.22 www 610: my $returnval='';
1.49 www 611: if (($ENV{'browser.interface'} eq 'textual') ||
1.111 albertel 612: ($ENV{'environment.remote'} eq 'off')) {
613: return '<script type="text/javascript">self.name="loncapaclient";</script>';
614: }
1.30 www 615: my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
1.22 www 616: unless (shift eq 'unix') {
617: # resizing does not work on linux because of virtual desktop sizes
618: $returnval.=(<<ENDRESIZE);
619: if (window.screen) {
1.28 www 620: self.resizeTo(screen.availWidth-215,screen.availHeight-55);
1.22 www 621: self.moveTo(190,15);
622: }
623: ENDRESIZE
624: }
625: $returnval.=(<<ENDOPEN);
1.35 www 626: window.status='Opening LON-CAPA Remote Control';
1.30 www 627: var menu=window.open("/res/adm/pages/menu.html","$menuname",
1.14 www 628: "height=350,width=150,scrollbars=no,menubar=no,top=5,left=5,screenX=5,screenY=5");
1.71 www 629: self.name='loncapaclient';
1.1 www 630: ENDOPEN
1.22 www 631: return '<script>'.$returnval.'</script>';
1.1 www 632: }
633:
1.2 www 634:
635: # ================================================================== Raw Config
636:
1.3 www 637: sub clear {
638: my ($row,$col)=@_;
1.49 www 639: unless (($ENV{'browser.interface'} eq 'textual') ||
640: ($ENV{'environment.remote'} eq 'off')) {
1.35 www 641: return "\n".qq(window.status+='.';swmenu.clearbut($row,$col););
1.56 www 642: } else {
643: $inlineremote[10*$row+$col]='';
644: return '';
645: }
1.3 www 646: }
647:
1.40 www 648: # ============================================ Switch a button or create a link
1.25 matthew 649: # Switch acts on the javascript that is executed when a button is clicked.
650: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
1.40 www 651:
1.2 www 652: sub switch {
1.40 www 653: my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$nobreak)=@_;
1.2 www 654: $act=~s/\$uname/$uname/g;
655: $act=~s/\$udom/$udom/g;
1.88 www 656: $top=&mt($top);
657: $bot=&mt($bot);
658: $desc=&mt($desc);
1.105 www 659: $img=&mt($img);
1.49 www 660: unless (($ENV{'browser.interface'} eq 'textual') ||
661: ($ENV{'environment.remote'} eq 'off')) {
1.50 www 662: # Remote
1.34 www 663: return "\n".
1.35 www 664: qq(window.status+='.';swmenu.switchbutton($row,$col,"$img","$top","$bot","$act","$desc"););
1.50 www 665: } elsif ($ENV{'browser.interface'} eq 'textual') {
666: # Accessibility
667: if ($nobreak==2) { return ''; }
668: my $text=$top.' '.$bot;
1.78 www 669: $text=~s/\s*\-\s*//gs;
1.94 www 670: if ($nobreak) {
671: $inlineremote[10*$row+$col]=
672: '<a href="javascript:'.$act.';">'.$text.'</a>';
673: } else {
674: $inlineremote[10*$row+$col]="\n<br />".
1.100 www 675: $desc.' <a href="javascript:'.$act.';">'.$text.'</a>';
1.94 www 676: }
1.34 www 677: } else {
1.50 www 678: # Inline Remote
1.41 www 679: if ($nobreak==2) { return ''; }
1.34 www 680: my $text=$top.' '.$bot;
1.78 www 681: $text=~s/\s*\-\s*//gs;
1.105 www 682:
683: my $lonhttpdPort=$Apache::lonnet::perlvar{'lonhttpdPort'};
684: if (!defined($lonhttpdPort)) { $lonhttpdPort='8080'; }
1.99 www 685: my $pic=
1.105 www 686: '<img border="0" alt="'.$text.'" src="http://'.$ENV{'HTTP_HOST'}.
687: ':'.$lonhttpdPort.'/res/adm/pages/'.$img.'" align="'.
1.103 www 688: ($nobreak==3?'right':'left').'" />';
689: if (($ENV{'browser.interface'} eq 'textual') || ($ENV{'browser.interface'} eq 'faketextual')) {
690: # Accessibility
691: if ($nobreak==3) {
692: $inlineremote[10*$row+$col]="\n".
693: '<td width="40%" align="right"><font color="'.$font.'" size="+1">'.$text.
694: '</font></td><td width="10%" align="right" bgcolor="'.$tabbg.'">'.
695: '<a href="javascript:'.$act.';">'.$pic.'</a></td></tr>';
696: } elsif ($nobreak) {
697: $inlineremote[10*$row+$col]="\n<tr>".
698: '<td width="10%" align="left" bgcolor="'.$tabbg.'">'.
699: '<a href="javascript:'.$act.';">'.$pic.
700: '</a></td><td width="40%" align="left"><font color="'.$font.'" size="+1">'.$text.'</font></td>';
701: } else {
702: $inlineremote[10*$row+$col]="\n<tr>".
703: '<td width="10%" align="left" bgcolor="'.$tabbg.'">'.
704: '<a href="javascript:'.$act.';">'.$pic.
705: '</a></td><td colspan="3"><font color="'.$font.'">'.$desc.
706: '</font></td></tr>';
707: }
1.94 www 708: } else {
1.103 www 709: # Inline Menu
710: $inlineremote[10*$row+$col]=
711: '<a href="javascript:'.$act.';">'.$pic.
712: '</a><font color="'.$font.'" size="2">'.$desc.
713: '</font>';
1.94 www 714: }
1.34 www 715: }
1.56 www 716: return '';
1.2 www 717: }
718:
719: sub secondlevel {
720: my $output='';
721: my
1.27 www 722: ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc)=@_;
1.2 www 723: if ($prt eq 'any') {
1.27 www 724: $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
1.2 www 725: } elsif ($prt=~/^r(\w+)/) {
726: if ($rol eq $1) {
1.27 www 727: $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
1.2 www 728: }
729: }
730: return $output;
731: }
732:
1.18 www 733: sub openmenu {
1.30 www 734: my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
1.49 www 735: if (($ENV{'browser.interface'} eq 'textual') ||
736: ($ENV{'environment.remote'} eq 'off')) { return ''; }
1.47 matthew 737: my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
738: return "window.open(".$nothing.",'".$menuname."');";
1.18 www 739: }
740:
1.56 www 741: sub inlinemenu {
742: @inlineremote=();
743: undef @inlineremote;
744: &rawconfig(1);
745: return join('',map { (defined($_)?$_:'') } @inlineremote);
746: }
747:
1.2 www 748: sub rawconfig {
1.34 www 749: my $textualoverride=shift;
750: my $output='';
1.49 www 751: unless (($ENV{'browser.interface'} eq 'textual') ||
752: ($ENV{'environment.remote'} eq 'off')) {
1.35 www 753: $output.=
754: "window.status='Opening Remote Control';var swmenu=".&openmenu().
755: "\nwindow.status='Configuring Remote Control ';";
1.34 www 756: } else {
757: unless ($textualoverride) { return ''; }
758: }
1.2 www 759: my $uname=$ENV{'user.name'};
760: my $udom=$ENV{'user.domain'};
761: my $adv=$ENV{'user.adv'};
1.4 www 762: my $author=$ENV{'user.author'};
1.5 www 763: my $crs='';
764: if ($ENV{'request.course.id'}) {
765: $crs='/'.$ENV{'request.course.id'};
1.7 www 766: if ($ENV{'request.course.sec'}) {
767: $crs.='_'.$ENV{'request.course.sec'};
768: }
1.8 www 769: $crs=~s/\_/\//g;
1.5 www 770: }
1.2 www 771: my $pub=($ENV{'request.state'} eq 'published');
772: my $con=($ENV{'request.state'} eq 'construct');
773: my $rol=$ENV{'request.role'};
1.25 matthew 774: my $requested_domain = $ENV{'request.role.domain'};
1.13 harris41 775: foreach (@desklines) {
1.27 www 776: my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc)=split(/\:/,$_);
1.3 www 777: $prt=~s/\$uname/$uname/g;
778: $prt=~s/\$udom/$udom/g;
1.5 www 779: $prt=~s/\$crs/$crs/g;
1.25 matthew 780: $prt=~s/\$requested_domain/$requested_domain/g;
1.3 www 781: if ($pro eq 'clear') {
1.4 www 782: $output.=&clear($row,$col);
1.3 www 783: } elsif ($pro eq 'any') {
1.2 www 784: $output.=&secondlevel(
1.27 www 785: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
1.2 www 786: } elsif ($pro eq 'smp') {
787: unless ($adv) {
788: $output.=&secondlevel(
1.27 www 789: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
1.2 www 790: }
791: } elsif ($pro eq 'adv') {
792: if ($adv) {
793: $output.=&secondlevel(
1.27 www 794: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
1.2 www 795: }
1.81 matthew 796: } elsif (($pro=~/^p(\w+)/) && ($prt)) {
1.2 www 797: if (&Apache::lonnet::allowed($1,$prt)) {
1.27 www 798: $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
1.4 www 799: }
1.26 www 800: } elsif ($pro eq 'course') {
801: if ($ENV{'request.course.fn'}) {
1.27 www 802: $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
1.81 matthew 803: }
804: } elsif ($pro =~ /^course_(.*)$/) {
805: # Check for permissions inside of a course
806: if (($ENV{'request.course.id'}) &&
807: (&Apache::lonnet::allowed($1,$ENV{'request.course.id'}.
808: ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))
809: )) {
810: $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
1.26 www 811: }
1.4 www 812: } elsif ($pro eq 'author') {
813: if ($author) {
1.29 matthew 814: if ((($prt eq 'rca') && ($ENV{'request.role'}=~/^ca/)) ||
815: (($prt eq 'rau') && ($ENV{'request.role'}=~/^au/))) {
1.19 matthew 816: # Check that we are on the correct machine
1.29 matthew 817: my $cadom=$requested_domain;
818: my $caname=$ENV{'user.name'};
819: if ($prt eq 'rca') {
820: ($cadom,$caname)=
1.6 www 821: ($ENV{'request.role'}=~/(\w+)\/(\w+)$/);
1.29 matthew 822: }
823: $act =~ s/\$caname/$caname/g;
1.19 matthew 824: my $home = &Apache::lonnet::homeserver($caname,$cadom);
1.109 albertel 825: my $allowed=0;
826: my @ids=&Apache::lonnet::current_machine_ids();
827: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
828: if ($allowed) {
1.19 matthew 829: $output.=switch($caname,$cadom,
1.27 www 830: $row,$col,$img,$top,$bot,$act,$desc);
1.19 matthew 831: }
1.6 www 832: }
1.2 www 833: }
834: }
1.13 harris41 835: }
1.49 www 836: unless (($ENV{'browser.interface'} eq 'textual') ||
837: ($ENV{'environment.remote'} eq 'off')) {
1.35 www 838: $output.="\nwindow.status='Synchronizing Time';swmenu.syncclock(1000*".time.");\nwindow.status='Remote Control Configured.';";
1.34 www 839: }
1.2 www 840: return $output;
841: }
842:
843: # ======================================================================= Close
1.1 www 844:
845: sub close {
1.49 www 846: if (($ENV{'browser.interface'} eq 'textual') ||
847: ($ENV{'environment.remote'} eq 'off')) { return ''; }
1.30 www 848: my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
1.1 www 849: return(<<ENDCLOSE);
850: <script>
1.35 www 851: window.status='Accessing Remote Control';
1.30 www 852: menu=window.open("/adm/rat/empty.html","$menuname",
1.1 www 853: "height=350,width=150,scrollbars=no,menubar=no");
1.35 www 854: window.status='Disabling Remote Control';
855: menu.active=0;
1.31 www 856: menu.autologout=0;
1.35 www 857: window.status='Closing Remote Control';
1.1 www 858: menu.close();
1.35 www 859: window.status='Done.';
1.1 www 860: </script>
861: ENDCLOSE
862: }
863:
864: # ====================================================================== Footer
865:
866: sub footer {
867:
1.33 www 868: }
869:
1.42 www 870: sub utilityfunctions {
1.51 www 871: unless (($ENV{'browser.interface'} eq 'textual') ||
872: ($ENV{'environment.remote'} eq 'off')) { return ''; }
1.97 www 873: my $currenturl=$ENV{'request.noversionuri'};
1.42 www 874: my $currentsymb=$ENV{'request.symb'};
875: return (<<ENDUTILITY)
876:
877: var currentURL="$currenturl";
878: var reloadURL="$currenturl";
879: var currentSymb="$currentsymb";
880:
881: function go(url) {
882: if (url!='' && url!= null) {
883: currentURL = null;
884: currentSymb= null;
885: window.location.href=url;
886: }
887: }
888:
889: function gopost(url,postdata) {
890: if (url!='') {
891: this.document.server.action=url;
892: this.document.server.postdata.value=postdata;
893: this.document.server.command.value='';
894: this.document.server.url.value='';
895: this.document.server.symb.value='';
896: this.document.server.submit();
897: }
898: }
899:
900: function gocmd(url,cmd) {
901: if (url!='') {
902: this.document.server.action=url;
903: this.document.server.postdata.value='';
904: this.document.server.command.value=cmd;
905: this.document.server.url.value=currentURL;
906: this.document.server.symb.value=currentSymb;
907: this.document.server.submit();
908: }
1.57 www 909: }
910:
911: function catalog_info() {
1.102 albertel 912: 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 913: }
914:
915: function chat_win() {
1.102 albertel 916: lonchat=window.open('/res/adm/pages/chatroom.html',"LONchat",'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
1.42 www 917: }
918: ENDUTILITY
919: }
920:
921: sub serverform {
922: return(<<ENDSERVERFORM);
923:
1.62 www 924: <form name="server" action="/adm/logout" method="post" target="_top">
1.42 www 925: <input type="hidden" name="postdata" value="none" />
926: <input type="hidden" name="command" value="none" />
927: <input type="hidden" name="url" value="none" />
928: <input type="hidden" name="symb" value="none" />
929: </form>
930: ENDSERVERFORM
931: }
1.33 www 932: # ================================================ Handler when called directly
933:
934:
935: sub handler {
936: my $r = shift;
1.93 www 937: &Apache::loncommon::content_type($r,'text/html');
1.33 www 938: $r->send_http_header;
939: return OK if $r->header_only;
940:
1.42 www 941: my $form=&serverform();
1.34 www 942: my $bodytag=&Apache::loncommon::bodytag('Main Menu');
1.58 www 943: my $function='student';
944: if ($ENV{'request.role'}=~/^(cc|in|ta|ep)/) {
945: $function='coordinator';
946: }
947: if ($ENV{'request.role'}=~/^(su|dc|ad|li)/) {
948: $function='admin';
949: }
950: if (($ENV{'request.role'}=~/^(au|ca)/) ||
1.97 www 951: ($ENV{'request.noversionuri'}=~/^(\/priv|\~)/)) {
1.58 www 952: $function='author';
953: }
954: my $domain=&Apache::loncommon::determinedomain();
955: $pgbg=&Apache::loncommon::designparm($function.'.pgbg',$domain);
956: $tabbg=&Apache::loncommon::designparm($function.'.tabbg',$domain);
957: $font=&Apache::loncommon::designparm($function.'.font',$domain);
1.53 www 958: # ---- Print the screen, pretent to be in text mode to generate text-based menu
1.103 www 959: unless ($ENV{'browser.interface'} eq 'textual') {
960: $ENV{'browser.interface'}='faketextual';
1.53 www 961: $ENV{'environment.remote'}='off';
962: }
963: my $utility=&utilityfunctions();
1.36 www 964: $r->print(<<ENDHEADER);
965: <html><head>
966: <title>LON-CAPA Main Menu</title>
967: <script>
1.42 www 968: $utility
1.36 www 969: </script>
970: </head>
971: $bodytag
972: ENDHEADER
1.58 www 973: $r->print('<table>'.&inlinemenu().'</table>'.$form);
1.33 www 974: $r->print('</body></html>');
975: return OK;
1.1 www 976: }
977:
1.2 www 978: # ================================================================ Main Program
979:
1.16 harris41 980: BEGIN {
1.15 matthew 981: if (! defined($readdesk)) {
1.14 www 982: {
1.104 raeburn 983: my $tabfile = $Apache::lonnet::perlvar{'lonTabDir'}.'/mydesk.tab';
984: if ( CORE::open( my $config,"<$tabfile") ) {
985: while (my $configline=<$config>) {
986: $configline=(split(/\#/,$configline))[0];
987: $configline=~s/^\s+//;
988: chomp($configline);
989: if ($configline) {
990: $desklines[$#desklines+1]=$configline;
991: }
992: }
993: CORE::close($config);
1.2 www 994: }
1.14 www 995: }
996: $readdesk='done';
1.10 albertel 997: }
1.2 www 998: }
1.30 www 999:
1.1 www 1000: 1;
1001: __END__
1002:
1003:
1004:
1005:
1006:
1007:
1008:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>