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