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