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