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