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