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