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