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