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