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