Annotation of loncom/interface/lonmenu.pm, revision 1.119
1.1 www 1: # The LearningOnline Network with CAPA
2: # Routines to control the menu
3: #
1.119 ! www 4: # $Id: lonmenu.pm,v 1.118 2004/10/28 16:25:21 albertel 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.115 albertel 42: use Apache::lonnet();
1.33 www 43: use Apache::Constants qw(:common);
1.47 matthew 44: use Apache::lonhtmlcommon();
1.115 albertel 45: use Apache::loncommon();
46: use Apache::lonnavmaps();
1.88 www 47: use Apache::lonlocal;
48:
1.2 www 49: use vars qw(@desklines $readdesk);
1.88 www 50:
51:
1.56 www 52: my @inlineremote;
1.58 www 53: my $font;
54: my $tabbg;
55: my $pgbg;
1.38 www 56:
1.88 www 57: # ================================================================ Little texts
58:
59: sub initlittle {
60: return &Apache::lonlocal::texthash('ret' => 'Return to Last Location',
61: 'nav' => 'Navigate Contents',
62: 'main' => 'Main Menu',
63: 'launch' => 'Launch Remote Control');
64: }
65:
1.40 www 66: # ============================= This gets called at the top of the body section
1.38 www 67:
68: sub menubuttons {
69: my $forcereg=shift;
70: my $target =shift;
1.40 www 71: my $registration=shift;
1.112 albertel 72: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
73: ['inhibitmenu']);
74: if ($ENV{'form.inhibitmenu'} eq 'yes') { return ''; }
75:
1.55 www 76: my $navmaps='';
1.59 www 77: my $reloadlink='';
1.97 www 78: my $escurl=&Apache::lonnet::escape($ENV{'request.noversionuri'});
1.55 www 79: my $escsymb=&Apache::lonnet::escape($ENV{'request.symb'});
1.48 www 80: if ($ENV{'browser.interface'} eq 'textual') {
1.41 www 81: # Textual display only
1.88 www 82: my %lt=&initlittle();
1.101 www 83: $pgbg='#FFFFFF';
84: $tabbg='#FFFFFF';
85: $font='#000000';
1.55 www 86: if ($ENV{'request.course.id'}) {
87: $navmaps=(<<ENDNAV);
1.88 www 88: <a href="/adm/navmaps?postdata=$escurl&postsymb=$escsymb" target="_top">$lt{'nav'}</a>
1.55 www 89: ENDNAV
1.97 www 90: if (($ENV{'request.noversionuri'}=~/^\/adm\//) &&
91: ($ENV{'request.noversionuri'}!~/^\/adm\/wrapper\//) &&
92: ($ENV{'request.noversionuri'}!~/^\/adm\/.*\/(smppg|bulletinboard|aboutme)(\?|$)/)) {
1.59 www 93: my $escreload=&Apache::lonnet::escape('return:');
94: $reloadlink=(<<ENDRELOAD);
1.88 www 95: <a href="/adm/flip?postdata=$escreload" target="_top"><font color="$font">$lt{'ret'}</font></a>
1.59 www 96: ENDRELOAD
97: }
1.55 www 98: }
1.116 albertel 99: my $utility=&utilityfunctions();
1.48 www 100: my $output=(<<ENDMAINMENU);
1.44 www 101: <script>
102: // BEGIN LON-CAPA Internal
1.116 albertel 103: $utility
1.44 www 104: </script>
1.88 www 105: <a href="/adm/menu" target="_top">$lt{'main'}</a>
1.59 www 106: $reloadlink $navmaps<br />
1.44 www 107: <script>
108: // END LON-CAPA Internal
109: </script>
110: ENDMAINMENU
1.48 www 111: if ($registration) { $output.=&innerregister($forcereg,$target); }
112: return $output."<hr />";
113: } elsif ($ENV{'environment.remote'} eq 'off') {
114: # Remote Control is switched off
1.58 www 115: # figure out colors
1.88 www 116: my %lt=&initlittle();
1.58 www 117: my $function='student';
118: if ($ENV{'request.role'}=~/^(cc|in|ta|ep)/) {
119: $function='coordinator';
120: }
121: if ($ENV{'request.role'}=~/^(su|dc|ad|li)/) {
122: $function='admin';
123: }
124: if (($ENV{'request.role'}=~/^(au|ca)/) ||
1.97 www 125: ($ENV{'request.noversionuri'}=~/^(\/priv|\~)/)) {
1.58 www 126: $function='author';
127: }
128: my $domain=&Apache::loncommon::determinedomain();
129: $pgbg=&Apache::loncommon::designparm($function.'.pgbg',$domain);
130: $tabbg=&Apache::loncommon::designparm($function.'.tabbg',$domain);
131: $font=&Apache::loncommon::designparm($function.'.font',$domain);
132: my $link=&Apache::loncommon::designparm($function.'.link',$domain);
133: my $alink=&Apache::loncommon::designparm($function.'.alink',$domain);
134: my $vlink=&Apache::loncommon::designparm($function.'.vlink',$domain);
135: my $sidebg=&Apache::loncommon::designparm($function.'.sidebg',$domain);
136: # Do we have a NAV link?
1.55 www 137: if ($ENV{'request.course.id'}) {
1.116 albertel 138: $navmaps=(<<ENDNAV);
1.58 www 139: <td bgcolor="$tabbg">
1.114 albertel 140: <a href="javascript:gonav('/adm/navmaps?postdata=$escurl&postsymb=$escsymb')"><font color="$font">$lt{'nav'}</font></a></td>
141: ENDNAV
142: if (($ENV{'request.noversionuri'}=~/^\/adm\//) &&
1.97 www 143: ($ENV{'request.noversionuri'}!~/^\/adm\/wrapper\//) &&
144: ($ENV{'request.noversionuri'}!~/^\/adm\/.*\/(smppg|bulletinboard|aboutme)(\?|$)/)) {
1.59 www 145: my $escreload=&Apache::lonnet::escape('return:');
146: $reloadlink=(<<ENDRELOAD);
147: <td bgcolor="$tabbg">
1.88 www 148: <a href="/adm/flip?postdata=$escreload" target="_top"><font color="$font">$lt{'ret'}</font></a></td>
1.59 www 149: ENDRELOAD
150: }
1.55 www 151: }
1.58 www 152: my $reg='';
153: if ($registration) {
154: $reg=&innerregister($forcereg,$target);
155: }
1.116 albertel 156: my $utility=&utilityfunctions();
1.58 www 157: return (<<ENDINLINEMENU);
1.48 www 158: <script>
159: // BEGIN LON-CAPA Internal
1.116 albertel 160: $utility
1.48 www 161: </script>
1.99 www 162: <font face="Arial,Helvetica,sans-serif"><table bgcolor="$pgbg" width="100%" border="0" cellpadding="1" cellspacing="1">
1.58 www 163: <tr>
164: <td bgcolor="$tabbg">
1.88 www 165: <a href="/adm/menu" target="_top"><font color="$font">$lt{'main'}</font></a>
1.58 www 166: </td>
1.59 www 167: $reloadlink
1.55 www 168: $navmaps
1.58 www 169: <td bgcolor="$tabbg">
1.117 albertel 170: <a href="/adm/remote?action=launch&url=$escurl" target="_top">
1.88 www 171: <font color="$font">$lt{'launch'}</font></a></td>
1.65 www 172: <td bgcolor="$tabbg">
173: <img align="right" src="/adm/lonIcons/minilogo.gif" />
174: <b>LON-CAPA</b></td>
1.58 www 175: </tr>
176: </table>
1.99 www 177: </font>
1.48 www 178: <script>
179: // END LON-CAPA Internal
180: </script>
1.58 www 181: $reg
1.48 www 182: ENDINLINEMENU
183: } else {
184: return '';
185: }
1.72 www 186: }
187:
1.40 www 188: # ====================================== This gets called in the header section
1.38 www 189:
190: sub registerurl {
191: my $forcereg=shift;
192: my $target = shift;
193: my $result = '';
1.97 www 194: if ($ENV{'request.noversionuri'} eq '/res/adm/pages/menu.html') { return ''; }
1.66 albertel 195: my $force_title='';
196: if ($ENV{'request.state'} eq 'construct') {
197: $force_title=&Apache::lonxml::display_title();
198: }
1.38 www 199: if ($target eq 'edit') {
1.45 www 200: $result .="<script type=\"text/javascript\">\n".
1.38 www 201: "if (typeof swmenu != 'undefined') {swmenu.currentURL=null;}\n".
202: &Apache::loncommon::browser_and_searcher_javascript().
203: "\n</script>\n";
204: }
205: if (($ENV{'browser.interface'} eq 'textual') ||
1.53 www 206: ($ENV{'environment.remote'} eq 'off') ||
1.38 www 207: ((($ENV{'request.publicaccess'}) ||
1.83 www 208: (!&Apache::lonnet::is_on_map(
1.97 www 209: &Apache::lonnet::unescape($ENV{'request.noversionuri'})))) &&
1.38 www 210: (!$forcereg))) {
1.76 www 211: return $result.
212: '<script type="text/javascript">function LONCAPAreg(){;} function LONCAPAstale(){}</script>'.$force_title;
1.38 www 213: }
1.41 www 214: # Graphical display after login only
1.38 www 215: if ($Apache::lonxml::registered && !$forcereg) { return ''; }
1.96 albertel 216: if ($target ne 'edit') {
217: $result.=&innerregister($forcereg,$target);
218: }
1.66 albertel 219: return $result.$force_title;
1.40 www 220: }
221:
222: # =========== This gets called in order to register a URL, both with the Remote
223: # =========== and in the body of the document
224:
225: sub innerregister {
226: my $forcereg=shift;
227: my $target = shift;
228: my $result = '';
1.97 www 229: if ($ENV{'request.noversionuri'} eq '/res/adm/pages/menu.html') { return ''; }
1.40 www 230:
1.38 www 231: $Apache::lonxml::registered=1;
1.40 www 232:
1.49 www 233: my $textinter=($ENV{'browser.interface'} eq 'textual');
234: my $noremote=($ENV{'environment.remote'} eq 'off');
235:
236: my $textual=($textinter || $noremote);
237:
1.56 www 238: @inlineremote=();
239: undef @inlineremote;
240:
1.38 www 241: my $reopen=&Apache::lonmenu::reopenmenu();
1.40 www 242:
1.38 www 243: my $newmail='';
1.65 www 244: if ($noremote) {
1.99 www 245: $newmail='<font face="Arial,Helvetica,sans-serif"><table bgcolor="'.$pgbg.'" border="0" cellspacing="1" cellpadding="1" width="100%"><tr><td bgcolor="'.$tabbg.'">';
1.65 www 246: }
1.61 www 247: if (($textual) && ($ENV{'request.symb'}) && ($ENV{'request.course.id'})) {
1.87 www 248: my ($mapurl,$rid,$resurl)=&Apache::lonnet::decode_symb($ENV{'request.symb'});
1.65 www 249: $newmail.=$ENV{'course.'.$ENV{'request.course.id'}.'.description'};
1.61 www 250: my $maptitle=&Apache::lonnet::gettitle($mapurl);
251: my $restitle=&Apache::lonnet::gettitle($resurl);
252: if ($maptitle) {
253: $newmail.=', '.$maptitle;
254: }
255: if ($restitle) {
256: $newmail.=': '.$restitle;
257: }
258: $newmail.=' ';
1.60 www 259: }
1.38 www 260: if (&Apache::lonmsg::newmail()) {
1.41 www 261: $newmail=($textual?
1.80 www 262: '<b><a href="/adm/communicate" target="_top">You have new messages</a></b><br />':
1.40 www 263: 'swmenu.setstatus("you have","messages");');
1.65 www 264: }
265: if ($noremote) {
1.99 www 266: $newmail.='</td></tr></table></font>';
1.38 www 267: }
1.40 www 268: my $timesync=($textual?'':'swmenu.syncclock(1000*'.time.');');
1.100 www 269: my $tablestart=($noremote?'<font face="Arial,Helvetica,sans-serif"><table bgcolor="'.$pgbg.'" border="0" cellspacing="1" cellpadding="1" width="100%">':'').($textinter?'<br /><a href="#content">'.&mt('Skip to Content').'</a><br />':'');
270: my $tableend=($noremote?'</table></font>':'').($textinter?'<a name="content" />':'');
1.41 www 271: # =============================================================================
272: # ============================ This is for URLs that actually can be registered
1.97 www 273: if (($ENV{'request.noversionuri'}!~/^\/(res\/)*adm\//) || ($forcereg)) {
1.40 www 274: # -- This applies to homework problems for users with grading privileges
1.107 albertel 275: my $crs='/'.$ENV{'request.course.id'};
276: if ($ENV{'request.course.sec'}) {
277: $crs.='_'.$ENV{'request.course.sec'};
278: }
279: $crs=~s/\_/\//g;
280:
1.38 www 281: my $hwkadd='';
1.107 albertel 282: if ($ENV{'request.filename'}=~/\.(problem|exam|quiz|assess|survey|form)$/) {
1.79 www 283: if (&Apache::lonnet::allowed('vgr',$crs)) {
1.106 www 284: $hwkadd.=&switch('','',7,1,'subm.gif','view sub-[_1]','missions[_1]',
1.40 www 285: "gocmd('/adm/grades','submission')",
286: 'View user submissions for this assessment resource');
1.38 www 287: }
1.79 www 288: if (&Apache::lonnet::allowed('mgr',$crs)) {
1.106 www 289: $hwkadd.=&switch('','',7,2,'pgrd.gif','problem[_1]','grades[_3]',
1.40 www 290: "gocmd('/adm/grades','gradingmenu')",
291: 'Modify user grades for this assessment resource');
1.38 www 292: }
1.107 albertel 293: }
294: if (&Apache::lonnet::allowed('opa',$crs)) {
295: $hwkadd.=&switch('','',7,3,'pparm.gif','problem[_2]','parms[_2]',
296: "gocmd('/adm/parmset','set')",
297: 'Modify deadlines, etc, for this resource');
1.38 www 298: }
1.40 www 299: # -- End Homework
1.38 www 300: ###
301: ### Determine whether or not to display the 'cstr' button for this
302: ### resource
303: ###
304: my $editbutton = '';
305: if ($ENV{'user.author'}) {
306: if ($ENV{'request.role'}=~/^(ca|au)/) {
307: # Set defaults for authors
308: my ($top,$bottom) = ('con-','struct');
309: my $action = "go('/priv/".$ENV{'user.name'}."');";
310: my $cadom = $ENV{'request.role.domain'};
311: my $caname = $ENV{'user.name'};
312: my $desc = "Enter my resource construction space";
313: # Set defaults for co-authors
314: if ($ENV{'request.role'} =~ /^ca/) {
315: ($cadom,$caname)=($ENV{'request.role'}=~/(\w+)\/(\w+)$/);
316: ($top,$bottom) = ('co con-','struct');
317: $action = "go('/priv/".$caname."');";
318: $desc = "Enter construction space as co-author";
319: }
320: # Check that we are on the correct machine
321: my $home = &Apache::lonnet::homeserver($caname,$cadom);
1.109 albertel 322: my $allowed=0;
323: my @ids=&Apache::lonnet::current_machine_ids();
324: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
325: if (!$allowed) {
326: $editbutton=&switch('','',6,1,$top,,$bottom,$action,$desc);
1.38 www 327: }
328: }
329: ##
330: ## Determine if user can edit url.
331: ##
332: my $cfile='';
333: my $cfuname='';
334: my $cfudom='';
335: if ($ENV{'request.filename'}) {
336: my $file=&Apache::lonnet::declutter($ENV{'request.filename'});
337: $file=~s/^(\w+)\/(\w+)/\/priv\/$2/;
1.109 albertel 338: # Check that the user has permission to edit this resource
1.38 www 339: ($cfuname,$cfudom)=&Apache::loncacc::constructaccess($file,$1);
340: if (defined($cfudom)) {
1.109 albertel 341: my $home=&Apache::lonnet::homeserver($cfuname,$cfudom);
342: my $allowed=0;
343: my @ids=&Apache::lonnet::current_machine_ids();
344: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
345: if ($allowed) {
1.38 www 346: $cfile=$file;
347: }
348: }
349: }
350: # Finally, turn the button on or off
351: if ($cfile) {
1.40 www 352: $editbutton=&switch
1.106 www 353: ('','',6,1,'cstr.gif','edit[_1]','resource[_2]',
1.38 www 354: "go('".$cfile."');","Edit this resource");
355: } elsif ($editbutton eq '') {
1.40 www 356: $editbutton=&clear(6,1);
1.38 www 357: }
358: }
359: ###
360: ###
1.41 www 361: # Prepare the rest of the buttons
362: my $menuitems=(<<ENDMENUITEMS);
363: c&3&1
1.106 www 364: s&2&1&back.gif&backward[_1]&&gopost('/adm/flip','back:'+currentURL)&Go to the previous resource in the course sequence&1
365: s&2&3&forw.gif&forward[_1]&&gopost('/adm/flip','forward:'+currentURL)&Go to the next resource in the course sequence&3
1.77 www 366: c&6&3
367: c&8&1
368: c&8&2
1.106 www 369: s&8&3&prt.gif&prepare[_1]&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
370: s&9&1&sbkm.gif&set[_1]&bookmark[_2]&set_bookmark()&Set a bookmark for this resource&2
371: s&9&3&anot.gif&anno-[_1]&tations[_1]&annotate()&Make notes and annotations about this resource&2
1.41 www 372: ENDMENUITEMS
1.97 www 373: unless ($ENV{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme)(\?|$)/) {
1.77 www 374: $menuitems.=(<<ENDREALRES);
1.106 www 375: s&6&3&catalog.gif&catalog[_1]&info[_1]&catalog_info()&Show catalog information
376: s&8&1&eval.gif&evaluate[_1]&this[_1]&gopost('/adm/evaluate',currentURL,1)&Provide my evaluation of this resource
377: s&8&2&fdbk.gif&feedback[_1]&discuss[_1]&gopost('/adm/feedback',currentURL,1)&Provide feedback messages or contribute to the course discussion about this resource
1.77 www 378: ENDREALRES
379: }
1.41 www 380: my $buttons='';
381: foreach (split(/\n/,$menuitems)) {
382: my ($command,@rest)=split(/\&/,$_);
383: if ($command eq 's') {
384: $buttons.=&switch('','',@rest);
385: } else {
386: $buttons.=&clear(@rest);
387: }
388: }
389: if ($textual) {
390: # Registered, textual output
1.42 www 391: my $form=&serverform();
1.103 www 392: my $inlinebuttons='';
393:
394: if ($ENV{'browser.interface'} eq 'textual') {
395: $inlinebuttons=
1.56 www 396: join('',map { (defined($_)?$_:'') } @inlineremote);
1.103 www 397: } else {
398: $inlinebuttons=(<<ENDINLINE);
399: <tr><td>$inlineremote[21]</td><td> </td><td>$inlineremote[23]</td></tr>
400: <tr><td>$inlineremote[61]</td><td>$inlineremote[62]</td><td>$inlineremote[63]</td></tr>
401: <tr><td>$inlineremote[71]</td><td>$inlineremote[72]</td><td>$inlineremote[73]</td></tr>
402: <tr><td>$inlineremote[81]</td><td>$inlineremote[82]</td><td>$inlineremote[83]</td></tr>
403: <tr><td>$inlineremote[91]</td><td>$inlineremote[92]</td><td>$inlineremote[93]</td></tr>
404: ENDINLINE
405: }
1.41 www 406: $result =(<<ENDREGTEXT);
1.42 www 407: <script>
408: // BEGIN LON-CAPA Internal
409: </script>
1.41 www 410: $timesync
411: $newmail
1.58 www 412: $tablestart
1.56 www 413: $inlinebuttons
1.58 www 414: $tableend
1.42 www 415: $form
416: <script>
1.64 www 417: // END LON-CAPA Internal
1.42 www 418: </script>
419:
1.41 www 420: ENDREGTEXT
421: # Registered, graphical output
422: } else {
1.97 www 423: my $requri=(split(/\?/,$ENV{'request.noversionuri'}))[0];
1.86 albertel 424: $requri=&Apache::lonnet::unescape($requri);
1.113 albertel 425: my $navstatus=&get_nav_status();
1.41 www 426: $result = (<<ENDREGTHIS);
1.38 www 427:
428: <script language="JavaScript">
429: // BEGIN LON-CAPA Internal
1.42 www 430: var swmenu=null;
1.38 www 431:
432: function LONCAPAreg() {
433: swmenu=$reopen;
434: swmenu.clearTimeout(swmenu.menucltim);
435: $timesync
436: $newmail
1.41 www 437: $buttons
1.84 www 438: swmenu.currentURL="$requri";
1.85 www 439: swmenu.reloadURL=swmenu.currentURL+window.location.search;
1.38 www 440: swmenu.currentSymb="$ENV{'request.symb'}";
441: swmenu.reloadSymb="$ENV{'request.symb'}";
442: swmenu.currentStale=0;
1.113 albertel 443: $navstatus
1.38 www 444: $hwkadd
445: $editbutton
446: }
447:
448: function LONCAPAstale() {
449: swmenu=$reopen
450: swmenu.currentStale=1;
451: if (swmenu.reloadURL!='' && swmenu.reloadURL!= null) {
452: swmenu.switchbutton
453: (3,1,'reload.gif','return','location','go(reloadURL)','Return to the last known location in the course sequence');
454: }
455: swmenu.clearbut(7,1);
456: swmenu.clearbut(7,2);
457: swmenu.clearbut(7,3);
458: swmenu.menucltim=swmenu.setTimeout(
459: 'clearbut(2,1);clearbut(2,3);clearbut(8,1);clearbut(8,2);clearbut(8,3);'+
1.108 www 460: 'clearbut(9,1);clearbut(9,3);clearbut(6,3);clearbut(6,1)',
1.38 www 461: 2000);
462: }
463:
464: // END LON-CAPA Internal
465: </script>
466: ENDREGTHIS
1.41 www 467: }
468: # =============================================================================
1.38 www 469: } else {
1.41 www 470: # ========================================== This can or will not be registered
471: if ($textual) {
472: # Not registered, textual
473: $result= (<<ENDDONOTREGTEXT);
474: ENDDONOTREGTEXT
475: } else {
476: # Not registered, graphical
477: $result = (<<ENDDONOTREGTHIS);
1.38 www 478:
479: <script language="JavaScript">
480: // BEGIN LON-CAPA Internal
1.42 www 481: var swmenu=null;
1.38 www 482:
483: function LONCAPAreg() {
484: swmenu=$reopen
485: $timesync
486: swmenu.currentStale=1;
487: swmenu.clearbut(2,1);
488: swmenu.clearbut(2,3);
489: swmenu.clearbut(8,1);
490: swmenu.clearbut(8,2);
491: swmenu.clearbut(8,3);
492: if (swmenu.currentURL) {
493: swmenu.switchbutton
494: (3,1,'reload.gif','return','location','go(currentURL)');
495: } else {
496: swmenu.clearbut(3,1);
497: }
498: }
499:
500: function LONCAPAstale() {
501: }
502:
503: // END LON-CAPA Internal
504: </script>
505: ENDDONOTREGTHIS
1.41 www 506: }
507: # =============================================================================
1.38 www 508: }
509: return $result;
510: }
511:
512: sub loadevents() {
1.97 www 513: if ($ENV{'request.noversionuri'} eq '/res/adm/pages/menu.html') { return ''; }
1.38 www 514: return 'LONCAPAreg();';
515: }
516:
517: sub unloadevents() {
1.97 www 518: if ($ENV{'request.noversionuri'} eq '/res/adm/pages/menu.html') { return ''; }
1.38 www 519: return 'LONCAPAstale();';
520: }
1.30 www 521:
1.32 www 522: # ============================================================= Start up remote
523:
524: sub startupremote {
525: my ($lowerurl)=@_;
1.49 www 526: if (($ENV{'browser.interface'} eq 'textual') ||
527: ($ENV{'environment.remote'} eq 'off')) {
1.34 www 528: return ('<meta HTTP-EQUIV="Refresh" CONTENT="0.5; url='.$lowerurl.'" />');
529: }
1.49 www 530: #
531: # The Remote actually gets launched!
532: #
1.32 www 533: my $configmenu=&rawconfig();
1.52 www 534: my $esclowerurl=&Apache::lonnet::escape($lowerurl);
1.119 ! www 535: my $message=&mt('"Waiting for Remote Control window to load: "+[_1]','waited');
1.32 www 536: return(<<ENDREMOTESTARTUP);
537: <script>
1.118 albertel 538: var timestart;
1.35 www 539: function wheelswitch() {
1.118 albertel 540: if (typeof(document.wheel) != 'undefined') {
541: if (typeof(document.wheel.spin) != 'undefined') {
542: var date=new Date();
543: var waited=Math.round(30-((date.getTime()-timestart)/1000));
544: document.wheel.spin.value=$message;
545: }
546: }
1.35 www 547: if (window.status=='|') {
548: window.status='/';
549: } else {
550: if (window.status=='/') {
551: window.status='-';
552: } else {
553: if (window.status=='-') {
554: window.status='\\\\';
555: } else {
556: if (window.status=='\\\\') { window.status='|'; }
557: }
558: }
559: }
560: }
561:
1.32 www 562: // ---------------------------------------------------------- The wait function
563: var canceltim;
564: function wait() {
565: if ((menuloaded==1) || (tim==1)) {
1.35 www 566: window.status='Done.';
1.32 www 567: if (tim==0) {
568: clearTimeout(canceltim);
569: $configmenu
570: window.location='$lowerurl';
571: } else {
1.52 www 572: window.location='/adm/remote?action=collapse&url=$esclowerurl';
1.32 www 573: }
574: } else {
1.35 www 575: wheelswitch();
576: setTimeout('wait();',200);
1.32 www 577: }
578: }
579:
580: function main() {
1.52 www 581: canceltim=setTimeout('tim=1;',30000);
1.35 www 582: window.status='-';
1.118 albertel 583: var date=new Date();
584: timestart=date.getTime();
1.32 www 585: wait();
586: }
587:
588: </script>
589: ENDREMOTESTARTUP
590: }
591:
592: sub setflags() {
593: return(<<ENDSETFLAGS);
594: <script>
595: menuloaded=0;
596: tim=0;
597: </script>
598: ENDSETFLAGS
599: }
600:
601: sub maincall() {
1.49 www 602: if (($ENV{'browser.interface'} eq 'textual') ||
603: ($ENV{'environment.remote'} eq 'off')) { return ''; }
1.32 www 604: return(<<ENDMAINCALL);
605: <script>
606: main();
607: </script>
608: ENDMAINCALL
609: }
1.118 albertel 610:
611: sub load_remote_msg {
612: my ($lowerurl)=@_;
613:
614: if (($ENV{'browser.interface'} eq 'textual') ||
615: ($ENV{'environment.remote'} eq 'off')) { return ''; }
616:
617: my $esclowerurl=&Apache::lonnet::escape($lowerurl);
1.119 ! www 618: my $link=&mt('<a href="[_1]">Continue</a> on in Inline Menu mode',
1.118 albertel 619: "/adm/remote?action=collapse?url=$esclowerurl");
620: return(<<ENDREMOTEFORM);
621: <p>
622: <form name="wheel">
1.119 ! www 623: <input name="spin" type="text" size="60" />
1.118 albertel 624: </form>
625: </p>
626: <p>$link</p>
627: ENDREMOTEFORM
628: }
1.30 www 629: # ================================================================= Reopen menu
630:
631: sub reopenmenu {
1.49 www 632: if (($ENV{'browser.interface'} eq 'textual') ||
633: ($ENV{'environment.remote'} eq 'off')) { return ''; }
1.30 www 634: my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
1.47 matthew 635: my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
636: return('window.open('.$nothing.',"'.$menuname.'","",false);');
1.30 www 637: }
638:
1.1 www 639: # =============================================================== Open the menu
640:
641: sub open {
1.22 www 642: my $returnval='';
1.49 www 643: if (($ENV{'browser.interface'} eq 'textual') ||
1.111 albertel 644: ($ENV{'environment.remote'} eq 'off')) {
645: return '<script type="text/javascript">self.name="loncapaclient";</script>';
646: }
1.30 www 647: my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
1.22 www 648: unless (shift eq 'unix') {
649: # resizing does not work on linux because of virtual desktop sizes
650: $returnval.=(<<ENDRESIZE);
651: if (window.screen) {
1.28 www 652: self.resizeTo(screen.availWidth-215,screen.availHeight-55);
1.22 www 653: self.moveTo(190,15);
654: }
655: ENDRESIZE
656: }
657: $returnval.=(<<ENDOPEN);
1.35 www 658: window.status='Opening LON-CAPA Remote Control';
1.30 www 659: var menu=window.open("/res/adm/pages/menu.html","$menuname",
1.14 www 660: "height=350,width=150,scrollbars=no,menubar=no,top=5,left=5,screenX=5,screenY=5");
1.71 www 661: self.name='loncapaclient';
1.1 www 662: ENDOPEN
1.22 www 663: return '<script>'.$returnval.'</script>';
1.1 www 664: }
665:
1.2 www 666:
667: # ================================================================== Raw Config
668:
1.3 www 669: sub clear {
670: my ($row,$col)=@_;
1.49 www 671: unless (($ENV{'browser.interface'} eq 'textual') ||
672: ($ENV{'environment.remote'} eq 'off')) {
1.35 www 673: return "\n".qq(window.status+='.';swmenu.clearbut($row,$col););
1.56 www 674: } else {
675: $inlineremote[10*$row+$col]='';
676: return '';
677: }
1.3 www 678: }
679:
1.40 www 680: # ============================================ Switch a button or create a link
1.25 matthew 681: # Switch acts on the javascript that is executed when a button is clicked.
682: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
1.40 www 683:
1.2 www 684: sub switch {
1.40 www 685: my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$nobreak)=@_;
1.2 www 686: $act=~s/\$uname/$uname/g;
687: $act=~s/\$udom/$udom/g;
1.88 www 688: $top=&mt($top);
689: $bot=&mt($bot);
690: $desc=&mt($desc);
1.105 www 691: $img=&mt($img);
1.49 www 692: unless (($ENV{'browser.interface'} eq 'textual') ||
693: ($ENV{'environment.remote'} eq 'off')) {
1.50 www 694: # Remote
1.34 www 695: return "\n".
1.35 www 696: qq(window.status+='.';swmenu.switchbutton($row,$col,"$img","$top","$bot","$act","$desc"););
1.50 www 697: } elsif ($ENV{'browser.interface'} eq 'textual') {
698: # Accessibility
699: if ($nobreak==2) { return ''; }
700: my $text=$top.' '.$bot;
1.78 www 701: $text=~s/\s*\-\s*//gs;
1.94 www 702: if ($nobreak) {
703: $inlineremote[10*$row+$col]=
704: '<a href="javascript:'.$act.';">'.$text.'</a>';
705: } else {
706: $inlineremote[10*$row+$col]="\n<br />".
1.100 www 707: $desc.' <a href="javascript:'.$act.';">'.$text.'</a>';
1.94 www 708: }
1.34 www 709: } else {
1.50 www 710: # Inline Remote
1.41 www 711: if ($nobreak==2) { return ''; }
1.34 www 712: my $text=$top.' '.$bot;
1.78 www 713: $text=~s/\s*\-\s*//gs;
1.105 www 714:
715: my $lonhttpdPort=$Apache::lonnet::perlvar{'lonhttpdPort'};
716: if (!defined($lonhttpdPort)) { $lonhttpdPort='8080'; }
1.99 www 717: my $pic=
1.105 www 718: '<img border="0" alt="'.$text.'" src="http://'.$ENV{'HTTP_HOST'}.
719: ':'.$lonhttpdPort.'/res/adm/pages/'.$img.'" align="'.
1.103 www 720: ($nobreak==3?'right':'left').'" />';
721: if (($ENV{'browser.interface'} eq 'textual') || ($ENV{'browser.interface'} eq 'faketextual')) {
722: # Accessibility
723: if ($nobreak==3) {
724: $inlineremote[10*$row+$col]="\n".
725: '<td width="40%" align="right"><font color="'.$font.'" size="+1">'.$text.
726: '</font></td><td width="10%" align="right" bgcolor="'.$tabbg.'">'.
727: '<a href="javascript:'.$act.';">'.$pic.'</a></td></tr>';
728: } elsif ($nobreak) {
729: $inlineremote[10*$row+$col]="\n<tr>".
730: '<td width="10%" align="left" bgcolor="'.$tabbg.'">'.
731: '<a href="javascript:'.$act.';">'.$pic.
732: '</a></td><td width="40%" align="left"><font color="'.$font.'" size="+1">'.$text.'</font></td>';
733: } else {
734: $inlineremote[10*$row+$col]="\n<tr>".
735: '<td width="10%" align="left" bgcolor="'.$tabbg.'">'.
736: '<a href="javascript:'.$act.';">'.$pic.
737: '</a></td><td colspan="3"><font color="'.$font.'">'.$desc.
738: '</font></td></tr>';
739: }
1.94 www 740: } else {
1.103 www 741: # Inline Menu
742: $inlineremote[10*$row+$col]=
743: '<a href="javascript:'.$act.';">'.$pic.
744: '</a><font color="'.$font.'" size="2">'.$desc.
745: '</font>';
1.94 www 746: }
1.34 www 747: }
1.56 www 748: return '';
1.2 www 749: }
750:
751: sub secondlevel {
752: my $output='';
753: my
1.27 www 754: ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc)=@_;
1.2 www 755: if ($prt eq 'any') {
1.27 www 756: $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
1.2 www 757: } elsif ($prt=~/^r(\w+)/) {
758: if ($rol eq $1) {
1.27 www 759: $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
1.2 www 760: }
761: }
762: return $output;
763: }
764:
1.18 www 765: sub openmenu {
1.30 www 766: my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
1.49 www 767: if (($ENV{'browser.interface'} eq 'textual') ||
768: ($ENV{'environment.remote'} eq 'off')) { return ''; }
1.47 matthew 769: my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
770: return "window.open(".$nothing.",'".$menuname."');";
1.18 www 771: }
772:
1.56 www 773: sub inlinemenu {
774: @inlineremote=();
775: undef @inlineremote;
776: &rawconfig(1);
777: return join('',map { (defined($_)?$_:'') } @inlineremote);
778: }
779:
1.2 www 780: sub rawconfig {
1.34 www 781: my $textualoverride=shift;
782: my $output='';
1.49 www 783: unless (($ENV{'browser.interface'} eq 'textual') ||
784: ($ENV{'environment.remote'} eq 'off')) {
1.35 www 785: $output.=
786: "window.status='Opening Remote Control';var swmenu=".&openmenu().
787: "\nwindow.status='Configuring Remote Control ';";
1.34 www 788: } else {
789: unless ($textualoverride) { return ''; }
790: }
1.2 www 791: my $uname=$ENV{'user.name'};
792: my $udom=$ENV{'user.domain'};
793: my $adv=$ENV{'user.adv'};
1.4 www 794: my $author=$ENV{'user.author'};
1.5 www 795: my $crs='';
796: if ($ENV{'request.course.id'}) {
797: $crs='/'.$ENV{'request.course.id'};
1.7 www 798: if ($ENV{'request.course.sec'}) {
799: $crs.='_'.$ENV{'request.course.sec'};
800: }
1.8 www 801: $crs=~s/\_/\//g;
1.5 www 802: }
1.2 www 803: my $pub=($ENV{'request.state'} eq 'published');
804: my $con=($ENV{'request.state'} eq 'construct');
805: my $rol=$ENV{'request.role'};
1.25 matthew 806: my $requested_domain = $ENV{'request.role.domain'};
1.13 harris41 807: foreach (@desklines) {
1.27 www 808: my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc)=split(/\:/,$_);
1.3 www 809: $prt=~s/\$uname/$uname/g;
810: $prt=~s/\$udom/$udom/g;
1.5 www 811: $prt=~s/\$crs/$crs/g;
1.25 matthew 812: $prt=~s/\$requested_domain/$requested_domain/g;
1.3 www 813: if ($pro eq 'clear') {
1.4 www 814: $output.=&clear($row,$col);
1.3 www 815: } elsif ($pro eq 'any') {
1.2 www 816: $output.=&secondlevel(
1.27 www 817: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
1.2 www 818: } elsif ($pro eq 'smp') {
819: unless ($adv) {
820: $output.=&secondlevel(
1.27 www 821: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
1.2 www 822: }
823: } elsif ($pro eq 'adv') {
824: if ($adv) {
825: $output.=&secondlevel(
1.27 www 826: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
1.2 www 827: }
1.81 matthew 828: } elsif (($pro=~/^p(\w+)/) && ($prt)) {
1.2 www 829: if (&Apache::lonnet::allowed($1,$prt)) {
1.27 www 830: $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
1.4 www 831: }
1.26 www 832: } elsif ($pro eq 'course') {
833: if ($ENV{'request.course.fn'}) {
1.27 www 834: $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
1.81 matthew 835: }
836: } elsif ($pro =~ /^course_(.*)$/) {
837: # Check for permissions inside of a course
838: if (($ENV{'request.course.id'}) &&
839: (&Apache::lonnet::allowed($1,$ENV{'request.course.id'}.
840: ($ENV{'request.course.sec'}?'/'.$ENV{'request.course.sec'}:''))
841: )) {
842: $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
1.26 www 843: }
1.4 www 844: } elsif ($pro eq 'author') {
845: if ($author) {
1.29 matthew 846: if ((($prt eq 'rca') && ($ENV{'request.role'}=~/^ca/)) ||
847: (($prt eq 'rau') && ($ENV{'request.role'}=~/^au/))) {
1.19 matthew 848: # Check that we are on the correct machine
1.29 matthew 849: my $cadom=$requested_domain;
850: my $caname=$ENV{'user.name'};
851: if ($prt eq 'rca') {
852: ($cadom,$caname)=
1.6 www 853: ($ENV{'request.role'}=~/(\w+)\/(\w+)$/);
1.29 matthew 854: }
855: $act =~ s/\$caname/$caname/g;
1.19 matthew 856: my $home = &Apache::lonnet::homeserver($caname,$cadom);
1.109 albertel 857: my $allowed=0;
858: my @ids=&Apache::lonnet::current_machine_ids();
859: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
860: if ($allowed) {
1.19 matthew 861: $output.=switch($caname,$cadom,
1.27 www 862: $row,$col,$img,$top,$bot,$act,$desc);
1.19 matthew 863: }
1.6 www 864: }
1.2 www 865: }
866: }
1.13 harris41 867: }
1.49 www 868: unless (($ENV{'browser.interface'} eq 'textual') ||
869: ($ENV{'environment.remote'} eq 'off')) {
1.35 www 870: $output.="\nwindow.status='Synchronizing Time';swmenu.syncclock(1000*".time.");\nwindow.status='Remote Control Configured.';";
1.34 www 871: }
1.2 www 872: return $output;
873: }
874:
875: # ======================================================================= Close
1.1 www 876:
877: sub close {
1.49 www 878: if (($ENV{'browser.interface'} eq 'textual') ||
879: ($ENV{'environment.remote'} eq 'off')) { return ''; }
1.30 www 880: my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
1.1 www 881: return(<<ENDCLOSE);
882: <script>
1.35 www 883: window.status='Accessing Remote Control';
1.30 www 884: menu=window.open("/adm/rat/empty.html","$menuname",
1.1 www 885: "height=350,width=150,scrollbars=no,menubar=no");
1.35 www 886: window.status='Disabling Remote Control';
887: menu.active=0;
1.31 www 888: menu.autologout=0;
1.35 www 889: window.status='Closing Remote Control';
1.1 www 890: menu.close();
1.35 www 891: window.status='Done.';
1.1 www 892: </script>
893: ENDCLOSE
894: }
895:
896: # ====================================================================== Footer
897:
898: sub footer {
899:
1.33 www 900: }
901:
1.42 www 902: sub utilityfunctions {
1.51 www 903: unless (($ENV{'browser.interface'} eq 'textual') ||
904: ($ENV{'environment.remote'} eq 'off')) { return ''; }
1.97 www 905: my $currenturl=$ENV{'request.noversionuri'};
1.42 www 906: my $currentsymb=$ENV{'request.symb'};
1.114 albertel 907: my $nav_control=&Apache::lonnavmaps::nav_control_js();
1.42 www 908: return (<<ENDUTILITY)
909:
910: var currentURL="$currenturl";
911: var reloadURL="$currenturl";
912: var currentSymb="$currentsymb";
913:
1.114 albertel 914: $nav_control
915:
1.42 www 916: function go(url) {
917: if (url!='' && url!= null) {
918: currentURL = null;
919: currentSymb= null;
920: window.location.href=url;
921: }
922: }
923:
924: function gopost(url,postdata) {
925: if (url!='') {
926: this.document.server.action=url;
927: this.document.server.postdata.value=postdata;
928: this.document.server.command.value='';
929: this.document.server.url.value='';
930: this.document.server.symb.value='';
931: this.document.server.submit();
932: }
933: }
934:
935: function gocmd(url,cmd) {
936: if (url!='') {
937: this.document.server.action=url;
938: this.document.server.postdata.value='';
939: this.document.server.command.value=cmd;
940: this.document.server.url.value=currentURL;
941: this.document.server.symb.value=currentSymb;
942: this.document.server.submit();
943: }
1.57 www 944: }
945:
946: function catalog_info() {
1.102 albertel 947: loncatinfo=window.open(window.location.pathname+'.meta',"LONcatInfo",'height=320,width=280,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
1.57 www 948: }
949:
950: function chat_win() {
1.102 albertel 951: lonchat=window.open('/res/adm/pages/chatroom.html',"LONchat",'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
1.42 www 952: }
953: ENDUTILITY
954: }
955:
956: sub serverform {
957: return(<<ENDSERVERFORM);
958:
1.62 www 959: <form name="server" action="/adm/logout" method="post" target="_top">
1.42 www 960: <input type="hidden" name="postdata" value="none" />
961: <input type="hidden" name="command" value="none" />
962: <input type="hidden" name="url" value="none" />
963: <input type="hidden" name="symb" value="none" />
964: </form>
965: ENDSERVERFORM
966: }
1.113 albertel 967:
968: sub get_nav_status {
969: my $navstatus="swmenu.w_loncapanav_flag=";
970: if ($ENV{'environment.remotenavmap'} eq 'on') {
971: $navstatus.="1";
972: } else {
973: $navstatus.="-1";
974: }
975: return $navstatus;
976: }
977:
1.33 www 978: # ================================================ Handler when called directly
979:
980:
981: sub handler {
982: my $r = shift;
1.93 www 983: &Apache::loncommon::content_type($r,'text/html');
1.33 www 984: $r->send_http_header;
985: return OK if $r->header_only;
986:
1.42 www 987: my $form=&serverform();
1.34 www 988: my $bodytag=&Apache::loncommon::bodytag('Main Menu');
1.58 www 989: my $function='student';
990: if ($ENV{'request.role'}=~/^(cc|in|ta|ep)/) {
991: $function='coordinator';
992: }
993: if ($ENV{'request.role'}=~/^(su|dc|ad|li)/) {
994: $function='admin';
995: }
996: if (($ENV{'request.role'}=~/^(au|ca)/) ||
1.97 www 997: ($ENV{'request.noversionuri'}=~/^(\/priv|\~)/)) {
1.58 www 998: $function='author';
999: }
1000: my $domain=&Apache::loncommon::determinedomain();
1001: $pgbg=&Apache::loncommon::designparm($function.'.pgbg',$domain);
1002: $tabbg=&Apache::loncommon::designparm($function.'.tabbg',$domain);
1003: $font=&Apache::loncommon::designparm($function.'.font',$domain);
1.53 www 1004: # ---- Print the screen, pretent to be in text mode to generate text-based menu
1.103 www 1005: unless ($ENV{'browser.interface'} eq 'textual') {
1006: $ENV{'browser.interface'}='faketextual';
1.53 www 1007: $ENV{'environment.remote'}='off';
1008: }
1.36 www 1009: $r->print(<<ENDHEADER);
1010: <html><head>
1011: <title>LON-CAPA Main Menu</title>
1012: </head>
1013: $bodytag
1014: ENDHEADER
1.58 www 1015: $r->print('<table>'.&inlinemenu().'</table>'.$form);
1.33 www 1016: $r->print('</body></html>');
1017: return OK;
1.1 www 1018: }
1019:
1.2 www 1020: # ================================================================ Main Program
1021:
1.16 harris41 1022: BEGIN {
1.15 matthew 1023: if (! defined($readdesk)) {
1.14 www 1024: {
1.104 raeburn 1025: my $tabfile = $Apache::lonnet::perlvar{'lonTabDir'}.'/mydesk.tab';
1026: if ( CORE::open( my $config,"<$tabfile") ) {
1027: while (my $configline=<$config>) {
1028: $configline=(split(/\#/,$configline))[0];
1029: $configline=~s/^\s+//;
1030: chomp($configline);
1031: if ($configline) {
1032: $desklines[$#desklines+1]=$configline;
1033: }
1034: }
1035: CORE::close($config);
1.2 www 1036: }
1.14 www 1037: }
1038: $readdesk='done';
1.10 albertel 1039: }
1.2 www 1040: }
1.30 www 1041:
1.1 www 1042: 1;
1043: __END__
1044:
1045:
1046:
1047:
1048:
1049:
1050:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>