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