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