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