File:
[LON-CAPA] /
loncom /
interface /
lonmenu.pm
Revision
1.386:
download - view:
text,
annotated -
select for diffs
Tue Sep 4 20:47:56 2012 UTC (11 years, 10 months ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
- Bug 6419.
- "Switch role to ..." in a course can handle switching back and forth
between roles with/without request.role.adv = 1, where course item has
URL hidden (from Course Editor).
1: # The LearningOnline Network with CAPA
2: # Routines to control the menu
3: #
4: # $Id: lonmenu.pm,v 1.386 2012/09/04 20:47:56 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:
30: =head1 NAME
31:
32: Apache::lonmenu
33:
34: =head1 SYNOPSIS
35:
36: Loads contents of /home/httpd/lonTabs/mydesk.tab,
37: used to generate inline menu, and Main Menu page.
38:
39: This is part of the LearningOnline Network with CAPA project
40: described at http://www.lon-capa.org.
41:
42: =head1 GLOBAL VARIABLES
43:
44: =over
45:
46: =item @desklines
47:
48: Each element of this array contains a line of mydesk.tab that doesn't start with
49: cat, prim or scnd.
50: It gets filled in the BEGIN block of this module.
51:
52: =item %category_names
53:
54: The keys of this hash are the abbreviations used in mydesk.tab in those lines that
55: start with cat, the values are strings representing titles.
56: It gets filled in the BEGIN block of this module.
57:
58: =item %category_members
59:
60: TODO
61:
62: =item %category_positions
63:
64: The keys of this hash are the abbreviations used in mydesk.tab in those lines that
65: start with cat, its values are position vectors (column, row).
66: It gets filled in the BEGIN block of this module.
67:
68: =item $readdesk
69:
70: Indicates that mydesk.tab has been read.
71: It is set to 'done' in the BEGIN block of this module.
72:
73: =item @primary_menu
74:
75: The elements of this array reference arrays that are made up of the components
76: of those lines of mydesk.tab that start with prim:.
77: It is used by primary_menu() to generate the corresponding menu.
78: It gets filled in the BEGIN block of this module.
79:
80: =item %primary_sub_menu
81:
82: The keys of this hash reference are the names of items in the primary_menu array
83: which have sub-menus. For each key, the corresponding value is a reference to
84: an array containing components extracted from lines in mydesk.tab which begin
85: with primsub:.
86: This hash, which is used by primary_menu to generate sub-menus, is populated in
87: the BEGIN block.
88:
89: =item @secondary_menu
90:
91: The elements of this array reference arrays that are made up of the components
92: of those lines of mydesk.tab that start with scnd.
93: It is used by secondary_menu() to generate the corresponding menu.
94: It gets filled in the BEGIN block of this module.
95:
96: =back
97:
98: =head1 SUBROUTINES
99:
100: =over
101:
102: =item prep_menuitems(\@menuitem)
103:
104: This routine wraps a menuitem in proper HTML. It is used by primary_menu() and
105: secondary_menu().
106:
107: =item primary_menu()
108:
109: This routine evaluates @primary_menu and returns XHTML for the menu
110: that contains following links: About, Message, Roles, Help, Logout
111: @primary_menu is filled within the BEGIN block of this module with
112: entries from mydesk.tab
113:
114: =item secondary_menu()
115:
116: Same as primary_menu() but operates on @secondary_menu.
117:
118: =item create_submenu()
119:
120: Creates XHTML for unordered list of sub-menu items which belong to a
121: particular top-level menu item. Uses hover pseudo class in css to display
122: dropdown list when mouse hovers over top-level item. Support for IE6
123: (no hover psuedo class) via LC_hoverable class for <li> tag for top-
124: level item, which employs jQuery to handle behavior on mouseover.
125:
126: Inputs: 4 - (a) link and (b) target for anchor href in top level item,
127: (c) title for text wrapped by anchor tag in top level item.
128: (d) reference to array of arrays of sub-menu items.
129:
130: =item innerregister()
131:
132: This gets called in order to register a URL in the body of the document
133:
134: =item clear()
135:
136: =item switch()
137:
138: Switch a button or create a link
139: Switch acts on the javascript that is executed when a button is clicked.
140: The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
141:
142: =item secondlevel()
143:
144: =item openmenu()
145:
146: =item inlinemenu()
147:
148: =item rawconfig()
149:
150: =item utilityfunctions()
151:
152: Output from this routine is a number of javascript functions called by
153: items in the inline menu, and in some cases items in the Main Menu page.
154:
155: =item serverform()
156:
157: =item constspaceform()
158:
159: =item get_nav_status()
160:
161: =item hidden_button_check()
162:
163: =item roles_selector()
164:
165: =item jump_to_role()
166:
167: =back
168:
169: =cut
170:
171: package Apache::lonmenu;
172:
173: use strict;
174: use Apache::lonnet;
175: use Apache::lonhtmlcommon();
176: use Apache::loncommon();
177: use Apache::lonenc();
178: use Apache::lonlocal;
179: use Apache::lonmsg();
180: use LONCAPA qw(:DEFAULT :match);
181: use HTML::Entities();
182: use Apache::lonwishlist();
183:
184: use vars qw(@desklines %category_names %category_members %category_positions
185: $readdesk @primary_menu %primary_submenu @secondary_menu);
186:
187: my @inlineremote;
188:
189: sub prep_menuitem {
190: my ($menuitem) = @_;
191: return '' unless(ref($menuitem) eq 'ARRAY');
192: my $link;
193: if ($$menuitem[1]) { # graphical Link
194: $link = "<img class=\"LC_noBorder\""
195: . " src=\"" . &Apache::loncommon::lonhttpdurl($$menuitem[1]) . "\""
196: . " alt=\"" . &mt($$menuitem[2]) . "\" />";
197: } else { # textual Link
198: $link = &mt($$menuitem[3]);
199: }
200: return '<li><a'
201: # highlighting for new messages
202: . ( $$menuitem[4] eq 'newmsg' ? ' class="LC_new_message"' : '')
203: . qq| href="$$menuitem[0]" target="_top">$link</a></li>|;
204: }
205:
206: # primary_menu() evaluates @primary_menu and returns XHTML for the menu
207: # that contains following links:
208: # About, Message, Personal, Roles, Help, Logout
209: # @primary_menu is filled within the BEGIN block of this module with
210: # entries from mydesk.tab
211: sub primary_menu {
212: my $menu;
213: # each element of @primary contains following array:
214: # (link url, icon path, alt text, link text, condition)
215: my $public;
216: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
217: || (($env{'user.name'} eq '') && ($env{'user.domain'} eq ''))) {
218: $public = 1;
219: }
220: foreach my $menuitem (@primary_menu) {
221: # evaluate conditions
222: next if ref($menuitem) ne 'ARRAY'; #
223: next if $$menuitem[4] eq 'nonewmsg' # show links depending on
224: && &Apache::lonmsg::mynewmail(); # whether a new msg
225: next if $$menuitem[4] eq 'newmsg' # arrived or not
226: && !&Apache::lonmsg::mynewmail(); #
227: next if $$menuitem[4] !~ /public/ ##we've a public user,
228: && $public; ##who should not see all
229: ##links
230: next if $$menuitem[4] eq 'onlypublic'# hide links which are
231: && !$public; # only visible to public
232: # users
233: next if $$menuitem[4] eq 'roles' ##show links depending on
234: && &Apache::loncommon::show_course(); ##term 'Courses' or
235: next if $$menuitem[4] eq 'courses' ##'Roles' wanted
236: && !&Apache::loncommon::show_course(); ##
237:
238: my $title = $menuitem->[3];
239: if (defined($primary_submenu{$title})) {
240: my ($link,$target);
241: if ($menuitem->[0] ne '') {
242: $link = $menuitem->[0];
243: $target = '_top';
244: } else {
245: $link = '#';
246: }
247: my @primsub;
248: if (ref($primary_submenu{$title}) eq 'ARRAY') {
249: foreach my $item (@{$primary_submenu{$title}}) {
250: next if (($item->[2] eq 'wishlist') && (!$env{'user.adv'}));
251: next if (($item->[2] eq 'reqcrs') && (!&check_for_rcrs()));
252: next if ((($item->[2] eq 'portfolio') ||
253: ($item->[2] eq 'blog')) &&
254: (!&Apache::lonnet::usertools_access('','',$item->[2],
255: undef,'tools')));
256: push(@primsub,$item);
257: }
258: if (@primsub > 0) {
259: $menu .= &create_submenu($link,$target,$title,\@primsub);
260: } elsif ($link) {
261: $menu .= '<li><a href="'.$link.'" target="'.$target.'">'.&mt($title).'</a></li>';
262: }
263: }
264: } elsif ($$menuitem[3] eq 'Help') { # special treatment for helplink
265: if ($public) {
266: my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
267: my $defdom = &Apache::lonnet::default_login_domain();
268: my $to = &Apache::loncommon::build_recipient_list(undef,
269: 'helpdeskmail',
270: $defdom,$origmail);
271: if ($to ne '') {
272: $menu .= &prep_menuitem($menuitem);
273: }
274: } else {
275: $menu .= '<li>'.&Apache::loncommon::top_nav_help('Help').'</li>';
276: }
277: } else {
278: $menu .= prep_menuitem($menuitem);
279: }
280: }
281: $menu =~ s/\[domain\]/$env{'user.domain'}/g;
282: $menu =~ s/\[user\]/$env{'user.name'}/g;
283:
284: return "<ol class=\"LC_primary_menu LC_right\">$menu</ol>";
285: }
286:
287: #returns hashref {user=>'',dom=>''} containing:
288: # own name, domain if user is au
289: # name, domain of parent author if user is ca or aa
290: #empty return if user is not an author or not on homeserver
291: #
292: #TODO this should probably be moved somewhere more central
293: #since it can be used by different parts of the system
294: sub getauthor{
295: return unless $env{'request.role'}=~/^(ca|aa|au)/; #nothing to do if user isn't some kind of author
296:
297: #co- or assistent author?
298: my ($dom, $user) = ($env{'request.role'} =~ /^(?:ca|aa)\.\/($match_domain)\/($match_username)$/)
299: ? ($1, $2) #domain, username of the parent author
300: : @env{ ('request.role.domain', 'user.name') }; #own domain, username
301:
302: # current server == home server?
303: my $home = &Apache::lonnet::homeserver($user,$dom);
304: foreach (&Apache::lonnet::current_machine_ids()){
305: return {user => $user, dom => $dom} if $_ eq $home;
306: }
307:
308: # if wrong server
309: return;
310: }
311:
312: sub secondary_menu {
313: my $menu;
314:
315: my $crstype = &Apache::loncommon::course_type();
316: my $crs_sec = $env{'request.course.id'} . ($env{'request.course.sec'}
317: ? "/$env{'request.course.sec'}"
318: : '');
319: my $canedit = &Apache::lonnet::allowed('mdc', $env{'request.course.id'});
320: my $canviewroster = $env{'course.'.$env{'request.course.id'}.'.student_classlist_view'};
321: my $canviewgrps = &Apache::lonnet::allowed('vcg', $crs_sec);
322: my $canmodifyuser = &Apache::lonnet::allowed('cst', $crs_sec);
323: my $canviewwnew = &Apache::lonnet::allowed('whn', $crs_sec);
324: my $canmodpara = &Apache::lonnet::allowed('opa', $crs_sec);
325: my $canvgr = &Apache::lonnet::allowed('vgr', $crs_sec);
326: my $canmgr = &Apache::lonnet::allowed('mgr', $crs_sec);
327: my $author = &getauthor();
328:
329: my %groups = &Apache::lonnet::get_active_groups(
330: $env{'user.domain'}, $env{'user.name'},
331: $env{'course.' . $env{'request.course.id'} . '.domain'},
332: $env{'course.' . $env{'request.course.id'} . '.num'});
333:
334: foreach my $menuitem (@secondary_menu) {
335: # evaluate conditions
336: next if ref($menuitem) ne 'ARRAY';
337: next if $$menuitem[4] ne 'always'
338: && $$menuitem[4] ne 'author'
339: && !$env{'request.course.id'};
340: next if $$menuitem[4] =~ /^mdc/
341: && !$canedit;
342: next if $$menuitem[4] eq 'nvgr'
343: && $canvgr;
344: next if $$menuitem[4] eq 'vgr'
345: && !$canvgr;
346: next if $$menuitem[4] eq 'cst'
347: && !$canmodifyuser;
348: next if $$menuitem[4] eq 'ncst'
349: && ($canmodifyuser || !$canviewroster);
350: next if $$menuitem[4] eq 'mgr'
351: && !$canmgr;
352: next if $$menuitem[4] eq 'nmgr'
353: && $canmgr;
354: next if $$menuitem[4] eq 'whn'
355: && !$canviewwnew;
356: next if $$menuitem[4] eq 'opa'
357: && !$canmodpara;
358: next if $$menuitem[4] =~ /showgroups$/
359: && !$canviewgrps
360: && !%groups;
361: next if $$menuitem[4] eq 'author'
362: && !$author;
363:
364: if ($$menuitem[3] eq 'Roles' && $env{'request.course.id'}) {
365: # special treatment for role selector
366: my $roles_selector = &roles_selector(
367: $env{'course.' . $env{'request.course.id'} . '.domain'},
368: $env{'course.' . $env{'request.course.id'} . '.num'} );
369:
370: $menu .= $roles_selector ? "<li>$roles_selector</li>"
371: : '';
372: } else {
373: $menu .= &prep_menuitem(\@$menuitem);
374: }
375: }
376: if ($menu =~ /\[url\].*\[symb\]/) {
377: my $escurl = &escape( &Apache::lonenc::check_encrypt(
378: $env{'request.noversionuri'}));
379:
380: my $escsymb = &escape( &Apache::lonenc::check_encrypt(
381: $env{'request.symb'}));
382:
383: if ( $env{'request.state'} eq 'construct'
384: and ( $env{'request.noversionuri'} eq ''
385: || !defined($env{'request.noversionuri'})))
386: {
387: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
388: ($escurl = $env{'request.filename'}) =~ s{^\Q$londocroot\E}{};
389: $escurl = &escape($escurl);
390: }
391: $menu =~ s/\[url\]/$escurl/g;
392: $menu =~ s/\[symb\]/$escsymb/g;
393: }
394: $menu =~ s/\[uname\]/$$author{user}/g;
395: $menu =~ s/\[udom\]/$$author{dom}/g;
396: if ($menu) {
397: $menu = "<ul id=\"LC_secondary_menu\">$menu</ul>";
398: }
399: return $menu;
400: }
401:
402: sub create_submenu {
403: my ($link,$target,$title,$submenu) = @_;
404: return unless (ref($submenu) eq 'ARRAY');
405: my $disptarget;
406: if ($target ne '') {
407: $disptarget = ' target="'.$target.'"';
408: }
409: my $menu = '<li class="LC_hoverable">'.
410: '<a href="'.$link.'"'.$disptarget.'>'.
411: '<span class="LC_nobreak">'.&mt($title).
412: '<span class="LC_fontsize_small" style="font-weight:normal;">'.
413: ' ▼</span></span></a>'.
414: '<ul>';
415: my $count = 0;
416: my $numsub = scalar(@{$submenu});
417: foreach my $item (@{$submenu}) {
418: $count ++;
419: if (ref($item) eq 'ARRAY') {
420: my $borderbot;
421: if ($count == $numsub) {
422: $borderbot = 'border-bottom:1px solid black;';
423: }
424: $menu .= '<li style="margin:0;padding:0;'.
425: $borderbot.'"><a href="'.$item->[0].'">'.
426: &mt($item->[1]).'</a></li>';
427: }
428: }
429: $menu .= '</ul></li>';
430: return $menu;
431: }
432:
433: sub innerregister {
434: my ($forcereg,$bread_crumbs) = @_;
435: my $const_space = ($env{'request.state'} eq 'construct');
436: my $is_const_dir = 0;
437:
438: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
439:
440: $env{'request.registered'} = 1;
441:
442: undef(@inlineremote);
443:
444: my $resurl;
445: if ( $env{'request.symb'} && $env{'request.course.id'} ) {
446:
447: (my $mapurl, my $rid, $resurl) = &Apache::lonnet::decode_symb(&Apache::lonnet::symbread());
448: my $coursetitle = $env{'course.'.$env{'request.course.id'}.'.description'};
449:
450: my $maptitle = &Apache::lonnet::gettitle($mapurl);
451: my $restitle = &Apache::lonnet::gettitle(&Apache::lonnet::symbread());
452:
453: #SD
454: #course_type only Course and Community?
455: #
456: my @crumbs;
457: unless (($forcereg) && ($env{'request.noversionuri'} eq '/adm/navmaps')
458: && ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'})) {
459: @crumbs = ({text => Apache::loncommon::course_type()
460: . ' Contents',
461: href => "Javascript:gopost('/adm/navmaps','')"});
462: }
463: if ($mapurl ne $env{'course.'.$env{'request.course.id'}.'.url'}) {
464: push(@crumbs, {text => '...',
465: no_mt => 1});
466: }
467:
468: push @crumbs, {text => $maptitle, no_mt => 1} if ($maptitle
469: && $maptitle ne 'default.sequence'
470: && $maptitle ne $coursetitle);
471:
472: push @crumbs, {text => $restitle, no_mt => 1} if $restitle;
473:
474: &Apache::lonhtmlcommon::clear_breadcrumbs();
475: &Apache::lonhtmlcommon::add_breadcrumb(@crumbs);
476: }elsif (! $const_space){
477: #a situation when we're looking at a resource outside of context of a
478: #course or construction space (e.g. with cumulative rights)
479: &Apache::lonhtmlcommon::clear_breadcrumbs();
480: &Apache::lonhtmlcommon::add_breadcrumb({text => 'View Resource'});
481: }
482: # =============================================================================
483: # ============================ This is for URLs that actually can be registered
484: return '' unless ( ($env{'request.noversionuri'}!~m{^/(res/)*adm/})
485: || $forcereg );
486:
487: # -- This applies to homework problems for users with grading privileges
488: my $crs='/'.$env{'request.course.id'};
489: if ($env{'request.course.sec'}) {
490: $crs.='_'.$env{'request.course.sec'};
491: }
492: $crs=~s/\_/\//g;
493:
494: my $hwkadd='';
495: if ($env{'request.symb'} ne '' &&
496: $env{'request.filename'}=~/$LONCAPA::assess_re/) {
497: if (&Apache::lonnet::allowed('mgr',$crs)) {
498: $hwkadd.=&switch('','',7,2,'pgrd.png','Content Grades','grades[_4]',
499: "gocmd('/adm/grades','gradingmenu')",
500: 'Content Grades');
501: } elsif (&Apache::lonnet::allowed('vgr',$crs)) {
502: $hwkadd.=&switch('','',7,2,'subm.png','Content Submissions','missions[_1]',
503: "gocmd('/adm/grades','submission')",
504: 'Content Submissions');
505: }
506: }
507: if ($env{'request.symb'} ne '' &&
508: &Apache::lonnet::allowed('opa',$crs)) {
509: $hwkadd.=&switch('','',7,3,'pparm.png','Content Settings','parms[_2]',
510: "gocmd('/adm/parmset','set')",
511: 'Content Settings');
512: }
513: if ($env{'request.symb'}=~/^uploaded/ &&
514: &Apache::lonnet::allowed('mdc',$crs)) {
515: $hwkadd.=&switch('','',7,4,'docs.png','Folder/Page Content','parms[_2]',
516: "gocmd('/adm/coursedocs','direct')",
517: 'Folder/Page Content');
518: }
519: # -- End Homework
520: ###
521: ### Determine whether or not to display the 'cstr' button for this
522: ### resource
523: ###
524: my $editbutton = '';
525: my $noeditbutton = 1;
526: my ($cnum,$cdom);
527: if ($env{'request.course.id'}) {
528: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
529: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
530: }
531: if ($env{'user.author'}) {
532: if ($env{'request.role'}=~/^(aa|ca|au)/) {
533: #
534: # We have the role of an author
535: #
536: # Set defaults for authors
537: my ($top,$bottom) = ('con-','struct');
538: my $action = "go('/priv/".$env{'user.domain'}.'/'.$env{'user.name'}."');";
539: my $cadom = $env{'request.role.domain'};
540: my $caname = $env{'user.name'};
541: my $desc = "Enter my construction space";
542: # Set defaults for co-authors
543: if ($env{'request.role'} =~ /^ca/) {
544: ($cadom,$caname)=($env{'request.role'}=~/($match_domain)\/($match_username)$/);
545: ($top,$bottom) = ('co con-','struct');
546: $action = "go('/priv/".$cadom.'/'.$caname."');";
547: $desc = "Enter construction space as co-author";
548: } elsif ($env{'request.role'} =~ /^aa/) {
549: ($cadom,$caname)=($env{'request.role'}=~/($match_domain)\/($match_username)$/);
550: ($top,$bottom) = ('co con-','struct');
551: $action = "go('/priv/".$cadom.'/'.$caname."');";
552: $desc = "Enter construction space as assistant co-author";
553: }
554: # Check that we are on the correct machine
555: my $home = &Apache::lonnet::homeserver($caname,$cadom);
556: my $allowed=0;
557: my @ids=&Apache::lonnet::current_machine_ids();
558: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
559: if (!$allowed) {
560: $editbutton=&switch('','',6,1,$top,,$bottom,$action,$desc);
561: $noeditbutton = 0;
562: }
563: }
564: #
565: # We are an author for some stuff, but currently do not have the role of author.
566: # Figure out if we have authoring privileges for the resource we are looking at.
567: # This should maybe become a privilege check in lonnet
568: #
569: ##
570: ## Determine if user can edit url.
571: ##
572: my $cfile='';
573: my $cfuname='';
574: my $cfudom='';
575: my $uploaded;
576: my $switchserver='';
577: my $home;
578: if ($env{'request.filename'}) {
579: my $file=&Apache::lonnet::declutter($env{'request.filename'});
580: if (defined($cnum) && defined($cdom)) {
581: $uploaded = &is_course_upload($file,$cnum,$cdom);
582: }
583: if (!$uploaded) {
584:
585: $file=~s{^(priv/$match_domain/$match_username)}{/$1};
586: $file=~s{^($match_domain/$match_username)}{/priv/$1};
587:
588: # Check that the user has permission to edit this resource
589: my $setpriv = 1;
590: ($cfuname,$cfudom)=&Apache::loncacc::constructaccess($file,$setpriv);
591: if (defined($cfudom)) {
592: $home=&Apache::lonnet::homeserver($cfuname,$cfudom);
593: my $allowed=0;
594: my @ids=&Apache::lonnet::current_machine_ids();
595: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
596: if ($allowed) {
597: $cfile=$file;
598: } else {
599: $switchserver=$file;
600: }
601: }
602: }
603: }
604: # Finally, turn the button on or off
605: if (($cfile || $switchserver) && !$const_space) {
606: my $nocrsedit;
607: # Suppress display where CC has switched to student role.
608: if ($env{'request.course.id'}) {
609: unless(&Apache::lonnet::allowed('mdc',
610: $env{'request.course.id'})) {
611: $nocrsedit = 1;
612: }
613: }
614: if ($nocrsedit) {
615: $editbutton=&clear(6,1);
616: } else {
617: my $bot = "go('$cfile')";
618: if ($switchserver) {
619: if ( $env{'request.symb'} && $env{'request.course.id'} ) {
620: $cfile = '/adm/switchserver?otherserver='.$home.'&role='.
621: &HTML::Entities::encode($env{'request.role'},'"<>&').'&symb='.
622: &HTML::Entities::encode($env{'request.symb'},'"<>&');
623: $bot = "need_switchserver('$cfile');";
624: }
625: }
626: $editbutton=&switch
627: ('','',6,1,'pcstr.png','Edit','resource[_2]',
628: $bot,"Edit this resource");
629: $noeditbutton = 0;
630: }
631: } elsif ($editbutton eq '') {
632: $editbutton=&clear(6,1);
633: }
634: }
635: if (($noeditbutton) && ($env{'request.filename'})) {
636: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
637: my $file=&Apache::lonnet::declutter($env{'request.filename'});
638: if (defined($cnum) && defined($cdom)) {
639: if (&is_course_upload($file,$cnum,$cdom)) {
640: my $cfile = &edit_course_upload($file,$cnum,$cdom);
641: if ($cfile) {
642: $editbutton=&switch
643: ('','',6,1,'pcstr.png','Edit',
644: 'resource[_2]',"go('".$cfile."');",
645: 'Edit this resource');
646: }
647: }
648: }
649: }
650: }
651: if ($env{'request.course.id'}) {
652: if ($resurl eq "public/$cdom/$cnum/syllabus") {
653: if ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ /\w/) {
654: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
655: $editbutton=&switch('','',6,1,'pcstr.png','Edit',
656: 'resource[_2]',
657: "go('/adm/courseprefs?phase=display&actions=courseinfo')",
658: 'Edit this resource');
659: }
660: }
661: }
662: }
663: ###
664: ###
665: # Prepare the rest of the buttons
666: my ($menuitems,$got_prt,$got_wishlist);
667: if ($const_space) {
668: #
669: # We are in construction space
670: #
671:
672: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
673: my ($udom,$uname,$thisdisfn) =
674: ($env{'request.filename'}=~m{^\Q$londocroot/priv/\E([^/]+)/([^/]+)/(.*)$});
675: my $currdir = '/priv/'.$udom.'/'.$uname.'/'.$thisdisfn;
676: if ($currdir =~ m-/$-) {
677: $is_const_dir = 1;
678: } else {
679: $currdir =~ s|[^/]+$||;
680: my $cleandisfn = &Apache::loncommon::escape_single($thisdisfn);
681: my $esc_currdir = &Apache::loncommon::escape_single($currdir);
682: #
683: # Probably should be in mydesk.tab
684: #
685: $menuitems=(<<ENDMENUITEMS);
686: s&6&1&list.png&Directory&dir[_1]&golist('$esc_currdir')&List current directory
687: s&6&2&rtrv.png&Retrieve&version[_1]&gocstr('/adm/retrieve','/priv/$udom/$uname/$cleandisfn')&Retrieve old version
688: s&6&3&pub.png&Publish&resource[_3]&gocstr('/adm/publish','/priv/$udom/$uname/$cleandisfn')&Publish this resource
689: s&7&1&del.png&Delete&resource[_2]&gocstr('/adm/cfile?action=delete','/priv/$udom/$uname/$cleandisfn')&Delete this resource
690: s&7&2&prt.png&Print&printout[_1]&gocstr('/adm/printout','/priv/$udom/$uname/$cleandisfn')&Prepare a printable document
691: ENDMENUITEMS
692: }
693: if (ref($bread_crumbs) eq 'ARRAY') {
694: &Apache::lonhtmlcommon::clear_breadcrumbs();
695: foreach my $crumb (@{$bread_crumbs}){
696: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
697: }
698: }
699: } elsif ( defined($env{'request.course.id'}) &&
700: $env{'request.symb'} ne '' ) {
701: #
702: # We are in a course and looking at a registered URL
703: # Should probably be in mydesk.tab
704: #
705: $menuitems=(<<ENDMENUITEMS);
706: c&3&1
707: s&2&1&back.png&&&gopost('/adm/flip','back:'+currentURL)&Previous content resource&&1
708: s&2&3&forw.png&&&gopost('/adm/flip','forward:'+currentURL)&Next content resource&&3
709: c&6&3
710: c&8&1
711: c&8&2
712: s&8&3&prt.png&Print&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
713: ENDMENUITEMS
714: $got_prt = 1;
715: if (($env{'user.adv'}) && ($env{'request.uri'} =~ /^\/res/)
716: && (!$env{'request.enc'})) {
717: # wishlist is only available for users with access to resource-pool
718: # and links can only be set for resources within the resource-pool
719: $menuitems .= (<<ENDMENUITEMS);
720: s&9&1&wishlist-link.png&Stored Links&wishlistlink[_2]&set_wishlistlink()&Save a link for this resource in your personal Stored Links repository&&1
721: ENDMENUITEMS
722: $got_wishlist = 1;
723: }
724:
725: my $currentURL = &Apache::loncommon::get_symb();
726: my ($symb_old,$symb_old_enc) = &Apache::loncommon::clean_symb($currentURL);
727: my $annotation = &Apache::loncommon::get_annotation($symb_old,$symb_old_enc);
728: $menuitems.="s&9&3&";
729: if(length($annotation) > 0){
730: $menuitems.="anot2.png";
731: }else{
732: $menuitems.="anot.png";
733: }
734: $menuitems.="&Notes&&annotate()&";
735: $menuitems.="Make notes and annotations about this resource&&1\n";
736:
737: unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme|viewclasslist|portfolio)(\?|$)/) {
738: if ((!$env{'request.enc'}) && ($env{'request.noversionuri'} !~ m{^/adm/wrapper/ext/}) && ($env{'request.noversionuri'} !~ m{^/uploaded/$match_domain/$match_courseid/docs/})) {
739: $menuitems.=(<<ENDREALRES);
740: s&6&3&catalog.png&Info&info[_1]&catalog_info()&Show Metadata
741: ENDREALRES
742: }
743: unless ($env{'request.noversionuri'} =~ m{^/uploaded/$match_domain/$match_courseid/docs/}) {
744: $menuitems.=(<<ENDREALRES);
745: s&8&1&eval.png&Evaluate&this[_1]&gopost('/adm/evaluate',currentURL,1)&Provide my evaluation of this resource
746: ENDREALRES
747: }
748: $menuitems.=(<<ENDREALRES);
749: s&8&2&fdbk.png&Communicate&discuss[_1]&gopost('/adm/feedback',currentURL,1)&Provide feedback messages or contribute to the course discussion about this resource
750: ENDREALRES
751: }
752: }
753: if ($env{'request.uri'} =~ /^\/res/) {
754: unless ($got_prt) {
755: $menuitems .= (<<ENDMENUITEMS);
756: s&8&3&prt.png&Print&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
757: ENDMENUITEMS
758: $got_prt = 1;
759: }
760: unless ($got_wishlist) {
761: if (($env{'user.adv'}) && (!$env{'request.enc'})) {
762: # wishlist is only available for users with access to resource-pool
763: $menuitems .= (<<ENDMENUITEMS);
764: s&9&1&wishlist-link.png&Stored Links&wishlistlink[_2]&set_wishlistlink()&Save a link for this resource in your personal Stored Links repository&&1
765: ENDMENUITEMS
766: $got_wishlist = 1;
767: }
768: }
769: }
770: my $buttons='';
771: foreach (split(/\n/,$menuitems)) {
772: my ($command,@rest)=split(/\&/,$_);
773: my $idx=10*$rest[0]+$rest[1];
774: if (&hidden_button_check() eq 'yes') {
775: if ($idx == 21 ||$idx == 23) {
776: $buttons.=&switch('','',@rest);
777: } else {
778: $buttons.=&clear(@rest);
779: }
780: } else {
781: if ($command eq 's') {
782: $buttons.=&switch('','',@rest);
783: } else {
784: $buttons.=&clear(@rest);
785: }
786: }
787: }
788:
789: my $addremote=0;
790: foreach (@inlineremote) { if ($_ ne '') { $addremote=1; last;} }
791: if ($addremote) {
792:
793: &Apache::lonhtmlcommon::clear_breadcrumb_tools();
794:
795: &Apache::lonhtmlcommon::add_breadcrumb_tool(
796: 'navigation', @inlineremote[21,23]);
797:
798: my $countdown = &countdown_timer();
799: if (&hidden_button_check() eq 'yes') {
800: if ($countdown) {
801: &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$countdown);
802: }
803: } else {
804: my @tools = @inlineremote[93,91,81,82,83];
805: if ($countdown) {
806: unshift(@tools,$countdown);
807: }
808: &Apache::lonhtmlcommon::add_breadcrumb_tool(
809: 'tools',@tools);
810:
811: #publish button in construction space
812: if ($env{'request.state'} eq 'construct'){
813: &Apache::lonhtmlcommon::add_breadcrumb_tool(
814: 'advtools', $inlineremote[63]);
815: } else {
816: &Apache::lonhtmlcommon::add_breadcrumb_tool(
817: 'tools', $inlineremote[63]);
818: }
819:
820: unless ($env{'request.noversionuri'}=~ m{^/adm/(navmaps|viewclasslist)(\?|$)}) {
821: &Apache::lonhtmlcommon::add_breadcrumb_tool(
822: 'advtools', @inlineremote[61,71,72,73,74,92]);
823: }
824: }
825: }
826:
827: return &Apache::lonhtmlcommon::scripttag('', 'start')
828: . &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0)
829: . &Apache::lonhtmlcommon::scripttag('', 'end');
830: }
831:
832: sub is_course_upload {
833: my ($file,$cnum,$cdom) = @_;
834: my $uploadpath = &LONCAPA::propath($cdom,$cnum);
835: $uploadpath =~ s{^\/}{};
836: if (($file =~ m{^\Q$uploadpath\E/userfiles/docs/}) ||
837: ($file =~ m{^userfiles/\Q$cdom\E/\Q$cnum\E/docs/})) {
838: return 1;
839: }
840: return;
841: }
842:
843: sub edit_course_upload {
844: my ($file,$cnum,$cdom) = @_;
845: my $cfile;
846: if ($file =~/\.(htm|html|css|js|txt)$/) {
847: my $ext = $1;
848: my $url = &Apache::lonnet::hreflocation('',$file);
849: my $home = &Apache::lonnet::homeserver($cnum,$cdom);
850: my @ids=&Apache::lonnet::current_machine_ids();
851: my $dest;
852: if ($home && grep(/^\Q$home\E$/,@ids)) {
853: $dest = $url.'?forceedit=1';
854: } else {
855: unless (&Apache::lonnet::get_locks()) {
856: $dest = '/adm/switchserver?otherserver='.
857: $home.'&role='.$env{'request.role'}.
858: '&url='.$url.'&forceedit=1';
859: }
860: }
861: if ($dest) {
862: $cfile = &HTML::Entities::encode($dest,'"<>&');
863: }
864: }
865: return $cfile;
866: }
867:
868: # ================================================================== Raw Config
869:
870: sub clear {
871: my ($row,$col)=@_;
872: $inlineremote[10*$row+$col]='';
873: return '';
874: }
875:
876: # ============================================ Switch a button or create a link
877: # Switch acts on the javascript that is executed when a button is clicked.
878: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
879:
880: sub switch {
881: my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat,$nobreak)=@_;
882: $act=~s/\$uname/$uname/g;
883: $act=~s/\$udom/$udom/g;
884: $top=&mt($top);
885: $bot=&mt($bot);
886: $desc=&mt($desc);
887: my $idx=10*$row+$col;
888: $category_members{$cat}.=':'.$idx;
889:
890: # Inline Menu
891: if ($nobreak==2) { return ''; }
892: my $text=$top.' '.$bot;
893: $text=~s/\s*\-\s*//gs;
894:
895: my $pic=
896: '<img alt="'.$text.'" src="'.
897: &Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$img).
898: '" align="'.($nobreak==3?'right':'left').'" class="LC_icon" />';
899: if ($env{'browser.interface'} eq 'faketextual') {
900: # Main Menu
901: if ($nobreak==3) {
902: $inlineremote[$idx]="\n".
903: '<td class="LC_menubuttons_text" align="right">'.$text.
904: '</td><td align="left">'.
905: '<a href="javascript:'.$act.';">'.$pic.'</a></td></tr>';
906: } elsif ($nobreak) {
907: $inlineremote[$idx]="\n<tr>".
908: '<td align="left">'.
909: '<a href="javascript:'.$act.';">'.$pic.'</a></td>
910: <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>';
911: } else {
912: $inlineremote[$idx]="\n<tr>".
913: '<td align="left">'.
914: '<a href="javascript:'.$act.';">'.$pic.
915: '</a></td><td class="LC_menubuttons_text" colspan="3">'.
916: '<a class="LC_menubuttons_link" href="javascript:'.$act.';"><span class="LC_menubuttons_inline_text">'.$desc.'</span></a></td></tr>';
917: }
918: } else {
919: # Inline Menu
920: my @tools = (93,91,81,82,83);
921: unless ($env{'request.state'} eq 'construct') {
922: push(@tools,63);
923: }
924: if (($env{'environment.icons'} eq 'iconsonly') &&
925: (grep(/^$idx$/,@tools))) {
926: $inlineremote[$idx] =
927: '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.'</a>';
928: } else {
929: $inlineremote[$idx] =
930: '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.
931: '<span class="LC_menubuttons_inline_text">'.$top.' </span></a>';
932: }
933: }
934: return '';
935: }
936:
937: sub secondlevel {
938: my $output='';
939: my
940: ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat)=@_;
941: if ($prt eq 'any') {
942: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
943: } elsif ($prt=~/^r(\w+)/) {
944: if ($rol eq $1) {
945: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
946: }
947: }
948: return $output;
949: }
950:
951: sub inlinemenu {
952: undef(@inlineremote);
953: undef(%category_members);
954: # calling rawconfig with "1" will evaluate mydesk.tab, even if there is no active remote control
955: &rawconfig(1);
956: my $output='<table><tr>';
957: for (my $col=1; $col<=2; $col++) {
958: $output.='<td class="LC_mainmenu_col_fieldset">';
959: for (my $row=1; $row<=8; $row++) {
960: foreach my $cat (keys(%category_members)) {
961: if ($category_positions{$cat} ne "$col,$row") { next; }
962: #$output.='<table><tr><td colspan="4" class="LC_menubuttons_category">'.&mt($category_names{$cat}).'</td></tr>';
963: $output.='<div class="LC_Box LC_400Box">';
964: $output.='<h3 class="LC_hcell">'.&mt($category_names{$cat}).'</h3>';
965: $output.='<table>';
966: my %active=();
967: foreach my $menu_item (split(/\:/,$category_members{$cat})) {
968: if ($inlineremote[$menu_item]) {
969: $active{$menu_item}=1;
970: }
971: }
972: foreach my $item (sort(keys(%active))) {
973: $output.=$inlineremote[$item];
974: }
975: $output.='</table>';
976: $output.='</div>';
977: }
978: }
979: $output.="</td>";
980: }
981: $output.="</tr></table>";
982: return $output;
983: }
984:
985: sub rawconfig {
986: #
987: # This evaluates mydesk.tab
988: # Need to add more positions and more privileges to deal with all
989: # menu items.
990: #
991: my $textualoverride=shift;
992: my $output='';
993: return '' unless $textualoverride;
994: my $uname=$env{'user.name'};
995: my $udom=$env{'user.domain'};
996: my $adv=$env{'user.adv'};
997: my $show_course=&Apache::loncommon::show_course();
998: my $author=$env{'user.author'};
999: my $crs='';
1000: my $crstype='';
1001: if ($env{'request.course.id'}) {
1002: $crs='/'.$env{'request.course.id'};
1003: if ($env{'request.course.sec'}) {
1004: $crs.='_'.$env{'request.course.sec'};
1005: }
1006: $crs=~s/\_/\//g;
1007: $crstype = &Apache::loncommon::course_type();
1008: }
1009: my $pub=($env{'request.state'} eq 'published');
1010: my $con=($env{'request.state'} eq 'construct');
1011: my $rol=$env{'request.role'};
1012: my $requested_domain = $env{'request.role.domain'};
1013: foreach my $line (@desklines) {
1014: my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc,$cat)=split(/\:/,$line);
1015: $prt=~s/\$uname/$uname/g;
1016: $prt=~s/\$udom/$udom/g;
1017: if ($prt =~ /\$crs/) {
1018: next unless ($env{'request.course.id'});
1019: next if ($crstype eq 'Community');
1020: $prt=~s/\$crs/$crs/g;
1021: } elsif ($prt =~ /\$cmty/) {
1022: next unless ($env{'request.course.id'});
1023: next if ($crstype ne 'Community');
1024: $prt=~s/\$cmty/$crs/g;
1025: }
1026: $prt=~s/\$requested_domain/$requested_domain/g;
1027: if ($category_names{$cat}!~/\w/) { $cat='oth'; }
1028: if ($pro eq 'clear') {
1029: $output.=&clear($row,$col);
1030: } elsif ($pro eq 'any') {
1031: $output.=&secondlevel(
1032: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1033: } elsif ($pro eq 'smp') {
1034: unless ($adv) {
1035: $output.=&secondlevel(
1036: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1037: }
1038: } elsif ($pro eq 'adv') {
1039: if ($adv) {
1040: $output.=&secondlevel(
1041: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1042: }
1043: } elsif ($pro eq 'shc') {
1044: if ($show_course) {
1045: $output.=&secondlevel(
1046: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1047: }
1048: } elsif ($pro eq 'nsc') {
1049: if (!$show_course) {
1050: $output.=&secondlevel(
1051: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1052: }
1053: } elsif (($pro=~/^p(\w+)/) && ($prt)) {
1054: my $priv = $1;
1055: if ($priv =~ /^mdc(Course|Community)/) {
1056: if ($crstype eq $1) {
1057: $priv = 'mdc';
1058: } else {
1059: next;
1060: }
1061: }
1062: if (&Apache::lonnet::allowed($priv,$prt)) {
1063: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1064: }
1065: } elsif ($pro eq 'course') {
1066: if (($env{'request.course.fn'}) && ($crstype ne 'Community')) {
1067: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1068: }
1069: } elsif ($pro eq 'community') {
1070: if (($env{'request.course.fn'}) && ($crstype eq 'Community')) {
1071: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1072: }
1073: } elsif ($pro =~ /^courseenv_(.*)$/) {
1074: my $key = $1;
1075: if ($crstype ne 'Community') {
1076: my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
1077: if ($key eq 'canuse_pdfforms') {
1078: if ($env{'request.course.id'} && $coursepref eq '') {
1079: my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
1080: $coursepref = $domdefs{'canuse_pdfforms'};
1081: }
1082: }
1083: if ($coursepref) {
1084: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1085: }
1086: }
1087: } elsif ($pro =~ /^communityenv_(.*)$/) {
1088: my $key = $1;
1089: if ($crstype eq 'Community') {
1090: my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
1091: if ($key eq 'canuse_pdfforms') {
1092: if ($env{'request.course.id'} && $coursepref eq '') {
1093: my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
1094: $coursepref = $domdefs{'canuse_pdfforms'};
1095: }
1096: }
1097: if ($coursepref) {
1098: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1099: }
1100: }
1101: } elsif ($pro =~ /^course_(.*)$/) {
1102: # Check for permissions inside of a course
1103: if (($env{'request.course.id'}) && ($crstype ne 'Community') &&
1104: (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
1105: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
1106: )) {
1107: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1108: }
1109: } elsif ($pro =~ /^community_(.*)$/) {
1110: # Check for permissions inside of a community
1111: if (($env{'request.course.id'}) && ($crstype eq 'Community') &&
1112: (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
1113: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
1114: )) {
1115: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1116: }
1117: } elsif ($pro eq 'author') {
1118: if ($author) {
1119: if ((($prt eq 'rca') && ($env{'request.role'}=~/^ca/)) ||
1120: (($prt eq 'raa') && ($env{'request.role'}=~/^aa/)) ||
1121: (($prt eq 'rau') && ($env{'request.role'}=~/^au/))) {
1122: # Check that we are on the correct machine
1123: my $cadom=$requested_domain;
1124: my $caname=$env{'user.name'};
1125: if (($prt eq 'rca') || ($prt eq 'raa')) {
1126: ($cadom,$caname)=
1127: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1128: }
1129: $act =~ s/\$caname/$caname/g;
1130: $act =~ s/\$cadom/$cadom/g;
1131: my $home = &Apache::lonnet::homeserver($caname,$cadom);
1132: my $allowed=0;
1133: my @ids=&Apache::lonnet::current_machine_ids();
1134: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
1135: if ($allowed) {
1136: $output.=&switch($caname,$cadom,
1137: $row,$col,$img,$top,$bot,$act,$desc,$cat);
1138: }
1139: }
1140: }
1141: } elsif ($pro eq 'tools') {
1142: my @tools = ('aboutme','blog','portfolio');
1143: if (grep(/^\Q$prt\E$/,@tools)) {
1144: if (!&Apache::lonnet::usertools_access($env{'user.name'},
1145: $env{'user.domain'},
1146: $prt,undef,'tools')) {
1147: $output.=&clear($row,$col);
1148: next;
1149: }
1150: } elsif (($prt eq 'reqcrsnsc') || ($prt eq 'reqcrsshc')) {
1151: if (($prt eq 'reqcrsnsc') && ($show_course)) {
1152: next;
1153: }
1154: if (($prt eq 'reqcrsshc') && (!$show_course)) {
1155: next;
1156: }
1157: my $showreqcrs = &check_for_rcrs();
1158: if (!$showreqcrs) {
1159: $output.=&clear($row,$col);
1160: next;
1161: }
1162: }
1163: $prt='any';
1164: $output.=&secondlevel(
1165: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1166: }
1167: }
1168: return $output;
1169: }
1170:
1171: sub check_for_rcrs {
1172: my $showreqcrs = 0;
1173: my @reqtypes = ('official','unofficial','community');
1174: foreach my $type (@reqtypes) {
1175: if (&Apache::lonnet::usertools_access($env{'user.name'},
1176: $env{'user.domain'},
1177: $type,undef,'requestcourses')) {
1178: $showreqcrs = 1;
1179: last;
1180: }
1181: }
1182: if (!$showreqcrs) {
1183: foreach my $type (@reqtypes) {
1184: if ($env{'environment.reqcrsotherdom.'.$type} ne '') {
1185: $showreqcrs = 1;
1186: last;
1187: }
1188: }
1189: }
1190: return $showreqcrs;
1191: }
1192:
1193: sub dc_popup_js {
1194: my %lt = &Apache::lonlocal::texthash(
1195: more => '(More ...)',
1196: less => '(Less ...)',
1197: );
1198: return <<"END";
1199:
1200: function showCourseID() {
1201: document.getElementById('dccid').style.display='block';
1202: document.getElementById('dccid').style.textAlign='left';
1203: document.getElementById('dccid').style.textFace='normal';
1204: document.getElementById('dccidtext').innerHTML ='<a href="javascript:hideCourseID();" class="LC_menubuttons_link">$lt{'less'}</a>';
1205: return;
1206: }
1207:
1208: function hideCourseID() {
1209: document.getElementById('dccid').style.display='none';
1210: document.getElementById('dccidtext').innerHTML ='<a href="javascript:showCourseID()" class="LC_menubuttons_link">$lt{'more'}</a>';
1211: return;
1212: }
1213:
1214: END
1215:
1216: }
1217:
1218: sub countdown_toggle_js {
1219: return <<"END";
1220:
1221: function toggleCountdown() {
1222: var countdownid = document.getElementById('duedatecountdown');
1223: var currstyle = countdownid.style.display;
1224: if (currstyle == 'inline') {
1225: countdownid.style.display = 'none';
1226: document.getElementById('ddcountcollapse').innerHTML='';
1227: document.getElementById('ddcountexpand').innerHTML='◄ ';
1228: } else {
1229: countdownid.style.display = 'inline';
1230: document.getElementById('ddcountcollapse').innerHTML='► ';
1231: document.getElementById('ddcountexpand').innerHTML='';
1232: }
1233: return;
1234: }
1235:
1236: END
1237: }
1238:
1239: sub utilityfunctions {
1240: my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
1241: if ($currenturl =~ m{^/adm/wrapper/ext/}
1242: && $env{'request.external.querystring'} ) {
1243: $currenturl .= ($currenturl=~/\?/)?'&':'?'.$env{'request.external.querystring'};
1244: }
1245: $currenturl=&Apache::lonenc::check_encrypt(&unescape($currenturl));
1246:
1247: my $currentsymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
1248:
1249: my $dc_popup_cid;
1250: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
1251: $env{'course.'.$env{'request.course.id'}.
1252: '.domain'}.'/'})) {
1253: $dc_popup_cid = &dc_popup_js();
1254: }
1255:
1256: my $start_page_annotate =
1257: &Apache::loncommon::start_page('Annotator',undef,
1258: {'only_body' => 1,
1259: 'js_ready' => 1,
1260: 'bgcolor' => '#BBBBBB',
1261: 'add_entries' => {
1262: 'onload' => 'javascript:document.goannotate.submit();'}});
1263:
1264: my $end_page_annotate =
1265: &Apache::loncommon::end_page({'js_ready' => 1});
1266:
1267: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
1268: &mt('Switch server?');
1269:
1270: my $esc_url=&escape($currenturl);
1271: my $esc_symb=&escape($currentsymb);
1272:
1273: my $countdown = &countdown_toggle_js();
1274:
1275: return (<<ENDUTILITY)
1276:
1277: var currentURL=unescape("$esc_url");
1278: var reloadURL=unescape("$esc_url");
1279: var currentSymb=unescape("$esc_symb");
1280:
1281: $dc_popup_cid
1282:
1283: function go(url) {
1284: if (url!='' && url!= null) {
1285: currentURL = null;
1286: currentSymb= null;
1287: window.location.href=url;
1288: }
1289: }
1290:
1291: function need_switchserver(url) {
1292: if (url!='' && url!= null) {
1293: if (confirm("$confirm_switch")) {
1294: go(url);
1295: }
1296: }
1297: return;
1298: }
1299:
1300: function gopost(url,postdata) {
1301: if (url!='') {
1302: this.document.server.action=url;
1303: this.document.server.postdata.value=postdata;
1304: this.document.server.command.value='';
1305: this.document.server.url.value='';
1306: this.document.server.symb.value='';
1307: this.document.server.submit();
1308: }
1309: }
1310:
1311: function gocmd(url,cmd) {
1312: if (url!='') {
1313: this.document.server.action=url;
1314: this.document.server.postdata.value='';
1315: this.document.server.command.value=cmd;
1316: this.document.server.url.value=currentURL;
1317: this.document.server.symb.value=currentSymb;
1318: this.document.server.submit();
1319: }
1320: }
1321:
1322: function gocstr(url,filename) {
1323: if (url == '/adm/cfile?action=delete') {
1324: this.document.cstrdelete.filename.value = filename
1325: this.document.cstrdelete.submit();
1326: return;
1327: }
1328: if (url == '/adm/printout') {
1329: this.document.cstrprint.postdata.value = filename
1330: this.document.cstrprint.curseed.value = 0;
1331: this.document.cstrprint.problemtype.value = 0;
1332: if (this.document.lonhomework) {
1333: if ((this.document.lonhomework.rndseed) && (this.document.lonhomework.rndseed.value != null) && (this.document.lonhomework.rndseed.value != '')) {
1334: this.document.cstrprint.curseed.value = this.document.lonhomework.rndseed.value
1335: }
1336: if (this.document.lonhomework.problemtype) {
1337: if (this.document.lonhomework.problemtype.value) {
1338: this.document.cstrprint.problemtype.value =
1339: this.document.lonhomework.problemtype.value;
1340: } else if (this.document.lonhomework.problemtype.options) {
1341: for (var i=0; i<this.document.lonhomework.problemtype.options.length; i++) {
1342: if (this.document.lonhomework.problemtype.options[i].selected) {
1343: if (this.document.lonhomework.problemtype.options[i].value != null && this.document.lonhomework.problemtype.options[i].value != '') {
1344: this.document.cstrprint.problemtype.value = this.document.lonhomework.problemtype.options[i].value
1345: }
1346: }
1347: }
1348: }
1349: }
1350: }
1351: this.document.cstrprint.submit();
1352: return;
1353: }
1354: if (url !='') {
1355: this.document.constspace.filename.value = filename;
1356: this.document.constspace.action = url;
1357: this.document.constspace.submit();
1358: }
1359: }
1360:
1361: function golist(url) {
1362: if (url!='' && url!= null) {
1363: currentURL = null;
1364: currentSymb= null;
1365: top.location.href=url;
1366: }
1367: }
1368:
1369:
1370:
1371: function catalog_info() {
1372: openMyModal(window.location.pathname+'.meta',500,400,'yes');
1373: }
1374:
1375: function chat_win() {
1376: lonchat=window.open('/res/adm/pages/chatroom.html',"LONchat",'height=320,width=480,resizable=yes,location=no,menubar=no,toolbar=no');
1377: }
1378:
1379: function group_chat(group) {
1380: var url = '/adm/groupchat?group='+group;
1381: var winName = 'LONchat_'+group;
1382: grpchat=window.open(url,winName,'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
1383: }
1384:
1385: function annotate() {
1386: w_Annotator_flag=1;
1387: annotator=window.open('','Annotator','width=365,height=265,scrollbars=0');
1388: annotator.document.write(
1389: '$start_page_annotate'
1390: +"<form name='goannotate' target='Annotator' method='post' "
1391: +"action='/adm/annotations'>"
1392: +"<input type='hidden' name='symbnew' value='"+currentSymb+"' />"
1393: +"<\\/form>"
1394: +'$end_page_annotate');
1395: annotator.document.close();
1396: }
1397:
1398: function open_StoredLinks_Import(rat) {
1399: var newWin;
1400: if (rat) {
1401: newWin = window.open('/adm/wishlist?inhibitmenu=yes&mode=import&rat='+rat,
1402: 'wishlistImport','scrollbars=1,resizable=1,menubar=0');
1403: }
1404: else {
1405: newWin = window.open('/adm/wishlist?inhibitmenu=yes&mode=import',
1406: 'wishlistImport','scrollbars=1,resizable=1,menubar=0');
1407: }
1408: newWin.focus();
1409: }
1410:
1411: (function (\$) {
1412: \$(document).ready(function () {
1413: \$.single=function(a){return function(b){a[0]=b;return a}}(\$([1]));
1414: /*\@cc_on
1415: if (!window.XMLHttpRequest) {
1416: \$('.LC_hoverable').each(function () {
1417: this.attachEvent('onmouseenter', function (evt) { \$.single(evt.srcElement).addClass('hover'); });
1418: this.attachEvent('onmouseleave', function (evt) { \$.single(evt.srcElement).removeClass('hover'); });
1419: });
1420: }
1421: \@*/
1422: });
1423: }(jQuery));
1424:
1425: $countdown
1426:
1427: ENDUTILITY
1428: }
1429:
1430: sub serverform {
1431: return(<<ENDSERVERFORM);
1432: <form name="server" action="/adm/logout" method="post" target="_top">
1433: <input type="hidden" name="postdata" value="none" />
1434: <input type="hidden" name="command" value="none" />
1435: <input type="hidden" name="url" value="none" />
1436: <input type="hidden" name="symb" value="none" />
1437: </form>
1438: ENDSERVERFORM
1439: }
1440:
1441: sub constspaceform {
1442: return(<<ENDCONSTSPACEFORM);
1443: <form name="constspace" action="/adm/logout" method="post" target="_top">
1444: <input type="hidden" name="filename" value="" />
1445: </form>
1446: <form name="cstrdelete" action="/adm/cfile" method="post" target="_top">
1447: <input type="hidden" name="action" value="delete" />
1448: <input type="hidden" name="filename" value="" />
1449: </form>
1450: <form name="cstrprint" action="/adm/printout" target="_parent" method="post">
1451: <input type="hidden" name="postdata" value="" />
1452: <input type="hidden" name="curseed" value="" />
1453: <input type="hidden" name="problemtype" value="" />
1454: </form>
1455:
1456: ENDCONSTSPACEFORM
1457: }
1458:
1459: sub hidden_button_check {
1460: if ( $env{'request.course.id'} eq ''
1461: || $env{'request.role.adv'} ) {
1462:
1463: return;
1464: }
1465: my $buttonshide = &Apache::lonnet::EXT('resource.0.buttonshide');
1466: return $buttonshide;
1467: }
1468:
1469: sub roles_selector {
1470: my ($cdom,$cnum) = @_;
1471: my $crstype = &Apache::loncommon::course_type();
1472: my $now = time;
1473: my (%courseroles,%seccount,%courseprivs);
1474: my $is_cc;
1475: my $role_selector;
1476: my $ccrole;
1477: if ($crstype eq 'Community') {
1478: $ccrole = 'co';
1479: } else {
1480: $ccrole = 'cc';
1481: }
1482: my ($priv,$gotsymb,$destsymb);
1483: my $destinationurl = $ENV{'REQUEST_URI'};
1484: if ($destinationurl =~ /\?symb=/) {
1485: $gotsymb = 1;
1486: } elsif ($destinationurl =~ m{^/enc/}) {
1487: my $plainurl = &Apache::lonenc::unencrypted($destinationurl);
1488: if ($plainurl =~ /\?symb=/) {
1489: $gotsymb = 1;
1490: }
1491: }
1492: unless ($gotsymb) {
1493: $destsymb = &Apache::lonnet::symbread();
1494: if ($destsymb ne '') {
1495: $destsymb = &Apache::lonenc::check_encrypt($destsymb);
1496: }
1497: }
1498: my $reqprivs = &required_privs();
1499: if (ref($reqprivs) eq 'HASH') {
1500: my $destination = $destinationurl;
1501: $destination =~ s/(\?.*)$//;
1502: if (exists($reqprivs->{$destination})) {
1503: $priv = $reqprivs->{$destination};
1504: }
1505: }
1506: if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) {
1507: my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum});
1508:
1509: if ((($start) && ($start<0)) ||
1510: (($end) && ($end<$now)) ||
1511: (($start) && ($now<$start))) {
1512: $is_cc = 0;
1513: } else {
1514: $is_cc = 1;
1515: }
1516: }
1517: if ($is_cc) {
1518: &get_all_courseroles($cdom,$cnum,\%courseroles,\%seccount,\%courseprivs,$priv);
1519: } else {
1520: my %gotnosection;
1521: foreach my $item (keys(%env)) {
1522: if ($item =~ m-^user\.role\.([^.]+)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
1523: my $role = $1;
1524: my $sec = $2;
1525: next if ($role eq 'gr');
1526: my ($start,$end) = split(/\./,$env{$item});
1527: next if (($start && $start > $now) || ($end && $end < $now));
1528: if ($sec eq '') {
1529: if (!$gotnosection{$role}) {
1530: $seccount{$role} ++;
1531: $gotnosection{$role} = 1;
1532: }
1533: }
1534: if ($priv ne '') {
1535: my $cnumsec = $cnum;
1536: if ($sec ne '') {
1537: $cnumsec .= "/$sec";
1538: }
1539: $courseprivs{"$role./$cdom/$cnumsec./"} =
1540: $env{"user.priv.$role./$cdom/$cnumsec./"};
1541: $courseprivs{"$role./$cdom/$cnumsec./$cdom/"} =
1542: $env{"user.priv.$role./$cdom/$cnumsec./$cdom/"};
1543: $courseprivs{"$role./$cdom/$cnumsec./$cdom/$cnumsec"} =
1544: $env{"user.priv.$role./$cdom/$cnumsec./$cdom/$cnumsec"};
1545: }
1546: if (ref($courseroles{$role}) eq 'ARRAY') {
1547: if ($sec ne '') {
1548: if (!grep(/^\Q$sec\E$/,@{$courseroles{$role}})) {
1549: push(@{$courseroles{$role}},$sec);
1550: $seccount{$role} ++;
1551: }
1552: }
1553: } else {
1554: @{$courseroles{$role}} = ();
1555: if ($sec ne '') {
1556: $seccount{$role} ++;
1557: push(@{$courseroles{$role}},$sec);
1558: }
1559: }
1560: }
1561: }
1562: }
1563: my $switchtext;
1564: if ($crstype eq 'Community') {
1565: $switchtext = &mt('Switch community role to...')
1566: } else {
1567: $switchtext = &mt('Switch course role to...')
1568: }
1569: my @roles_order = ($ccrole,'in','ta','ep','ad','st');
1570: if (keys(%courseroles) > 1) {
1571: $role_selector = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles,\%courseprivs,$priv);
1572: $role_selector .= '<form name="rolechooser" method="post" action="/adm/roles">
1573: <select name="switchrole" onchange="javascript:adhocRole('."'switchrole'".')">';
1574: $role_selector .= '<option value="">'.$switchtext.'</option>';
1575: foreach my $role (@roles_order) {
1576: if (defined($courseroles{$role})) {
1577: $role_selector .= "\n".'<option value="'.$role.'">'.&Apache::lonnet::plaintext($role,$crstype).'</option>';
1578: }
1579: }
1580: foreach my $role (sort(keys(%courseroles))) {
1581: if ($role =~ /^cr/) {
1582: $role_selector .= "\n".'<option value="'.$role.'">'.&Apache::lonnet::plaintext($role).'</option>';
1583: }
1584: }
1585: $role_selector .= '</select>'."\n";
1586: if ($destsymb ne '') {
1587: $role_selector .= '<input type="hidden" name="destsymb" value="'.
1588: &HTML::Entities::encode($destsymb).'" />'."\n";
1589: }
1590: $role_selector .=
1591: '<input type="hidden" name="destinationurl" value="'.
1592: &HTML::Entities::encode($destinationurl).'" />'."\n".
1593: '<input type="hidden" name="gotorole" value="1" />'."\n".
1594: '<input type="hidden" name="selectrole" value="" />'."\n".
1595: '<input type="hidden" name="switch" value="1" />'."\n".
1596: '</form>';
1597: }
1598: return $role_selector;
1599: }
1600:
1601: sub get_all_courseroles {
1602: my ($cdom,$cnum,$courseroles,$seccount,$courseprivs) = @_;
1603: unless ((ref($courseroles) eq 'HASH') && (ref($seccount) eq 'HASH') &&
1604: (ref($courseprivs) eq 'HASH')) {
1605: return;
1606: }
1607: my ($result,$cached) =
1608: &Apache::lonnet::is_cached_new('getcourseroles',$cdom.'_'.$cnum);
1609: if (defined($cached)) {
1610: if (ref($result) eq 'HASH') {
1611: if ((ref($result->{'roles'}) eq 'HASH') &&
1612: (ref($result->{'seccount'}) eq 'HASH') &&
1613: (ref($result->{'privs'}) eq 'HASH')) {
1614: %{$courseroles} = %{$result->{'roles'}};
1615: %{$seccount} = %{$result->{'seccount'}};
1616: %{$courseprivs} = %{$result->{'privs'}};
1617: return;
1618: }
1619: }
1620: }
1621: my %gotnosection;
1622: my %adv_roles =
1623: &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
1624: foreach my $role (keys(%adv_roles)) {
1625: my ($urole,$usec) = split(/:/,$role);
1626: if (!$gotnosection{$urole}) {
1627: $seccount->{$urole} ++;
1628: $gotnosection{$urole} = 1;
1629: }
1630: if (ref($courseroles->{$urole}) eq 'ARRAY') {
1631: if ($usec ne '') {
1632: if (!grep(/^Q$usec\E$/,@{$courseroles->{$urole}})) {
1633: push(@{$courseroles->{$urole}},$usec);
1634: $seccount->{$urole} ++;
1635: }
1636: }
1637: } else {
1638: @{$courseroles->{$urole}} = ();
1639: if ($usec ne '') {
1640: $seccount->{$urole} ++;
1641: push(@{$courseroles->{$urole}},$usec);
1642: }
1643: }
1644: my $area = '/'.$cdom.'/'.$cnum;
1645: if ($usec ne '') {
1646: $area .= '/'.$usec;
1647: }
1648: if ($role =~ /^cr\//) {
1649: &Apache::lonnet::custom_roleprivs($courseprivs,$urole,$cdom,$cnum,$urole.'.'.$area,$area);
1650: } else {
1651: &Apache::lonnet::standard_roleprivs($courseprivs,$urole,$cdom,$urole.'.'.$area,$cnum,$area);
1652: }
1653: }
1654: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum,['st']);
1655: @{$courseroles->{'st'}} = ();
1656: &Apache::lonnet::standard_roleprivs($courseprivs,'st',$cdom,"st./$cdom/$cnum",$cnum,"/$cdom/$cnum");
1657: if (keys(%sections_count) > 0) {
1658: push(@{$courseroles->{'st'}},keys(%sections_count));
1659: $seccount->{'st'} = scalar(keys(%sections_count));
1660: }
1661: my $rolehash = {
1662: 'roles' => $courseroles,
1663: 'seccount' => $seccount,
1664: 'privs' => $courseprivs,
1665: };
1666: &Apache::lonnet::do_cache_new('getcourseroles',$cdom.'_'.$cnum,$rolehash);
1667: return;
1668: }
1669:
1670: sub jump_to_role {
1671: my ($cdom,$cnum,$seccount,$courseroles,$courseprivs,$priv) = @_;
1672: my %lt = &Apache::lonlocal::texthash(
1673: this => 'This role has section(s) associated with it.',
1674: ente => 'Enter a specific section.',
1675: orlb => 'Enter a specific section, or leave blank for no section.',
1676: avai => 'Available sections are:',
1677: youe => 'You entered an invalid section choice:',
1678: plst => 'Please try again.',
1679: role => 'The role you selected is not permitted to view the current page.',
1680: swit => 'Switch role, but display Main Menu page instead?',
1681: );
1682: my $js;
1683: if (ref($courseroles) eq 'HASH') {
1684: $js = ' var secpick = new Array("'.$lt{'ente'}.'","'.$lt{'orlb'}.'");'."\n".
1685: ' var numsec = new Array();'."\n".
1686: ' var rolesections = new Array();'."\n".
1687: ' var rolenames = new Array();'."\n".
1688: ' var roleseclist = new Array();'."\n";
1689: my @items = keys(%{$courseroles});
1690: for (my $i=0; $i<@items; $i++) {
1691: $js .= ' rolenames['.$i.'] = "'.$items[$i].'";'."\n";
1692: my ($secs,$secstr);
1693: if (ref($courseroles->{$items[$i]}) eq 'ARRAY') {
1694: my @sections = sort { $a <=> $b } @{$courseroles->{$items[$i]}};
1695: $secs = join('","',@sections);
1696: $secstr = join(', ',@sections);
1697: }
1698: $js .= ' rolesections['.$i.'] = new Array("'.$secs.'");'."\n".
1699: ' roleseclist['.$i.'] = "'.$secstr.'";'."\n".
1700: ' numsec['.$i.'] = "'.$seccount->{$items[$i]}.'";'."\n";
1701: }
1702: }
1703: my $checkroles = 0;
1704: if ($priv && ref($courseprivs) eq 'HASH') {
1705: my (%disallowed,%allowed,@disallow);
1706: foreach my $role (sort(keys(%{$courseprivs}))) {
1707: my $trole;
1708: if ($role =~ m{^(.+?)\Q./$cdom/$cnum\E}) {
1709: $trole = $1;
1710: }
1711: if (($trole ne '') && ($trole ne 'cm')) {
1712: if ($courseprivs->{$role} =~ /\Q:$priv\E($|:|\&\w+)/) {
1713: $allowed{$trole} = 1;
1714: } else {
1715: $disallowed{$trole} = 1;
1716: }
1717: }
1718: }
1719: foreach my $trole (keys(%disallowed)) {
1720: unless ($allowed{$trole}) {
1721: push(@disallow,$trole);
1722: }
1723: }
1724: if (@disallow > 0) {
1725: $checkroles = 1;
1726: $js .= " var disallow = new Array('".join("','",@disallow)."');\n".
1727: " var rolecheck = 1;\n";
1728: }
1729: }
1730: if (!$checkroles) {
1731: $js .= " var disallow = new Array();\n".
1732: " rolecheck = 0;\n";
1733: }
1734: return <<"END";
1735: <script type="text/javascript">
1736: //<![CDATA[
1737: function adhocRole(roleitem) {
1738: $js
1739: var newrole = document.rolechooser.elements[roleitem].options[document.rolechooser.elements[roleitem].selectedIndex].value;
1740: if (newrole == '') {
1741: return;
1742: }
1743: var fullrole = newrole+'./$cdom/$cnum';
1744: var selidx = '';
1745: for (var i=0; i<rolenames.length; i++) {
1746: if (rolenames[i] == newrole) {
1747: selidx = i;
1748: }
1749: }
1750: if (rolecheck > 0) {
1751: for (var i=0; i<disallow.length; i++) {
1752: if (disallow[i] == newrole) {
1753: if (confirm("$lt{'role'}\\n$lt{'swit'}")) {
1754: document.rolechooser.destinationurl.value = '/adm/menu';
1755: } else {
1756: document.rolechooser.elements[roleitem].selectedIndex = 0;
1757: return;
1758: }
1759: }
1760: }
1761: }
1762: var secok = 1;
1763: var secchoice = '';
1764: if (selidx >= 0) {
1765: if (numsec[selidx] > 1) {
1766: secok = 0;
1767: var numrolesec = rolesections[selidx].length;
1768: var msgidx = numsec[selidx] - numrolesec;
1769: secchoice = prompt("$lt{'this'} "+secpick[msgidx]+"\\n$lt{'avai'} "+roleseclist[selidx],"");
1770: if (secchoice == '') {
1771: if (msgidx > 0) {
1772: secok = 1;
1773: }
1774: } else {
1775: for (var j=0; j<rolesections[selidx].length; j++) {
1776: if (rolesections[selidx][j] == secchoice) {
1777: secok = 1;
1778: }
1779: }
1780: }
1781: } else {
1782: if (rolesections[selidx].length == 1) {
1783: secchoice = rolesections[selidx][0];
1784: }
1785: }
1786: }
1787: if (secok == 1) {
1788: if (secchoice != '') {
1789: fullrole += '/'+secchoice;
1790: }
1791: } else {
1792: document.rolechooser.elements[roleitem].selectedIndex = 0;
1793: if (secchoice != null) {
1794: alert("$lt{'youe'} \\""+secchoice+"\\".\\n $lt{'plst'}");
1795: }
1796: return;
1797: }
1798: if (fullrole == "$env{'request.role'}") {
1799: document.rolechooser.elements[roleitem].selectedIndex = 0;
1800: return;
1801: }
1802: itemid = retrieveIndex('gotorole');
1803: if (itemid != -1) {
1804: document.rolechooser.elements[itemid].name = fullrole;
1805: }
1806: document.rolechooser.elements[roleitem].options[document.rolechooser.elements[roleitem].selectedIndex].value = fullrole;
1807: document.rolechooser.selectrole.value = '1';
1808: document.rolechooser.submit();
1809: return;
1810: }
1811:
1812: function retrieveIndex(item) {
1813: for (var i=0;i<document.rolechooser.elements.length;i++) {
1814: if (document.rolechooser.elements[i].name == item) {
1815: return i;
1816: }
1817: }
1818: return -1;
1819: }
1820: // ]]>
1821: </script>
1822: END
1823: }
1824:
1825: sub required_privs {
1826: my $privs = {
1827: '/adm/parmset' => 'opa',
1828: '/adm/courseprefs' => 'opa',
1829: '/adm/whatsnew' => 'whn',
1830: '/adm/populate' => 'cst',
1831: '/adm/trackstudent' => 'vsa',
1832: '/adm/statistics' => 'vgr',
1833: '/adm/setblock' => 'dcm',
1834: '/adm/coursedocs' => 'mdc',
1835: };
1836: unless ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'spreadsheet') {
1837: $privs->{'/adm/classcalc'} = 'vgr',
1838: $privs->{'/adm/assesscalc'} = 'vgr',
1839: $privs->{'/adm/studentcalc'} = 'vgr';
1840: }
1841: return $privs;
1842: }
1843:
1844: sub countdown_timer {
1845: if (($env{'request.course.id'}) && ($env{'request.symb'} ne '') &&
1846: ($env{'request.filename'}=~/$LONCAPA::assess_re/) &&
1847: ($Apache::inputtags::status[-1] eq 'CAN_ANSWER')) {
1848: my $duedate = &Apache::lonnet::EXT("resource.0.duedate");
1849: my @interval=&Apache::lonnet::EXT("resource.0.interval");
1850: my $hastimeleft;
1851: if (@interval > 1) {
1852: my $first_access=&Apache::lonnet::get_first_access($interval[1]);
1853: if ($first_access > 0) {
1854: if ($first_access+$interval[0] > time) {
1855: $hastimeleft = 1;
1856: }
1857: }
1858: }
1859: if (($duedate && $duedate > time) ||
1860: (!$duedate && $hastimeleft)) {
1861: my ($collapse,$expand,$alttxt,$title,$currdisp);
1862: if (@interval > 1 && $hastimeleft) {
1863: $currdisp = 'inline';
1864: $collapse = '► ';
1865: } else {
1866: $currdisp = 'none';
1867: $expand = '◄ ';
1868: }
1869: unless ($env{'environment.icons'} eq 'iconsonly') {
1870: $alttxt = &mt('Timer');
1871: $title = $alttxt.' ';
1872: }
1873: my $desc = &mt('Countdown to due date/time');
1874: return <<END;
1875:
1876: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
1877: <span id="ddcountcollapse" class="LC_menubuttons_inline_text">
1878: $collapse
1879: </span></a>
1880: <span id="duedatecountdown" class="LC_menubuttons_inline_text" style="display: $currdisp;"></span>
1881: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
1882: <span id="ddcountexpand" class="LC_menubuttons_inline_text" >$expand</span>
1883: <img src="/res/adm/pages/timer.png" title="$desc" class="LC_icon" alt="$alttxt" /><span class="LC_menubuttons_inline_text">$title</span></a>
1884: END
1885: }
1886: }
1887: return;
1888: }
1889:
1890: # ================================================================ Main Program
1891:
1892: BEGIN {
1893: if (! defined($readdesk)) {
1894: {
1895: my $tabfile = $Apache::lonnet::perlvar{'lonTabDir'}.'/mydesk.tab';
1896: if ( CORE::open( my $config,"<$tabfile") ) {
1897: while (my $configline=<$config>) {
1898: $configline=(split(/\#/,$configline))[0];
1899: $configline=~s/^\s+//;
1900: chomp($configline);
1901: if ($configline=~/^cat\:/) {
1902: my @entries=split(/\:/,$configline);
1903: $category_positions{$entries[2]}=$entries[1];
1904: $category_names{$entries[2]}=$entries[3];
1905: } elsif ($configline=~/^prim\:/) {
1906: my @entries = (split(/\:/, $configline))[1..5];
1907: push @primary_menu, \@entries;
1908: } elsif ($configline=~/^primsub\:/) {
1909: my ($parent,@entries) = (split(/\:/, $configline))[1..4];
1910: push (@{$primary_submenu{$parent}},\@entries);
1911: } elsif ($configline=~/^scnd\:/) {
1912: my @entries = (split(/\:/, $configline))[1..5];
1913: push @secondary_menu, \@entries;
1914: } elsif ($configline) {
1915: push(@desklines,$configline);
1916: }
1917: }
1918: CORE::close($config);
1919: }
1920: }
1921: $readdesk='done';
1922: }
1923: }
1924:
1925: 1;
1926: __END__
1927:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>