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