1: # The LearningOnline Network with CAPA
2: # Routines to control the menu
3: #
4: # $Id: lonmenu.pm,v 1.240 2008/09/04 22:47:20 riegler Exp $
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: #
28: #
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'
37: #
38:
39: package Apache::lonmenu;
40:
41: use strict;
42: use Apache::lonnet;
43: use Apache::lonhtmlcommon();
44: use Apache::loncommon();
45: use Apache::lonenc();
46: use Apache::lonlocal;
47: use LONCAPA qw(:DEFAULT :match);
48:
49: use vars qw(@desklines %category_names %category_members %category_positions $readdesk);
50:
51:
52: my @inlineremote;
53:
54:
55:
56: # ================================================================ Little texts
57: sub show_course {
58: my $course = !$env{'user.adv'};
59: if (!$env{'user.adv'}) {
60: foreach my $env (keys(%env)) {
61: next if ($env !~ m/^user\.priv\./);
62: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
63: $course = 0;
64: last;
65: }
66: }
67: }
68: return $course;
69: }
70:
71: sub initlittle {
72: return &Apache::lonlocal::texthash('ret' => 'Return to Last Location',
73: 'nav' => 'Navigate Contents',
74: 'main' => 'Main Menu',
75: 'roles' => (&show_course()?
76: 'Courses':'Roles'),
77: 'other' => 'Other Roles',
78: 'docs' => 'Edit Course',
79: 'exit' => 'Exit',
80: 'login' => 'Log In',
81: 'launch' => 'Launch Remote Control',
82: 'groups' => 'Groups',
83: 'gdoc' => 'Group Documents',
84: );
85: }
86:
87: # ============================= This gets called at the top of the body section
88:
89: sub menubuttons {
90: my $forcereg=shift;
91: my $registration=shift;
92: my $titletable=shift;
93: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
94: ['inhibitmenu']);
95: if (($env{'form.inhibitmenu'} eq 'yes') ||
96: ($ENV{'REQUEST_URI'} eq '/adm/logout')) { return ''; }
97:
98: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
99:
100: my %lt=&initlittle();
101: my $navmaps='';
102: my $reloadlink='';
103: my $docs='';
104: my $groups='';
105: my $roles='<a href="/adm/roles" target="_top">'.$lt{'roles'}.'</a>';
106: my $role_selector;
107: my $showgroups=0;
108: my ($cnum,$cdom);
109: my $escurl=&escape(&Apache::lonenc::check_encrypt($env{'request.noversionuri'}));
110: my $escsymb=&escape(&Apache::lonenc::check_encrypt($env{'request.symb'}));
111:
112: my $logo=&Apache::loncommon::lonhttpdurl("/adm/lonIcons/minilogo.gif");
113: $logo = '<td class="LC_top_nav_logo"><a href="/adm/about.html"><img src="'.
114: $logo.'" alt="LON-CAPA Logo" /></a></td>';
115:
116: if ($env{'request.state'} eq 'construct') {
117: if (($env{'request.noversionuri'} eq '') || (!defined($env{'request.noversionuri'}))) {
118: my $returnurl = $env{'request.filename'};
119: $returnurl =~ s:^/home/([^/]+)/public_html/(.*)$:/priv/$1/$2:;
120: $escurl = &escape($returnurl);
121: }
122: }
123: if ($env{'request.course.id'}) {
124: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
125: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
126: my %coursegroups;
127: my $viewgrps_permission =
128: &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
129: if (!$viewgrps_permission) {
130: %coursegroups = &Apache::lonnet::get_active_groups($env{'user.domain'},$env{'user.name'},$cdom,$cnum);
131: }
132: if ((keys(%coursegroups) > 0) || ($viewgrps_permission)) {
133: $showgroups = 1;
134: }
135: $role_selector = &roles_selector($cdom,$cnum);
136: if ($role_selector) {
137: $roles = '<span class="LC_nobreak">'.$role_selector.' <a href="/adm/roles" target="_top">'.$lt{'other'}.'</a></span>';
138: }
139: }
140:
141: if ($env{'browser.interface'} eq 'textual') {
142: # Textual display only
143: if ($env{'request.course.id'}) {
144: $navmaps=(<<ENDNAV);
145: <a href="/adm/navmaps?postdata=$escurl&postsymb=$escsymb" target="_top">$lt{'nav'}</a>
146: ENDNAV
147: if (&show_return_link()) {
148: my $escreload=&escape('return:');
149: $reloadlink=(<<ENDRELOAD);
150: <a href="/adm/flip?postdata=$escreload" target="_top">$lt{'ret'}</a>
151: ENDRELOAD
152: }
153: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
154: $docs=(<<ENDDOCS);
155: <a href="/adm/coursedocs" target="_top">$lt{'docs'}</a>
156: ENDDOCS
157: }
158: if ($showgroups) {
159: $groups =(<<ENDGROUPS);
160: <a href="/adm/coursegroups" target="_top">$lt{'groups'}</a>
161: ENDGROUPS
162: }
163: }
164: my $form=&serverform();
165: my $utility=&utilityfunctions();
166: my $output=(<<ENDMAINMENU);
167: <script type="text/javascript">
168: // BEGIN LON-CAPA Internal
169: $utility
170: </script>
171: <div id="LC_top_nav">
172: <a href="/adm/menu" target="_top">$lt{'main'}</a>
173: $reloadlink $navmaps $docs $groups $roles
174: <a href="/adm/logout" target="_top">$lt{'exit'}</a>
175: </div>
176: <br />
177: <script type="text/javascript">
178: // END LON-CAPA Internal
179: </script>
180: $form
181: ENDMAINMENU
182: if ($registration) { $output.=&innerregister($forcereg); }
183: return $output."<hr />";
184: } elsif ($env{'environment.remote'} eq 'off') {
185: # Remote Control is switched off
186: # figure out colors
187: my %lt=&initlittle();
188:
189: my $domain=&Apache::loncommon::determinedomain();
190: my $function =&Apache::loncommon::get_users_function();
191: my $link=&Apache::loncommon::designparm($function.'.link',$domain);
192: my $alink=&Apache::loncommon::designparm($function.'.alink',$domain);
193: my $vlink=&Apache::loncommon::designparm($function.'.vlink',$domain);
194: my $sidebg=&Apache::loncommon::designparm($function.'.sidebg',$domain);
195: if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
196: return (<<ENDINLINEMENU);
197: <table id="LC_top_nav">
198: <tr>
199: $logo
200: <td></td>
201: <td class="LC_top_nav_login">
202: <a href="/adm/roles" target="_top">$lt{'login'}</a>
203: </td>
204: </tr>
205: </table>
206: </font>
207: ENDINLINEMENU
208: }
209: $roles = '<td><a href="/adm/roles" target="_top">'.$lt{'roles'}.'</a></td>';
210: # Do we have a NAV link?
211: if ($env{'request.course.id'}) {
212: my $link='/adm/navmaps?postdata='.$escurl.'&postsymb='.
213: $escsymb;
214: if ($env{'environment.remotenavmap'} eq 'on') {
215: $link="javascript:gonav('".$link."')";
216: }
217: $navmaps=(<<ENDNAV);
218: <td><a href="$link" target="_top">$lt{'nav'}</a></td>
219: ENDNAV
220: my $is_group = (&Apache::loncommon::course_type() eq 'Group');
221: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
222: my $text = ($is_group) ? $lt{'gdoc'} : $lt{'docs'};
223: $docs=(<<ENDDOCS);
224: <td><a href="/adm/coursedocs" target="_top">$text</a></td>
225: ENDDOCS
226: }
227: if ($showgroups) {
228: $groups =(<<ENDGROUPS);
229: <td><a href="/adm/coursegroups" target="_top">$lt{'groups'}</a></td>
230: ENDGROUPS
231: }
232: if (&show_return_link()) {
233: my $escreload=&escape('return:');
234: $reloadlink=(<<ENDRELOAD);
235: <td><a href="/adm/flip?postdata=$escreload" target="_top">$lt{'ret'}</a></td>
236: ENDRELOAD
237: }
238: if ($role_selector) {
239: $roles = '<td>'.$role_selector.'</td><td><a href="/adm/roles" target="_top">'.$lt{'other'}.'</a></td>';
240: }
241: }
242: if (($env{'request.state'} eq 'construct') && ($env{'request.course.id'})) {
243: my $escreload=&escape('return:');
244: $reloadlink=(<<ENDCRELOAD);
245: <td><a href="/adm/flip?postdata=$escreload" target="_top">$lt{'ret'}</a></td>
246: ENDCRELOAD
247: }
248: my $reg='';
249: if ($registration) {
250: $reg=&innerregister($forcereg,$titletable);
251: }
252: my $form=&serverform();
253: my $utility=&utilityfunctions();
254: my $remote;
255: if ($env{'user.adv'}) {
256: $remote = '<td><a href="/adm/remote?action=launch&url='.$escurl.'" target="_top">'.$lt{'launch'}.'</a></td>'
257: }
258:
259: my $helplink=&Apache::loncommon::top_nav_help('Help');
260: return (<<ENDINLINEMENU);
261: <script type="text/javascript">
262: // BEGIN LON-CAPA Internal
263: // <![CDATA[
264: $utility
265: // ]]>
266: </script>
267: <table id="LC_top_nav">
268: <tr>
269: $logo
270: <td><a href="/adm/menu" target="_top">$lt{'main'}</a></td>
271: $reloadlink
272: $navmaps
273: $docs
274: $groups
275: $remote
276: $roles
277: <td class="LC_top_nav_help">$helplink</td>
278: <td class="LC_top_nav_exit"><a href="/adm/logout" target="_top">$lt{'exit'}</a></td>
279: </tr>
280: </table>
281: $form
282: <script type="text/javascript">
283: // END LON-CAPA Internal
284: </script>
285: $reg
286: ENDINLINEMENU
287: } else {
288: return '';
289: }
290: }
291:
292: sub show_return_link {
293: return (($env{'request.noversionuri'}=~m{^/(res|public)/} &&
294: $env{'request.symb'} eq '')
295: ||
296: ($env{'request.noversionuri'}=~ m{^/cgi-bin/printout.pl})
297: ||
298: (($env{'request.noversionuri'}=~/^\/adm\//) &&
299: ($env{'request.noversionuri'}!~/^\/adm\/wrapper\//) &&
300: ($env{'request.noversionuri'}!~
301: m[^/adm/.*/(smppg|bulletinboard|aboutme)($|\?)])
302: ));
303: }
304:
305: # ====================================== This gets called in the header section
306:
307: sub registerurl {
308: my ($forcereg) = @_;
309: my $result = '';
310: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
311: my $force_title='';
312: if ($env{'request.state'} eq 'construct') {
313: $force_title=&Apache::lonxml::display_title();
314: }
315: if (($env{'browser.interface'} eq 'textual') ||
316: ($env{'environment.remote'} eq 'off') ||
317: ((($env{'request.publicaccess'}) ||
318: (!&Apache::lonnet::is_on_map(
319: &unescape($env{'request.noversionuri'})))) &&
320: (!$forcereg))) {
321: return $result.
322: '<script type="text/javascript">function LONCAPAreg(){;} function LONCAPAstale(){}</script>'.$force_title;
323: }
324: # Graphical display after login only
325: if ($env{'request.registered'} && !$forcereg) { return ''; }
326: $result.=&innerregister($forcereg);
327: return $result.$force_title;
328: }
329:
330: # =========== This gets called in order to register a URL, both with the Remote
331: # =========== and in the body of the document
332:
333: sub innerregister {
334: my ($forcereg, $titletable) = @_;
335: my $result = '';
336: my ($uname,$thisdisfn);
337: my $const_space = ($env{'request.state'} eq 'construct');
338: my $is_const_dir = 0;
339:
340: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
341:
342: $env{'request.registered'} = 1;
343:
344: my $textinter=($env{'browser.interface'} eq 'textual');
345: my $noremote=($env{'environment.remote'} eq 'off');
346:
347: my $textual=($textinter || $noremote);
348:
349: undef(@inlineremote);
350:
351: my $reopen=&Apache::lonmenu::reopenmenu();
352:
353: my $newmail='';
354: if ($noremote) {
355: $newmail='<table id="LC_nav_location"><tr>';
356: }
357: if (&Apache::lonmsg::newmail()) {
358: if ($textual) {
359: $newmail.= '<td class="LC_new_mail">
360: <a href="/adm/communicate" target="_top">'.
361: &mt('You have new messages').'</a></td>';
362: } else {
363: $newmail= 'swmenu.setstatus("you have","messages");';
364: }
365: }
366: if (($textual)
367: && ($env{'request.symb'})
368: && ($env{'request.course.id'})) {
369: $newmail.= '<td class="LC_current_location">';
370: my ($mapurl,$rid,$resurl)=
371: &Apache::lonnet::decode_symb(&Apache::lonnet::symbread());
372: my $coursetitle=$env{'course.'.$env{'request.course.id'}.'.description'};
373: $newmail.=$coursetitle;
374: my $maptitle=&Apache::lonnet::gettitle($mapurl);
375: my $restitle=&Apache::lonnet::gettitle(&Apache::lonnet::symbread());
376: if ($maptitle && ($maptitle ne 'default.sequence') && ($maptitle ne $coursetitle)) {
377: $newmail.=', '.$maptitle;
378: }
379: if ($restitle) {
380: $newmail.=': '.$restitle;
381: }
382: $newmail.=' </td>';
383: }
384: if ($env{'request.state'} eq 'construct') {
385: $newmail = $titletable;
386: } else {
387: if ($noremote) {
388: $newmail.='</tr></table>';
389: }
390: }
391: my $timesync=($textual?'':'swmenu.syncclock(1000*'.time.');');
392: my $tablestart=($noremote?'<table id="LC_menubuttons">':'').
393: ($textinter?'<br /><a href="#content">'.&mt('Skip to Content').'</a><br />':'');
394: my $tableend=($noremote?'</table>':'').($textinter?'<a name="content" />':'');
395: # =============================================================================
396: # ============================ This is for URLs that actually can be registered
397: if (($env{'request.noversionuri'}!~m|^/(res/)*adm/|) || ($forcereg)) {
398: # -- This applies to homework problems for users with grading privileges
399: my $crs='/'.$env{'request.course.id'};
400: if ($env{'request.course.sec'}) {
401: $crs.='_'.$env{'request.course.sec'};
402: }
403: $crs=~s/\_/\//g;
404:
405: my $hwkadd='';
406: if ($env{'request.symb'} ne '' &&
407: $env{'request.filename'}=~/\.(problem|exam|quiz|assess|survey|form|task)$/) {
408: if (&Apache::lonnet::allowed('mgr',$crs)) {
409: $hwkadd.=&switch('','',7,2,'pgrd.gif','problem[_1]','grades[_3]',
410: "gocmd('/adm/grades','gradingmenu')",
411: 'Modify user grades for this assessment resource');
412: } elsif (&Apache::lonnet::allowed('vgr',$crs)) {
413: $hwkadd.=&switch('','',7,2,'subm.gif','view sub-[_1]','missions[_1]',
414: "gocmd('/adm/grades','submission')",
415: 'View user submissions for this assessment resource');
416: }
417: }
418: if ($env{'request.symb'} ne '' &&
419: &Apache::lonnet::allowed('opa',$crs)) {
420: $hwkadd.=&switch('','',7,3,'pparm.gif','problem[_2]','parms[_2]',
421: "gocmd('/adm/parmset','set')",
422: 'Modify parameter settings for this resource');
423: }
424: # -- End Homework
425: ###
426: ### Determine whether or not to display the 'cstr' button for this
427: ### resource
428: ###
429: my $editbutton = '';
430: if ($env{'user.author'}) {
431: if ($env{'request.role'}=~/^(aa|ca|au)/) {
432: # Set defaults for authors
433: my ($top,$bottom) = ('con-','struct');
434: my $action = "go('/priv/".$env{'user.name'}."');";
435: my $cadom = $env{'request.role.domain'};
436: my $caname = $env{'user.name'};
437: my $desc = "Enter my construction space";
438: # Set defaults for co-authors
439: if ($env{'request.role'} =~ /^ca/) {
440: ($cadom,$caname)=($env{'request.role'}=~/($match_domain)\/($match_username)$/);
441: ($top,$bottom) = ('co con-','struct');
442: $action = "go('/priv/".$caname."');";
443: $desc = "Enter construction space as co-author";
444: } elsif ($env{'request.role'} =~ /^aa/) {
445: ($cadom,$caname)=($env{'request.role'}=~/($match_domain)\/($match_username)$/);
446: ($top,$bottom) = ('co con-','struct');
447: $action = "go('/priv/".$caname."');";
448: $desc = "Enter construction space as assistant co-author";
449: }
450: # Check that we are on the correct machine
451: my $home = &Apache::lonnet::homeserver($caname,$cadom);
452: my $allowed=0;
453: my @ids=&Apache::lonnet::current_machine_ids();
454: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
455: if (!$allowed) {
456: $editbutton=&switch('','',6,1,$top,,$bottom,$action,$desc);
457: }
458: }
459: ##
460: ## Determine if user can edit url.
461: ##
462: my $cfile='';
463: my $cfuname='';
464: my $cfudom='';
465: if ($env{'request.filename'}) {
466: my $file=&Apache::lonnet::declutter($env{'request.filename'});
467: $file=~s/^($match_domain)\/($match_username)/\/priv\/$2/;
468: # Check that the user has permission to edit this resource
469: ($cfuname,$cfudom)=&Apache::loncacc::constructaccess($file,$1);
470: if (defined($cfudom)) {
471: my $home=&Apache::lonnet::homeserver($cfuname,$cfudom);
472: my $allowed=0;
473: my @ids=&Apache::lonnet::current_machine_ids();
474: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
475: if ($allowed) {
476: $cfile=$file;
477: }
478: }
479: }
480: # Finally, turn the button on or off
481: if ($cfile && !$const_space) {
482: $editbutton=&switch
483: ('','',6,1,'pcstr.gif','edit[_1]','resource[_2]',
484: "go('".$cfile."');","Edit this resource");
485: } elsif ($editbutton eq '') {
486: $editbutton=&clear(6,1);
487: }
488: }
489: ###
490: ###
491: # Prepare the rest of the buttons
492: my $menuitems;
493: if ($const_space) {
494: my ($uname,$thisdisfn) =
495: ($env{'request.filename'}=~m|^/home/([^/]+)/public_html/(.*)|);
496: my $currdir = '/priv/'.$uname.'/'.$thisdisfn;
497: if ($currdir =~ m-/$-) {
498: $is_const_dir = 1;
499: } else {
500: $currdir =~ s#[^/]+$##;
501: my $cleandisfn = &Apache::loncommon::escape_single($thisdisfn);
502: my $esc_currdir = &Apache::loncommon::escape_single($currdir);
503: $menuitems=(<<ENDMENUITEMS);
504: s&6&1&list.gif&list[_1]&dir[_1]&golist('$esc_currdir')&List current directory
505: s&6&2&rtrv.gif&retrieve[_1]&version[_1]&gocstr('/adm/retrieve','/~$uname/$cleandisfn')&Retrieve old version
506: s&6&3&pub.gif&publish[_1]&resource[_1]&gocstr('/adm/publish','/~$uname/$cleandisfn')&Publish this resource
507: s&7&1&del.gif&delete[_1]&resource[_2]&gocstr('/adm/cfile?action=delete','/~$uname/$cleandisfn')&Delete this resource
508: s&7&2&prt.gif&prepare[_1]&printout[_1]&gocstr('/adm/printout','/~$uname/$cleandisfn')&Prepare a printable document
509: ENDMENUITEMS
510: }
511: } elsif ( defined($env{'request.course.id'}) &&
512: $env{'request.symb'} ne '' ) {
513: $menuitems=(<<ENDMENUITEMS);
514: c&3&1
515: s&2&1&back.gif&backward[_1]&&gopost('/adm/flip','back:'+currentURL)&Go to the previous resource in the course sequence&&1
516: s&2&3&forw.gif&forward[_1]&&gopost('/adm/flip','forward:'+currentURL)&Go to the next resource in the course sequence&&3
517: c&6&3
518: c&8&1
519: c&8&2
520: s&8&3&prt.gif&prepare[_1]&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
521: s&9&1&sbkm.gif&set[_1]&bookmark[_2]&set_bookmark()&Set a bookmark for this resource&&1
522: s&9&3&anot.gif&anno-[_1]&tations[_1]&annotate()&Make notes and annotations about this resource&&1
523: ENDMENUITEMS
524:
525: unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme)(\?|$)/) {
526: if (!$env{'request.enc'}) {
527: $menuitems.=(<<ENDREALRES);
528: s&6&3&catalog.gif&catalog[_1]&info[_1]&catalog_info()&Show catalog information
529: ENDREALRES
530: }
531: $menuitems.=(<<ENDREALRES);
532: s&8&1&eval.gif&evaluate[_1]&this[_1]&gopost('/adm/evaluate',currentURL,1)&Provide my evaluation of this resource
533: 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
534: ENDREALRES
535: }
536: }
537: if ($env{'request.uri'} =~ /^\/res/) {
538: $menuitems .= (<<ENDMENUITEMS);
539: s&8&3&prt.gif&prepare[_1]&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
540: ENDMENUITEMS
541: }
542: my $buttons='';
543: foreach (split(/\n/,$menuitems)) {
544: my ($command,@rest)=split(/\&/,$_);
545: my $idx=10*$rest[0]+$rest[1];
546: if (&hidden_button_check() eq 'yes') {
547: if ($idx == 21 ||$idx == 23) {
548: $buttons.=&switch('','',@rest);
549: } else {
550: $buttons.=&clear(@rest);
551: }
552: } else {
553: if ($command eq 's') {
554: $buttons.=&switch('','',@rest);
555: } else {
556: $buttons.=&clear(@rest);
557: }
558: }
559: }
560:
561: if ($textual) {
562: my $addremote=0;
563: foreach (@inlineremote) { if ($_ ne '') { $addremote=1; } }
564: my $inlinebuttons='';
565: if ($addremote) {
566: # Registered, textual output
567: if ($env{'browser.interface'} eq 'textual') {
568: $inlinebuttons=
569: join('',map { (defined($_)?$_:'') } @inlineremote);
570: } else {
571: if ($env{'environment.icons'} eq 'iconsonly') {
572: $inlinebuttons=(<<ENDARROWSINLINE);
573: <tr><td>
574: $inlineremote[21] $inlineremote[23]
575: ENDARROWSINLINE
576: if (&hidden_button_check() ne 'yes') {
577: $inlinebuttons .= (<<ENDINLINEICONS);
578: $inlineremote[61] $inlineremote[63]
579: $inlineremote[71] $inlineremote[72] $inlineremote[73]
580: $inlineremote[81] $inlineremote[82] $inlineremote[83]
581: $inlineremote[91] $inlineremote[92] $inlineremote[93]</td></tr>
582: ENDINLINEICONS
583: }
584: } else {
585: if ($inlineremote[21] ne '' || $inlineremote[23] ne '') {
586: $inlinebuttons=(<<ENDFIRSTLINE);
587: <tr><td>$inlineremote[21]</td><td> </td><td>$inlineremote[23]</td></tr>
588: ENDFIRSTLINE
589: }
590: if (&hidden_button_check() ne 'yes') {
591: foreach my $row (6..9) {
592: if ($inlineremote[${row}.'1'] ne ''
593: || $inlineremote[$row.'2'] ne ''
594: || $inlineremote[$row.'3'] ne '') {
595: $inlinebuttons .= <<"ENDLINE";
596: <tr><td>$inlineremote["${row}1"]</td><td>$inlineremote["${row}2"]</td><td>$inlineremote["${row}3"]</td></tr>
597: ENDLINE
598: }
599: }
600: }
601: }
602: }
603: }
604: $result =(<<ENDREGTEXT);
605: <script type="text/javascript">
606: // BEGIN LON-CAPA Internal
607: </script>
608: $timesync
609: $tablestart
610: $inlinebuttons
611: $tableend
612: $newmail
613: <script type="text/javascript">
614: // END LON-CAPA Internal
615: </script>
616:
617: ENDREGTEXT
618: # Registered, graphical output
619: } else {
620: my $requri=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
621: $requri=&Apache::lonenc::check_encrypt(&unescape($requri));
622: my $cursymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
623: my $navstatus=&get_nav_status();
624: my $clearcstr;
625:
626: if ($env{'user.adv'}) { $clearcstr='clearbut(6,1)'; }
627: $result = (<<ENDREGTHIS);
628:
629: <script type="text/javascript">
630: // BEGIN LON-CAPA Internal
631: var swmenu=null;
632:
633: function LONCAPAreg() {
634: swmenu=$reopen;
635: swmenu.clearTimeout(swmenu.menucltim);
636: $timesync
637: $newmail
638: $buttons
639: swmenu.currentURL="$requri";
640: swmenu.reloadURL=swmenu.currentURL+window.location.search;
641: swmenu.currentSymb="$cursymb";
642: swmenu.reloadSymb="$cursymb";
643: swmenu.currentStale=0;
644: $navstatus
645: $hwkadd
646: $editbutton
647: }
648:
649: function LONCAPAstale() {
650: swmenu=$reopen
651: swmenu.currentStale=1;
652: if (swmenu.reloadURL!='' && swmenu.reloadURL!= null) {
653: swmenu.switchbutton
654: (3,1,'reload.gif','return','location','go(reloadURL)','Return to the last known location in the course sequence');
655: }
656: swmenu.clearbut(7,2);
657: swmenu.clearbut(7,3);
658: swmenu.menucltim=swmenu.setTimeout(
659: 'clearbut(2,1);clearbut(2,3);clearbut(8,1);clearbut(8,2);clearbut(8,3);'+
660: 'clearbut(9,1);clearbut(9,3);clearbut(6,3);$clearcstr',
661: 2000);
662: }
663:
664: // END LON-CAPA Internal
665: </script>
666: ENDREGTHIS
667: }
668: # =============================================================================
669: } else {
670: # ========================================== This can or will not be registered
671: if ($textual) {
672: # Not registered, textual
673: $result= (<<ENDDONOTREGTEXT);
674: ENDDONOTREGTEXT
675: } else {
676: # Not registered, graphical
677: $result = (<<ENDDONOTREGTHIS);
678:
679: <script type="text/javascript">
680: // BEGIN LON-CAPA Internal
681: var swmenu=null;
682:
683: function LONCAPAreg() {
684: swmenu=$reopen
685: $timesync
686: swmenu.currentStale=1;
687: swmenu.clearbut(2,1);
688: swmenu.clearbut(2,3);
689: swmenu.clearbut(8,1);
690: swmenu.clearbut(8,2);
691: swmenu.clearbut(8,3);
692: if (swmenu.currentURL) {
693: swmenu.switchbutton
694: (3,1,'reload.gif','return','location','go(currentURL)');
695: } else {
696: swmenu.clearbut(3,1);
697: }
698: }
699:
700: function LONCAPAstale() {
701: }
702:
703: // END LON-CAPA Internal
704: </script>
705: ENDDONOTREGTHIS
706: }
707: # =============================================================================
708: }
709: return $result;
710: }
711:
712: sub loadevents() {
713: if ($env{'request.state'} eq 'construct' ||
714: $env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
715: return 'LONCAPAreg();';
716: }
717:
718: sub unloadevents() {
719: if ($env{'request.state'} eq 'construct' ||
720: $env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
721: return 'LONCAPAstale();';
722: }
723:
724: # ============================================================= Start up remote
725:
726: sub startupremote {
727: my ($lowerurl)=@_;
728: if (($env{'browser.interface'} eq 'textual') ||
729: ($env{'environment.remote'} eq 'off')) {
730: return ('<meta HTTP-EQUIV="Refresh" CONTENT="0.5; url='.$lowerurl.'" />');
731: }
732: #
733: # The Remote actually gets launched!
734: #
735: my $configmenu=&rawconfig();
736: my $esclowerurl=&escape($lowerurl);
737: my $message=&mt('"Waiting for Remote Control window to load: "+[_1]','waited');
738: return(<<ENDREMOTESTARTUP);
739: <script type="text/javascript">
740: var timestart;
741: function wheelswitch() {
742: if (typeof(document.wheel) != 'undefined') {
743: if (typeof(document.wheel.spin) != 'undefined') {
744: var date=new Date();
745: var waited=Math.round(30-((date.getTime()-timestart)/1000));
746: document.wheel.spin.value=$message;
747: }
748: }
749: if (window.status=='|') {
750: window.status='/';
751: } else {
752: if (window.status=='/') {
753: window.status='-';
754: } else {
755: if (window.status=='-') {
756: window.status='\\\\';
757: } else {
758: if (window.status=='\\\\') { window.status='|'; }
759: }
760: }
761: }
762: }
763:
764: // ---------------------------------------------------------- The wait function
765: var canceltim;
766: function wait() {
767: if ((menuloaded==1) || (tim==1)) {
768: window.status='Done.';
769: if (tim==0) {
770: clearTimeout(canceltim);
771: $configmenu
772: window.location='$lowerurl';
773: } else {
774: window.location='/adm/remote?action=collapse&url=$esclowerurl';
775: }
776: } else {
777: wheelswitch();
778: setTimeout('wait();',200);
779: }
780: }
781:
782: function main() {
783: canceltim=setTimeout('tim=1;',30000);
784: window.status='-';
785: var date=new Date();
786: timestart=date.getTime();
787: wait();
788: }
789:
790: </script>
791: ENDREMOTESTARTUP
792: }
793:
794: sub setflags() {
795: return(<<ENDSETFLAGS);
796: <script type="text/javascript">
797: menuloaded=0;
798: tim=0;
799: </script>
800: ENDSETFLAGS
801: }
802:
803: sub maincall() {
804: if (($env{'browser.interface'} eq 'textual') ||
805: ($env{'environment.remote'} eq 'off')) { return ''; }
806: return(<<ENDMAINCALL);
807: <script type="text/javascript">
808: main();
809: </script>
810: ENDMAINCALL
811: }
812:
813: sub load_remote_msg {
814: my ($lowerurl)=@_;
815:
816: if (($env{'browser.interface'} eq 'textual') ||
817: ($env{'environment.remote'} eq 'off')) { return ''; }
818:
819: my $esclowerurl=&escape($lowerurl);
820: my $link=&mt('<a href="[_1]">Continue</a> on in Inline Menu mode',
821: "/adm/remote?action=collapse&url=$esclowerurl");
822: return(<<ENDREMOTEFORM);
823: <p>
824: <form name="wheel">
825: <input name="spin" type="text" size="60" />
826: </form>
827: </p>
828: <p>$link</p>
829: ENDREMOTEFORM
830: }
831:
832: sub get_menu_name {
833: my $hostid = $Apache::lonnet::perlvar{'lonHostID'};
834: $hostid =~ s/\W//g;
835: return 'LCmenu'.$hostid;
836: }
837:
838: # ================================================================= Reopen menu
839:
840: sub reopenmenu {
841: if (($env{'browser.interface'} eq 'textual') ||
842: ($env{'environment.remote'} eq 'off')) { return ''; }
843: my $menuname = &get_menu_name();
844: my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
845: return('window.open('.$nothing.',"'.$menuname.'","",false);');
846: }
847:
848: # =============================================================== Open the menu
849:
850: sub open {
851: my $returnval='';
852: if (($env{'browser.interface'} eq 'textual') ||
853: ($env{'environment.remote'} eq 'off')) {
854: return '<script type="text/javascript">self.name="loncapaclient";</script>';
855: }
856: my $menuname = &get_menu_name();
857:
858: # unless (shift eq 'unix') {
859: # resizing does not work on linux because of virtual desktop sizes
860: # $returnval.=(<<ENDRESIZE);
861: #if (window.screen) {
862: # self.resizeTo(screen.availWidth-215,screen.availHeight-55);
863: # self.moveTo(190,15);
864: #}
865: #ENDRESIZE
866: # }
867: $returnval.=(<<ENDOPEN);
868: window.status='Opening LON-CAPA Remote Control';
869: var menu=window.open("/res/adm/pages/menu.html","$menuname",
870: "height=375,width=150,scrollbars=no,menubar=no,top=5,left=5,screenX=5,screenY=5");
871: self.name='loncapaclient';
872: ENDOPEN
873: return '<script type="text/javascript">'.$returnval.'</script>';
874: }
875:
876:
877: # ================================================================== Raw Config
878:
879: sub clear {
880: my ($row,$col)=@_;
881: unless (($env{'browser.interface'} eq 'textual') ||
882: ($env{'environment.remote'} eq 'off')) {
883: return "\n".qq(window.status+='.';swmenu.clearbut($row,$col););
884: } else {
885: $inlineremote[10*$row+$col]='';
886: return '';
887: }
888: }
889:
890: # ============================================ Switch a button or create a link
891: # Switch acts on the javascript that is executed when a button is clicked.
892: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
893:
894: sub switch {
895: my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat,$nobreak)=@_;
896: $act=~s/\$uname/$uname/g;
897: $act=~s/\$udom/$udom/g;
898: $top=&mt($top);
899: $bot=&mt($bot);
900: $desc=&mt($desc);
901: if (($env{'environment.remote'} ne 'off') || ($env{'environment.icons'} eq 'classic')) {
902: $img=&mt($img);
903: }
904: my $idx=10*$row+$col;
905: $category_members{$cat}.=':'.$idx;
906:
907: unless (($env{'browser.interface'} eq 'textual') ||
908: ($env{'environment.remote'} eq 'off')) {
909: # Remote
910: return "\n".
911: qq(window.status+='.';swmenu.switchbutton($row,$col,"$img","$top","$bot","$act","$desc"););
912: } elsif ($env{'browser.interface'} eq 'textual') {
913: # Accessibility
914: if ($nobreak==2) { return ''; }
915: my $text=$top.' '.$bot;
916: $text=~s/\s*\-\s*//gs;
917: if ($nobreak) {
918: $inlineremote[$idx]=
919: '<a href="javascript:'.$act.';">'.$text.'</a>';
920: } else {
921: $inlineremote[$idx]="\n<br />".
922: $desc.' <a href="javascript:'.$act.';">'.$text.'</a>';
923: }
924: } else {
925: # Inline Remote
926: if ($env{'environment.icons'} ne 'classic') {
927: $img=~s/\.gif$/\.png/;
928: }
929: if ($nobreak==2) { return ''; }
930: my $text=$top.' '.$bot;
931: $text=~s/\s*\-\s*//gs;
932:
933: my $pic=
934: '<img alt="'.$text.'" src="'.
935: &Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$img).
936: '" align="'.($nobreak==3?'right':'left').'" />';
937: if ($env{'browser.interface'} eq 'faketextual') {
938: # Accessibility
939: if ($nobreak==3) {
940: $inlineremote[$idx]="\n".
941: '<td class="LC_menubuttons_text" align="right">'.$text.
942: '</td><td class="LC_menubuttons_img" align="left">'.
943: '<a href="javascript:'.$act.';">'.$pic.'</a></td></tr>';
944: } elsif ($nobreak) {
945: $inlineremote[$idx]="\n<tr>".
946: '<td class="LC_menubuttons_img" align="left">'.
947: '<a href="javascript:'.$act.';">'.$pic.'</a></td>
948: <td class="LC_menubuttons_text" align="left"><a class="LC_menubuttons_link" href="javascript:'.$act.';"><span class="LC_menubuttons_inline_text">'.$text.'</span></a></td>';
949: } else {
950: $inlineremote[$idx]="\n<tr>".
951: '<td class="LC_menubuttons_img" align="left">'.
952: '<a href="javascript:'.$act.';">'.$pic.
953: '</a></td><td class="LC_menubuttons_text" colspan="3">'.
954: '<a class="LC_menubuttons_link" href="javascript:'.$act.';"><span class="LC_menubuttons_inline_text">'.$desc.'</span></a></td></tr>';
955: }
956: } else {
957: # Inline Menu
958: if ($env{'environment.icons'} eq 'iconsonly') {
959: $inlineremote[$idx]='<a title="'.$desc.'" href="javascript:'.$act.';">'.$pic.'</a>';
960: } else {
961: $inlineremote[$idx]=
962: '<a class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.
963: '<span class="LC_menubuttons_inline_text">'.$desc.'</span></a>';
964: }
965: }
966: }
967: return '';
968: }
969:
970: sub secondlevel {
971: my $output='';
972: my
973: ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat)=@_;
974: if ($prt eq 'any') {
975: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
976: } elsif ($prt=~/^r(\w+)/) {
977: if ($rol eq $1) {
978: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
979: }
980: }
981: return $output;
982: }
983:
984: sub openmenu {
985: my $menuname = &get_menu_name();
986: if (($env{'browser.interface'} eq 'textual') ||
987: ($env{'environment.remote'} eq 'off')) { return ''; }
988: my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
989: return "window.open(".$nothing.",'".$menuname."');";
990: }
991:
992: sub inlinemenu {
993: undef(@inlineremote);
994: undef(%category_members);
995: &rawconfig(1);
996: my $output='<table id="LC_mainmenu"><tr>';
997: for (my $col=1; $col<=2; $col++) {
998: $output.='<td class="LC_mainmenu_column">';
999: for (my $row=1; $row<=8; $row++) {
1000: foreach my $cat (keys(%category_members)) {
1001: if ($category_positions{$cat} ne "$col,$row") { next; }
1002: $output.='<table id="LC_menubuttons_mainmenu"><tr><td colspan="4" class="LC_menubuttons_category">'.&mt($category_names{$cat}).'</td></tr>';
1003: my %active=();
1004: foreach my $menu_item (split(/\:/,$category_members{$cat})) {
1005: if ($inlineremote[$menu_item]) {
1006: $active{$menu_item}=1;
1007: }
1008: }
1009: foreach my $item (sort(keys(%active))) {
1010: $output.=$inlineremote[$item];
1011: }
1012: $output.='</table>';
1013: }
1014: }
1015: $output.="</td>";
1016: }
1017: $output.="</tr></table>";
1018: return $output;
1019: }
1020:
1021: sub inlinemenu_new {
1022: undef(@inlineremote);
1023: undef(%category_members);
1024: &rawconfig(1);
1025: my $output='<table id="LC_mainmenu"><tr>';
1026: for (my $col=1; $col<=2; $col++) {
1027: $output.='<td class="LC_mainmenu_column">';
1028: for (my $row=1; $row<=8; $row++) {
1029: foreach my $cat (keys(%category_members)) {
1030: if ($category_positions{$cat} ne "$col,$row") { next; }
1031: $output.='<table id="LC_menubuttons_mainmenu"><tr><td colspan="4" class="LC_menubuttons_category">'.&mt($category_names{$cat}).'</td></tr>';
1032: my %active=();
1033: foreach my $menu_item (split(/\:/,$category_members{$cat})) {
1034: if ($inlineremote[$menu_item]) {
1035: $active{$menu_item}=1;
1036: }
1037: }
1038: foreach my $item (sort(keys(%active))) {
1039: $output.=$inlineremote[$item];
1040: }
1041: $output.='</table>';
1042: }
1043: }
1044: $output.="</td>";
1045: }
1046: $output.="</tr></table>";
1047: return $output;
1048: }
1049:
1050: sub rawconfig {
1051: my $textualoverride=shift;
1052: my $output='';
1053: unless (($env{'browser.interface'} eq 'textual') ||
1054: ($env{'environment.remote'} eq 'off')) {
1055: $output.=
1056: "window.status='Opening Remote Control';var swmenu=".&openmenu().
1057: "\nwindow.status='Configuring Remote Control ';";
1058: } else {
1059: unless ($textualoverride) { return ''; }
1060: }
1061: my $uname=$env{'user.name'};
1062: my $udom=$env{'user.domain'};
1063: my $adv=$env{'user.adv'};
1064: my $show_course=&show_course();
1065: my $author=$env{'user.author'};
1066: my $crs='';
1067: if ($env{'request.course.id'}) {
1068: $crs='/'.$env{'request.course.id'};
1069: if ($env{'request.course.sec'}) {
1070: $crs.='_'.$env{'request.course.sec'};
1071: }
1072: $crs=~s/\_/\//g;
1073: }
1074: my $pub=($env{'request.state'} eq 'published');
1075: my $con=($env{'request.state'} eq 'construct');
1076: my $rol=$env{'request.role'};
1077: my $requested_domain = $env{'request.role.domain'};
1078: foreach my $line (@desklines) {
1079: my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc,$cat)=split(/\:/,$line);
1080: $prt=~s/\$uname/$uname/g;
1081: $prt=~s/\$udom/$udom/g;
1082: $prt=~s/\$crs/$crs/g;
1083: $prt=~s/\$requested_domain/$requested_domain/g;
1084: if ($category_names{$cat}!~/\w/) { $cat='oth'; }
1085: my $type = &Apache::loncommon::course_type();
1086: if ($type eq 'Group') {
1087: $desc = &convert_menu_function($desc,$type);
1088: }
1089: if ($pro eq 'clear') {
1090: $output.=&clear($row,$col);
1091: } elsif ($pro eq 'any') {
1092: $output.=&secondlevel(
1093: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1094: } elsif ($pro eq 'smp') {
1095: unless ($adv) {
1096: $output.=&secondlevel(
1097: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1098: }
1099: } elsif ($pro eq 'adv') {
1100: if ($adv) {
1101: $output.=&secondlevel(
1102: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1103: }
1104: } elsif ($pro eq 'shc') {
1105: if ($show_course) {
1106: $output.=&secondlevel(
1107: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1108: }
1109: } elsif ($pro eq 'nsc') {
1110: if (!$show_course) {
1111: $output.=&secondlevel(
1112: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1113: }
1114: } elsif (($pro=~/^p(\w+)/) && ($prt)) {
1115: if (&Apache::lonnet::allowed($1,$prt)) {
1116: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1117: }
1118: } elsif ($pro eq 'course') {
1119: if ($env{'request.course.fn'}) {
1120: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1121: }
1122: } elsif ($pro =~ /^courseenv_(.*)$/) {
1123: my $key = $1;
1124: if ($env{'course.'.$env{'request.course.id'}.'.'.$key}) {
1125: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1126: }
1127: } elsif ($pro =~ /^course_(.*)$/) {
1128: # Check for permissions inside of a course
1129: if (($env{'request.course.id'}) &&
1130: (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
1131: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
1132: )) {
1133: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1134: }
1135: } elsif ($pro eq 'author') {
1136: if ($author) {
1137: if ((($prt eq 'rca') && ($env{'request.role'}=~/^ca/)) ||
1138: (($prt eq 'raa') && ($env{'request.role'}=~/^aa/)) ||
1139: (($prt eq 'rau') && ($env{'request.role'}=~/^au/))) {
1140: # Check that we are on the correct machine
1141: my $cadom=$requested_domain;
1142: my $caname=$env{'user.name'};
1143: if (($prt eq 'rca') || ($prt eq 'raa')) {
1144: ($cadom,$caname)=
1145: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1146: }
1147: $act =~ s/\$caname/$caname/g;
1148: my $home = &Apache::lonnet::homeserver($caname,$cadom);
1149: my $allowed=0;
1150: my @ids=&Apache::lonnet::current_machine_ids();
1151: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
1152: if ($allowed) {
1153: $output.=&switch($caname,$cadom,
1154: $row,$col,$img,$top,$bot,$act,$desc,$cat);
1155: }
1156: }
1157: }
1158: }
1159: }
1160: unless (($env{'browser.interface'} eq 'textual') ||
1161: ($env{'environment.remote'} eq 'off')) {
1162: $output.="\nwindow.status='Synchronizing Time';swmenu.syncclock(1000*".time.");\nwindow.status='Remote Control Configured.';";
1163: if (&Apache::lonmsg::newmail()) {
1164: $output.='swmenu.setstatus("you have","messages");';
1165: }
1166: }
1167:
1168: return $output;
1169: }
1170:
1171: # ======================================================================= Close
1172:
1173: sub close {
1174: if (($env{'browser.interface'} eq 'textual') ||
1175: ($env{'environment.remote'} eq 'off')) { return ''; }
1176: my $menuname = &get_menu_name();
1177: return(<<ENDCLOSE);
1178: <script type="text/javascript">
1179: window.status='Accessing Remote Control';
1180: menu=window.open("/adm/rat/empty.html","$menuname",
1181: "height=350,width=150,scrollbars=no,menubar=no");
1182: window.status='Disabling Remote Control';
1183: menu.active=0;
1184: menu.autologout=0;
1185: window.status='Closing Remote Control';
1186: menu.close();
1187: window.status='Done.';
1188: </script>
1189: ENDCLOSE
1190: }
1191:
1192: # ====================================================================== Footer
1193:
1194: sub footer {
1195:
1196: }
1197:
1198: sub nav_control_js {
1199: my $nav=($env{'environment.remotenavmap'} eq 'on');
1200: return (<<NAVCONTROL);
1201: var w_loncapanav_flag="$nav";
1202:
1203:
1204: function gonav(url) {
1205: if (w_loncapanav_flag != 1) {
1206: gopost(url,'');
1207: } else {
1208: navwindow=window.open(url,
1209: "loncapanav","height=600,width=400,scrollbars=1");
1210: }
1211: }
1212: NAVCONTROL
1213: }
1214:
1215: sub utilityfunctions {
1216: my $caller = shift;
1217: unless (($env{'browser.interface'} eq 'textual') ||
1218: ($env{'environment.remote'} eq 'off') || ($caller eq '/adm/menu')) { return ''; }
1219: my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
1220: $currenturl=&Apache::lonenc::check_encrypt(&unescape($currenturl));
1221:
1222: my $currentsymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
1223: my $nav_control=&nav_control_js();
1224:
1225: my $start_page_annotate =
1226: &Apache::loncommon::start_page('Annotator',undef,
1227: {'only_body' => 1,
1228: 'js_ready' => 1,
1229: 'bgcolor' => '#BBBBBB',
1230: 'add_entries' => {
1231: 'onload' => 'javascript:document.goannotate.submit();'}});
1232:
1233: my $end_page_annotate =
1234: &Apache::loncommon::end_page({'js_ready' => 1});
1235:
1236: my $start_page_bookmark =
1237: &Apache::loncommon::start_page('Bookmarks',undef,
1238: {'only_body' => 1,
1239: 'js_ready' => 1,
1240: 'bgcolor' => '#BBBBBB',});
1241:
1242: my $end_page_bookmark =
1243: &Apache::loncommon::end_page({'js_ready' => 1});
1244:
1245: return (<<ENDUTILITY)
1246:
1247: var currentURL="$currenturl";
1248: var reloadURL="$currenturl";
1249: var currentSymb="$currentsymb";
1250:
1251: $nav_control
1252:
1253: function go(url) {
1254: if (url!='' && url!= null) {
1255: currentURL = null;
1256: currentSymb= null;
1257: window.location.href=url;
1258: }
1259: }
1260:
1261: function gopost(url,postdata) {
1262: if (url!='') {
1263: this.document.server.action=url;
1264: this.document.server.postdata.value=postdata;
1265: this.document.server.command.value='';
1266: this.document.server.url.value='';
1267: this.document.server.symb.value='';
1268: this.document.server.submit();
1269: }
1270: }
1271:
1272: function gocmd(url,cmd) {
1273: if (url!='') {
1274: this.document.server.action=url;
1275: this.document.server.postdata.value='';
1276: this.document.server.command.value=cmd;
1277: this.document.server.url.value=currentURL;
1278: this.document.server.symb.value=currentSymb;
1279: this.document.server.submit();
1280: }
1281: }
1282:
1283: function gocstr(url,filename) {
1284: if (url == '/adm/cfile?action=delete') {
1285: this.document.cstrdelete.filename.value = filename
1286: this.document.cstrdelete.submit();
1287: return;
1288: }
1289: if (url == '/adm/printout') {
1290: this.document.cstrprint.postdata.value = filename
1291: this.document.cstrprint.curseed.value = 0;
1292: this.document.cstrprint.problemtype.value = 0;
1293: if (this.document.lonhomework) {
1294: if ((this.document.lonhomework.rndseed) && (this.document.lonhomework.rndseed.value != null) && (this.document.lonhomework.rndseed.value != '')) {
1295: this.document.cstrprint.curseed.value = this.document.lonhomework.rndseed.value
1296: }
1297: if (this.document.lonhomework.problemtype) {
1298: if (this.document.lonhomework.problemtype.value) {
1299: this.document.cstrprint.problemtype.value =
1300: this.document.lonhomework.problemtype.value;
1301: } else if (this.document.lonhomework.problemtype.options) {
1302: for (var i=0; i<this.document.lonhomework.problemtype.options.length; i++) {
1303: if (this.document.lonhomework.problemtype.options[i].selected) {
1304: if (this.document.lonhomework.problemtype.options[i].value != null && this.document.lonhomework.problemtype.options[i].value != '') {
1305: this.document.cstrprint.problemtype.value = this.document.lonhomework.problemtype.options[i].value
1306: }
1307: }
1308: }
1309: }
1310: }
1311: }
1312: this.document.cstrprint.submit();
1313: return;
1314: }
1315: if (url !='') {
1316: this.document.constspace.filename.value = filename;
1317: this.document.constspace.action = url;
1318: this.document.constspace.submit();
1319: }
1320: }
1321:
1322: function golist(url) {
1323: if (url!='' && url!= null) {
1324: currentURL = null;
1325: currentSymb= null;
1326: top.location.href=url;
1327: }
1328: }
1329:
1330:
1331:
1332: function catalog_info() {
1333: loncatinfo=window.open(window.location.pathname+'.meta',"LONcatInfo",'height=320,width=280,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
1334: }
1335:
1336: function chat_win() {
1337: lonchat=window.open('/res/adm/pages/chatroom.html',"LONchat",'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
1338: }
1339:
1340: function group_chat(group) {
1341: var url = '/adm/groupchat?group='+group;
1342: var winName = 'LONchat_'+group;
1343: grpchat=window.open(url,winName,'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
1344: }
1345:
1346: function edit_bookmarks() {
1347: go('');
1348: w_BookmarkPal_flag=1;
1349: bookmarkpal=window.open("/adm/bookmarks",
1350: "BookmarkPal", "width=400,height=505,scrollbars=0");
1351: }
1352:
1353: function annotate() {
1354: w_Annotator_flag=1;
1355: annotator=window.open('','Annotator','width=365,height=265,scrollbars=0');
1356: annotator.document.write(
1357: '$start_page_annotate'
1358: +"<form name='goannotate' target='Annotator' method='post' "
1359: +"action='/adm/annotations'>"
1360: +"<input type='hidden' name='symbnew' value='"+currentSymb+"' />"
1361: +"<\\/form>"
1362: +'$end_page_annotate');
1363: annotator.document.close();
1364: }
1365:
1366: function set_bookmark() {
1367: go('');
1368: clienttitle=document.title;
1369: clienthref=location.pathname;
1370: w_bmquery_flag=1;
1371: bmquery=window.open('','bmquery','width=365,height=165,scrollbars=0');
1372: bmquery.document.write(
1373: '$start_page_bookmark'
1374: +"<center><form method='post'"
1375: +" name='newlink' action='/adm/bookmarks' target='bmquery' "
1376: +">\\n <table width=340 height=150 "
1377: +"bgcolor='ffffff' align=center><tr><td>Link Name:<br /><input "
1378: +"type='text' name='title' size=45 value='"+clienttitle+"' />"
1379: +"<br />Address:<br /><input type='text' name='address' size='45' "
1380: +"value='"+clienthref+"' /><br /><center><input type='submit' "
1381: +"value='Save' /> <input type='button' value='Close (no save)' "
1382: +"onclick='javascript:window.close();' /><\\/center><\\/td>"
1383: +"<\\/tr><\\/table><\\/form><\\/center>"
1384: +'$end_page_bookmark' );
1385: bmquery.document.close();
1386: }
1387:
1388: ENDUTILITY
1389: }
1390:
1391: sub serverform {
1392: return(<<ENDSERVERFORM);
1393: <form name="server" action="/adm/logout" method="post" target="_top">
1394: <input type="hidden" name="postdata" value="none" />
1395: <input type="hidden" name="command" value="none" />
1396: <input type="hidden" name="url" value="none" />
1397: <input type="hidden" name="symb" value="none" />
1398: </form>
1399: ENDSERVERFORM
1400: }
1401:
1402: sub constspaceform {
1403: return(<<ENDCONSTSPACEFORM);
1404: <form name="constspace" action="/adm/logout" method="post" target="_top">
1405: <input type="hidden" name="filename" value="" />
1406: </form>
1407: <form name="cstrdelete" action="/adm/cfile" method="post" target="_top">
1408: <input type="hidden" name="action" value="delete" />
1409: <input type="hidden" name="filename" value="" />
1410: </form>
1411: <form name="cstrprint" action="/adm/printout" target="_parent" method="post">
1412: <input type="hidden" name="postdata" value="" />
1413: <input type="hidden" name="curseed" value="" />
1414: <input type="hidden" name="problemtype" value="" />
1415: </form>
1416:
1417: ENDCONSTSPACEFORM
1418: }
1419:
1420:
1421: sub get_nav_status {
1422: my $navstatus="swmenu.w_loncapanav_flag=";
1423: if ($env{'environment.remotenavmap'} eq 'on') {
1424: $navstatus.="1";
1425: } else {
1426: $navstatus.="-1";
1427: }
1428: return $navstatus;
1429: }
1430:
1431: #FIXME this needs to move into mydesktab and the other locations
1432: # the text is generated
1433: sub convert_menu_function {
1434: my ($rolename,$type) = @_;
1435: if ($type eq 'Group') {
1436: $rolename =~ s/student/member/g;
1437: $rolename =~ s/group/team/g;
1438: $rolename =~ s/course/group/g;
1439: $rolename =~ s/Course/Group/g;
1440: }
1441: return $rolename;
1442: }
1443:
1444: sub hidden_button_check {
1445: my $hidden;
1446: if ($env{'request.course.id'} eq '') {
1447: return;
1448: }
1449: if ($env{'request.role.adv'}) {
1450: return;
1451: }
1452: my $buttonshide = &Apache::lonnet::EXT('resource.0.buttonshide');
1453: return $buttonshide;
1454: }
1455:
1456: sub roles_selector {
1457: my ($cdom,$cnum) = @_;
1458: my $now = time;
1459: my (%courseroles,%seccount,%gotnosection);
1460: my $is_cc;
1461: my $role_selector;
1462: if ($env{'user.role.cc./'.$cdom.'/'.$cnum}) {
1463: my ($start,$end) = split(/\./,$env{'user.role.cc./'.$cdom.'/'.$cnum});
1464:
1465: if ((($start) && ($start<0)) ||
1466: (($end) && ($end<$now)) ||
1467: (($start) && ($now<$start))) {
1468: $is_cc = 0;
1469: } else {
1470: $is_cc = 1;
1471: }
1472: }
1473: if ($is_cc) {
1474: my %adv_roles =
1475: &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
1476: foreach my $role (keys(%adv_roles)) {
1477: my ($urole,$usec) = split(/:/,$role);
1478: if (!$gotnosection{$urole}) {
1479: $seccount{$urole} ++;
1480: $gotnosection{$urole} = 1;
1481: }
1482: if (ref($courseroles{$urole}) eq 'ARRAY') {
1483: if ($usec ne '') {
1484: if (!grep(/^Q$usec\E$/,@{$courseroles{$urole}})) {
1485: push(@{$courseroles{$urole}},$usec);
1486: $seccount{$urole} ++;
1487: }
1488: }
1489: } else {
1490: @{$courseroles{$urole}} = ();
1491: if ($usec ne '') {
1492: $seccount{$urole} ++;
1493: push(@{$courseroles{$urole}},$usec);
1494: }
1495: }
1496: }
1497: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
1498: @{$courseroles{'st'}} = ();
1499: if (keys(%sections_count) > 0) {
1500: push(@{$courseroles{'st'}},keys(%sections_count));
1501: }
1502: } else {
1503: foreach my $item (keys(%env)) {
1504: if ($item =~ m-^user\.role\.([^.]+)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
1505: my $role = $1;
1506: my $sec = $2;
1507: next if ($role eq 'gr');
1508: my ($start,$end) = split(/\./,$env{$item});
1509: next if (($start && $start > $now) || ($end && $end < $now));
1510: if ($sec eq '') {
1511: if (!$gotnosection{$role}) {
1512: $seccount{$role} ++;
1513: $gotnosection{$role} = 1;
1514: }
1515: }
1516: if (ref($courseroles{$role}) eq 'ARRAY') {
1517: if ($sec ne '') {
1518: if (!grep(/^Q$sec\E$/,@{$courseroles{$role}})) {
1519: push(@{$courseroles{$role}},$sec);
1520: $seccount{$role} ++;
1521: }
1522: }
1523: } else {
1524: @{$courseroles{$role}} = ();
1525: if ($sec ne '') {
1526: $seccount{$role} ++;
1527: push(@{$courseroles{$role}},$sec);
1528: }
1529: }
1530: }
1531: }
1532: }
1533: my @roles_order = ('cc','in','ta','ep','ad','st');
1534: if (keys(%courseroles) > 1) {
1535: $role_selector = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles);
1536: $role_selector .= '<form name="rolechooser" method="post" action="/adm/roles">
1537: <select name="switchrole" onchange="javascript:adhocRole('."'switchrole'".')">';
1538: $role_selector .= '<option value="">'.&mt('Switch course role to...').'</option>';
1539: foreach my $role (@roles_order) {
1540: if (defined($courseroles{$role})) {
1541: $role_selector .= "\n".'<option value="'.$role.'">'.&Apache::lonnet::plaintext($role).'</option>';
1542: }
1543: }
1544: foreach my $role (sort(keys(%courseroles))) {
1545: if ($role =~ /^cr/) {
1546: $role_selector .= "\n".'<option value="'.$role.'">'.&Apache::lonnet::plaintext($role).'</option>';
1547: }
1548: }
1549: $role_selector .= '</select>'."\n".
1550: '<input type="hidden" name="destinationurl" value="'.
1551: $ENV{'REQUEST_URI'}.'" />'."\n".
1552: '<input type="hidden" name="gotorole" value="1" />'."\n".
1553: '<input type="hidden" name="selectrole" value="" />'."\n".
1554: '<input type="hidden" name="switch" value="1" />'."\n".
1555: '</form>';
1556: }
1557: return $role_selector;
1558: }
1559:
1560: sub jump_to_role {
1561: my ($cdom,$cnum,$seccount,$courseroles) = @_;
1562: my %lt = &Apache::lonlocal::texthash(
1563: this => 'This role has section(s) associated with it.',
1564: ente => 'Enter a specific section.',
1565: orlb => 'Enter a specific section, or leave blank for no section.',
1566: avai => 'Available sections are:',
1567: youe => 'You entered an invalid section choice:',
1568: plst => 'Please try again',
1569: );
1570: my $js;
1571: if (ref($courseroles) eq 'HASH') {
1572: $js = ' var secpick = new Array("'.$lt{'ente'}.'","'.$lt{'orlb'}.'");'."\n".
1573: ' var numsec = new Array();'."\n".
1574: ' var rolesections = new Array();'."\n".
1575: ' var rolenames = new Array();'."\n".
1576: ' var roleseclist = new Array();'."\n";
1577: my @items = keys(%{$courseroles});
1578: for (my $i=0; $i<@items; $i++) {
1579: $js .= ' rolenames['.$i.'] = "'.$items[$i].'";'."\n";
1580: my ($secs,$secstr);
1581: if (ref($courseroles->{$items[$i]}) eq 'ARRAY') {
1582: my @sections = sort { $a <=> $b } @{$courseroles->{$items[$i]}};
1583: $secs = join('","',@sections);
1584: $secstr = join(', ',@sections);
1585: }
1586: $js .= ' rolesections['.$i.'] = new Array("'.$secs.'");'."\n".
1587: ' roleseclist['.$i.'] = "'.$secstr.'";'."\n".
1588: ' numsec['.$i.'] = "'.$seccount->{$items[$i]}.'";'."\n";
1589: }
1590: }
1591: my $output = <<"END";
1592: <script type="text/javascript">
1593: function adhocRole(roleitem) {
1594: $js
1595: var newrole = document.rolechooser.elements[roleitem].options[document.rolechooser.elements[roleitem].selectedIndex].value;
1596: if (newrole == '') {
1597: return;
1598: }
1599: var fullrole = newrole+'./$cdom/$cnum';
1600: var selidx = '';
1601: for (var i=0; i<rolenames.length; i++) {
1602: if (rolenames[i] == newrole) {
1603: selidx = i;
1604: }
1605: }
1606: var secok = 1;
1607: var secchoice = '';
1608: if (selidx >= 0) {
1609: if (numsec[selidx] > 1) {
1610: secok = 0;
1611: var numrolesec = rolesections[selidx].length;
1612: var msgidx = numsec[selidx] - numrolesec;
1613: secchoice = prompt("$lt{'this'}\\n"+secpick[msgidx]+"\\n$lt{'avai'} "+roleseclist[selidx],"");
1614: if (secchoice == '') {
1615: if (msgidx > 0) {
1616: secok = 1;
1617: }
1618: } else {
1619: for (var j=0; j<rolesections[selidx].length; j++) {
1620: if (rolesections[selidx][j] == secchoice) {
1621: secok = 1;
1622: }
1623: }
1624: }
1625: } else {
1626: if (rolesections[selidx].length == 1) {
1627: secchoice = rolesections[selidx][0];
1628: }
1629: }
1630: }
1631: if (secok == 1) {
1632: if (secchoice != '') {
1633: fullrole += '/'+secchoice;
1634: }
1635: } else {
1636: document.rolechooser.elements[roleitem].selectedIndex = 0;
1637: if (secchoice != null) {
1638: alert("$lt{'youe'} \\""+secchoice+"\\".\\n $lt{'plst'}");
1639: }
1640: return;
1641: }
1642: if (fullrole == "$env{'request.role'}") {
1643: return;
1644: }
1645: itemid = retrieveIndex('gotorole');
1646: if (itemid != -1) {
1647: document.rolechooser.elements[itemid].name = fullrole;
1648: }
1649: document.rolechooser.elements[roleitem].options[document.rolechooser.elements[roleitem].selectedIndex].value = fullrole;
1650: document.rolechooser.selectrole.value = '1';
1651: document.rolechooser.submit();
1652: return;
1653: }
1654:
1655: function retrieveIndex(item) {
1656: for (var i=0;i<document.rolechooser.elements.length;i++) {
1657: if (document.rolechooser.elements[i].name == item) {
1658: return i;
1659: }
1660: }
1661: return -1;
1662: }
1663:
1664:
1665: </script>
1666: END
1667: return $output;
1668: }
1669:
1670:
1671: # ================================================================ Main Program
1672:
1673: BEGIN {
1674: if (! defined($readdesk)) {
1675: {
1676: my $tabfile = $Apache::lonnet::perlvar{'lonTabDir'}.'/mydesk.tab';
1677: if ( CORE::open( my $config,"<$tabfile") ) {
1678: while (my $configline=<$config>) {
1679: $configline=(split(/\#/,$configline))[0];
1680: $configline=~s/^\s+//;
1681: chomp($configline);
1682: if ($configline=~/^cat\:/) {
1683: my @entries=split(/\:/,$configline);
1684: $category_positions{$entries[2]}=$entries[1];
1685: $category_names{$entries[2]}=$entries[3];
1686: } elsif ($configline) {
1687: push(@desklines,$configline);
1688: }
1689: }
1690: CORE::close($config);
1691: }
1692: }
1693: $readdesk='done';
1694: }
1695: }
1696:
1697: 1;
1698: __END__
1699:
1700:
1701:
1702:
1703:
1704:
1705:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>