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