File:
[LON-CAPA] /
loncom /
interface /
lonmenu.pm
Revision
1.541:
download - view:
text,
annotated -
select for diffs
Fri Nov 3 01:12:15 2023 UTC (9 months, 2 weeks ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
- Authoring Space defaults defaults which domain coordinator can override.
- Available Editors, WebDAV access, Disk Quota for Authoring Space
can be set for specific users by DC via "Add/modify user"
- Bug 5273 Co-authors in "group authoring" accounts can manage co-authors
- Existing co-author(s) can be assigned rights to add/revoke co-author
roles. Can be set by DC via "Add/modify user" or by author via "People"
- Co-authors and Assistant co-authors can view a list of co-authors for
the Authoring Space. Availability set by Author or Co-author "manager".
Listing can be set to "opt-in".
1: # The LearningOnline Network with CAPA
2: # Routines to control the menu
3: #
4: # $Id: lonmenu.pm,v 1.541 2023/11/03 01:12:15 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,$target,$listclass,$linkattr)
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 a two item array,
110: with the array elements containing XHTML for the left and right sides of
111: the menu that contains the following links: About, Message, Roles, Help, Logout
112: @primary_menu is filled within the BEGIN block of this module with
113: entries from mydesk.tab
114:
115: =item secondary_menu()
116:
117: Same as primary_menu() but operates on @secondary_menu.
118:
119: =item create_submenu()
120:
121: Creates XHTML for unordered list of sub-menu items which belong to a
122: particular top-level menu item. Uses hover pseudo class in css to display
123: dropdown list when mouse hovers over top-level item. Support for IE6
124: (no hover psuedo class) via LC_hoverable class for <li> tag for top-
125: level item, which employs jQuery to handle behavior on mouseover.
126:
127: Inputs: 6 - (a) link and (b) target for anchor href in top level item,
128: (c) title for text wrapped by anchor tag in top level item,
129: (d) reference to array of arrays of sub-menu items,
130: (e) boolean to indicate whether to call &mt() to translate
131: name of menu item,
132: (f) optional class for <li> element in primary menu, for which
133: sub menu is being generated.
134:
135: The underlying datastructure used in (d) contains data from mydesk.tab.
136: It consists of an array which has an array for each item appearing in
137: the menu (e.g. [["link", "title", "condition"]] for a single-item menu).
138: create_submenu() supports also the creation of XHTML for nested dropdown
139: menus represented by unordered lists. This is done by replacing the
140: scalar used for the link with an arrayreference containing the menuitems
141: for the nested menu. This can be done recursively so that the next menu
142: may also contain nested submenus.
143:
144: Example:
145: [ # begin of datastructure
146: ["/home/", "Home", "condition1"], # 1st item of the 1st layer menu
147: [ # 2nd item of the 1st layer menu
148: [ # anon. array for nested menu
149: ["/path1", "Path1", undef], # 1st item of the 2nd layer menu
150: ["/path2", "Path2", undef], # 2nd item of the 2nd layer menu
151: [ # 3rd item of the 2nd layer menu
152: [[...], [...], ..., [...]], # containing another menu layer
153: "Sub-Sub-Menu", # title for this container
154: undef
155: ]
156: ], # end of array/nested menu
157: "Sub-Menu", # title for the container item
158: undef
159: ] # end of 2nd item of the 1st layer menu
160: ]
161:
162: =item innerregister()
163:
164: This gets called in order to register a URL in the body of the document
165:
166: =item clear()
167:
168: =item switch()
169:
170: Switch a button or create a link
171: Switch acts on the javascript that is executed when a button is clicked.
172: The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
173:
174: =item secondlevel()
175:
176: =item openmenu()
177:
178: =item inlinemenu()
179:
180: =item rawconfig()
181:
182: =item utilityfunctions()
183:
184: Output from this routine is a number of javascript functions called by
185: items in the inline menu, and in some cases items in the Main Menu page.
186:
187: =item serverform()
188:
189: =item constspaceform()
190:
191: =item get_nav_status()
192:
193: =item hidden_button_check()
194:
195: =item roles_selector()
196:
197: =item jump_to_role()
198:
199: =back
200:
201: =cut
202:
203: package Apache::lonmenu;
204:
205: use strict;
206: use Apache::lonnet;
207: use Apache::lonhtmlcommon();
208: use Apache::loncommon();
209: use Apache::lonenc();
210: use Apache::lonlocal;
211: use Apache::lonmsg();
212: use LONCAPA qw(:DEFAULT :match);
213: use HTML::Entities();
214: use Apache::lonwishlist();
215:
216: use vars qw(@desklines %category_names %category_members %category_positions
217: $readdesk @primary_menu %primary_submenu @secondary_menu %secondary_submenu);
218:
219: my @inlineremote;
220:
221: sub prep_menuitem {
222: my ($menuitem,$target,$listclass,$linkattr) = @_;
223: return '' unless(ref($menuitem) eq 'ARRAY');
224: my ($link,$targetattr);
225: if ($$menuitem[1]) { # graphical Link
226: $link = "<img class=\"LC_noBorder\""
227: . " src=\"" . &Apache::loncommon::lonhttpdurl($$menuitem[1]) . "\""
228: . " alt=\"" . &mt($$menuitem[2]) . "\" />";
229: } else { # textual Link
230: $link = &mt($$menuitem[3]);
231: }
232: if ($target ne '') {
233: $targetattr = ' target="'.$target.'"';
234: }
235: return ($listclass?'<li class="'.$listclass.'">':'<li>').'<a'
236: # highlighting for new messages
237: . ( $$menuitem[4] eq 'newmsg' ? ' class="LC_new_message"' : '')
238: . qq| href="$$menuitem[0]"$targetattr $linkattr>$link</a></li>|;
239: }
240:
241: # primary_menu() evaluates @primary_menu and returns a two item array,
242: # with the array elements containing XHTML for the left and right sides of
243: # the menu that contains the following links:
244: # Personal, About, Message, Roles, Help, Logout
245: # @primary_menu is filled within the BEGIN block of this module with
246: # entries from mydesk.tab
247: sub primary_menu {
248: my ($crstype,$ltimenu,$menucoll,$menuref,$links_disabled,$links_target) = @_;
249: my (%menu,%ltiexc,%menuopts);
250: # each element of @primary contains following array:
251: # (link url, icon path, alt text, link text, condition, position)
252: my $public;
253: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
254: || (($env{'user.name'} eq '') && ($env{'user.domain'} eq ''))) {
255: $public = 1;
256: }
257: my $rolecount;
258: if (($crstype eq 'Placement') && (!$env{'request.role.adv'})) {
259: my $update=$env{'user.update.time'};
260: if (!$update) {
261: $update = $env{'user.login.time'};
262: }
263: my %roles_in_env;
264: $rolecount = &Apache::lonroles::roles_from_env(\%roles_in_env,$update);
265: }
266: my $lti;
267: if ($env{'request.lti.login'}) {
268: $lti = 1;
269: if (ref($ltimenu) eq 'HASH') {
270: foreach my $item ('fullname','logout') {
271: unless ($ltimenu->{$item}) {
272: $ltiexc{$item} = 1;
273: }
274: }
275: }
276: }
277: my ($listclass,$linkattr,$target);
278: if ($links_disabled) {
279: $listclass = 'LCisDisabled';
280: $linkattr = 'aria-disabled="true"';
281: }
282: if ($links_target ne '') {
283: $target = $links_target;
284: } else {
285: my ($ltitarget,$deeplinktarget);
286: if ($env{'request.lti.login'}) {
287: $ltitarget = $env{'request.lti.target'};
288: }
289: if ($env{'request.deeplink.login'}) {
290: $deeplinktarget = $env{'request.deeplink.target'};
291: }
292: if (($ltitarget eq 'iframe') || ($deeplinktarget eq '_self')) {
293: $target = '_self';
294: } else {
295: $target = '_top';
296: }
297: }
298: if (($menucoll) && (ref($menuref) eq 'HASH')) {
299: %menuopts = %{$menuref};
300: }
301: foreach my $menuitem (@primary_menu) {
302: # evaluate conditions
303: next if ref($menuitem) ne 'ARRAY'; #
304: next if $$menuitem[4] eq 'nonewmsg' # show links depending on
305: && &Apache::lonmsg::mynewmail(); # whether a new msg
306: next if $$menuitem[4] eq 'newmsg' # arrived or not
307: && !&Apache::lonmsg::mynewmail(); #
308: next if $$menuitem[4] !~ /public/ ##we've a public user,
309: && $public; ##who should not see all
310: ##links
311: next if $$menuitem[4] eq 'onlypublic'# hide links which are
312: && !$public; # only visible to public
313: # users
314: next if $$menuitem[4] eq 'roles' ##show links depending on
315: && (&Apache::loncommon::show_course() ##term 'Courses' or
316: || $lti); ##'Roles' wanted
317: next if $$menuitem[4] eq 'courses' ##and not LTI access
318: && (!&Apache::loncommon::show_course()
319: || $lti);
320: next if $$menuitem[4] eq 'notlti'
321: && $lti;
322: next if $$menuitem[4] eq 'ltiexc'
323: && exists($ltiexc{lc($menuitem->[3])});
324: my $title = $menuitem->[3];
325: if (($crstype eq 'Placement') && (!$env{'request.role.adv'})) {
326: if ($menuitem->[4] eq 'courses') {
327: next unless ($rolecount>1);
328: } else {
329: next unless (($title eq 'Personal') || ($title eq 'Logout'));
330: }
331: }
332: my $position = $menuitem->[5];
333: if ($position eq '') {
334: $position = 'right';
335: }
336: if ($env{'request.course.id'} && $menucoll) {
337: if (($menuitem->[6]) && (!$menuopts{$menuitem->[6]})) {
338: if ($menuitem->[6] eq 'pers') {
339: if ($menuopts{'name'} && !$ltiexc{'fullname'} &&
340: $env{'user.name'} && $env{'user.domain'}) {
341: $menu{$position} .= '<li><a href="#">'.
342: &Apache::loncommon::plainname($env{'user.name'},
343: $env{'user.domain'}).'</a></li>';
344: next;
345: } else {
346: next;
347: }
348: } else {
349: next;
350: }
351: }
352: }
353: if (defined($primary_submenu{$title})) {
354: my $link;
355: if ($menuitem->[0] ne '') {
356: $link = $menuitem->[0];
357: } else {
358: $link = '#';
359: }
360: my @primsub;
361: if (ref($primary_submenu{$title}) eq 'ARRAY') {
362: foreach my $item (@{$primary_submenu{$title}}) {
363: next if (($crstype eq 'Placement') && (!$env{'request.role.adv'}));
364: next if (($item->[2] eq 'wishlist') && (!$env{'user.adv'}));
365: next if ((($item->[2] eq 'portfolio') ||
366: ($item->[2] eq 'blog')) &&
367: (!&Apache::lonnet::usertools_access('','',$item->[2],
368: undef,'tools')));
369: if ($env{'request.course.id'} && $menucoll) {
370: next if ($item->[3]) && (!$menuopts{$item->[3]});
371: }
372: push(@primsub,$item);
373: }
374: if ($title eq 'Personal') {
375: if ($env{'user.name'} && $env{'user.domain'} && !$ltiexc{'fullname'}) {
376: unless (($env{'request.course.id'}) && ($menucoll) && (!$menuopts{'name'})) {
377: $title = &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'});
378: }
379: }
380: next if (($env{'request.course.id'}) && ($menucoll) && ($title eq 'Personal') &&
381: (!@primsub));
382: if ($title eq 'Personal') {
383: $title = &mt($title);
384: }
385: } else {
386: $title = &mt($title);
387: }
388: if (@primsub > 0) {
389: $menu{$position} .= &create_submenu($link,$target,$title,\@primsub,1,undef,$listclass,$linkattr);
390: } elsif ($link) {
391: $menu{$position} .= ($listclass?'<li class="'.$listclass.'">':'<li>').
392: '<a href="'.$link.'" target="'.$target.'" '.$linkattr.'>'.$title.'</a></li>';
393: }
394: }
395: } elsif ($$menuitem[3] eq 'Help') { # special treatment for helplink
396: next if ($crstype eq 'Placement');
397: if ($public) {
398: my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
399: my $defdom = &Apache::lonnet::default_login_domain();
400: my $to = &Apache::loncommon::build_recipient_list(undef,
401: 'helpdeskmail',
402: $defdom,$origmail);
403: if ($to ne '') {
404: $menu{$position} .= &prep_menuitem($menuitem,$target,$listclass,$linkattr);
405: }
406: } else {
407: $menu{$position} .= ($listclass?'<li class="'.$listclass.'">':'<li>').
408: &Apache::loncommon::top_nav_help('Help',$linkattr).
409: '</li>';
410: }
411: } elsif ($$menuitem[3] eq 'Log In') {
412: if ($public) {
413: if (&Apache::lonnet::get_saml_landing()) {
414: $$menuitem[0] = '/adm/login';
415: }
416: }
417: $menu{$position} .= prep_menuitem($menuitem,$target,$listclass,$linkattr);
418: } else {
419: $menu{$position} .= prep_menuitem($menuitem,$target,$listclass,$linkattr);
420: }
421: }
422: my @output = ('','');
423: if ($menu{'left'} ne '') {
424: $output[0] = "<ol class=\"LC_primary_menu LC_floatleft\">$menu{'left'}</ol>";
425: }
426: if ($menu{'right'} ne '') {
427: $output[1] = "<ol class=\"LC_primary_menu LC_floatright LC_right\">$menu{'right'}</ol>";
428: }
429: return @output;
430: }
431:
432: #returns hashref {user=>'',dom=>''} containing:
433: # own name, domain if user is au
434: # name, domain of parent author if user is ca or aa
435: #empty return if user is not an author or not on homeserver
436: #
437: #TODO this should probably be moved somewhere more central
438: #since it can be used by different parts of the system
439: sub getauthor {
440: return unless $env{'request.role'}=~/^(ca|aa|au)/; #nothing to do if user isn't some kind of author
441:
442: #co- or assistant author?
443: my ($dom, $user) = ($env{'request.role'} =~ /^(?:ca|aa)\.\/($match_domain)\/($match_username)$/)
444: ? ($1, $2) #domain, username of the parent author
445: : @env{ ('request.role.domain', 'user.name') }; #own domain, username
446:
447: # current server == home server?
448: my $home = &Apache::lonnet::homeserver($user,$dom);
449: foreach (&Apache::lonnet::current_machine_ids()){
450: return {user => $user, dom => $dom} if $_ eq $home;
451: }
452:
453: # if wrong server
454: return;
455: }
456:
457: sub secondary_menu {
458: my ($httphost,$ltiscope,$ltimenu,$noprimary,$menucoll,$menuref,
459: $links_disabled,$links_target) = @_;
460: my $menu;
461:
462: my $crstype = &Apache::loncommon::course_type();
463: my $crs_sec = $env{'request.course.id'} . ($env{'request.course.sec'}
464: ? "/$env{'request.course.sec'}"
465: : '');
466: my $canedit = &Apache::lonnet::allowed('mdc', $env{'request.course.id'});
467: my $canvieweditor = &Apache::lonnet::allowed('cev', $env{'request.course.id'});
468: my $canviewroster = $env{'course.'.$env{'request.course.id'}.'.student_classlist_view'};
469: if ($canviewroster eq 'disabled') {
470: undef($canviewroster);
471: }
472: my $canviewgrps = &Apache::lonnet::allowed('vcg', $crs_sec);
473: my $canmodifyuser = &Apache::lonnet::allowed('cst', $crs_sec);
474: my $canviewusers = &Apache::lonnet::allowed('vcl', $crs_sec);
475: my $canviewwnew = &Apache::lonnet::allowed('whn', $crs_sec);
476: my $canviewpara = &Apache::lonnet::allowed('vpa', $crs_sec);
477: my $canmodpara = &Apache::lonnet::allowed('opa', $crs_sec);
478: my $canvgr = &Apache::lonnet::allowed('vgr', $crs_sec);
479: my $canmgr = &Apache::lonnet::allowed('mgr', $crs_sec);
480: my $canplc = &Apache::lonnet::allowed('plc', $crs_sec);
481: my $author = &getauthor();
482:
483: my ($is_author,$is_coauthor);
484: if ($author) {
485: if ($env{'request.role'} =~ /^au\./) {
486: $is_author = 1;
487: } elsif ($env{'request.role'} =~ /^ca\./) {
488: $is_coauthor = 1;
489: }
490: }
491:
492: my ($cdom,$cnum,$showsyllabus,$showfeeds,$showresv,$grouptools,
493: $lti,$ltimapres,%ltiexc,%menuopts);
494: $grouptools = 0;
495: if ($env{'request.course.id'}) {
496: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
497: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
498: unless ($canedit || $canvieweditor) {
499: unless (&Apache::lonnet::is_on_map("public/$cdom/$cnum/syllabus")) {
500: if (($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'}) ||
501: ($env{'course.'.$env{'request.course.id'}.'.uploadedsyllabus'}) ||
502: ($env{'course.'.$env{'request.course.id'}.'.updatedsyllabus'}) ||
503: ($env{'request.course.syllabustime'})) {
504: $showsyllabus = 1;
505: }
506: }
507: if ($env{'request.course.feeds'}) {
508: $showfeeds = 1;
509: }
510: }
511: unless ($canmgr || $canvgr) {
512: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
513: if (keys(%slots) > 0) {
514: $showresv = 1;
515: }
516: }
517: if ($env{'request.course.groups'} ne '') {
518: foreach my $group (split(/:/,$env{'request.course.groups'})) {
519: next unless ($group =~ /^\w+$/);
520: my @privs = split(/:/,$env{"user.priv.$env{'request.role'}./$cdom/$cnum/$group"});
521: shift(@privs);
522: if (@privs) {
523: $grouptools ++;
524: }
525: }
526: }
527: if ($env{'request.lti.login'}) {
528: $lti = 1;
529: if (ref($ltimenu) eq 'HASH') {
530: foreach my $item ('fullname','coursetitle','role','logout','grades') {
531: unless ($ltimenu->{$item}) {
532: $ltiexc{$item} = 1;
533: }
534: }
535: }
536: if (($ltiscope eq 'map') || ($ltiscope eq 'resource')) {
537: $ltimapres = 1;
538: }
539: }
540: }
541: if (($menucoll) && (ref($menuref) eq 'HASH')) {
542: %menuopts = %{$menuref};
543: }
544:
545: my ($listclass,$linkattr,$target);
546: if ($links_disabled) {
547: $listclass = 'LCisDisabled';
548: $linkattr = 'aria-disabled="true"';
549: }
550:
551: my ($canlistcoauthors,$canmodifycoauthor);
552: if ($env{'request.role'} eq "au./$env{'user.domain'}/") {
553: my $extent = "$env{'user.domain'}/$env{'user.name'}";
554: if ((&Apache::lonnet::allowed('cca',$extent)) ||
555: (&Apache::lonnet::allowed('caa',$extent))) {
556: $canmodifycoauthor = 1;
557: }
558: } elsif ($env{'request.role'} =~ m{^(aa|ca)\./($match_domain/$match_username)$}) {
559: my ($role,$extent) = ($1,$2);
560: if (&Apache::lonnet::allowed('vca',$extent)) {
561: if ($env{"environment.internal.manager./$extent"}) {
562: $canmodifycoauthor = 1;
563: } else {
564: $canlistcoauthors = 1;
565: }
566: } elsif (&Apache::lonnet::allowed('vaa',$extent)) {
567: $canlistcoauthors = 1;
568: }
569: }
570: my ($roleswitcher_js,$roleswitcher_form);
571: if ($links_target ne '') {
572: $target = $links_target;
573: } else {
574: my ($ltitarget,$deeplinktarget);
575: if ($env{'request.lti.login'}) {
576: $ltitarget = $env{'request.lti.target'};
577: }
578: if ($env{'request.deeplink.login'}) {
579: $deeplinktarget = $env{'request.deeplink.target'};
580: }
581: if (($ltitarget eq 'iframe') || ($deeplinktarget eq '_self')) {
582: $target = '_self';
583: } else {
584: $target = '_top';
585: }
586: }
587:
588: foreach my $menuitem (@secondary_menu) {
589: # evaluate conditions
590: next if ref($menuitem) ne 'ARRAY';
591: next if (($crstype eq 'Placement') && ($$menuitem[3] ne 'Roles') && (!$env{'request.role.adv'}));
592: next if $$menuitem[4] ne 'always'
593: && $$menuitem[4] ne 'coauthor'
594: && $$menuitem[4] ne 'author'
595: && $$menuitem[4] ne 'authorspace'
596: && $$menuitem[4] ne 'vca'
597: && $$menuitem[4] ne 'mca'
598: && !$env{'request.course.id'};
599: next if $$menuitem[4] =~ /^crsedit/
600: && (!$canedit && !$canvieweditor);
601: next if $$menuitem[4] eq 'nvgr'
602: && ($canvgr || $ltiexc{'grades'});
603: next if $$menuitem[4] eq 'vgr'
604: && !$canvgr;
605: next if $$menuitem[4] eq 'viewusers'
606: && !$canmodifyuser && !$canviewusers;
607: next if $$menuitem[4] eq 'noviewusers'
608: && ($canmodifyuser || $canviewusers || !$canviewroster);
609: next if $$menuitem[4] eq 'mgr'
610: && !$canmgr;
611: next if $$menuitem[4] eq 'showresv'
612: && !$showresv;
613: next if $$menuitem[4] eq 'whn'
614: && !$canviewwnew;
615: next if $$menuitem[4] eq 'params'
616: && (!$canmodpara && !$canviewpara);
617: next if $$menuitem[4] eq 'showgroups'
618: && ($canviewgrps || !$grouptools);
619: next if $$menuitem[4] eq 'showsyllabus'
620: && !$showsyllabus;
621: next if $$menuitem[4] eq 'showfeeds'
622: && !$showfeeds;
623: next if $$menuitem[4] eq 'plc'
624: && !$canplc;
625: next if $$menuitem[4] eq 'authorspace'
626: && !$author;
627: next if $$menuitem[4] eq 'author'
628: && !$is_author;
629: next if $$menuitem[4] eq 'coauthor'
630: && !$is_coauthor;
631: next if $$menuitem[4] eq 'vca'
632: && (!$canlistcoauthors || $canmodifycoauthor);
633: next if $$menuitem[4] eq 'vaa'
634: && (!$canlistcoauthors || $canmodifycoauthor);
635: next if $$menuitem[4] eq 'mca'
636: && !$canmodifycoauthor;
637: next if $$menuitem[4] eq 'notltimapres'
638: && $ltimapres;
639: next if $$menuitem[4] eq 'notlti'
640: && $lti;
641: next if $$menuitem[4] eq 'lti'
642: && (!$lti || !$noprimary);
643: next if $$menuitem[3] eq 'Logout'
644: && $ltiexc{'logout'};
645:
646: my $title = $menuitem->[3];
647: if ($env{'request.course.id'} && $menucoll) {
648: unless ($$menuitem[5] eq 'roles') {
649: next if (($$menuitem[5]) && (!$menuopts{$$menuitem[5]}));
650: }
651: }
652: if (defined($secondary_submenu{$title})) {
653: my $link;
654: if ($menuitem->[0] ne '') {
655: $link = $menuitem->[0];
656: } else {
657: $link = '#';
658: }
659: my @scndsub;
660: if (ref($secondary_submenu{$title}) eq 'ARRAY') {
661: foreach my $item (@{$secondary_submenu{$title}}) {
662: if (ref($item) eq 'ARRAY') {
663: next if ($item->[2] eq 'vgr' && !$canvgr);
664: next if ($item->[2] eq 'opa' && !$canmodpara);
665: next if ($item->[2] eq 'vpa' && !$canviewpara);
666: next if ($item->[2] eq 'viewusers' && !($canmodifyuser || $canviewusers));
667: next if ($item->[2] eq 'mgr' && !$canmgr);
668: next if ($item->[2] eq 'vcg' && !$canviewgrps);
669: next if ($item->[2] eq 'crsedit' && !$canedit && !$canvieweditor);
670: next if ($item->[2] eq 'params' && !$canmodpara && !$canviewpara);
671: next if ($item->[2] eq 'author' && !$is_author);
672: next if ($item->[2] eq 'vca' && !$canlistcoauthors);
673: next if ($item->[2] eq 'lti' && !$lti);
674: if ($item->[2] =~ /^lti(portfolio|wishlist|blog)$/) {
675: my $tool = $1;
676: next if !$lti;
677: next if (!&Apache::lonnet::usertools_access('','',$tool,
678: undef,'tools'));
679: }
680: push(@scndsub,$item);
681: }
682: }
683: if ($title eq 'Personal' && $env{'user.name'} && $env{'user.domain'}) {
684: unless ($ltiexc{'fullname'}) {
685: $title = &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'});
686: }
687: }
688: if (@scndsub > 0) {
689: $menu .= &create_submenu($link,$target,&mt($title),\@scndsub,1,undef,
690: $listclass,$linkattr);
691: } elsif ($link ne '#') {
692: $menu .= ($listclass?'<li class="'.$listclass.'">':'<li>').
693: '<a href="'.$link.'" target="'.$target.'" '.$linkattr.'>'.
694: &mt($title).'</a></li>';
695: }
696: }
697: } elsif ($$menuitem[3] eq 'Roles' && $env{'request.course.id'}) {
698: # special treatment for role selector
699: my ($switcher,$has_opa_priv);
700: ($roleswitcher_js,$roleswitcher_form,$switcher,$has_opa_priv) =
701: &roles_selector(
702: $env{'course.' . $env{'request.course.id'} . '.domain'},
703: $env{'course.' . $env{'request.course.id'} . '.num'},
704: $httphost,$target,$menucoll,$menuref
705: );
706: if (($$menuitem[5]) && (!$menuopts{$$menuitem[5]})) {
707: next unless ($has_opa_priv);
708: }
709: $menu .= $switcher;
710: } elsif ($$menuitem[3] eq 'Help') { # special treatment for helplink
711: next if ($crstype eq 'Placement');
712: $menu .= '<li>'.&Apache::loncommon::top_nav_help('Help').'</li>';
713: } else {
714: if ($$menuitem[3] eq 'Syllabus' && $env{'request.course.id'}) {
715: my $url = $$menuitem[0];
716: $url =~ s{\[cdom\]/\[cnum\]}{$cdom/$cnum};
717: if (&Apache::lonnet::is_on_map($url)) {
718: unless ($$menuitem[0] =~ /(\?|\&)register=1/) {
719: $$menuitem[0] .= (($$menuitem[0]=~/\?/)? '&' : '?').'register=1';
720: }
721: } else {
722: $$menuitem[0] =~ s{\&?register=1}{};
723: }
724: if ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://}) {
725: if (($ENV{'SERVER_PORT'} == 443) || ($env{'request.use_absolute'} =~ m{^https://})) {
726: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl())) {
727: unless ($$menuitem[0] =~ m{^https?://}) {
728: $$menuitem[0] = 'http://'.$ENV{'SERVER_NAME'}.$$menuitem[0];
729: }
730: unless ($$menuitem[0] =~ /(\&|\?)usehttp=1/) {
731: $$menuitem[0] .= (($$menuitem[0]=~/\?/) ? '&' : '?').'usehttp=1';
732: }
733: }
734: }
735: }
736: $$menuitem[0] = &HTML::Entities::encode($$menuitem[0],'&<>"');
737: }
738: $menu .= &prep_menuitem(\@$menuitem,$target,$listclass,$linkattr);
739: }
740: }
741: if ($menu =~ /\[url\].*\[symb\]/) {
742: my $escurl = &escape( &Apache::lonenc::check_encrypt(
743: $env{'request.noversionuri'}));
744:
745: my $escsymb = &escape( &Apache::lonenc::check_encrypt(
746: $env{'request.symb'}));
747:
748: if ( $env{'request.state'} eq 'construct'
749: and ( $env{'request.noversionuri'} eq ''
750: || !defined($env{'request.noversionuri'})))
751: {
752: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
753: ($escurl = $env{'request.filename'}) =~ s{^\Q$londocroot\E}{};
754: $escurl = &escape($escurl);
755: }
756: $menu =~ s/\[url\]/$escurl/g;
757: $menu =~ s/\[symb\]/$escsymb/g;
758: } elsif (($menu =~ m{/adm/preferences\?}) && ($menu =~ /\[returnurl\]/)) {
759: my $returnurl = $ENV{'REQUEST_URI'};
760: if ($ENV{'REQUEST_URI'} =~ m{/adm/preferences\?action=authorsettings\&returnurl=([^\&]+)$}) {
761: $returnurl = $1;
762: }
763: if (($returnurl =~ m{^/adm/createuser($|\?action=)}) ||
764: ($returnurl =~ m{^/priv/$match_domain/$match_username}) ||
765: ($returnurl =~ m{^/res(/?$|/$match_domain/$match_username)})) {
766: $returnurl =~ s{\?.*$}{};
767: $returnurl = '&returnurl='.&HTML::Entities::encode($returnurl,'"<>&\'');
768: } else {
769: undef($returnurl);
770: }
771: $menu =~ s/\[returnurl\]/$returnurl/;
772: }
773: $menu =~ s/\[uname\]/$$author{user}/g;
774: $menu =~ s/\[udom\]/$$author{dom}/g;
775: $menu =~ s/\[javascript\]/javascript:/g;
776: if ($env{'request.course.id'}) {
777: $menu =~ s/\[cnum\]/$cnum/g;
778: $menu =~ s/\[cdom\]/$cdom/g;
779: }
780: if ($menu) {
781: $menu = "<ul id=\"LC_secondary_menu\">$menu</ul>";
782: }
783: if ($roleswitcher_form) {
784: $menu .= "\n$roleswitcher_js\n$roleswitcher_form";
785: }
786: return $menu;
787: }
788:
789: sub create_submenu {
790: my ($link,$target,$title,$submenu,$translate,$addclass,$listclass,$linkattr) = @_;
791: return unless (ref($submenu) eq 'ARRAY');
792: my $targetattr;
793: if (($target ne '') && ($link ne '#')) {
794: $targetattr = ' target="'.$target.'"';
795: }
796: my $menu = '<li class="LC_hoverable '.$addclass.'">'.
797: '<a href="'.$link.'"'.$targetattr.'>'.
798: '<span class="LC_nobreak">'.$title.
799: '<span class="LC_fontsize_small" style="font-weight:normal;">'.
800: ' ▼</span></span></a>'.
801: '<ul>';
802:
803: # $link and $title are only used in the initial string written in $menu
804: # as seen above, not needed for nested submenus
805: $menu .= &build_submenu($target, $submenu, $translate, '1', $listclass, $linkattr);
806: $menu .= '</ul></li>';
807:
808: return $menu;
809: }
810:
811: # helper routine for create_submenu
812: # build the dropdown (and nested submenus) recursively
813: # see perldoc create_submenu documentation for further information
814: sub build_submenu {
815: my ($target, $submenu, $translate, $first_level, $listclass, $linkattr) = @_;
816: unless (@{$submenu}) {
817: return '';
818: }
819:
820: my $menu = '';
821: my $count = 0;
822: my $numsub = scalar(@{$submenu});
823: foreach my $item (@{$submenu}) {
824: $count ++;
825: if (ref($item) eq 'ARRAY') {
826: my $href = $item->[0];
827: my $bordertop;
828: my $borderbot;
829: my $title;
830:
831: if ($translate) {
832: $title = &mt($item->[1]);
833: } else {
834: $title = $item->[1];
835: }
836:
837: if ($count == 1 && !$first_level) {
838: $bordertop = 'border-top: 1px solid black;';
839: }
840: if ($count == $numsub) {
841: $borderbot = 'border-bottom: 1px solid black;';
842: }
843:
844: # href is a reference to another submenu
845: if (ref($href) eq 'ARRAY') {
846: $menu .= '<li style="margin:0;padding:0;'.$bordertop . $borderbot . '">';
847: $menu .= '<p><span class="LC_primary_menu_innertitle">'
848: . $title . '</span><span class="LC_primary_menu_innerarrow">▶</span></p>';
849: $menu .= '<ul>';
850: $menu .= &build_submenu($target, $href, $translate);
851: $menu .= '</ul>';
852: $menu .= '</li>';
853: } else { # href is the actual hyperlink and does not represent another submenu
854: # for the current menu title
855: if ($href =~ /(aboutme|rss\.html)$/) {
856: next unless (($env{'user.name'} ne '') && ($env{'user.domain'} ne ''));
857: $href =~ s/\[domain\]/$env{'user.domain'}/g;
858: $href =~ s/\[user\]/$env{'user.name'}/g;
859: } elsif (($href =~ m{^/adm/preferences\?}) && ($href =~ /\[returnurl\]/)) {
860: my $returnurl = $ENV{'REQUEST_URI'};
861: if ($ENV{'REQUEST_URI'} =~ m{/adm/preferences\?action=(?:changedomcoord|authorsettings)\&returnurl=([^\&]+)$}) {
862: $returnurl = $1;
863: }
864: if (($returnurl =~ m{^/adm/createuser($|\?action=)}) ||
865: ($returnurl =~ m{^/priv/$match_domain/$match_username}) ||
866: ($returnurl =~ m{^/res(/?$|/$match_domain/$match_username)})) {
867: $returnurl =~ s{\?.*$}{};
868: $returnurl = '&returnurl='.&HTML::Entities::encode($returnurl,'"<>&\'');
869: } else {
870: undef($returnurl);
871: }
872: $href =~ s/\[returnurl\]/$returnurl/;
873: }
874: my $targetattr;
875: unless (($href eq '') || ($href =~ /^\#/)) {
876: if ($target ne '') {
877: $targetattr = ' target="'.$target.'"';
878: }
879: }
880:
881: $menu .= '<li ';
882: $menu .= ($listclass?'class="'.$listclass.'" ':'');
883: $menu .= 'style="margin:0;padding:0;'. $bordertop . $borderbot .'">';
884: $menu .= '<a href="'.$href.'"'.$targetattr.' '.$linkattr.'>' . $title . '</a>';
885: $menu .= '</li>';
886: }
887: }
888: }
889: return $menu;
890: }
891:
892: sub innerregister {
893: my ($forcereg,$bread_crumbs,$group,$pagebuttonshide,$hostname,
894: $ltiscope,$ltiuri,$showncrumbsref) = @_;
895: my $const_space = ($env{'request.state'} eq 'construct');
896: my $is_const_dir = 0;
897:
898: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
899:
900: $env{'request.registered'} = 1;
901:
902: undef(@inlineremote);
903:
904: my ($mapurl,$resurl,$crstype,$navmap);
905:
906: if ($env{'request.course.id'}) {
907: #
908: #course_type: Course, Community, or Placement
909: #
910: $crstype = &Apache::loncommon::course_type();
911: if ($env{'request.symb'}) {
912: my $ignorenull;
913: unless ($env{'request.noversionuri'} eq '/adm/navmaps') {
914: $ignorenull = 1;
915: }
916: my $symb = &Apache::lonnet::symbread('','',$ignorenull);
917: ($mapurl, my $rid, $resurl) = &Apache::lonnet::decode_symb($symb);
918: my $coursetitle = $env{'course.'.$env{'request.course.id'}.'.description'};
919:
920: my $maptitle = &Apache::lonnet::gettitle($mapurl);
921: my $restitle = &Apache::lonnet::gettitle($symb);
922: my (@crumbs,@mapcrumbs);
923: if (($env{'request.noversionuri'} ne '/adm/navmaps') && ($mapurl ne '') &&
924: (!(($crstype eq 'Placement') && !$env{'request.role.adv'}))) {
925: unless ($ltiscope eq 'resource') {
926: if (($mapurl ne $env{'course.'.$env{'request.course.id'}.'.url'}) &&
927: !(($ltiscope eq 'map') && (&Apache::lonnet::clutter($resurl) eq $ltiuri))) {
928: $navmap = Apache::lonnavmaps::navmap->new();
929: if (ref($navmap)) {
930: @mapcrumbs = $navmap->recursed_crumbs($mapurl,$restitle);
931: }
932: }
933: }
934: }
935: unless ((($crstype eq 'Placement') && (!$env{'request.role.adv'})) ||
936: ($ltiscope eq 'map') || ($ltiscope eq 'resource')) {
937: @crumbs = ({text => $crstype.' Contents',
938: href => "Javascript:gopost('/adm/navmaps','')"});
939: }
940: if ($mapurl ne $env{'course.'.$env{'request.course.id'}.'.url'}) {
941: if (@mapcrumbs) {
942: push(@crumbs,@mapcrumbs);
943: } elsif (!(($crstype eq 'Placement') && (!$env{'request.role.adv'})) &&
944: ($ltiscope ne 'map') && ($ltiscope ne 'resource')) {
945: push(@crumbs, {text => '...',
946: no_mt => 1});
947: }
948: }
949:
950: unless ((($crstype eq 'Placement') && (!$env{'request.role.adv'})) || (@mapcrumbs) ||
951: (!$maptitle) || ($maptitle eq 'default.sequence') ||
952: ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'}) ||
953: ($ltiscope eq 'resource')) {
954: push @crumbs, {text => $maptitle, no_mt => 1,
955: href => &Apache::lonnet::clutter($mapurl).'?navmap=1'};
956: }
957: if ($restitle && !@mapcrumbs) {
958: push(@crumbs,{text => $restitle, no_mt => 1});
959: }
960: my @tools;
961: if ($env{'request.filename'} =~ /\.page$/) {
962: my %breadcrumb_tools = &Apache::lonhtmlcommon::current_breadcrumb_tools();
963: if (ref($breadcrumb_tools{'tools'}) eq 'ARRAY') {
964: @tools = @{$breadcrumb_tools{'tools'}};
965: }
966: }
967: &Apache::lonhtmlcommon::clear_breadcrumbs();
968: &Apache::lonhtmlcommon::add_breadcrumb(@crumbs);
969: if (@tools) {
970: &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',@tools);
971: }
972: } else {
973: $resurl = $env{'request.noversionuri'};
974: my $courseurl = &Apache::lonnet::courseid_to_courseurl($env{'request.course.id'});
975: my $title = &mt('View Resource');
976: if ($resurl =~ m{^\Q/uploaded$courseurl/supplemental/\E(default|\d+)/}) {
977: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['folderpath','title']);
978: &Apache::lonhtmlcommon::clear_breadcrumbs();
979: if ($env{'form.title'}) {
980: $title = $env{'form.title'};
981: }
982: my ($trail,$cnum,$cdom);
983: if ($env{'form.folderpath'}) {
984: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
985: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
986: &Apache::loncommon::validate_folderpath(1,'',$cnum,$cdom);
987: }
988: if ($env{'form.folderpath'}) {
989: &prepare_functions($resurl,$forcereg,$group,undef,undef,1,$hostname);
990: $title = &HTML::Entities::encode($title,'\'"<>&');
991: ($trail) =
992: &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1,1);
993: } else {
994: &Apache::lonhtmlcommon::add_breadcrumb(
995: {text => "Supplemental $crstype Content",
996: href => "javascript:gopost('/adm/supplemental','')"});
997: $title = &HTML::Entities::encode(&mt('View Resource'),'\'"<>&');
998: ($trail) =
999: &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1,1);
1000: }
1001: if (ref($showncrumbsref)) {
1002: $$showncrumbsref = 1;
1003: }
1004: return $trail;
1005: } elsif ($resurl =~ m{^\Q/uploaded$courseurl/portfolio/syllabus/}) {
1006: &Apache::lonhtmlcommon::clear_breadcrumbs();
1007: &prepare_functions('/public'.$courseurl."/syllabus",
1008: $forcereg,$group,undef,undef,1,$hostname);
1009: $title = &HTML::Entities::encode(&mt('Syllabus File'),'\'"<>&');
1010: my ($trail) =
1011: &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1,1);
1012: if (ref($showncrumbsref)) {
1013: $$showncrumbsref = 1;
1014: }
1015: return $trail;
1016: } elsif (($resurl eq '/public'.$courseurl.'/syllabus') &&
1017: ($env{'form.folderpath'})) {
1018: if ($env{'form.title'}) {
1019: $title = $env{'form.title'};
1020: } else {
1021: $title = 'Syllabus';
1022: }
1023: &prepare_functions($resurl,$forcereg,$group,undef,undef,1,$hostname);
1024: $title = &HTML::Entities::encode($title,'\'"<>&');
1025: my ($trail) =
1026: &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1,1);
1027: return $trail;
1028: }
1029: unless ($env{'request.state'} eq 'construct') {
1030: &Apache::lonhtmlcommon::clear_breadcrumbs();
1031: &Apache::lonhtmlcommon::add_breadcrumb({text => 'View Resource'});
1032: }
1033: }
1034: } elsif (! $const_space){
1035: #a situation when we're looking at a resource outside of context of a
1036: #course or construction space (e.g. with cumulative rights)
1037: &Apache::lonhtmlcommon::clear_breadcrumbs();
1038: unless ($env{'request.noversionuri'} =~ m{^/adm/$match_domain/$match_username/aboutme$}) {
1039: &Apache::lonhtmlcommon::add_breadcrumb({text => 'View Resource'});
1040: }
1041: }
1042: # =============================================================================
1043: # ============================ This is for URLs that actually can be registered
1044: return '' unless ( ($env{'request.noversionuri'}!~m{^/(res/)*adm/})
1045: || $forcereg );
1046: my ($cdom,$cnum,%perms,$cfile,$switchserver,$home,$forceedit,
1047: $forceview,$editbutton);
1048: if (($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) ||
1049: ($env{'request.role'} !~/^(aa|ca|au)/)) {
1050: $editbutton = &prepare_functions($resurl,$forcereg,$group,'','','',$hostname);
1051: }
1052: if ($editbutton eq '') {
1053: $editbutton = &clear(6,1);
1054: }
1055:
1056: #
1057: # This applies in course context
1058: #
1059: if ($env{'request.course.id'}) {
1060: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1061: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1062: $perms{'mdc'} = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
1063: $perms{'cev'} = &Apache::lonnet::allowed('cev',$env{'request.course.id'});
1064: my @privs;
1065: my $gradable_exttool;
1066: if ($env{'request.symb'} ne '') {
1067: if ($env{'request.noversionuri'} =~ m{^/adm/$cdom/$cnum/(\d+)/ext\.tool$}) {
1068: if (&Apache::lonnet::EXT('resource.0.gradable') =~ /^yes$/i) {
1069: $gradable_exttool = 1;
1070: push(@privs,('mgr','vgr'));
1071: }
1072: } elsif ($env{'request.filename'}=~/$LONCAPA::assess_re/) {
1073: push(@privs,('mgr','vgr'));
1074: }
1075: push(@privs,('opa','vpa'));
1076: }
1077: foreach my $priv (@privs) {
1078: $perms{$priv} = &Apache::lonnet::allowed($priv,$env{'request.course.id'});
1079: if (!$perms{$priv} && $env{'request.course.sec'} ne '') {
1080: $perms{$priv} =
1081: &Apache::lonnet::allowed($priv,"$env{'request.course.id'}/$env{'request.course.sec'}");
1082: }
1083: }
1084: #
1085: # Determine whether or not to show Grades and Submissions buttons
1086: #
1087: if (($env{'request.symb'} ne '') &&
1088: (($env{'request.filename'}=~/$LONCAPA::assess_re/) || ($gradable_exttool))) {
1089: if ($perms{'mgr'}) {
1090: &switch('','',7,2,'pgrd.png','Content Grades','grades[_4]',
1091: "gocmd('/adm/grades','gradingmenu')",
1092: 'Content Grades');
1093: } elsif ($perms{'vgr'}) {
1094: &switch('','',7,2,'subm.png','Content Submissions','missions[_1]',
1095: "gocmd('/adm/grades','submission')",
1096: 'Content Submissions');
1097: }
1098: }
1099: if (($env{'request.symb'} ne '') && (($perms{'opa'}) || ($perms{'vpa'}))) {
1100: &switch('','',7,3,'pparm.png','Content Settings','parms[_2]',
1101: "gocmd('/adm/parmset','set')",
1102: 'Content Settings');
1103: }
1104: # End grades/submissions check
1105:
1106: #
1107: # This applies to items inside a folder/page modifiable in the course.
1108: #
1109: if (($env{'request.symb'}=~/^uploaded/) && (($perms{'mdc'}) || ($perms{'cev'}))) {
1110: my $text = 'Edit Folder';
1111: if (($mapurl =~ /\.page$/) ||
1112: ($env{'request.symb'}=~
1113: m{uploaded/$cdom/$cnum/default_\d+\.page$})) {
1114: $text = 'Edit Page';
1115: }
1116: &switch('','',7,4,'docs-22x22.png',$text,'parms[_2]',
1117: "gocmd('/adm/coursedocs','direct')",
1118: 'Folder/Page Content');
1119: }
1120: # End modifiable folder/page container check
1121:
1122: #
1123: # Determine whether to show View As button for shortcut to display problem, answer, and submissions
1124: #
1125:
1126: if (($env{'request.symb'} ne '') &&
1127: ($env{'request.filename'}=~/$LONCAPA::assess_re/) &&
1128: (($perms{'mgr'}) || ($perms{'vgr'}))) {
1129: my ($viewas,$text,$change,$visibility,$vuname,$vudom,$vid,$leftvis,$defdom,
1130: $domselector,$righticon);
1131: my %lt = &Apache::lonlocal::texthash(
1132: view => 'View',
1133: upda => 'Update',
1134: );
1135: my $possdomstr = $env{'course.'.$env{'request.course.id'}.'.internal.userdomains'};
1136: if ($possdomstr =~ /,/) {
1137: my @possdoms = split(/,/,$possdomstr);
1138: if ($env{'request.user_in_effect'} =~ /^$match_username:($match_domain)$/) {
1139: $defdom = $1;
1140: } elsif (grep(/^\Q$cdom\E$/,@possdoms)) {
1141: $defdom = $cdom;
1142: } elsif (&Apache::lonnet::domain($possdoms[0]) ne '') {
1143: $defdom = $possdoms[0];
1144: }
1145: $domselector = &Apache::loncommon::select_dom_form($defdom,'vudom','','','',\@possdoms);
1146: } elsif (($possdomstr ne '') && (&Apache::lonnet::domain($possdomstr) ne '')) {
1147: if ($env{'request.user_in_effect'} =~ /^$match_username:($match_domain)$/) {
1148: $defdom = $1;
1149: } else {
1150: $defdom = $possdomstr;
1151: }
1152: }
1153: if ($env{'request.user_in_effect'} =~ /^($match_username):($match_domain)$/) {
1154: ($vuname,$vudom) = ($1,$2);
1155: unless (&Apache::lonnet::is_advanced_user($vudom,$vuname)) {
1156: $vid = (&Apache::lonnet::idrget($vudom,$vuname))[1];
1157: }
1158: $viewas = $env{'request.user_in_effect'};
1159: $text = $lt{'upda'};
1160: $change = 'off';
1161: $visibility = 'inline';
1162: $leftvis = 'none';
1163: $defdom = $vudom;
1164: $righticon = '✖';
1165: } else {
1166: $text = $lt{'view'};
1167: $change = 'on';
1168: $visibility = 'none';
1169: $leftvis = 'inline';
1170: if ($defdom eq '') {
1171: $defdom = $cdom;
1172: }
1173: }
1174: my $sellink = &Apache::loncommon::selectstudent_link('userview','vuname','vudom','','','vuidentifier');
1175: my $selscript=&Apache::loncommon::studentbrowser_javascript();
1176: my $shownsymb = &HTML::Entities::encode(&Apache::lonenc::check_encrypt($env{'request.symb'}),'<>&"');
1177: my $input;
1178: my @items = (
1179: '<label><input type="radio" name="vuidentifier" value="uname" checked="checked" onclick="javascript:toggleIdentifier(this.form);" />',
1180: '</label><input name="vuname" type="text" size="6" value="'.$vuname.'" id="LC_vuname" />',
1181: '<label><input type="radio" name="vuidentifier" value="uid" onclick="javascript:toggleIdentifier(this.form);" />',
1182: '</label><input name="vid" type="hidden" size="6" value="'.$vid.'" id="LC_vid" />'
1183: );
1184: if ($domselector) {
1185: push(@items,$domselector);
1186: $input = &mt('[_1]User:[_2] or [_3]ID:[_4] at [_5] | ',@items);
1187: } else {
1188: $input = &mt('[_1]Username:[_2] or [_3]ID:[_4] | ',@items).
1189: '<input name="vudom" type="hidden" value="'.$defdom.'" />';
1190: }
1191: $input .= '<input name="LC_viewas" type="hidden" value="'.$viewas.'" />',
1192: '<input name="symb" type="hidden" value="'.$shownsymb.'" />';
1193: my $chooser = <<END;
1194: $selscript
1195: <a href="javascript:toggleViewAsUser('$change');" class="LC_menubuttons_link">
1196: <span id="usexpand" class="LC_menubuttons_inline_text" style="display:$leftvis">► </span>
1197: </a>
1198: <fieldset id="LC_selectuser" style="display:$visibility">
1199: <form name="userview" action="" method="post" onsubmit="event.preventDefault(); return validCourseUser(this,'$change');">
1200: <span class="LC_menubuttons_inline_text LC_nobreak">
1201: $input
1202: $sellink
1203: </span>
1204: <input type="submit" value="$text" />
1205: </form>
1206: </fieldset>
1207: <a href="javascript:toggleViewAsUser('$change');" class="LC_menubuttons_link">
1208: <span id="uscollapse" class="LC_menubuttons_inline_text">$righticon</span>
1209: </a>
1210: END
1211: &switch('','',7,5,'viewuser.png','View As','user[_1]',
1212: 'toggleViewAsUser('."'$change'".')',
1213: 'View As','','',$chooser);
1214: }
1215: # End view as user check
1216:
1217: }
1218: # End course context
1219:
1220: # Prepare the rest of the buttons
1221: my ($menuitems,$got_prt,$got_wishlist,$crsauthor);
1222: if ($const_space) {
1223: #
1224: # We are in construction space
1225: #
1226:
1227: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1228: my ($udom,$uname,$thisdisfn) =
1229: ($env{'request.filename'}=~m{^\Q$londocroot/priv/\E([^/]+)/([^/]+)/(.*)$});
1230: my $crsauthor;
1231: if (($env{'request.course.id'}) &&
1232: ($env{'course.'.$env{'request.course.id'}.'.num'} eq $uname) &&
1233: ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $udom)) {
1234: $crsauthor = 1;
1235: }
1236: my $currdir = '/priv/'.$udom.'/'.$uname.'/'.$thisdisfn;
1237: if ($currdir =~ m-/$-) {
1238: $is_const_dir = 1;
1239: if (($thisdisfn eq '') && ($crsauthor)) {
1240: $is_const_dir = 2;
1241: }
1242: my $esc_currdir = &Apache::loncommon::escape_single($currdir);
1243: $menuitems=(<<ENDMENUITEMS);
1244: s&6&3&pub.png&Publish&dir[_2]&gocstr('/adm/publish','$esc_currdir')&Publish this Directory
1245: s&7&4&docs-22x22.png&Edit Metadata&defaults[_1]&gopost('${esc_currdir}default.meta','')&Edit metadata for this Directory
1246: s&7&2&prt.png&Print&printout[_1]&gocstr('/adm/printout','$esc_currdir')&Print contents of directory
1247: s&7&1&del.png&Delete&dir[_3]&gocstr('/adm/cfile?action=delete','$esc_currdir')&Delete this Directory
1248: ENDMENUITEMS
1249: } else {
1250: $currdir =~ s|[^/]+$||;
1251: my $cleandisfn = &Apache::loncommon::escape_single($thisdisfn);
1252: my $esc_currdir = &Apache::loncommon::escape_single($currdir);
1253: my $pubfile = "/res/$udom/$uname/$thisdisfn";
1254: my $candelete = 1;
1255: if (-e $londocroot.$pubfile) {
1256: unless (&Apache::lonnet::metadata($pubfile,'obsolete')) {
1257: undef($candelete);
1258: }
1259: }
1260: #
1261: # Probably should be in mydesk.tab
1262: #
1263: if (($crsauthor) && ($pubfile eq "/res/$udom/$uname/default.rights")) {
1264: $menuitems=(<<ENDMENUITEMS);
1265: s&6&1&list.png&Directory&dir[_1]&golist('$esc_currdir')&List current directory
1266: s&6&3&pub.png&Publish&resource[_3]&gocstr('/adm/publish','/priv/$udom/$uname/$cleandisfn')&Publish this resource
1267: ENDMENUITEMS
1268: } else {
1269: $menuitems=(<<ENDMENUITEMS);
1270: s&6&1&list.png&Directory&dir[_1]&golist('$esc_currdir')&List current directory
1271: s&6&2&rtrv.png&Retrieve&version[_1]&gocstr('/adm/retrieve','/priv/$udom/$uname/$cleandisfn')&Retrieve old version
1272: s&6&3&pub.png&Publish&resource[_3]&gocstr('/adm/publish','/priv/$udom/$uname/$cleandisfn')&Publish this resource
1273: s&7&3©.png&Copy&resource[_4]&gocstr('/adm/cfile?action=copy','/priv/$udom/$uname/$cleandisfn')&Copy this resource
1274: ENDMENUITEMS
1275: }
1276: #
1277: # Rename and Delete only available if obsolete or unpublished
1278: #
1279: if ($candelete) {
1280: $menuitems .= (<<ENDMENUITEMS);
1281: s&7&4&rename.png&Rename&resource[_5]&gocstr('/adm/cfile?action=rename','/priv/$udom/$uname/$cleandisfn')&Rename this resource
1282: s&7&1&del.png&Delete&resource[_2]&gocstr('/adm/cfile?action=delete','/priv/$udom/$uname/$cleandisfn')&Delete this resource
1283: ENDMENUITEMS
1284: }
1285: $menuitems .= (<<ENDMENUITEMS);
1286: s&7&2&prt.png&Print&printout[_1]&gocstr('/adm/printout','/priv/$udom/$uname/$cleandisfn')&Prepare a printable document
1287: ENDMENUITEMS
1288: }
1289: if (ref($bread_crumbs) eq 'ARRAY') {
1290: &Apache::lonhtmlcommon::clear_breadcrumbs();
1291: foreach my $crumb (@{$bread_crumbs}){
1292: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
1293: }
1294: }
1295: } elsif ( defined($env{'request.course.id'}) &&
1296: $env{'request.symb'} ne '' ) {
1297: #
1298: # We are in a course and looking at a registered URL
1299: # Should probably be in mydesk.tab
1300: #
1301: $menuitems = "c&3&1";
1302: if ($ltiscope eq 'resource') {
1303: # Suppress display of backward arrow for LTI Provider if scope is resource.
1304: # Suppress display of forward arrow for LTI Provider if scope is resource.
1305: } elsif ($ltiscope eq 'map') {
1306: # Suppress display of backward arrow for LTI Provider if scope is map and this is first resource.
1307: # Suppress display of forward arrow for LTI Provider if scope is map and this is the last resource.
1308: my $showforw = 1;
1309: my $showback = 1;
1310: my $navmap = Apache::lonnavmaps::navmap->new();
1311: if (ref($navmap)) {
1312: my $mapres = $navmap->getResourceByUrl($ltiuri);
1313: if (ref($mapres)) {
1314: if ($navmap->isLastResource($mapres,$env{'request.symb'})) {
1315: $showforw = 0;
1316: }
1317: if ($navmap->isFirstResource($mapres,$env{'request.symb'})) {
1318: $showback = 0;
1319: }
1320: }
1321: }
1322: if ($showback) {
1323: $menuitems.="
1324: s&2&1&back.png&&&gopost('/adm/flip','back:'+currentURL)&Previous content resource&&1";
1325: }
1326: if ($showforw) {
1327: $menuitems.="
1328: s&2&3&forw.png&&&gopost('/adm/flip','forward:'+currentURL)&Next content resource&&3";
1329: }
1330: } elsif (($crstype ne 'Placement') || ($env{'request.role.adv'})) {
1331: $menuitems.="
1332: s&2&1&back.png&&&gopost('/adm/flip','back:'+currentURL)&Previous content resource&&1
1333: s&2&3&forw.png&&&gopost('/adm/flip','forward:'+currentURL)&Next content resource&&3";
1334: } else {
1335: # Suppress display of backward arrow for Placement Tests
1336: # Suppress display of forward arrow for Placement Tests if this is the last resource.
1337: my $showforw = 1;
1338: if ($env{'request.symb'}) {
1339: my $navmap = Apache::lonnavmaps::navmap->new();
1340: if (ref($navmap)) {
1341: if (&Apache::lonplacementtest::is_lastres($env{'request.symb'},$navmap)) {
1342: $showforw = 0;
1343: }
1344: }
1345: }
1346: if ($showforw) {
1347: $menuitems.="
1348: s&2&3&forw.png&&&gopost('/adm/flip','forward:'+currentURL)&Next content resource&&3";
1349: }
1350: }
1351: $menuitems .= (<<ENDMENUITEMS);
1352:
1353: c&6&3
1354: c&8&1
1355: c&8&2
1356: s&8&3&prt.png&Print&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
1357: ENDMENUITEMS
1358: $got_prt = 1;
1359: if (($env{'user.adv'}) && ($env{'request.uri'} =~ /^\/res/)
1360: && (!$env{'request.enc'})) {
1361: my $privurl = $env{'request.uri'};
1362: $privurl =~ s{^/res/}{/priv/};
1363: my ($cnum,$cdom) = &Apache::loncommon::crsauthor_url($privurl);
1364: if ($cnum) {
1365: $crsauthor = 1;
1366: } else {
1367: # wishlist is only available for users with access to resource-pool
1368: # and links can only be set for resources within the resource-pool
1369: $menuitems .= (<<ENDMENUITEMS);
1370: s&9&1&wishlist-link.png&Stored Links&wishlistlink[_2]&set_wishlistlink()&Save a link for this resource in my personal Stored Links repository&&1
1371: ENDMENUITEMS
1372: $got_wishlist = 1;
1373: }
1374: }
1375:
1376: my $currentURL = &Apache::loncommon::get_symb();
1377: my ($symb_old,$symb_old_enc) = &Apache::loncommon::clean_symb($currentURL);
1378: my $annotation = &Apache::loncommon::get_annotation($symb_old,$symb_old_enc);
1379: $menuitems.="s&9&3&";
1380: if(length($annotation) > 0){
1381: $menuitems.="anot2.png";
1382: }else{
1383: $menuitems.="anot.png";
1384: }
1385: $menuitems.="&Notes&&annotate()&";
1386: $menuitems.="Make notes and annotations about this resource&&1\n";
1387: my $is_mobile;
1388: if ($env{'browser.mobile'}) {
1389: $is_mobile = 1;
1390: }
1391:
1392: unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme|viewclasslist|portfolio)(\?|$)/) {
1393: if ((!$env{'request.enc'}) && ($env{'request.noversionuri'} !~ m{^/adm/wrapper/ext/}) &&
1394: ($env{'request.noversionuri'} !~ m{^/uploaded/$match_domain/$match_courseid/(docs/|default_\d+\.page$)}) &&
1395: ($env{'request.noversionuri'} !~ m{^/adm/.+/ext\.tool$})) {
1396: $menuitems.=(<<ENDREALRES);
1397: s&6&3&catalog.png&Info&info[_1]&catalog_info(currentURL,'$is_mobile')&Show Metadata
1398: ENDREALRES
1399: }
1400: unless (($env{'request.noversionuri'} =~ m{^/uploaded/$match_domain/$match_courseid/(docs/|default_\d+\.page$)}) ||
1401: ($env{'request.noversionuri'} =~ m{^\Q/adm/wrapper/\E(ext|uploaded)/}) ||
1402: ($env{'request.noversionuri'} =~ m{^/adm/.+/ext\.tool$})) {
1403: $menuitems.=(<<ENDREALRES);
1404: s&8&1&eval.png&Evaluate&this[_1]&gopost('/adm/evaluate',currentURL,1)&Provide my evaluation of this resource
1405: ENDREALRES
1406: }
1407: unless ($env{'request.noversionuri'} =~ m{^\Q/adm/wrapper/\E(ext|uploaded)/}) {
1408: $menuitems.=(<<ENDREALRES);
1409: 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
1410: ENDREALRES
1411: }
1412: }
1413: }
1414: if ($env{'request.uri'} =~ /^\/res/) {
1415: unless ($got_prt) {
1416: $menuitems .= (<<ENDMENUITEMS);
1417: s&8&3&prt.png&Print&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
1418: ENDMENUITEMS
1419: $got_prt = 1;
1420: }
1421: unless (($got_wishlist) || ($crsauthor)) {
1422: if (($env{'user.adv'}) && (!$env{'request.enc'})) {
1423: # wishlist is only available for users with access to resource-pool
1424: $menuitems .= (<<ENDMENUITEMS);
1425: 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
1426: ENDMENUITEMS
1427: $got_wishlist = 1;
1428: }
1429: }
1430: }
1431: my $buttons='';
1432: foreach (split(/\n/,$menuitems)) {
1433: my ($command,@rest)=split(/\&/,$_);
1434: my $idx=10*$rest[0]+$rest[1];
1435: if (&hidden_button_check() eq 'yes') {
1436: if ($idx == 21 ||$idx == 23) {
1437: $buttons.=&switch('','',@rest);
1438: } else {
1439: $buttons.=&clear(@rest);
1440: }
1441: } else {
1442: if ($command eq 's') {
1443: $buttons.=&switch('','',@rest);
1444: } else {
1445: $buttons.=&clear(@rest);
1446: }
1447: }
1448: }
1449: my ($showprogress,$linkprotout);
1450: if (($crstype eq 'Placement') && (!$env{'request.role.adv'})) {
1451: $showprogress = &placement_progress();
1452: }
1453: if ($env{'request.deeplink.login'}) {
1454: $linkprotout = &linkprot_exit();
1455: }
1456:
1457: my $addremote=0;
1458: foreach (@inlineremote) { if ($_ ne '') { $addremote=1; last;} }
1459:
1460: if ($addremote) {
1461: my ($countdown,$buttonshide);
1462: if ($env{'request.filename'} =~ /\.page$/) {
1463: my %breadcrumb_tools = &Apache::lonhtmlcommon::current_breadcrumb_tools();
1464: if (ref($breadcrumb_tools{'tools'}) eq 'ARRAY') {
1465: $countdown = $breadcrumb_tools{'tools'}->[0];
1466: }
1467: $buttonshide = $pagebuttonshide;
1468: } else {
1469: $countdown = &countdown_timer();
1470: $buttonshide = &hidden_button_check();
1471: }
1472: &Apache::lonhtmlcommon::clear_breadcrumb_tools();
1473:
1474: &Apache::lonhtmlcommon::add_breadcrumb_tool(
1475: 'navigation', @inlineremote[21,23]);
1476:
1477: if ($buttonshide eq 'yes') {
1478: if ($countdown) {
1479: &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$countdown);
1480: }
1481: if ($linkprotout) {
1482: &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$linkprotout);
1483: }
1484: if ($showprogress) {
1485: &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$showprogress);
1486: }
1487: } else {
1488: my @tools = @inlineremote[93,91,81,82,83];
1489: if ($countdown) {
1490: unshift(@tools,$countdown);
1491: }
1492: if ($linkprotout) {
1493: unshift(@tools,$linkprotout);
1494: }
1495: &Apache::lonhtmlcommon::add_breadcrumb_tool(
1496: 'tools',@tools);
1497:
1498: #publish button in construction space
1499: if ($env{'request.state'} eq 'construct'){
1500: &Apache::lonhtmlcommon::add_breadcrumb_tool(
1501: 'advtools', $inlineremote[63]);
1502: } else {
1503: &Apache::lonhtmlcommon::add_breadcrumb_tool(
1504: 'tools', $inlineremote[63]);
1505: }
1506: &advtools_crumbs(@inlineremote);
1507: }
1508: } else {
1509: if ($showprogress) {
1510: &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$showprogress);
1511: }
1512: if ($linkprotout) {
1513: &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$linkprotout);
1514: }
1515: }
1516: my ($topic_help,$topic_help_text);
1517: if ($is_const_dir == 2) {
1518: if ((($ENV{'SERVER_PORT'} == 443) ||
1519: ($Apache::lonnet::protocol{$Apache::lonnet::perlvar{'lonHostID'}} eq 'https')) &&
1520: (&Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},'webdav'))) {
1521: $topic_help = 'Authoring_WebDAV,Authoring_WebDAV_Mac_10v6,Authoring_WebDAV_Mac_10v10,'.
1522: 'Authoring_WebDAV_Windows_v7,Authoring_WebDAV_Linux_Centos';
1523: $topic_help_text = 'About WebDAV access';
1524: }
1525: }
1526: if (ref($showncrumbsref)) {
1527: $$showncrumbsref = 1;
1528: }
1529: return &Apache::lonhtmlcommon::scripttag('', 'start')
1530: . &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0,'','','','',$topic_help,$topic_help_text)
1531: . &Apache::lonhtmlcommon::scripttag('', 'end');
1532: }
1533:
1534: sub get_editbutton {
1535: my ($cfile,$home,$switchserver,$forceedit,$forceview,$forcereg,$hostname) = @_;
1536: my $jscall;
1537: if (($forceview) && ($env{'form.todocs'})) {
1538: my ($folderpath,$command,$navmap);
1539: if ($env{'request.symb'}) {
1540: $folderpath = &Apache::loncommon::symb_to_docspath($env{'request.symb'},\$navmap);
1541: } elsif ($env{'form.folderpath'} =~ /^supplemental/) {
1542: $folderpath = $env{'form.folderpath'};
1543: $command = '&forcesupplement=1';
1544: }
1545: $folderpath = &escape(&HTML::Entities::encode(&escape($folderpath),'<>&"'));
1546: $jscall = "go('/adm/coursedocs?folderpath=$folderpath$command')";
1547: } else {
1548: my $suppanchor;
1549: if ($env{'form.folderpath'}) {
1550: $suppanchor = $env{'form.anchor'};
1551: }
1552: my $shownsymb;
1553: if ($env{'request.symb'}) {
1554: $shownsymb = &Apache::lonenc::check_encrypt($env{'request.symb'});
1555: }
1556: $jscall = &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,$switchserver,
1557: $forceedit,$forcereg,$env{'request.symb'},$shownsymb,
1558: &escape($env{'form.folderpath'}),
1559: &escape($env{'form.title'}),$hostname,
1560: $env{'form.idx'},&escape($env{'form.suppurl'}),
1561: $env{'form.todocs'},$suppanchor);
1562: }
1563: if ($jscall) {
1564: my $icon = 'pcstr.png';
1565: my $label = 'Edit';
1566: if ($forceview) {
1567: $icon = 'tolastloc.png';
1568: $label = 'Exit Editing';
1569: }
1570: &switch('','',6,1,$icon,$label,'resource[_2]',
1571: $jscall,"Edit this resource");
1572: return 1;
1573: }
1574: return;
1575: }
1576:
1577: sub prepare_functions {
1578: my ($resurl,$forcereg,$group,$bread_crumbs,$advtools,$docscrumbs,$hostname) = @_;
1579: unless ($env{'request.registered'}) {
1580: undef(@inlineremote);
1581: }
1582: my ($cdom,$cnum,%perms,$cfile,$switchserver,$home,$forceedit,
1583: $forceview);
1584:
1585: if ($env{'request.course.id'}) {
1586: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1587: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1588: $perms{'mdc'} = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
1589: }
1590:
1591: my $editbutton = '';
1592: my $viewsrcbutton = '';
1593: my $clientip = &Apache::lonnet::get_requestor_ip();
1594: #
1595: # Determine whether or not to display 'Edit' or 'View Source' icon/button
1596: #
1597: if ($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) {
1598: my $blocked = &Apache::loncommon::blocking_status('about',$clientip,$2,$1);
1599: my $file=&Apache::lonnet::declutter($env{'request.filename'});
1600: ($cfile,$home,$switchserver,$forceedit,$forceview) =
1601: &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
1602: &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
1603: if (($cfile) && ($home ne '') && ($home ne 'no_host') && (!$blocked)) {
1604: $editbutton = &get_editbutton($cfile,$home,$switchserver,
1605: $forceedit,$forceview,$forcereg);
1606: }
1607: } elsif (!$env{'request.course.id'}) {
1608: if (($env{'user.author'}) && ($resurl eq '/adm/viewcoauthors')) {
1609: if ($env{'request.role'} =~/^(ca|au)/) {
1610: my ($audom,$auname);
1611: if ($env{'request.role'} eq "au./$env{'user.domain'}/") {
1612: ($audom,$auname) = ($env{'user.domain'},$env{'user.name'});
1613: } elsif ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)}) {
1614: ($audom,$auname) = ($1,$2);
1615: }
1616: if (($audom ne '') && ($auname ne '')) {
1617: my $file=&Apache::lonnet::declutter($env{'request.filename'});
1618: ($cfile,$home,$switchserver,$forceedit,$forceview) =
1619: &Apache::lonnet::can_edit_resource($file,$auname,$audom,
1620: $resurl);
1621: if ($cfile) {
1622: $editbutton = &get_editbutton($resurl,'','',$forceedit,
1623: $forceview);
1624: }
1625: }
1626: }
1627: } elsif (($env{'user.author'}) && ($env{'request.filename'}) &&
1628: ($env{'request.role'} !~/^(aa|ca|au)/)) {
1629: #
1630: # Currently do not have the role of author or co-author.
1631: # Do we have authoring privileges for the resource?
1632: #
1633: my $file=&Apache::lonnet::declutter($env{'request.filename'});
1634: ($cfile,$home,$switchserver,$forceedit,$forceview) =
1635: &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
1636: &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
1637: if (($cfile) && ($home ne '') && ($home ne 'no_host')) {
1638: $editbutton = &get_editbutton($cfile,$home,$switchserver,
1639: $forceedit,$forceview,$forcereg);
1640: }
1641: }
1642: } elsif ($env{'request.course.id'}) {
1643: #
1644: # This applies in course context
1645: #
1646: if (($perms{'mdc'}) &&
1647: (($resurl =~ m{^/?public/$cdom/$cnum/syllabus}) ||
1648: ($resurl =~ m{^/?uploaded/$cdom/$cnum/portfolio/syllabus/}) ||
1649: (($resurl =~ m{^/?uploaded/$cdom/$cnum/default_\d+\.sequence$}) && ($env{'form.navmap'})))) {
1650: if ($resurl =~ m{^/}) {
1651: $cfile = $resurl;
1652: } else {
1653: $cfile = "/$resurl";
1654: }
1655: $home = &Apache::lonnet::homeserver($cnum,$cdom);
1656: if ($env{'form.forceedit'}) {
1657: $forceview = 1;
1658: } else {
1659: $forceedit = 1;
1660: }
1661: if ($cfile =~ m{^/uploaded/$cdom/$cnum/default_\d+\.sequence$}) {
1662: my $text = 'Edit Folder';
1663: &switch('','',7,4,'docs-22x22.png','Edit Folder','parms[_2]',
1664: "gocmd('/adm/coursedocs','direct')",
1665: 'Folder/Page Content');
1666: $editbutton = 1;
1667: } else {
1668: $editbutton = &get_editbutton($cfile,$home,$switchserver,
1669: $forceedit,$forceview,$forcereg,
1670: $hostname);
1671: }
1672: } elsif (($resurl eq '/adm/extresedit') &&
1673: (($env{'form.symb'}) || ($env{'form.folderpath'}))) {
1674: ($cfile,$home,$switchserver,$forceedit,$forceview) =
1675: &Apache::lonnet::can_edit_resource($resurl,$cnum,$cdom,$resurl,
1676: $env{'form.symb'});
1677: if ($cfile ne '') {
1678: $editbutton = &get_editbutton($cfile,$home,$switchserver,
1679: $forceedit,$forceview,$forcereg);
1680: }
1681: } elsif (($resurl =~ m{^/?adm/viewclasslist$}) &&
1682: (&Apache::lonnet::allowed('opa',$env{'request.course.id'}))) {
1683: ($cfile,$home,$switchserver,$forceedit,$forceview) =
1684: &Apache::lonnet::can_edit_resource($resurl,$cnum,$cdom,$resurl,
1685: $env{'form.symb'});
1686: $editbutton = &get_editbutton($cfile,$home,$switchserver,
1687: $forceedit,$forceview,$forcereg);
1688: } elsif (($resurl !~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) &&
1689: ($resurl ne '/cgi-bin/printout.pl')) {
1690: if ($env{'request.filename'}) {
1691: my $file=&Apache::lonnet::declutter($env{'request.filename'});
1692: ($cfile,$home,$switchserver,$forceedit,$forceview) =
1693: &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
1694: &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
1695: if ($cfile ne '') {
1696: $editbutton = &get_editbutton($cfile,$home,$switchserver,
1697: $forceedit,$forceview,$forcereg,
1698: $hostname);
1699: }
1700: if ((($cfile eq '') || (!$editbutton)) &&
1701: ($resurl =~ /$LONCAPA::assess_re/)) {
1702: my $showurl = &Apache::lonnet::clutter($resurl);
1703: my $crs_sec = $env{'request.course.id'} . (($env{'request.course.sec'} ne '')
1704: ? "/$env{'request.course.sec'}"
1705: : '');
1706: if ((&Apache::lonnet::allowed('cre','/')) &&
1707: (&Apache::lonnet::metadata($resurl,'sourceavail') eq 'open')) {
1708: $viewsrcbutton = 1;
1709: } elsif (&Apache::lonnet::allowed('vxc',$crs_sec)) {
1710: if ($showurl =~ m{^\Q/res/$cdom/\E($match_username)/}) {
1711: my $auname = $1;
1712: if (($env{'request.course.adhocsrcaccess'} ne '') &&
1713: (grep(/^\Q$auname\E$/,split(/,/,$env{'request.course.adhocsrcaccess'})))) {
1714: $viewsrcbutton = 1;
1715: } elsif ((&Apache::lonnet::metadata($resurl,'sourceavail') eq 'open') &&
1716: (&Apache::lonnet::allowed('bre',$crs_sec))) {
1717: $viewsrcbutton = 1;
1718: }
1719: }
1720: }
1721: if ($viewsrcbutton) {
1722: &switch('','',6,1,'pcstr.png','View Source','resource[_2]','open_source()',
1723: 'View source code');
1724: }
1725: }
1726: }
1727: }
1728: }
1729: # End determination of 'Edit' icon/button display
1730:
1731: if ($env{'request.course.id'}) {
1732: # This applies to about me page for users in a course
1733: if ($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) {
1734: my ($sdom,$sname) = ($1,$2);
1735: unless (&Apache::lonnet::is_course($sdom,$sname)) {
1736: my $blocked = &Apache::loncommon::blocking_status('about',$clientip,$sname,$sdom);
1737: unless ($blocked) {
1738: &switch('','',6,4,'mail-message-new-22x22.png','Message to user',
1739: '',
1740: "go('/adm/email?compose=individual&recname=$sname&recdom=$sdom')",
1741: 'Send message to specific user');
1742: }
1743: }
1744: my $hideprivileged = 1;
1745: if (&Apache::lonnet::in_course($sdom,$sname,$cdom,$cnum,undef,
1746: $hideprivileged)) {
1747: foreach my $priv ('vsa','vgr','srm') {
1748: $perms{$priv} = &Apache::lonnet::allowed($priv,$env{'request.course.id'});
1749: if (!$perms{$priv} && $env{'request.course.sec'} ne '') {
1750: $perms{$priv} =
1751: &Apache::lonnet::allowed($priv,"$env{'request.course.id'}/$env{'request.course.sec'}");
1752: }
1753: }
1754: if ($perms{'vsa'}) {
1755: &switch('','',6,5,'trck-22x22.png','Activity',
1756: '',
1757: "go('/adm/trackstudent?selected_student=$sname:$sdom')",
1758: 'View recent activity by this person');
1759: }
1760: if ($perms{'vgr'}) {
1761: &switch('','',6,6,'rsrv-22x22.png','Reservations',
1762: '',
1763: "go('/adm/slotrequest?command=showresv&origin=aboutme&uname=$sname&udom=$sdom')",
1764: 'Slot reservation history');
1765: }
1766: if ($perms{'srm'}) {
1767: &switch('','',6,7,'contact-new-22x22.png','Records',
1768: '',
1769: "go('/adm/email?recordftf=retrieve&recname=$sname&recdom=$sdom')",
1770: 'Add records');
1771: }
1772: }
1773: }
1774: if (($env{'form.folderpath'} =~ /^supplemental/) &&
1775: (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) &&
1776: (($resurl =~ m{^/adm/wrapper/ext/}) ||
1777: ($resurl =~ m{^/adm/$cdom/$cnum/\d+/ext\.tool$}) ||
1778: ($resurl =~ m{^/uploaded/$cdom/$cnum/supplemental/}) ||
1779: ($resurl eq '/adm/supplemental') ||
1780: ($resurl =~ m{^/public/$cdom/$cnum/syllabus$}) ||
1781: ($resurl =~ m{^/adm/$match_domain/$match_username/aboutme$}))) {
1782: my @folders=split('&',$env{'form.folderpath'});
1783: if ((@folders > 2) || ($resurl ne '/adm/supplemental')) {
1784: my $suppanchor;
1785: if ($resurl =~ m{^/adm/wrapper/ext/}) {
1786: $suppanchor = $env{'form.anchor'};
1787: }
1788: my $esc_path=&escape(&HTML::Entities::encode(&escape($env{'form.folderpath'}),'<>&"'));
1789: my $link = '/adm/coursedocs?command=direct&forcesupplement=1&supppath='.
1790: "$esc_path&anchor=$suppanchor";
1791: if ($env{'request.use_absolute'} ne '') {
1792: $link = $env{'request.use_absolute'}.$link;
1793: }
1794: &switch('','',7,4,'docs-22x22.png','Edit Folder','parms[_2]',
1795: "location.href='$link'",'Folder/Page Content');
1796: }
1797: }
1798: }
1799:
1800: # End checking for items for about me page for users in a course
1801: if ($docscrumbs) {
1802: &Apache::lonhtmlcommon::clear_breadcrumb_tools();
1803: &advtools_crumbs(@inlineremote);
1804: return $editbutton;
1805: } elsif ($env{'request.registered'}) {
1806: return $editbutton || $viewsrcbutton;
1807: } else {
1808: if (ref($bread_crumbs) eq 'ARRAY') {
1809: if (@inlineremote > 0) {
1810: if (ref($advtools) eq 'ARRAY') {
1811: @{$advtools} = @inlineremote;
1812: }
1813: }
1814: return;
1815: } elsif (@inlineremote > 0) {
1816: &Apache::lonhtmlcommon::clear_breadcrumb_tools();
1817: &advtools_crumbs(@inlineremote);
1818: return &Apache::lonhtmlcommon::scripttag('', 'start')
1819: . &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0)
1820: . &Apache::lonhtmlcommon::scripttag('', 'end');
1821: }
1822: }
1823: }
1824:
1825: sub advtools_crumbs {
1826: my @funcs = @_;
1827: if ($env{'request.noversionuri'} =~ m{^/adm/$match_domain/$match_username/aboutme$}) {
1828: &Apache::lonhtmlcommon::add_breadcrumb_tool(
1829: 'advtools', @funcs[61,64,65,66,67,74]);
1830: } elsif ($env{'request.noversionuri'} !~ m{^/adm/(navmaps|viewclasslist)(\?|$)}) {
1831: if ($env{'request.state'} eq 'construct') {
1832: &Apache::lonhtmlcommon::add_breadcrumb_tool(
1833: 'advtools', @funcs[61,73,74,71,72]);
1834: } else {
1835: &Apache::lonhtmlcommon::add_breadcrumb_tool(
1836: 'advtools', @funcs[61,71,72,73,74,75,92]);
1837: }
1838: } elsif ($env{'request.noversionuri'} eq '/adm/viewclasslist') {
1839: &Apache::lonhtmlcommon::add_breadcrumb_tool(
1840: 'advtools', $funcs[61]);
1841: }
1842: return;
1843: }
1844:
1845: # ================================================================== Raw Config
1846:
1847: sub clear {
1848: my ($row,$col)=@_;
1849: $inlineremote[10*$row+$col]='';
1850: return '';
1851: }
1852:
1853: # ============================================ Switch a button or create a link
1854: # Switch acts on the javascript that is executed when a button is clicked.
1855: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
1856:
1857: sub switch {
1858: my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat,$nobreak,$form)=@_;
1859: $act=~s/\$uname/$uname/g;
1860: $act=~s/\$udom/$udom/g;
1861: $top=&mt($top);
1862: $bot=&mt($bot);
1863: $desc=&mt($desc);
1864: my $idx=10*$row+$col;
1865: $category_members{$cat}.=':'.$idx;
1866:
1867: # Inline Menu
1868: if ($nobreak==2) { return ''; }
1869: my $text=$top.' '.$bot;
1870: $text=~s/\s*\-\s*//gs;
1871:
1872: my $pic=
1873: '<img alt="'.$text.'" src="'.
1874: &Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$img).
1875: '" align="'.($nobreak==3?'right':'left').'" class="LC_icon" />';
1876: if ($env{'browser.interface'} eq 'faketextual') {
1877: # Main Menu
1878: if ($nobreak==3) {
1879: $inlineremote[$idx]="\n".
1880: '<td class="LC_menubuttons_text" align="right">'.$text.
1881: '</td><td align="left">'.
1882: '<a href="javascript:'.$act.';">'.$pic.'</a></td></tr>';
1883: } elsif ($nobreak) {
1884: $inlineremote[$idx]="\n<tr>".
1885: '<td align="left">'.
1886: '<a href="javascript:'.$act.';">'.$pic.'</a></td>
1887: <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>';
1888: } else {
1889: $inlineremote[$idx]="\n<tr>".
1890: '<td align="left">'.
1891: '<a href="javascript:'.$act.';">'.$pic.
1892: '</a></td><td class="LC_menubuttons_text" colspan="3">'.
1893: '<a class="LC_menubuttons_link" href="javascript:'.$act.';"><span class="LC_menubuttons_inline_text">'.$desc.'</span></a></td></tr>';
1894: }
1895: } else {
1896: # Inline Menu
1897: my @tools = (93,91,81,82,83);
1898: unless ($env{'request.state'} eq 'construct') {
1899: push(@tools,63);
1900: }
1901: if ((($env{'environment.icons'} eq 'iconsonly') ||
1902: ($env{'environment.icons'} eq '') && ($env{'request.lti.login'})) &&
1903: (grep(/^$idx$/,@tools))) {
1904: $inlineremote[$idx] =
1905: '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.'</a>';
1906: } else {
1907: $inlineremote[$idx] =
1908: '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.
1909: '<span class="LC_menubuttons_inline_text">'.$top.' </span></a>'.$form;
1910: }
1911: }
1912: return '';
1913: }
1914:
1915: sub secondlevel {
1916: my $output='';
1917: my
1918: ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat)=@_;
1919: if ($prt eq 'any') {
1920: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1921: } elsif ($prt=~/^r(\w+)/) {
1922: if ($rol eq $1) {
1923: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1924: }
1925: }
1926: return $output;
1927: }
1928:
1929: sub inlinemenu {
1930: undef(@inlineremote);
1931: undef(%category_members);
1932: # calling rawconfig with "1" will evaluate mydesk.tab, even if there is no active remote control
1933: &rawconfig(1);
1934: my $output='<table><tr>';
1935: for (my $col=1; $col<=2; $col++) {
1936: $output.='<td class="LC_mainmenu_col_fieldset">';
1937: for (my $row=1; $row<=8; $row++) {
1938: foreach my $cat (keys(%category_members)) {
1939: if ($category_positions{$cat} ne "$col,$row") { next; }
1940: #$output.='<table><tr><td colspan="4" class="LC_menubuttons_category">'.&mt($category_names{$cat}).'</td></tr>';
1941: $output.='<div class="LC_Box LC_400Box">';
1942: $output.='<h3 class="LC_hcell">'.&mt($category_names{$cat}).'</h3>';
1943: $output.='<table>';
1944: my %active=();
1945: foreach my $menu_item (split(/\:/,$category_members{$cat})) {
1946: if ($inlineremote[$menu_item]) {
1947: $active{$menu_item}=1;
1948: }
1949: }
1950: foreach my $item (sort(keys(%active))) {
1951: $output.=$inlineremote[$item];
1952: }
1953: $output.='</table>';
1954: $output.='</div>';
1955: }
1956: }
1957: $output.="</td>";
1958: }
1959: $output.="</tr></table>";
1960: return $output;
1961: }
1962:
1963: sub rawconfig {
1964: #
1965: # This evaluates mydesk.tab
1966: # Need to add more positions and more privileges to deal with all
1967: # menu items.
1968: #
1969: my $textualoverride=shift;
1970: my $output='';
1971: return '' unless $textualoverride;
1972: my $uname=$env{'user.name'};
1973: my $udom=$env{'user.domain'};
1974: my $adv=$env{'user.adv'};
1975: my $show_course=&Apache::loncommon::show_course();
1976: my $author=$env{'user.author'};
1977: my $crs='';
1978: my $crstype='';
1979: if ($env{'request.course.id'}) {
1980: $crs='/'.$env{'request.course.id'};
1981: if ($env{'request.course.sec'}) {
1982: $crs.='_'.$env{'request.course.sec'};
1983: }
1984: $crs=~s/\_/\//g;
1985: $crstype = &Apache::loncommon::course_type();
1986: }
1987: my $pub=($env{'request.state'} eq 'published');
1988: my $con=($env{'request.state'} eq 'construct');
1989: my $rol=$env{'request.role'};
1990: my $requested_domain;
1991: if ($rol) {
1992: $requested_domain = $env{'request.role.domain'};
1993: }
1994: foreach my $line (@desklines) {
1995: my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc,$cat)=split(/\:/,$line);
1996: $prt=~s/\$uname/$uname/g;
1997: $prt=~s/\$udom/$udom/g;
1998: if ($prt =~ /\$crs/) {
1999: next unless ($env{'request.course.id'});
2000: next if ($crstype eq 'Community');
2001: $prt=~s/\$crs/$crs/g;
2002: } elsif ($prt =~ /\$cmty/) {
2003: next unless ($env{'request.course.id'});
2004: next if ($crstype ne 'Community');
2005: $prt=~s/\$cmty/$crs/g;
2006: }
2007: if ($prt =~ m/\$requested_domain/) {
2008: if ((!$requested_domain) && ($pro eq 'pbre') && ($env{'user.adv'})) {
2009: $prt=~s/\$requested_domain/$env{'user.domain'}/g;
2010: } else {
2011: $prt=~s/\$requested_domain/$requested_domain/g;
2012: }
2013: }
2014: if ($category_names{$cat}!~/\w/) { $cat='oth'; }
2015: if ($pro eq 'clear') {
2016: $output.=&clear($row,$col);
2017: } elsif ($pro eq 'any') {
2018: $output.=&secondlevel(
2019: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
2020: } elsif ($pro eq 'smp') {
2021: unless ($adv) {
2022: $output.=&secondlevel(
2023: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
2024: }
2025: } elsif ($pro eq 'adv') {
2026: if ($adv) {
2027: $output.=&secondlevel(
2028: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
2029: }
2030: } elsif ($pro eq 'shc') {
2031: if ($show_course) {
2032: $output.=&secondlevel(
2033: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
2034: }
2035: } elsif ($pro eq 'nsc') {
2036: if (!$show_course) {
2037: $output.=&secondlevel(
2038: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
2039: }
2040: } elsif (($pro=~/^p(\w+)/) && ($prt)) {
2041: my $priv = $1;
2042: if ($priv =~ /^mdc(Course|Community)/) {
2043: if ($crstype eq $1) {
2044: $priv = 'mdc';
2045: } else {
2046: next;
2047: }
2048: } elsif ($priv eq 'cca') {
2049: next if ($rol eq 'cm');
2050: }
2051: if ((($priv eq 'bre') && (&Apache::lonnet::allowed($priv,$prt) eq 'F')) ||
2052: (($priv ne 'bre') && (&Apache::lonnet::allowed($priv,$prt)))) {
2053: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
2054: }
2055: } elsif ($pro eq 'course') {
2056: if (($env{'request.course.fn'}) && ($crstype ne 'Community')) {
2057: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
2058: }
2059: } elsif ($pro eq 'community') {
2060: if (($env{'request.course.fn'}) && ($crstype eq 'Community')) {
2061: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
2062: }
2063: } elsif ($pro =~ /^courseenv_(.*)$/) {
2064: my $key = $1;
2065: if ($crstype ne 'Community') {
2066: my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
2067: if ($key eq 'canuse_pdfforms') {
2068: if ($env{'request.course.id'} && $coursepref eq '') {
2069: my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
2070: $coursepref = $domdefs{'canuse_pdfforms'};
2071: }
2072: }
2073: if ($coursepref) {
2074: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
2075: }
2076: }
2077: } elsif ($pro =~ /^communityenv_(.*)$/) {
2078: my $key = $1;
2079: if ($crstype eq 'Community') {
2080: my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
2081: if ($key eq 'canuse_pdfforms') {
2082: if ($env{'request.course.id'} && $coursepref eq '') {
2083: my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
2084: $coursepref = $domdefs{'canuse_pdfforms'};
2085: }
2086: }
2087: if ($coursepref) {
2088: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
2089: }
2090: }
2091: } elsif ($pro =~ /^course_(.*)$/) {
2092: # Check for permissions inside of a course
2093: if (($env{'request.course.id'}) && ($crstype ne 'Community') &&
2094: (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
2095: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
2096: )) {
2097: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
2098: }
2099: } elsif ($pro =~ /^community_(.*)$/) {
2100: # Check for permissions inside of a community
2101: if (($env{'request.course.id'}) && ($crstype eq 'Community') &&
2102: (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
2103: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
2104: )) {
2105: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
2106: }
2107: } elsif ($pro eq 'author') {
2108: if ($author) {
2109: if ((($prt eq 'rca') && ($env{'request.role'}=~/^ca/)) ||
2110: (($prt eq 'raa') && ($env{'request.role'}=~/^aa/)) ||
2111: (($prt eq 'rau') && ($env{'request.role'}=~/^au/))) {
2112: # Check that we are on the correct machine
2113: my $cadom=$requested_domain;
2114: my $caname=$env{'user.name'};
2115: if (($prt eq 'rca') || ($prt eq 'raa')) {
2116: ($cadom,$caname)=
2117: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
2118: }
2119: $act =~ s/\$caname/$caname/g;
2120: $act =~ s/\$cadom/$cadom/g;
2121: my $home = &Apache::lonnet::homeserver($caname,$cadom);
2122: my $allowed=0;
2123: my @ids=&Apache::lonnet::current_machine_ids();
2124: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
2125: if ($allowed) {
2126: $output.=&switch($caname,$cadom,
2127: $row,$col,$img,$top,$bot,$act,$desc,$cat);
2128: }
2129: }
2130: }
2131: } elsif ($pro eq 'coauthor') {
2132: if ($env{'request.role'}=~ m{^(ca|aa)\./($match_domain)/($match_username)$}) {
2133: my ($role,$audom,$auname) = ($1,$2,$3);
2134: if ((($prt eq 'raa') && ($role eq 'aa')) ||
2135: (($prt eq 'rca') && ($role eq 'ca') &&
2136: (!$env{"environment.internal.manager./$audom/$auname"}))) {
2137: $output.=&switch($auname,$audom,
2138: $row,$col,$img,$top,$bot,$act,$desc,$cat);
2139: }
2140: }
2141: } elsif ($pro eq 'coauthorenv_manager') {
2142: if ($env{'request.role'}=~ m{^ca\./($match_domain)/($match_username)$}) {
2143: my ($audom,$auname) = ($1,$2);
2144: if ($env{"environment.internal.manager./$audom/$auname"}) {
2145: $output.=&switch($auname,$audom,
2146: $row,$col,$img,$top,$bot,$act,$desc,$cat);
2147: }
2148: }
2149: } elsif ($pro eq 'tools') {
2150: my @tools = ('aboutme','blog','portfolio');
2151: if (grep(/^\Q$prt\E$/,@tools)) {
2152: if (!&Apache::lonnet::usertools_access($env{'user.name'},
2153: $env{'user.domain'},
2154: $prt,undef,'tools')) {
2155: $output.=&clear($row,$col);
2156: next;
2157: }
2158: } elsif (($prt eq 'reqcrsnsc') || ($prt eq 'reqcrsshc')) {
2159: if (($prt eq 'reqcrsnsc') && ($show_course)) {
2160: next;
2161: }
2162: if (($prt eq 'reqcrsshc') && (!$show_course)) {
2163: next;
2164: }
2165: my $showreqcrs = &check_for_rcrs();
2166: if (!$showreqcrs) {
2167: $output.=&clear($row,$col);
2168: next;
2169: }
2170: }
2171: $prt='any';
2172: $output.=&secondlevel(
2173: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
2174: }
2175: }
2176: return $output;
2177: }
2178:
2179: sub check_for_rcrs {
2180: my $showreqcrs = 0;
2181: my @reqtypes = ('official','unofficial','community','textbook','placement');
2182: foreach my $type (@reqtypes) {
2183: if (&Apache::lonnet::usertools_access($env{'user.name'},
2184: $env{'user.domain'},
2185: $type,undef,'requestcourses')) {
2186: $showreqcrs = 1;
2187: last;
2188: }
2189: }
2190: if (!$showreqcrs) {
2191: foreach my $type (@reqtypes) {
2192: if ($env{'environment.reqcrsotherdom.'.$type} ne '') {
2193: my @domains = split(',',$env{'environment.reqcrsotherdom.'.$type});
2194: foreach my $entry (@domains) {
2195: my ($extdom,$extopt) = split(':',$entry);
2196: if (&Apache::lonnet::will_trust('reqcrs',$env{'user.domain'},$extdom)) {
2197: $showreqcrs = 1;
2198: last;
2199: }
2200: }
2201: if ($showreqcrs) {
2202: last;
2203: }
2204: }
2205: }
2206: }
2207: return $showreqcrs;
2208: }
2209:
2210: sub dc_popup_js {
2211: my %lt = &Apache::lonlocal::texthash(
2212: more => '(More ...)',
2213: less => '(Less ...)',
2214: );
2215: return <<"END";
2216:
2217: function showCourseID() {
2218: document.getElementById('dccid').style.display='block';
2219: document.getElementById('dccid').style.textAlign='left';
2220: document.getElementById('dccid').style.textFace='normal';
2221: document.getElementById('dccidtext').innerHTML ='<a href="javascript:hideCourseID();" class="LC_menubuttons_link">$lt{'less'}</a>';
2222: return;
2223: }
2224:
2225: function hideCourseID() {
2226: document.getElementById('dccid').style.display='none';
2227: document.getElementById('dccidtext').innerHTML ='<a href="javascript:showCourseID()" class="LC_menubuttons_link">$lt{'more'}</a>';
2228: return;
2229: }
2230:
2231: END
2232:
2233: }
2234:
2235: sub countdown_toggle_js {
2236: return <<"END";
2237:
2238: function toggleCountdown() {
2239: var countdownid = document.getElementById('duedatecountdown');
2240: var currstyle = countdownid.style.display;
2241: if (currstyle == 'inline') {
2242: countdownid.style.display = 'none';
2243: document.getElementById('ddcountcollapse').innerHTML='';
2244: document.getElementById('ddcountexpand').innerHTML='◄ ';
2245: } else {
2246: countdownid.style.display = 'inline';
2247: document.getElementById('ddcountcollapse').innerHTML='► ';
2248: document.getElementById('ddcountexpand').innerHTML='';
2249: }
2250: return;
2251: }
2252:
2253: END
2254: }
2255:
2256: # This creates a "done button" for timed events. The confirmation box is a jQuery
2257: # dialog widget. If the interval parameter requires a proctor key for the timed
2258: # event to be marked done, there will also be a textbox where that can be entered.
2259: # Clicking OK will set the value of LC_interval_done to 'true', and, if needed will
2260: # set the value of LC_interval_done_proctorpass to the text entered in that box,
2261: # and submit the corresponding form.
2262: #
2263: # The &zero_time() routine in lonhomework.pm is called when a page is rendered if
2264: # LC_interval_done is true.
2265: #
2266: sub done_button_js {
2267: my ($type,$width,$height,$proctor,$donebuttontext) = @_;
2268: return unless (($type eq 'map') || ($type eq 'resource'));
2269: my %lt = &Apache::lonlocal::texthash(
2270: title => 'WARNING!',
2271: preamble => 'You are trying to end this timed event early.',
2272: map => 'Confirming that you are done will cause the time to expire and prevent you from changing any answers in the current folder.',
2273: resource => 'Confirming that you are done will cause the time to expire for this question, and prevent you from changing your answer(s).',
2274: okdone => 'Click "OK" if you are completely finished.',
2275: cancel => 'Click "Cancel" to continue working.',
2276: proctor => 'Ask a proctor to enter the key, then click "OK" if you are completely finished.',
2277: ok => 'OK',
2278: exit => 'Cancel',
2279: key => 'Key:',
2280: nokey => 'A proctor key is required',
2281: );
2282: my $shownsymb = &HTML::Entities::encode(&Apache::lonenc::check_encrypt($env{'request.symb'}));
2283: my $navmap = Apache::lonnavmaps::navmap->new();
2284: my ($missing,$tried) = (0,0);
2285: if (ref($navmap)) {
2286: my @resources=();
2287: if ($type eq 'map') {
2288: my ($mapurl,$rid,$resurl)=&Apache::lonnet::decode_symb($env{'request.symb'});
2289: if ($env{'request.symb'} =~ /\.page$/) {
2290: @resources=$navmap->retrieveResources($resurl,sub { $_[0]->is_problem() });
2291: } else {
2292: @resources=$navmap->retrieveResources($mapurl,sub { $_[0]->is_problem() });
2293: }
2294: } else {
2295: my $res = $navmap->getBySymb($env{'request.symb'});
2296: if (ref($res)) {
2297: if ($res->is_problem()) {
2298: push(@resources,$res);
2299: }
2300: }
2301: }
2302: foreach my $res (@resources) {
2303: if (ref($res->parts()) eq 'ARRAY') {
2304: foreach my $part (@{$res->parts()}) {
2305: if (!$res->tries($part)) {
2306: $missing++;
2307: } else {
2308: $tried++;
2309: }
2310: }
2311: }
2312: }
2313: }
2314: if ($missing) {
2315: $lt{'miss'} .= '<p class="LC_error">';
2316: if ($type eq 'map') {
2317: $lt{'miss'} .= &mt('Submissions are missing for [quant,_1,question part,question parts] in this folder.',$missing);
2318: } else {
2319: $lt{'miss'} .= &mt('Submissions are missing for [quant,_1,part] in this question.',$missing);
2320: }
2321: if ($missing > 1) {
2322: $lt{'miss'} .= ' '.&mt('If you confirm you are done you will be unable to submit answers for them.').'</span>';
2323: } else {
2324: $lt{'miss'} .= ' '.&mt('If you confirm you are done you will be unable to submit an answer for it.').'</p>';
2325: }
2326: }
2327: $donebuttontext = &HTML::Entities::encode($donebuttontext,'<>&"');
2328: if ($proctor) {
2329: if ($height !~ /^\d+$/) {
2330: $height = 400;
2331: if ($missing) {
2332: $height += 60;
2333: }
2334: }
2335: if ($width !~ /^\d+$/) {
2336: $width = 400;
2337: if ($missing) {
2338: $width += 60;
2339: }
2340: }
2341: return <<END;
2342: <form method="post" name="LCdoneButton" action="">
2343: <input type="hidden" name="LC_interval_done" value="" />
2344: <input type="hidden" name="LC_interval_done_proctorpass" value="" />
2345: <input type="hidden" name="symb" value="$shownsymb" />
2346: <button id="LC_done-confirm-opener" type="button">$donebuttontext</button>
2347: </form>
2348:
2349: <div id="LC_done-confirm" title="$lt{'title'}">
2350: <p>$lt{'preamble'} $lt{$type}</p>
2351: $lt{'miss'}
2352: <p>$lt{'proctor'}</p>
2353: <form name="LCdoneButtonProctor" action="">
2354: <label>$lt{'key'}<input type="password" name="LC_interval_done_proctorkey" value="" /></label>
2355: <input type="submit" tabindex="-1" style="position:absolute; top:-1000px" />
2356: </form>
2357: <p>$lt{'cancel'}</p>
2358: </div>
2359:
2360: <script type="text/javascript">
2361: // <![CDATA[
2362: \$( "#LC_done-confirm" ).dialog({ autoOpen: false });
2363: \$( "#LC_done-confirm-opener" ).on("click", function() {
2364: \$( "#LC_done-confirm" ).dialog("open");
2365: \$( "#LC_done-confirm" ).dialog({
2366: height: $height,
2367: width: $width,
2368: modal: true,
2369: resizable: false,
2370: buttons: [
2371: {
2372: text: "$lt{'ok'}",
2373: click: function() {
2374: var proctorkey = \$( '[name="LC_interval_done_proctorkey"]' )[0].value;
2375: if ((proctorkey == '') || (proctorkey == null)) {
2376: alert("$lt{'nokey'}");
2377: } else {
2378: \$( '[name="LC_interval_done"]' )[0].value = 'true';
2379: \$( '[name="LC_interval_done_proctorpass"]' )[0].value = proctorkey;
2380: \$( '[name="LCdoneButton"]' )[0].submit();
2381: }
2382: },
2383: },
2384: {
2385: text: "$lt{'exit'}",
2386: click: function() {
2387: \$("#LC_done-confirm").dialog( "close" );
2388: }
2389: }
2390: ],
2391: close: function() {
2392: \$( '[name="LC_interval_done_proctorkey"]' )[0].value = '';
2393: }
2394: });
2395: \$( "#LC_done-confirm" ).find( "form" ).on( "submit", function( event ) {
2396: event.preventDefault();
2397: \$( '[name="LC_interval_done"]' )[0].value = 'true';
2398: \$( '[name="LC_interval_done_proctorpass"]' )[0].value = \$( '[name="LC_interval_done_proctorkey"]' )[0].value;
2399: \$( '[name="LCdoneButton"]' )[0].submit();
2400: });
2401: });
2402:
2403: // ]]>
2404: </script>
2405:
2406: END
2407: } else {
2408: if ($height !~ /^\d+$/) {
2409: $height = 320;
2410: if ($missing) {
2411: $height += 60;
2412: }
2413: }
2414: if ($width !~ /^\d+$/) {
2415: $width = 320;
2416: if ($missing) {
2417: $width += 60;
2418: }
2419: }
2420: if ($missing) {
2421: $lt{'miss'} = '</p>'.$lt{'miss'}.'<p>';
2422: }
2423: return <<END;
2424:
2425: <form method="post" name="LCdoneButton" action="">
2426: <input type="hidden" name="LC_interval_done" value="" />
2427: <input type="hidden" name="symb" value="$shownsymb" />
2428: <button id="LC_done-confirm-opener" type="button">$donebuttontext</button>
2429: </form>
2430:
2431: <div id="LC_done-confirm" title="$lt{'title'}">
2432: <p>$lt{'preamble'} $lt{$type} $lt{'miss'} $lt{'okdone'} $lt{'cancel'}</p>
2433: </div>
2434:
2435: <script type="text/javascript">
2436: // <![CDATA[
2437: \$( "#LC_done-confirm" ).dialog({ autoOpen: false });
2438: \$( "#LC_done-confirm-opener" ).click(function() {
2439: \$( "#LC_done-confirm" ).dialog( "open" );
2440: \$( "#LC_done-confirm" ).dialog({
2441: resizable: false,
2442: height: $height,
2443: width: $width,
2444: modal: true,
2445: buttons: [
2446: {
2447: text: "$lt{'ok'}",
2448: click: function() {
2449: \$( this ).dialog( "close" );
2450: \$( '[name="LC_interval_done"]' )[0].value = 'true';
2451: \$( '[name="LCdoneButton"]' )[0].submit();
2452: },
2453: },
2454: {
2455: text: "$lt{'exit'}",
2456: click: function() {
2457: \$( this ).dialog( "close" );
2458: },
2459: },
2460: ],
2461: });
2462: });
2463: // ]]>
2464: </script>
2465:
2466: END
2467: }
2468: }
2469:
2470: sub view_as_js {
2471: my ($url,$symb) = @_;
2472: my %lt = &Apache::lonlocal::texthash(
2473: ente => 'Enter a username or a student/employee ID',
2474: info => 'Information you entered does not match a valid course user',
2475: );
2476: &js_escape(\%lt);
2477: return <<"END";
2478:
2479: function toggleViewAsUser(change) {
2480: if (document.getElementById('LC_selectuser')) {
2481: var seluserid = document.getElementById('LC_selectuser');
2482: var currstyle = seluserid.style.display;
2483: if (change == 'off') {
2484: document.userview.elements['LC_viewas'].value = '';
2485: document.userview.elements['vuname'].value = '';
2486: document.userview.elements['vid'].value = '';
2487: document.userview.submit();
2488: return;
2489: }
2490: if ((document.getElementById('usexpand')) && (document.getElementById('uscollapse'))) {
2491: if (currstyle == 'inline') {
2492: seluserid.style.display = 'none';
2493: document.getElementById('usexpand').innerHTML='► ';
2494: document.getElementById('uscollapse').innerHTML='';
2495: } else {
2496: seluserid.style.display = 'inline';
2497: document.getElementById('usexpand').innerHTML='';
2498: document.getElementById('uscollapse').innerHTML='◄ ';
2499: toggleIdentifier(document.userview);
2500: }
2501: }
2502: }
2503: return;
2504: }
2505:
2506: function validCourseUser(form,change) {
2507: var possuname = form.elements['vuname'].value;
2508: var possuid = form.elements['vid'].value;
2509: var domelem = form.elements['vudom'];
2510: var possudom = '';
2511: if ((domelem.tagName === 'INPUT') && ((domelem.type === 'text') || (domelem.type === 'hidden'))) {
2512: possudom = domelem.value;
2513: } else if (domelem.tagName === 'SELECT') {
2514: possudom = domelem.options[domelem.selectedIndex].value;
2515: }
2516: if ((possuname == '') && (possuid == '')) {
2517: if (change == 'off') {
2518: form.elements['LC_viewas'].value = '';
2519: form.submit();
2520: } else {
2521: alert("$lt{'ente'}");
2522: }
2523: return;
2524: }
2525: var http = new XMLHttpRequest();
2526: var url = "/adm/courseuser";
2527: var params = "uname="+possuname+"&uid="+possuid+"&udom="+possudom;
2528: http.open("POST", url, true);
2529: http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
2530: http.onreadystatechange = function() {
2531: if (http.readyState == 4 && http.status == 200) {
2532: var data = JSON.parse(http.responseText);
2533: if (Array.isArray(data.match)) {
2534: var len = data.match.length;
2535: if (len == 2) {
2536: if (data.match[0] != '' && data.match[1] != '') {
2537: form.elements['LC_viewas'].value = data.match[0]+':'+data.match[1];
2538: form.submit();
2539: }
2540: } else {
2541: alert("$lt{'info'}");
2542: }
2543: }
2544: }
2545: return;
2546: }
2547: http.send(params);
2548: return false;
2549: }
2550:
2551: function toggleIdentifier(form) {
2552: if ((document.getElementById('LC_vuname')) && (document.getElementById('LC_vid'))) {
2553: var radioelem = form.elements['vuidentifier'];
2554: if (radioelem.length > 0) {
2555: var i;
2556: for (i=0; i<radioelem.length; i++) {
2557: if (radioelem[i].checked == true) {
2558: if (radioelem[i].value == 'uname') {
2559: document.getElementById('LC_vuname').type = 'text';
2560: document.getElementById('LC_vid').type = 'hidden';
2561: document.getElementById('LC_vid').value = '';
2562: } else {
2563: document.getElementById('LC_vuname').type = 'hidden';
2564: document.getElementById('LC_vuname').value = '';
2565: document.getElementById('LC_vid').type = 'text';
2566: }
2567: break;
2568: }
2569: }
2570: }
2571: }
2572: return;
2573: }
2574:
2575: END
2576: }
2577:
2578: sub utilityfunctions {
2579: my ($httphost) = @_;
2580: my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
2581: my $currentsymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
2582: if ($currenturl =~ m{^/adm/wrapper/ext/}) {
2583: if ($env{'request.external.querystring'}) {
2584: $currenturl .= ($currenturl=~/\?/)?'&':'?'.$env{'request.external.querystring'};
2585: }
2586: my ($anchor) = ($env{'request.symb'} =~ /(\#[^\#]+)$/);
2587: if (($anchor) && ($currenturl !~ /\Q$anchor\E$/)) {
2588: $currenturl .= $1;
2589: }
2590: }
2591: $currenturl=&Apache::lonenc::check_encrypt(&unescape($currenturl));
2592:
2593: my $dc_popup_cid;
2594: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
2595: $env{'course.'.$env{'request.course.id'}.
2596: '.domain'}.'/'})) {
2597: $dc_popup_cid = &dc_popup_js();
2598: }
2599:
2600: my $start_page_annotate =
2601: &Apache::loncommon::start_page('Annotator',undef,
2602: {'only_body' => 1,
2603: 'js_ready' => 1,
2604: 'bgcolor' => '#BBBBBB',
2605: 'add_entries' => {
2606: 'onload' => 'javascript:document.goannotate.submit();'}});
2607:
2608: my $end_page_annotate =
2609: &Apache::loncommon::end_page({'js_ready' => 1});
2610:
2611: my $jumptores = &Apache::lonhtmlcommon::javascript_jumpto_resource();
2612:
2613: my $esc_url=&escape($currenturl);
2614: my $esc_symb=&escape($currentsymb);
2615: my $newname = &mt('New Name');
2616:
2617: my $countdown = &countdown_toggle_js();
2618:
2619: my $viewuser;
2620: if (($env{'request.course.id'}) &&
2621: ($env{'request.symb'} ne '') &&
2622: ($env{'request.filename'}=~/$LONCAPA::assess_re/)) {
2623: my $canview;
2624: foreach my $priv ('msg','vgr') {
2625: $canview = &Apache::lonnet::allowed($priv,$env{'request.course.id'});
2626: if (!$canview && $env{'request.course.sec'} ne '') {
2627: $canview =
2628: &Apache::lonnet::allowed($priv,"$env{'request.course.id'}/$env{'request.course.sec'}");
2629: }
2630: last if ($canview);
2631: }
2632: if ($canview) {
2633: $viewuser = &view_as_js($esc_url,$esc_symb);
2634: }
2635: }
2636:
2637: my ($ltitarget,$deeplinktarget);
2638: if ($env{'request.lti.login'}) {
2639: $ltitarget = $env{'request.lti.target'};
2640: }
2641: if ($env{'request.deeplink.login'}) {
2642: $deeplinktarget = $env{'request.deeplink.target'};
2643: }
2644:
2645: my $annotateurl = '/adm/annotation';
2646: if ($httphost) {
2647: $annotateurl = '/adm/annotations';
2648: }
2649: my $hostvar = '
2650: function setLCHost() {
2651: var lcHostname="";
2652: ';
2653: if ($httphost =~ m{^https?\://}) {
2654: $hostvar .= ' var lcServer="'.$httphost.'";'."\n".
2655: ' var hostReg = /^https?:\/\/([^\/]+)$/i;'."\n".
2656: ' var match = hostReg.exec(lcServer);'."\n".
2657: ' if (match.length) {'."\n".
2658: ' if (match[1] == location.hostname) {'."\n".
2659: ' lcHostname=lcServer;'."\n".
2660: ' }'."\n".
2661: ' }'."\n";
2662: }
2663:
2664: $hostvar .= ' return lcHostname;'."\n".
2665: '}'."\n";
2666:
2667: return (<<ENDUTILITY)
2668: $hostvar
2669: var currentURL=unescape("$esc_url");
2670: var reloadURL=unescape("$esc_url");
2671: var currentSymb=unescape("$esc_symb");
2672:
2673: $dc_popup_cid
2674:
2675: $jumptores
2676:
2677: function gopost(url,postdata) {
2678: if (url!='') {
2679: var lcHostname = setLCHost();
2680: this.document.server.action=lcHostname+url;
2681: this.document.server.postdata.value=postdata;
2682: this.document.server.command.value='';
2683: this.document.server.url.value='';
2684: this.document.server.symb.value='';
2685: this.document.server.submit();
2686: }
2687: }
2688:
2689: function gocmd(url,cmd) {
2690: if (url!='') {
2691: var lcHostname = setLCHost();
2692: this.document.server.action=lcHostname+url;
2693: this.document.server.postdata.value='';
2694: this.document.server.command.value=cmd;
2695: this.document.server.url.value=currentURL;
2696: this.document.server.symb.value=currentSymb;
2697: this.document.server.submit();
2698: }
2699: }
2700:
2701: function gocstr(url,filename) {
2702: if (url == '/adm/cfile?action=delete') {
2703: this.document.cstrdelete.filename.value = filename
2704: this.document.cstrdelete.submit();
2705: return;
2706: }
2707: if ((url == '/adm/cfile?action=copy') || (url == '/adm/cfile?action=rename')) {
2708: this.document.cstrcopy.filename.value = filename;
2709: var oldname = filename.substring(filename.lastIndexOf("/") + 1);
2710: var newname=prompt('$newname',oldname);
2711: if (newname == "" || !newname || newname == oldname) {
2712: return;
2713: }
2714: if (url == '/adm/cfile?action=rename') {
2715: this.document.cstrcopy.action.value = 'rename';
2716: } else {
2717: this.document.cstrcopy.action.value = 'copy';
2718: }
2719: this.document.cstrcopy.newfilename.value = newname;
2720: this.document.cstrcopy.submit();
2721: return;
2722: }
2723: if (url == '/adm/printout') {
2724: this.document.cstrprint.postdata.value = filename
2725: this.document.cstrprint.curseed.value = 0;
2726: this.document.cstrprint.problemtype.value = 0;
2727: if (this.document.lonhomework) {
2728: if ((this.document.lonhomework.rndseed) && (this.document.lonhomework.rndseed.value != null) && (this.document.lonhomework.rndseed.value != '')) {
2729: this.document.cstrprint.curseed.value = this.document.lonhomework.rndseed.value
2730: }
2731: if (this.document.lonhomework.problemtype) {
2732: if (this.document.lonhomework.problemtype.value) {
2733: this.document.cstrprint.problemtype.value =
2734: this.document.lonhomework.problemtype.value;
2735: } else if (this.document.lonhomework.problemtype.options) {
2736: for (var i=0; i<this.document.lonhomework.problemtype.options.length; i++) {
2737: if (this.document.lonhomework.problemtype.options[i].selected) {
2738: if (this.document.lonhomework.problemtype.options[i].value != null && this.document.lonhomework.problemtype.options[i].value != '') {
2739: this.document.cstrprint.problemtype.value = this.document.lonhomework.problemtype.options[i].value
2740: }
2741: }
2742: }
2743: }
2744: }
2745: }
2746: this.document.cstrprint.submit();
2747: return;
2748: }
2749: if (url !='') {
2750: this.document.constspace.filename.value = filename;
2751: this.document.constspace.action = url;
2752: this.document.constspace.submit();
2753: }
2754: }
2755:
2756: function golist(url) {
2757: if (url!='' && url!= null) {
2758: currentURL = null;
2759: currentSymb= null;
2760: var lcHostname = setLCHost();
2761: var ltitarget = '$ltitarget';
2762: var deeplinktarget = '$deeplinktarget';
2763: if ((ltitarget == 'iframe') || (deeplinktarget == '_self')) {
2764: document.location.href=lcHostname+url;
2765: } else {
2766: top.location.href=lcHostname+url;
2767: }
2768: }
2769: }
2770:
2771:
2772:
2773: function catalog_info(url,isMobile) {
2774: if (isMobile == 1) {
2775: openMyModal(url+'.meta?modal=1',500,400,'yes');
2776: } else {
2777: loncatinfo=window.open(url+'.meta',"LONcatInfo",'height=500,width=400,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
2778: }
2779: }
2780:
2781: function chat_win() {
2782: var lcHostname = setLCHost();
2783: lonchat=window.open(lcHostname+'/res/adm/pages/chatroom.html',"LONchat",'height=320,width=480,resizable=yes,location=no,menubar=no,toolbar=no');
2784: }
2785:
2786: function group_chat(group) {
2787: var lcHostname = setLCHost();
2788: var url = lcHostname+'/adm/groupchat?group='+group;
2789: var winName = 'LONchat_'+group;
2790: grpchat=window.open(url,winName,'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
2791: }
2792:
2793: function annotate() {
2794: w_Annotator_flag=1;
2795: annotator=window.open('','Annotator','width=365,height=265,scrollbars=0');
2796: annotator.document.write(
2797: '$start_page_annotate'
2798: +"<form name='goannotate' target='Annotator' method='post' "
2799: +"action='$annotateurl'>"
2800: +"<input type='hidden' name='symbnew' value='"+currentSymb+"' />"
2801: +"<\\/form>"
2802: +'$end_page_annotate');
2803: annotator.document.close();
2804: }
2805:
2806: function open_StoredLinks_Import(rat) {
2807: var newWin;
2808: var lcHostname = setLCHost();
2809: if (rat) {
2810: newWin = window.open(lcHostname+'/adm/wishlist?inhibitmenu=yes&mode=import&rat='+rat,
2811: 'wishlistImport','scrollbars=1,resizable=1,menubar=0');
2812: }
2813: else {
2814: newWin = window.open(lcHostname+'/adm/wishlist?inhibitmenu=yes&mode=import',
2815: 'wishlistImport','scrollbars=1,resizable=1,menubar=0');
2816: }
2817: newWin.focus();
2818: }
2819:
2820: function open_source() {
2821: sourcewin=window.open('/adm/source?inhibitmenu=yes&viewonly=1&filename='+currentURL,'LONsource',
2822: 'height=500,width=600,resizable=yes,location=no,menubar=no,toolbar=no,scrollbars=yes');
2823: }
2824:
2825: function open_aboutLC() {
2826: var isMobile = "$env{'browser.mobile'}";
2827: var url = '/adm/about.html';
2828: if (isMobile == 1) {
2829: openMyModal(url,600,400,'yes');
2830: } else {
2831: window.open(url,"aboutLONCAPA","height=400,width=600,scrollbars=1,resizable=1,menubar=0,location=1");
2832: }
2833: return;
2834: }
2835:
2836:
2837: (function (\$) {
2838: \$(document).ready(function () {
2839: \$.single=function(a){return function(b){a[0]=b;return a}}(\$([1]));
2840: /*\@cc_on
2841: if (!window.XMLHttpRequest) {
2842: \$('.LC_hoverable').each(function () {
2843: this.attachEvent('onmouseenter', function (evt) { \$.single(evt.srcElement).addClass('hover'); });
2844: this.attachEvent('onmouseleave', function (evt) { \$.single(evt.srcElement).removeClass('hover'); });
2845: });
2846: }
2847: \@*/
2848: });
2849: }(jQuery));
2850:
2851: $countdown
2852:
2853: $viewuser
2854:
2855: ENDUTILITY
2856: }
2857:
2858: sub serverform {
2859: my $target;
2860: unless (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {
2861: $target = ' target="_top"';
2862: }
2863: if (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self')) {
2864: $target = ' target="_self"';
2865: }
2866: return(<<ENDSERVERFORM);
2867: <form name="server" action="/adm/logout" method="post"$target>
2868: <input type="hidden" name="postdata" value="none" />
2869: <input type="hidden" name="command" value="none" />
2870: <input type="hidden" name="url" value="none" />
2871: <input type="hidden" name="symb" value="none" />
2872: </form>
2873: ENDSERVERFORM
2874: }
2875:
2876: sub constspaceform {
2877: my ($frameset) = @_;
2878: my ($target,$printtarget);
2879: if ($frameset) {
2880: $target = ' target="_parent"';
2881: $printtarget = ' target="_parent"';
2882: } else {
2883: unless ((($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) ||
2884: (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self'))) {
2885: $target = ' target="_top"';
2886: $printtarget = ' target="_top"';
2887: }
2888: }
2889: return(<<ENDCONSTSPACEFORM);
2890: <form name="constspace" action="/adm/logout" method="post"$target>
2891: <input type="hidden" name="filename" value="" />
2892: </form>
2893: <form name="cstrdelete" action="/adm/cfile" method="post"$target>
2894: <input type="hidden" name="action" value="delete" />
2895: <input type="hidden" name="filename" value="" />
2896: </form>
2897: <form name="cstrprint" action="/adm/printout" method="post"$printtarget>
2898: <input type="hidden" name="postdata" value="" />
2899: <input type="hidden" name="curseed" value="" />
2900: <input type="hidden" name="problemtype" value="" />
2901: </form>
2902: <form name="cstrcopy" action="/adm/cfile" method="post"$target>
2903: <input type="hidden" name="action" value="copy" />
2904: <input type="hidden" name="filename" value="" />
2905: <input type="hidden" name="newfilename" value="" />
2906: </form>
2907:
2908: ENDCONSTSPACEFORM
2909: }
2910:
2911: sub hidden_button_check {
2912: if ( $env{'request.course.id'} eq ''
2913: || $env{'request.role.adv'} ) {
2914:
2915: return;
2916: }
2917: my $buttonshide = &Apache::lonnet::EXT('resource.0.buttonshide');
2918: return $buttonshide;
2919: }
2920:
2921: sub roles_selector {
2922: my ($cdom,$cnum,$httphost,$target,$menucoll,$menuref) = @_;
2923: my $crstype = &Apache::loncommon::course_type();
2924: my $now = time;
2925: my (%courseroles,%seccount,%courseprivs,%roledesc);
2926: my $is_cc;
2927: my ($js,$form,$switcher,$has_opa_priv);
2928: my $ccrole;
2929: if ($crstype eq 'Community') {
2930: $ccrole = 'co';
2931: } else {
2932: $ccrole = 'cc';
2933: }
2934: my ($privref,$gotsymb,$destsymb);
2935: my $destinationurl = $ENV{'REQUEST_URI'};
2936: if ($destinationurl =~ /(\?|\&)symb=/) {
2937: $gotsymb = 1;
2938: } elsif ($destinationurl =~ m{^/enc/}) {
2939: my $plainurl = &Apache::lonenc::unencrypted($destinationurl);
2940: if ($plainurl =~ /(\?|\&)symb=/) {
2941: $gotsymb = 1;
2942: }
2943: }
2944: unless ($gotsymb) {
2945: $destsymb = &Apache::lonnet::symbread();
2946: if ($destsymb ne '') {
2947: $destsymb = &Apache::lonenc::check_encrypt($destsymb);
2948: }
2949: }
2950: my $reqprivs = &required_privs();
2951: if (ref($reqprivs) eq 'HASH') {
2952: my $destination = $destinationurl;
2953: $destination =~ s/(\?.*)$//;
2954: if (exists($reqprivs->{$destination})) {
2955: if ($reqprivs->{$destination} =~ /,/) {
2956: @{$privref} = split(/,/,$reqprivs->{$destination});
2957: } else {
2958: $privref = [$reqprivs->{$destination}];
2959: }
2960: }
2961: }
2962: if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) {
2963: my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum});
2964: if ((($start) && ($start<0)) ||
2965: (($end) && ($end<$now)) ||
2966: (($start) && ($now<$start))) {
2967: $is_cc = 0;
2968: } else {
2969: $is_cc = 1;
2970: }
2971: }
2972: if ($is_cc) {
2973: &get_all_courseroles($cdom,$cnum,\%courseroles,\%seccount,\%courseprivs);
2974: } elsif ($env{'request.role'} =~ m{^\Qcr/$cdom/$cdom-domainconfig/\E(\w+)\.\Q/$cdom/$cnum\E}) {
2975: &get_customadhoc_roles($cdom,$cnum,\%courseroles,\%seccount,\%courseprivs,\%roledesc,$privref);
2976: } else {
2977: my %gotnosection;
2978: foreach my $item (keys(%env)) {
2979: if ($item =~ m-^user\.role\.([^.]+)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
2980: my $role = $1;
2981: my $sec = $2;
2982: next if ($role eq 'gr');
2983: my ($start,$end) = split(/\./,$env{$item});
2984: next if (($start && $start > $now) || ($end && $end < $now));
2985: if ($sec eq '') {
2986: if (!$gotnosection{$role}) {
2987: $seccount{$role} ++;
2988: $gotnosection{$role} = 1;
2989: }
2990: }
2991: if ((ref($privref) eq 'ARRAY') && (@{$privref} > 0)) {
2992: my $cnumsec = $cnum;
2993: if ($sec ne '') {
2994: $cnumsec .= "/$sec";
2995: }
2996: $courseprivs{"$role./$cdom/$cnumsec./"} =
2997: $env{"user.priv.$role./$cdom/$cnumsec./"};
2998: $courseprivs{"$role./$cdom/$cnumsec./$cdom/"} =
2999: $env{"user.priv.$role./$cdom/$cnumsec./$cdom/"};
3000: $courseprivs{"$role./$cdom/$cnumsec./$cdom/$cnumsec"} =
3001: $env{"user.priv.$role./$cdom/$cnumsec./$cdom/$cnumsec"};
3002: }
3003: if (ref($courseroles{$role}) eq 'ARRAY') {
3004: if ($sec ne '') {
3005: if (!grep(/^\Q$sec\E$/,@{$courseroles{$role}})) {
3006: push(@{$courseroles{$role}},$sec);
3007: $seccount{$role} ++;
3008: }
3009: }
3010: } else {
3011: @{$courseroles{$role}} = ();
3012: if ($sec ne '') {
3013: $seccount{$role} ++;
3014: push(@{$courseroles{$role}},$sec);
3015: }
3016: }
3017: }
3018: }
3019: }
3020: my @roles_order = ($ccrole,'in','ta','ep','ad','st');
3021: my $numdiffsec;
3022: if (keys(%seccount) == 1) {
3023: foreach my $key (keys(%seccount)) {
3024: $numdiffsec = $seccount{$key};
3025: }
3026: }
3027: if ((keys(%seccount) > 1) || ($numdiffsec > 1)) {
3028: my $targetattr;
3029: if ($target ne '') {
3030: $targetattr = ' target="'.$target.'"';
3031: }
3032: my @submenu;
3033: $js = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles,\%courseprivs,
3034: \%roledesc,$privref,$menucoll,$menuref);
3035: $form =
3036: '<form name="rolechooser" method="post" action="'.$httphost.'/adm/roles"'.$targetattr.'>'."\n".
3037: ' <input type="hidden" name="destinationurl" value="'.
3038: &HTML::Entities::encode($destinationurl).'" />'."\n".
3039: ' <input type="hidden" name="gotorole" value="1" />'."\n".
3040: ' <input type="hidden" name="selectrole" value="" />'."\n".
3041: ' <input type="hidden" name="switchrole" value="" />'."\n";
3042: if ($destsymb ne '') {
3043: $form .= ' <input type="hidden" name="destsymb" value="'.
3044: &HTML::Entities::encode($destsymb).'" />'."\n";
3045: }
3046: $form .= '</form>'."\n";
3047: foreach my $role (@roles_order) {
3048: my $include;
3049: if (defined($courseroles{$role})) {
3050: if ($env{'request.role'} =~ m{^\Q$role\E}) {
3051: if ($seccount{$role} > 1) {
3052: $include = 1;
3053: } else {
3054: if ($env{'user.priv.'.$env{'request.role'}."./$cdom/$cnum"} =~/opa\&([^\:]*)/) {
3055: $has_opa_priv = 1;
3056: }
3057: }
3058: } else {
3059: $include = 1;
3060: }
3061: }
3062: if ($include) {
3063: if ($env{"user.priv.$role./$cdom/$cnum./$cdom/$cnum"} =~/opa\&([^\:]*)/) {
3064: $has_opa_priv = 1;
3065: }
3066: push(@submenu,['javascript:adhocRole('."'$role'".')',
3067: &Apache::lonnet::plaintext($role,$crstype)]);
3068: }
3069: }
3070: foreach my $role (sort(keys(%courseroles))) {
3071: if ($role =~ /^cr/) {
3072: my $include;
3073: if ($env{'request.role'} =~ m{^\Q$role\E}) {
3074: if ($seccount{$role} > 1) {
3075: $include = 1;
3076: }
3077: } else {
3078: $include = 1;
3079: }
3080: if ($include) {
3081: my $rolename;
3082: if ($role =~ m{^cr/$cdom/$cdom\-domainconfig/(\w+)(?:/\w+|$)}) {
3083: $rolename = $roledesc{$role};
3084: if ($rolename eq '') {
3085: $rolename = &mt('Helpdesk [_1]',$1);
3086: }
3087: } else {
3088: $rolename = &Apache::lonnet::plaintext($role);
3089: }
3090: if ($env{"user.priv.$role./$cdom/$cnum./$cdom/$cnum"} =~/opa\&([^\:]*)/) {
3091: $has_opa_priv = 1;
3092: }
3093: push(@submenu,['javascript:adhocRole('."'$role'".')',
3094: $rolename]);
3095: }
3096: }
3097: }
3098: if (@submenu > 0) {
3099: $switcher = &create_submenu('#',$target,&mt('Switch role'),\@submenu);
3100: }
3101: }
3102: return ($js,$form,$switcher,$has_opa_priv);
3103: }
3104:
3105: sub get_all_courseroles {
3106: my ($cdom,$cnum,$courseroles,$seccount,$courseprivs) = @_;
3107: unless ((ref($courseroles) eq 'HASH') && (ref($seccount) eq 'HASH') &&
3108: (ref($courseprivs) eq 'HASH')) {
3109: return;
3110: }
3111: my ($result,$cached) =
3112: &Apache::lonnet::is_cached_new('getcourseroles',$cdom.'_'.$cnum);
3113: if (defined($cached)) {
3114: if (ref($result) eq 'HASH') {
3115: if ((ref($result->{'roles'}) eq 'HASH') &&
3116: (ref($result->{'seccount'}) eq 'HASH') &&
3117: (ref($result->{'privs'}) eq 'HASH')) {
3118: %{$courseroles} = %{$result->{'roles'}};
3119: %{$seccount} = %{$result->{'seccount'}};
3120: %{$courseprivs} = %{$result->{'privs'}};
3121: return;
3122: }
3123: }
3124: }
3125: my %gotnosection;
3126: my %adv_roles =
3127: &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
3128: foreach my $role (keys(%adv_roles)) {
3129: my ($urole,$usec) = split(/:/,$role);
3130: if (!$gotnosection{$urole}) {
3131: $seccount->{$urole} ++;
3132: $gotnosection{$urole} = 1;
3133: }
3134: if (ref($courseroles->{$urole}) eq 'ARRAY') {
3135: if ($usec ne '') {
3136: if (!grep(/^Q$usec\E$/,@{$courseroles->{$urole}})) {
3137: push(@{$courseroles->{$urole}},$usec);
3138: $seccount->{$urole} ++;
3139: }
3140: }
3141: } else {
3142: @{$courseroles->{$urole}} = ();
3143: if ($usec ne '') {
3144: $seccount->{$urole} ++;
3145: push(@{$courseroles->{$urole}},$usec);
3146: }
3147: }
3148: my $area = '/'.$cdom.'/'.$cnum;
3149: if ($usec ne '') {
3150: $area .= '/'.$usec;
3151: }
3152: if ($role =~ /^cr\//) {
3153: &Apache::lonnet::custom_roleprivs($courseprivs,$urole,$cdom,$cnum,$urole.'.'.$area,$area);
3154: } else {
3155: &Apache::lonnet::standard_roleprivs($courseprivs,$urole,$cdom,$urole.'.'.$area,$cnum,$area);
3156: }
3157: }
3158: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum,['st']);
3159: @{$courseroles->{'st'}} = ();
3160: &Apache::lonnet::standard_roleprivs($courseprivs,'st',$cdom,"st./$cdom/$cnum",$cnum,"/$cdom/$cnum");
3161: if (keys(%sections_count) > 0) {
3162: push(@{$courseroles->{'st'}},keys(%sections_count));
3163: $seccount->{'st'} = scalar(keys(%sections_count));
3164: }
3165: $seccount->{'st'} ++; # Increment for a section-less student role.
3166: my $rolehash = {
3167: 'roles' => $courseroles,
3168: 'seccount' => $seccount,
3169: 'privs' => $courseprivs,
3170: };
3171: &Apache::lonnet::do_cache_new('getcourseroles',$cdom.'_'.$cnum,$rolehash);
3172: return;
3173: }
3174:
3175: sub get_customadhoc_roles {
3176: my ($cdom,$cnum,$courseroles,$seccount,$courseprivs,$roledesc,$privref) = @_;
3177: unless ((ref($courseroles) eq 'HASH') && (ref($seccount) eq 'HASH') &&
3178: (ref($courseprivs) eq 'HASH') && (ref($roledesc) eq 'HASH')) {
3179: return;
3180: }
3181: my $is_helpdesk = 0;
3182: my $now = time;
3183: foreach my $role ('dh','da') {
3184: if ($env{"user.role.$role./$cdom/"}) {
3185: my ($start,$end)=split(/\./,$env{"user.role.$role./$cdom/"});
3186: if (!($start && ($now<$start)) && !($end && ($now>$end))) {
3187: $is_helpdesk = 1;
3188: last;
3189: }
3190: }
3191: }
3192: if ($is_helpdesk) {
3193: my ($possroles,$description) = &Apache::lonnet::get_my_adhocroles($cdom.'_'.$cnum);
3194: my %available;
3195: if (ref($possroles) eq 'ARRAY') {
3196: map { $available{$_} = 1; } @{$possroles};
3197: }
3198: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
3199: if (ref($domdefaults{'adhocroles'}) eq 'HASH') {
3200: if (keys(%{$domdefaults{'adhocroles'}})) {
3201: my $numsec = 1;
3202: my @sections;
3203: my ($allseclist,$cached) =
3204: &Apache::lonnet::is_cached_new('courseseclist',$cdom.'_'.$cnum);
3205: if (defined($cached)) {
3206: if ($allseclist ne '') {
3207: @sections = split(/,/,$allseclist);
3208: $numsec += scalar(@sections);
3209: }
3210: } else {
3211: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
3212: @sections = sort(keys(%sections_count));
3213: $numsec += scalar(@sections);
3214: $allseclist = join(',',@sections);
3215: &Apache::lonnet::do_cache_new('courseseclist',$cdom.'_'.$cnum,$allseclist);
3216: }
3217: my (%adhoc,$gotprivs);
3218: my $prefix = "cr/$cdom/$cdom".'-domainconfig';
3219: foreach my $role (keys(%{$domdefaults{'adhocroles'}})) {
3220: next if (($role eq '') || ($role =~ /\W/));
3221: $seccount->{"$prefix/$role"} = $numsec;
3222: $roledesc->{"$prefix/$role"} = $description->{$role};
3223: if ((ref($privref) eq 'ARRAY') && (@{$privref} > 0)) {
3224: if (exists($env{"user.priv.$prefix/$role./$cdom/$cnum./"})) {
3225: $courseprivs->{"$prefix/$role./$cdom/$cnum./"} =
3226: $env{"user.priv.$prefix/$role./$cdom/$cnum./"};
3227: $courseprivs->{"$prefix/$role./$cdom/$cnum./$cdom/"} =
3228: $env{"user.priv.$prefix/$role./$cdom/$cnum./$cdom/"};
3229: $courseprivs->{"$prefix/$role./$cdom/$cnum./$cdom/$cnum"} =
3230: $env{"user.priv.$prefix/$role./$cdom/$cnum./$cdom/$cnum"};
3231: } else {
3232: unless ($gotprivs) {
3233: my ($adhocroles,$privscached) =
3234: &Apache::lonnet::is_cached_new('adhocroles',$cdom);
3235: if ((defined($privscached)) && (ref($adhocroles) eq 'HASH')) {
3236: %adhoc = %{$adhocroles};
3237: } else {
3238: my $confname = &Apache::lonnet::get_domainconfiguser($cdom);
3239: my %roledefs = &Apache::lonnet::dump('roles',$cdom,$confname,'rolesdef_');
3240: foreach my $key (keys(%roledefs)) {
3241: (undef,my $rolename) = split(/_/,$key);
3242: if ($rolename ne '') {
3243: my ($systempriv,$domainpriv,$coursepriv) = split(/\_/,$roledefs{$key});
3244: $coursepriv = &Apache::lonnet::course_adhocrole_privs($rolename,$cdom,$cnum,$coursepriv);
3245: $adhoc{$rolename} = join('_',($systempriv,$domainpriv,$coursepriv));
3246: }
3247: }
3248: &Apache::lonnet::do_cache_new('adhocroles',$cdom,\%adhoc);
3249: }
3250: $gotprivs = 1;
3251: }
3252: ($courseprivs->{"$prefix/$role./$cdom/$cnum./"},
3253: $courseprivs->{"$prefix/$role./$cdom/$cnum./$cdom/"},
3254: $courseprivs->{"$prefix/$role./$cdom/$cnum./$cdom/$cnum"}) =
3255: split(/\_/,$adhoc{$role});
3256: }
3257: }
3258: if ($available{$role}) {
3259: $courseroles->{"$prefix/$role"} = \@sections;
3260: }
3261: }
3262: }
3263: }
3264: }
3265: return;
3266: }
3267:
3268: sub jump_to_role {
3269: my ($cdom,$cnum,$seccount,$courseroles,$courseprivs,$roledesc,$privref,
3270: $menucoll,$menuref) = @_;
3271: my %lt = &Apache::lonlocal::texthash(
3272: this => 'This role has section(s) associated with it.',
3273: ente => 'Enter a specific section.',
3274: orlb => 'Enter a specific section, or leave blank for no section.',
3275: avai => 'Available sections are:',
3276: youe => 'You entered an invalid section choice:',
3277: plst => 'Please try again.',
3278: role => 'The role you selected is not permitted to view the current page.',
3279: swit => 'Switch role, but display Main Menu page instead?',
3280: );
3281: &js_escape(\%lt);
3282: my $js;
3283: if (ref($courseroles) eq 'HASH') {
3284: $js = ' var secpick = new Array("'.$lt{'ente'}.'","'.$lt{'orlb'}.'");'."\n".
3285: ' var numsec = new Array();'."\n".
3286: ' var rolesections = new Array();'."\n".
3287: ' var rolenames = new Array();'."\n".
3288: ' var roleseclist = new Array();'."\n";
3289: my @items = keys(%{$courseroles});
3290: for (my $i=0; $i<@items; $i++) {
3291: $js .= ' rolenames['.$i.'] = "'.$items[$i].'";'."\n";
3292: my ($secs,$secstr);
3293: if (ref($courseroles->{$items[$i]}) eq 'ARRAY') {
3294: my @sections = sort { $a <=> $b } @{$courseroles->{$items[$i]}};
3295: $secs = join('","',@sections);
3296: $secstr = join(', ',@sections);
3297: }
3298: $js .= ' rolesections['.$i.'] = new Array("'.$secs.'");'."\n".
3299: ' roleseclist['.$i.'] = "'.$secstr.'";'."\n".
3300: ' numsec['.$i.'] = "'.$seccount->{$items[$i]}.'";'."\n";
3301: }
3302: }
3303: my $checkroles = 0;
3304: my $fallback = '/adm/menu';
3305: my $displaymsg = $lt{'swit'};
3306: if ((ref($privref) eq 'ARRAY') && (@{$privref} > 0) && (ref($courseprivs) eq 'HASH')) {
3307: my %disallowed;
3308: foreach my $role (sort(keys(%{$courseprivs}))) {
3309: my $trole;
3310: if ($role =~ m{^(.+?)\Q./$cdom/$cnum\E}) {
3311: $trole = $1;
3312: }
3313: if (($trole ne '') && ($trole ne 'cm')) {
3314: $disallowed{$trole} = 1;
3315: foreach my $priv (@{$privref}) {
3316: if ($courseprivs->{$role} =~ /\Q:$priv\E($|:|\&\w+)/) {
3317: delete($disallowed{$trole});
3318: last;
3319: }
3320: }
3321: }
3322: }
3323: if (keys(%disallowed) > 0) {
3324: $checkroles = 1;
3325: $js .= " var disallow = new Array('".join("','",keys(%disallowed))."');\n".
3326: " var rolecheck = 1;\n";
3327: if ($menucoll) {
3328: if (ref($menuref) eq 'HASH') {
3329: if ($menuref->{'main'} eq 'n') {
3330: $fallback = '/adm/navmaps';
3331: if (&Apache::loncommon::course_type() eq 'Community') {
3332: $displaymsg = &mt('Switch role, but display Community Contents page instead?');
3333: } else {
3334: $displaymsg = &mt('Switch role, but display Course Contents page instead?');
3335: }
3336: &js_escape(\$displaymsg);
3337: }
3338: }
3339: }
3340: }
3341: }
3342: &js_escape(\$fallback);
3343: if (!$checkroles) {
3344: $js .= " var disallow = new Array();\n".
3345: " rolecheck = 0;\n";
3346: }
3347: return <<"END";
3348: <script type="text/javascript">
3349: //<![CDATA[
3350: function adhocRole(newrole) {
3351: $js
3352: if (newrole == '') {
3353: return;
3354: }
3355: var fullrole = newrole+'./$cdom/$cnum';
3356: var selidx = '';
3357: for (var i=0; i<rolenames.length; i++) {
3358: if (rolenames[i] == newrole) {
3359: selidx = i;
3360: }
3361: }
3362: if (rolecheck > 0) {
3363: for (var i=0; i<disallow.length; i++) {
3364: if (disallow[i] == newrole) {
3365: if (confirm("$lt{'role'}\\n$displaymsg")) {
3366: document.rolechooser.destinationurl.value = '$fallback';
3367: } else {
3368: return;
3369: }
3370: }
3371: }
3372: }
3373: var secok = 1;
3374: var secchoice = '';
3375: if (selidx >= 0) {
3376: if (numsec[selidx] > 1) {
3377: secok = 0;
3378: var numrolesec = rolesections[selidx].length;
3379: var msgidx = numsec[selidx] - numrolesec;
3380: secchoice = prompt("$lt{'this'} "+secpick[msgidx]+"\\n$lt{'avai'} "+roleseclist[selidx],"");
3381: if (secchoice == '') {
3382: if (msgidx > 0) {
3383: secok = 1;
3384: }
3385: } else {
3386: for (var j=0; j<rolesections[selidx].length; j++) {
3387: if (rolesections[selidx][j] == secchoice) {
3388: secok = 1;
3389: }
3390: }
3391: }
3392: } else {
3393: if (rolesections[selidx].length == 1) {
3394: secchoice = rolesections[selidx][0];
3395: }
3396: }
3397: }
3398: if (secok == 1) {
3399: if (secchoice != '') {
3400: fullrole += '/'+secchoice;
3401: }
3402: } else {
3403: if (secchoice != null) {
3404: alert("$lt{'youe'} \\""+secchoice+"\\".\\n $lt{'plst'}");
3405: }
3406: return;
3407: }
3408: if (fullrole == "$env{'request.role'}") {
3409: return;
3410: }
3411: itemid = retrieveIndex('gotorole');
3412: if (itemid != -1) {
3413: document.rolechooser.elements[itemid].name = fullrole;
3414: }
3415: document.rolechooser.switchrole.value = fullrole;
3416: document.rolechooser.selectrole.value = '1';
3417: document.rolechooser.submit();
3418: return;
3419: }
3420:
3421: function retrieveIndex(item) {
3422: for (var i=0;i<document.rolechooser.elements.length;i++) {
3423: if (document.rolechooser.elements[i].name == item) {
3424: return i;
3425: }
3426: }
3427: return -1;
3428: }
3429: // ]]>
3430: </script>
3431: END
3432: }
3433:
3434: sub required_privs {
3435: my $privs = {
3436: '/adm/parmset' => 'opa,vpa',
3437: '/adm/courseprefs' => 'opa,vpa',
3438: '/adm/whatsnew' => 'whn',
3439: '/adm/populate' => 'cst,vpa,vcl',
3440: '/adm/trackstudent' => 'vsa',
3441: '/adm/statistics' => 'mgr,vgr',
3442: '/adm/setblock' => 'dcm,vcb',
3443: '/adm/coursedocs' => 'mdc',
3444: };
3445: unless ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'spreadsheet') {
3446: $privs->{'/adm/classcalc'} = 'vgr',
3447: $privs->{'/adm/assesscalc'} = 'vgr',
3448: $privs->{'/adm/studentcalc'} = 'vgr';
3449: }
3450: return $privs;
3451: }
3452:
3453: sub countdown_timer {
3454: if (($env{'request.course.id'}) && ($env{'request.symb'} ne '') &&
3455: (($env{'request.filename'}=~/$LONCAPA::assess_re/) ||
3456: (($env{'request.symb'} =~ /ext\.tool$/) &&
3457: (&Apache::lonnet::EXT('resource.0.gradable',$env{'request.symb'}) =~ /^yes$/i)))) {
3458: my ($type,$hastimeleft,$slothastime);
3459: my $now = time;
3460: if ($env{'request.filename'} =~ /\.task$/) {
3461: $type = 'Task';
3462: } elsif ($env{'request.symb'} =~ /ext\.tool$/) {
3463: $type = 'tool';
3464: } else {
3465: $type = 'problem';
3466: }
3467: my ($status,$accessmsg,$slot_name,$slot);
3468: if ($type eq 'tool') {
3469: ($status,$accessmsg,$slot_name,$slot) =
3470: &Apache::lonhomework::check_slot_access('0',$type,$env{'request.symb'},['0']);
3471: } else {
3472: ($status,$accessmsg,$slot_name,$slot) =
3473: &Apache::lonhomework::check_slot_access('0',$type);
3474: }
3475: if ($slot_name ne '') {
3476: if (ref($slot) eq 'HASH') {
3477: if (($slot->{'starttime'} < $now) &&
3478: ($slot->{'endtime'} > $now)) {
3479: $slothastime = 1;
3480: }
3481: }
3482: }
3483: if ($status ne 'CAN_ANSWER') {
3484: return;
3485: }
3486: my $duedate = &Apache::lonnet::EXT("resource.0.duedate");
3487: my @interval=&Apache::lonnet::EXT("resource.0.interval");
3488: my ($timelimit,$usesdone,$donebuttontext,$proctor,$secret);
3489: if (@interval > 1) {
3490: ($timelimit,my $donesuffix) = split(/_/,$interval[0],2);
3491: if ($donesuffix =~ /^done\:([^\:]+)\:(.*)$/) {
3492: $usesdone = 'done';
3493: $donebuttontext = $1;
3494: (undef,$proctor,$secret) = split(/_/,$2);
3495: } elsif ($donesuffix =~ /^done(|_.+)$/) {
3496: $donebuttontext = &mt('Done');
3497: ($usesdone,$proctor,$secret) = split(/_/,$donesuffix);
3498: }
3499: my $first_access=&Apache::lonnet::get_first_access($interval[1]);
3500: if ($first_access > 0) {
3501: if ($first_access+$timelimit > time) {
3502: $hastimeleft = 1;
3503: }
3504: }
3505: }
3506: if (($duedate && $duedate > time) ||
3507: (!$duedate && $hastimeleft) ||
3508: ($slot_name ne '' && $slothastime)) {
3509: my ($collapse,$expand,$alttxt,$title,$currdisp,$donebutton);
3510: if ((@interval > 1 && $hastimeleft) ||
3511: ($type eq 'Task' && $slothastime)) {
3512: $currdisp = 'inline';
3513: $collapse = '► ';
3514: if ((@interval > 1) && ($hastimeleft)) {
3515: if ($usesdone eq 'done') {
3516: $donebutton = &done_button_js($interval[1],'','',$proctor,$donebuttontext);
3517: }
3518: }
3519: } else {
3520: $currdisp = 'none';
3521: $expand = '◄ ';
3522: }
3523: unless ($env{'environment.icons'} eq 'iconsonly') {
3524: $alttxt = &mt('Timer');
3525: $title = $alttxt.' ';
3526: }
3527: my $desc = &mt('Countdown to due date/time');
3528:
3529: return <<END;
3530: $donebutton
3531: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
3532: <span id="ddcountcollapse" class="LC_menubuttons_inline_text">
3533: $collapse
3534: </span></a>
3535: <span id="duedatecountdown" class="LC_menubuttons_inline_text" style="display: $currdisp;"></span>
3536: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
3537: <span id="ddcountexpand" class="LC_menubuttons_inline_text" >$expand</span>
3538: <img src="/res/adm/pages/timer.png" title="$desc" class="LC_icon" alt="$alttxt" /><span class="LC_menubuttons_inline_text">$title</span></a>
3539: END
3540: }
3541: }
3542: return;
3543: }
3544:
3545: sub placement_progress {
3546: my ($totalpoints,$incomplete) = &Apache::lonplacementtest::check_completion(undef,undef,1);
3547: my $complete = 100 - $incomplete;
3548: return '<span class="LC_placement_prog">'.
3549: &mt('Test is [_1]% complete',$complete).'</span>';
3550: }
3551:
3552: sub linkprot_exit {
3553: if (($env{'request.course.id'}) && ($env{'request.deeplink.login'})) {
3554: my ($deeplink_symb,$deeplink);
3555: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
3556: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3557: if (($cnum ne '') && ($cdom ne '')) {
3558: $deeplink_symb = &Apache::loncommon::deeplink_login_symb($cnum,$cdom);
3559: if ($deeplink_symb) {
3560: if ($deeplink_symb =~ /\.(page|sequence)$/) {
3561: my $mapname = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($deeplink_symb))[2]);
3562: my $navmap = Apache::lonnavmaps::navmap->new();
3563: if (ref($navmap)) {
3564: $deeplink = $navmap->get_mapparam(undef,$mapname,'0.deeplink');
3565: }
3566: } else {
3567: $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$deeplink_symb);
3568: }
3569: if ($deeplink ne '') {
3570: my ($state,$others,$listed,$scope,$protect,$display,$target,$exit) = split(/,/,$deeplink);
3571: my %lt = &Apache::lonlocal::texthash(
3572: title => 'Exit Tool',
3573: okdone => 'Click "OK" to exit embedded tool',
3574: cancel => 'Click "Cancel" to continue working.',
3575: ok => 'OK',
3576: exit => 'Cancel',
3577: );
3578: if ($exit) {
3579: my ($show,$text) = split(/:/,$exit);
3580: unless ($show eq 'no') {
3581: my $height = 250;
3582: my $width = 300;
3583: my $exitbuttontext;
3584: if ($text eq '') {
3585: $exitbuttontext = &mt('Exit Tool');
3586: } else {
3587: $exitbuttontext = $text;
3588: }
3589: return <<END;
3590: <form method="post" name="LCexitButton" action="/adm/linkexit">
3591: <input type="hidden" name="LC_deeplink_exit" value="" />
3592: <button id="LC_exit-confirm-opener" type="button">$exitbuttontext</button>
3593: </form>
3594:
3595: <div id="LC_exit-confirm" title="$lt{'title'}">
3596: <p>$lt{'okdone'} $lt{'cancel'}</p>
3597: </div>
3598:
3599: <script type="text/javascript">
3600: // <![CDATA[
3601: \$( "#LC_exit-confirm" ).dialog({ autoOpen: false });
3602: \$( "#LC_exit-confirm-opener" ).click(function() {
3603: \$( "#LC_exit-confirm" ).dialog( "open" );
3604: \$( "#LC_exit-confirm" ).dialog({
3605: resizable: false,
3606: height: $height,
3607: width: $width,
3608: modal: true,
3609: buttons: [
3610: {
3611: text: "$lt{'ok'}",
3612: click: function() {
3613: \$( this ).dialog( "close" );
3614: \$( '[name="LC_deeplink_exit"]' )[0].value = 'true';
3615: \$( '[name="LCexitButton"]' )[0].submit();
3616: },
3617: },
3618: {
3619: text: "$lt{'exit'}",
3620: click: function() {
3621: \$( this ).dialog( "close" );
3622: },
3623: },
3624: ],
3625: });
3626: });
3627: // ]]>
3628: </script>
3629:
3630: END
3631: }
3632: }
3633: }
3634: }
3635: }
3636: }
3637: return;
3638: }
3639:
3640: # ================================================================ Main Program
3641:
3642: BEGIN {
3643: if (! defined($readdesk)) {
3644: {
3645: my $tabfile = $Apache::lonnet::perlvar{'lonTabDir'}.'/mydesk.tab';
3646: if ( CORE::open( my $config,"<$tabfile") ) {
3647: while (my $configline=<$config>) {
3648: $configline=(split(/\#/,$configline))[0];
3649: $configline=~s/^\s+//;
3650: chomp($configline);
3651: if ($configline=~/^cat\:/) {
3652: my @entries=split(/\:/,$configline);
3653: $category_positions{$entries[2]}=$entries[1];
3654: $category_names{$entries[2]}=$entries[3];
3655: } elsif ($configline=~/^prim\:/) {
3656: my @entries = (split(/\:/, $configline))[1..7];
3657: push(@primary_menu,\@entries);
3658: } elsif ($configline=~/^primsub\:/) {
3659: my ($parent,@entries) = (split(/\:/, $configline))[1..5];
3660: push(@{$primary_submenu{$parent}},\@entries);
3661: } elsif ($configline=~/^scnd\:/) {
3662: my @entries = (split(/\:/, $configline))[1..6];
3663: push(@secondary_menu,\@entries);
3664: } elsif ($configline=~/^scndsub\:/) {
3665: my ($parent,@entries) = (split(/\:/, $configline))[1..4];
3666: push(@{$secondary_submenu{$parent}},\@entries);
3667: } elsif ($configline) {
3668: push(@desklines,$configline);
3669: }
3670: }
3671: CORE::close($config);
3672: }
3673: }
3674: $readdesk='done';
3675: }
3676: }
3677:
3678: 1;
3679: __END__
3680:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>