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