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