File:
[LON-CAPA] /
loncom /
interface /
lonmenu.pm
Revision
1.532:
download - view:
text,
annotated -
select for diffs
Sun Jun 11 20:45:35 2023 UTC (14 months, 1 week ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
- Remove "Actions for current directory" drop-down list from box created by
&CSTR_pageheader() when listing contents of a directory in Authoring Space
and replace with icons/links in Functions menu below standard inline menus.
- Reverse part of changes in lonpubdir.pm 1.176 and loncommon.pm 1.1406
1: # The LearningOnline Network with CAPA
2: # Routines to control the menu
3: #
4: # $Id: lonmenu.pm,v 1.532 2023/06/11 20:45:35 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,
850: $ltiscope,$ltiuri,$showncrumbsref) = @_;
851: my $const_space = ($env{'request.state'} eq 'construct');
852: my $is_const_dir = 0;
853:
854: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
855:
856: $env{'request.registered'} = 1;
857:
858: undef(@inlineremote);
859:
860: my ($mapurl,$resurl,$crstype,$navmap);
861:
862: if ($env{'request.course.id'}) {
863: #
864: #course_type: Course, Community, or Placement
865: #
866: $crstype = &Apache::loncommon::course_type();
867: if ($env{'request.symb'}) {
868: my $ignorenull;
869: unless ($env{'request.noversionuri'} eq '/adm/navmaps') {
870: $ignorenull = 1;
871: }
872: my $symb = &Apache::lonnet::symbread('','',$ignorenull);
873: ($mapurl, my $rid, $resurl) = &Apache::lonnet::decode_symb($symb);
874: my $coursetitle = $env{'course.'.$env{'request.course.id'}.'.description'};
875:
876: my $maptitle = &Apache::lonnet::gettitle($mapurl);
877: my $restitle = &Apache::lonnet::gettitle($symb);
878: my (@crumbs,@mapcrumbs);
879: if (($env{'request.noversionuri'} ne '/adm/navmaps') && ($mapurl ne '') &&
880: (!(($crstype eq 'Placement') && !$env{'request.role.adv'}))) {
881: unless ($ltiscope eq 'resource') {
882: if (($mapurl ne $env{'course.'.$env{'request.course.id'}.'.url'}) &&
883: !(($ltiscope eq 'map') && (&Apache::lonnet::clutter($resurl) eq $ltiuri))) {
884: $navmap = Apache::lonnavmaps::navmap->new();
885: if (ref($navmap)) {
886: @mapcrumbs = $navmap->recursed_crumbs($mapurl,$restitle);
887: }
888: }
889: }
890: }
891: unless ((($crstype eq 'Placement') && (!$env{'request.role.adv'})) ||
892: ($ltiscope eq 'map') || ($ltiscope eq 'resource')) {
893: @crumbs = ({text => $crstype.' Contents',
894: href => "Javascript:gopost('/adm/navmaps','')"});
895: }
896: if ($mapurl ne $env{'course.'.$env{'request.course.id'}.'.url'}) {
897: if (@mapcrumbs) {
898: push(@crumbs,@mapcrumbs);
899: } elsif (!(($crstype eq 'Placement') && (!$env{'request.role.adv'})) &&
900: ($ltiscope ne 'map') && ($ltiscope ne 'resource')) {
901: push(@crumbs, {text => '...',
902: no_mt => 1});
903: }
904: }
905:
906: unless ((($crstype eq 'Placement') && (!$env{'request.role.adv'})) || (@mapcrumbs) ||
907: (!$maptitle) || ($maptitle eq 'default.sequence') ||
908: ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'}) ||
909: ($ltiscope eq 'resource')) {
910: push @crumbs, {text => $maptitle, no_mt => 1,
911: href => &Apache::lonnet::clutter($mapurl).'?navmap=1'};
912: }
913: if ($restitle && !@mapcrumbs) {
914: push(@crumbs,{text => $restitle, no_mt => 1});
915: }
916: my @tools;
917: if ($env{'request.filename'} =~ /\.page$/) {
918: my %breadcrumb_tools = &Apache::lonhtmlcommon::current_breadcrumb_tools();
919: if (ref($breadcrumb_tools{'tools'}) eq 'ARRAY') {
920: @tools = @{$breadcrumb_tools{'tools'}};
921: }
922: }
923: &Apache::lonhtmlcommon::clear_breadcrumbs();
924: &Apache::lonhtmlcommon::add_breadcrumb(@crumbs);
925: if (@tools) {
926: &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',@tools);
927: }
928: } else {
929: $resurl = $env{'request.noversionuri'};
930: my $courseurl = &Apache::lonnet::courseid_to_courseurl($env{'request.course.id'});
931: my $title = &mt('View Resource');
932: if ($resurl =~ m{^\Q/uploaded$courseurl/supplemental/\E(default|\d+)/}) {
933: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['folderpath','title']);
934: &Apache::lonhtmlcommon::clear_breadcrumbs();
935: if ($env{'form.title'}) {
936: $title = $env{'form.title'};
937: }
938: my ($trail,$cnum,$cdom);
939: if ($env{'form.folderpath'}) {
940: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
941: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
942: &Apache::loncommon::validate_folderpath(1,'',$cnum,$cdom);
943: }
944: if ($env{'form.folderpath'}) {
945: &prepare_functions($resurl,$forcereg,$group,undef,undef,1,$hostname);
946: $title = &HTML::Entities::encode($title,'\'"<>&');
947: ($trail) =
948: &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1,1);
949: } else {
950: &Apache::lonhtmlcommon::add_breadcrumb(
951: {text => "Supplemental $crstype Content",
952: href => "javascript:gopost('/adm/supplemental','')"});
953: $title = &HTML::Entities::encode(&mt('View Resource'),'\'"<>&');
954: ($trail) =
955: &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1,1);
956: }
957: if (ref($showncrumbsref)) {
958: $$showncrumbsref = 1;
959: }
960: return $trail;
961: } elsif ($resurl =~ m{^\Q/uploaded$courseurl/portfolio/syllabus/}) {
962: &Apache::lonhtmlcommon::clear_breadcrumbs();
963: &prepare_functions('/public'.$courseurl."/syllabus",
964: $forcereg,$group,undef,undef,1,$hostname);
965: $title = &HTML::Entities::encode(&mt('Syllabus File'),'\'"<>&');
966: my ($trail) =
967: &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1,1);
968: if (ref($showncrumbsref)) {
969: $$showncrumbsref = 1;
970: }
971: return $trail;
972: }
973: unless ($env{'request.state'} eq 'construct') {
974: &Apache::lonhtmlcommon::clear_breadcrumbs();
975: &Apache::lonhtmlcommon::add_breadcrumb({text => 'View Resource'});
976: }
977: }
978: } elsif (! $const_space){
979: #a situation when we're looking at a resource outside of context of a
980: #course or construction space (e.g. with cumulative rights)
981: &Apache::lonhtmlcommon::clear_breadcrumbs();
982: unless ($env{'request.noversionuri'} =~ m{^/adm/$match_domain/$match_username/aboutme$}) {
983: &Apache::lonhtmlcommon::add_breadcrumb({text => 'View Resource'});
984: }
985: }
986: # =============================================================================
987: # ============================ This is for URLs that actually can be registered
988: return '' unless ( ($env{'request.noversionuri'}!~m{^/(res/)*adm/})
989: || $forcereg );
990: my ($cdom,$cnum,%perms,$cfile,$switchserver,$home,$forceedit,
991: $forceview,$editbutton);
992: if (($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) ||
993: ($env{'request.role'} !~/^(aa|ca|au)/)) {
994: $editbutton = &prepare_functions($resurl,$forcereg,$group,'','','',$hostname);
995: }
996: if ($editbutton eq '') {
997: $editbutton = &clear(6,1);
998: }
999:
1000: #
1001: # This applies in course context
1002: #
1003: if ($env{'request.course.id'}) {
1004: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1005: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1006: $perms{'mdc'} = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
1007: $perms{'cev'} = &Apache::lonnet::allowed('cev',$env{'request.course.id'});
1008: my @privs;
1009: my $gradable_exttool;
1010: if ($env{'request.symb'} ne '') {
1011: if ($env{'request.noversionuri'} =~ m{^/adm/$cdom/$cnum/(\d+)/ext\.tool$}) {
1012: if (&Apache::lonnet::EXT('resource.0.gradable') =~ /^yes$/i) {
1013: $gradable_exttool = 1;
1014: push(@privs,('mgr','vgr'));
1015: }
1016: } elsif ($env{'request.filename'}=~/$LONCAPA::assess_re/) {
1017: push(@privs,('mgr','vgr'));
1018: }
1019: push(@privs,('opa','vpa'));
1020: }
1021: foreach my $priv (@privs) {
1022: $perms{$priv} = &Apache::lonnet::allowed($priv,$env{'request.course.id'});
1023: if (!$perms{$priv} && $env{'request.course.sec'} ne '') {
1024: $perms{$priv} =
1025: &Apache::lonnet::allowed($priv,"$env{'request.course.id'}/$env{'request.course.sec'}");
1026: }
1027: }
1028: #
1029: # Determine whether or not to show Grades and Submissions buttons
1030: #
1031: if (($env{'request.symb'} ne '') &&
1032: (($env{'request.filename'}=~/$LONCAPA::assess_re/) || ($gradable_exttool))) {
1033: if ($perms{'mgr'}) {
1034: &switch('','',7,2,'pgrd.png','Content Grades','grades[_4]',
1035: "gocmd('/adm/grades','gradingmenu')",
1036: 'Content Grades');
1037: } elsif ($perms{'vgr'}) {
1038: &switch('','',7,2,'subm.png','Content Submissions','missions[_1]',
1039: "gocmd('/adm/grades','submission')",
1040: 'Content Submissions');
1041: }
1042: }
1043: if (($env{'request.symb'} ne '') && (($perms{'opa'}) || ($perms{'vpa'}))) {
1044: &switch('','',7,3,'pparm.png','Content Settings','parms[_2]',
1045: "gocmd('/adm/parmset','set')",
1046: 'Content Settings');
1047: }
1048: # End grades/submissions check
1049:
1050: #
1051: # This applies to items inside a folder/page modifiable in the course.
1052: #
1053: if (($env{'request.symb'}=~/^uploaded/) && (($perms{'mdc'}) || ($perms{'cev'}))) {
1054: my $text = 'Edit Folder';
1055: if (($mapurl =~ /\.page$/) ||
1056: ($env{'request.symb'}=~
1057: m{uploaded/$cdom/$cnum/default_\d+\.page$})) {
1058: $text = 'Edit Page';
1059: }
1060: &switch('','',7,4,'docs-22x22.png',$text,'parms[_2]',
1061: "gocmd('/adm/coursedocs','direct')",
1062: 'Folder/Page Content');
1063: }
1064: # End modifiable folder/page container check
1065:
1066: #
1067: # Determine whether to show View As button for shortcut to display problem, answer, and submissions
1068: #
1069:
1070: if (($env{'request.symb'} ne '') &&
1071: ($env{'request.filename'}=~/$LONCAPA::assess_re/) &&
1072: (($perms{'mgr'}) || ($perms{'vgr'}))) {
1073: my ($viewas,$text,$change,$visibility,$vuname,$vudom,$vid,$leftvis,$defdom,$righticon);
1074: my %lt = &Apache::lonlocal::texthash(
1075: view => 'View',
1076: upda => 'Update',
1077: );
1078: if ($env{'request.user_in_effect'} =~ /^($match_username):($match_domain)$/) {
1079: ($vuname,$vudom) = ($1,$2);
1080: unless (&Apache::lonnet::is_advanced_user($vudom,$vuname)) {
1081: $vid = (&Apache::lonnet::idrget($vudom,$vuname))[1];
1082: }
1083: $viewas = $env{'request.user_in_effect'};
1084: $text = $lt{'upda'};
1085: $change = 'off';
1086: $visibility = 'inline';
1087: $leftvis = 'none';
1088: $defdom = $vudom;
1089: $righticon = '✖';
1090: } else {
1091: $text = $lt{'view'};
1092: $change = 'on';
1093: $visibility = 'none';
1094: $leftvis = 'inline';
1095: $defdom = $cdom;
1096: }
1097: my $sellink = &Apache::loncommon::selectstudent_link('userview','vuname','vudom');
1098: my $selscript=&Apache::loncommon::studentbrowser_javascript();
1099: my $shownsymb = &HTML::Entities::encode(&Apache::lonenc::check_encrypt($env{'request.symb'}),'<>&"');
1100: my $input = &mt('User: [_1] or ID: [_2] at: [_3]',
1101: '<input name="vuname" type="text" size="8" value="'.$vuname.'" />',
1102: '<input name="vid" type="text" size="8" value="'.$vid.'" />',
1103: &Apache::loncommon::select_dom_form($defdom,'vudom')).
1104: '<input name="LC_viewas" type="hidden" value="'.$viewas.'" />',
1105: '<input name="symb" type="hidden" value="'.$shownsymb.'" />';
1106: my $chooser = <<END;
1107: $selscript
1108: <a href="javascript:toggleViewAsUser('$change');" class="LC_menubuttons_link">
1109: <span id="usexpand" class="LC_menubuttons_inline_text" style="display:$leftvis">► </span>
1110: </a>
1111: <fieldset id="LC_selectuser" style="display:$visibility">
1112: <form name="userview" action="" method="post" onsubmit="event.preventDefault(); return validCourseUser(this,'$change');">
1113: <span class="LC_menubuttons_inline_text LC_nobreak">
1114: $input
1115: $sellink
1116: </span>
1117: <input type="submit" value="$text" />
1118: </form>
1119: </fieldset>
1120: <a href="javascript:toggleViewAsUser('$change');" class="LC_menubuttons_link">
1121: <span id="uscollapse" class="LC_menubuttons_inline_text">$righticon</span>
1122: </a>
1123: END
1124: &switch('','',7,5,'viewuser.png','View As','user[_1]',
1125: 'toggleViewAsUser('."'$change'".')',
1126: 'View As','','',$chooser);
1127: }
1128: # End view as user check
1129:
1130: }
1131: # End course context
1132:
1133: # Prepare the rest of the buttons
1134: my ($menuitems,$got_prt,$got_wishlist);
1135: if ($const_space) {
1136: #
1137: # We are in construction space
1138: #
1139:
1140: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1141: my ($udom,$uname,$thisdisfn) =
1142: ($env{'request.filename'}=~m{^\Q$londocroot/priv/\E([^/]+)/([^/]+)/(.*)$});
1143: my $currdir = '/priv/'.$udom.'/'.$uname.'/'.$thisdisfn;
1144: if ($currdir =~ m-/$-) {
1145: $is_const_dir = 1;
1146: if ($thisdisfn eq '') {
1147: unless (($env{'request.course.id'}) &&
1148: ($env{'course.'.$env{'request.course.id'}.'.num'} eq $uname) &&
1149: ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $udom)) {
1150: $is_const_dir = 2;
1151: }
1152: }
1153: my $esc_currdir = &Apache::loncommon::escape_single($currdir);
1154: $menuitems=(<<ENDMENUITEMS);
1155: s&6&3&pub.png&Publish&dir[_2]&gocstr('/adm/publish','$esc_currdir')&Publish this Directory
1156: s&7&4&docs-22x22.png&Edit Metadata&defaults[_1]&gopost('${esc_currdir}default.meta','')&Edit metadata for this Directory
1157: s&7&2&prt.png&Print&printout[_1]&gocstr('/adm/printout','$esc_currdir')&Print contents of directory
1158: s&7&1&del.png&Delete&dir[_3]&gocstr('/adm/cfile?action=delete','$esc_currdir')&Delete this Directory
1159: ENDMENUITEMS
1160: } else {
1161: $currdir =~ s|[^/]+$||;
1162: my $cleandisfn = &Apache::loncommon::escape_single($thisdisfn);
1163: my $esc_currdir = &Apache::loncommon::escape_single($currdir);
1164: my $pubfile = "/res/$udom/$uname/$thisdisfn";
1165: my $candelete = 1;
1166: if (-e $londocroot.$pubfile) {
1167: unless (&Apache::lonnet::metadata($pubfile,'obsolete')) {
1168: undef($candelete);
1169: }
1170: }
1171: #
1172: # Probably should be in mydesk.tab
1173: #
1174: $menuitems=(<<ENDMENUITEMS);
1175: s&6&1&list.png&Directory&dir[_1]&golist('$esc_currdir')&List current directory
1176: s&6&2&rtrv.png&Retrieve&version[_1]&gocstr('/adm/retrieve','/priv/$udom/$uname/$cleandisfn')&Retrieve old version
1177: s&6&3&pub.png&Publish&resource[_3]&gocstr('/adm/publish','/priv/$udom/$uname/$cleandisfn')&Publish this resource
1178: s&7&3©.png&Copy&resource[_4]&gocstr('/adm/cfile?action=copy','/priv/$udom/$uname/$cleandisfn')&Copy this resource
1179: ENDMENUITEMS
1180: #
1181: # Rename and Delete only available if obsolete or unpublished
1182: #
1183: if ($candelete) {
1184: $menuitems .= (<<ENDMENUITEMS);
1185: s&7&4&rename.png&Rename&resource[_5]&gocstr('/adm/cfile?action=rename','/priv/$udom/$uname/$cleandisfn')&Rename this resource
1186: s&7&1&del.png&Delete&resource[_2]&gocstr('/adm/cfile?action=delete','/priv/$udom/$uname/$cleandisfn')&Delete this resource
1187: ENDMENUITEMS
1188: }
1189: $menuitems .= (<<ENDMENUITEMS);
1190: s&7&2&prt.png&Print&printout[_1]&gocstr('/adm/printout','/priv/$udom/$uname/$cleandisfn')&Prepare a printable document
1191: ENDMENUITEMS
1192: }
1193: if (ref($bread_crumbs) eq 'ARRAY') {
1194: &Apache::lonhtmlcommon::clear_breadcrumbs();
1195: foreach my $crumb (@{$bread_crumbs}){
1196: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
1197: }
1198: }
1199: } elsif ( defined($env{'request.course.id'}) &&
1200: $env{'request.symb'} ne '' ) {
1201: #
1202: # We are in a course and looking at a registered URL
1203: # Should probably be in mydesk.tab
1204: #
1205: $menuitems = "c&3&1";
1206: if ($ltiscope eq 'resource') {
1207: # Suppress display of backward arrow for LTI Provider if scope is resource.
1208: # Suppress display of forward arrow for LTI Provider if scope is resource.
1209: } elsif ($ltiscope eq 'map') {
1210: # Suppress display of backward arrow for LTI Provider if scope is map and this is first resource.
1211: # Suppress display of forward arrow for LTI Provider if scope is map and this is the last resource.
1212: my $showforw = 1;
1213: my $showback = 1;
1214: my $navmap = Apache::lonnavmaps::navmap->new();
1215: if (ref($navmap)) {
1216: my $mapres = $navmap->getResourceByUrl($ltiuri);
1217: if (ref($mapres)) {
1218: if ($navmap->isLastResource($mapres,$env{'request.symb'})) {
1219: $showforw = 0;
1220: }
1221: if ($navmap->isFirstResource($mapres,$env{'request.symb'})) {
1222: $showback = 0;
1223: }
1224: }
1225: }
1226: if ($showback) {
1227: $menuitems.="
1228: s&2&1&back.png&&&gopost('/adm/flip','back:'+currentURL)&Previous content resource&&1";
1229: }
1230: if ($showforw) {
1231: $menuitems.="
1232: s&2&3&forw.png&&&gopost('/adm/flip','forward:'+currentURL)&Next content resource&&3";
1233: }
1234: } elsif (($crstype ne 'Placement') || ($env{'request.role.adv'})) {
1235: $menuitems.="
1236: s&2&1&back.png&&&gopost('/adm/flip','back:'+currentURL)&Previous content resource&&1
1237: s&2&3&forw.png&&&gopost('/adm/flip','forward:'+currentURL)&Next content resource&&3";
1238: } else {
1239: # Suppress display of backward arrow for Placement Tests
1240: # Suppress display of forward arrow for Placement Tests if this is the last resource.
1241: my $showforw = 1;
1242: if ($env{'request.symb'}) {
1243: my $navmap = Apache::lonnavmaps::navmap->new();
1244: if (ref($navmap)) {
1245: if (&Apache::lonplacementtest::is_lastres($env{'request.symb'},$navmap)) {
1246: $showforw = 0;
1247: }
1248: }
1249: }
1250: if ($showforw) {
1251: $menuitems.="
1252: s&2&3&forw.png&&&gopost('/adm/flip','forward:'+currentURL)&Next content resource&&3";
1253: }
1254: }
1255: $menuitems .= (<<ENDMENUITEMS);
1256:
1257: c&6&3
1258: c&8&1
1259: c&8&2
1260: s&8&3&prt.png&Print&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
1261: ENDMENUITEMS
1262: $got_prt = 1;
1263: if (($env{'user.adv'}) && ($env{'request.uri'} =~ /^\/res/)
1264: && (!$env{'request.enc'})) {
1265: my ($cnum,$cdom) = &Apache::loncommon::crsauthor_url($env{'request.uri'});
1266: unless ($cnum) {
1267: # wishlist is only available for users with access to resource-pool
1268: # and links can only be set for resources within the resource-pool
1269: $menuitems .= (<<ENDMENUITEMS);
1270: 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
1271: ENDMENUITEMS
1272: $got_wishlist = 1;
1273: }
1274: }
1275:
1276: my $currentURL = &Apache::loncommon::get_symb();
1277: my ($symb_old,$symb_old_enc) = &Apache::loncommon::clean_symb($currentURL);
1278: my $annotation = &Apache::loncommon::get_annotation($symb_old,$symb_old_enc);
1279: $menuitems.="s&9&3&";
1280: if(length($annotation) > 0){
1281: $menuitems.="anot2.png";
1282: }else{
1283: $menuitems.="anot.png";
1284: }
1285: $menuitems.="&Notes&&annotate()&";
1286: $menuitems.="Make notes and annotations about this resource&&1\n";
1287: my $is_mobile;
1288: if ($env{'browser.mobile'}) {
1289: $is_mobile = 1;
1290: }
1291:
1292: unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme|viewclasslist|portfolio)(\?|$)/) {
1293: if ((!$env{'request.enc'}) && ($env{'request.noversionuri'} !~ m{^/adm/wrapper/ext/}) &&
1294: ($env{'request.noversionuri'} !~ m{^/uploaded/$match_domain/$match_courseid/(docs/|default_\d+\.page$)}) &&
1295: ($env{'request.noversionuri'} !~ m{^/adm/.+/ext\.tool$})) {
1296: $menuitems.=(<<ENDREALRES);
1297: s&6&3&catalog.png&Info&info[_1]&catalog_info(currentURL,'$is_mobile')&Show Metadata
1298: ENDREALRES
1299: }
1300: unless (($env{'request.noversionuri'} =~ m{^/uploaded/$match_domain/$match_courseid/(docs/|default_\d+\.page$)}) ||
1301: ($env{'request.noversionuri'} =~ m{^\Q/adm/wrapper/\E(ext|uploaded)/}) ||
1302: ($env{'request.noversionuri'} =~ m{^/adm/.+/ext\.tool$})) {
1303: $menuitems.=(<<ENDREALRES);
1304: s&8&1&eval.png&Evaluate&this[_1]&gopost('/adm/evaluate',currentURL,1)&Provide my evaluation of this resource
1305: ENDREALRES
1306: }
1307: unless ($env{'request.noversionuri'} =~ m{^\Q/adm/wrapper/\E(ext|uploaded)/}) {
1308: $menuitems.=(<<ENDREALRES);
1309: 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
1310: ENDREALRES
1311: }
1312: }
1313: }
1314: if ($env{'request.uri'} =~ /^\/res/) {
1315: unless ($got_prt) {
1316: $menuitems .= (<<ENDMENUITEMS);
1317: s&8&3&prt.png&Print&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
1318: ENDMENUITEMS
1319: $got_prt = 1;
1320: }
1321: unless ($got_wishlist) {
1322: if (($env{'user.adv'}) && (!$env{'request.enc'})) {
1323: # wishlist is only available for users with access to resource-pool
1324: $menuitems .= (<<ENDMENUITEMS);
1325: 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
1326: ENDMENUITEMS
1327: $got_wishlist = 1;
1328: }
1329: }
1330: }
1331: my $buttons='';
1332: foreach (split(/\n/,$menuitems)) {
1333: my ($command,@rest)=split(/\&/,$_);
1334: my $idx=10*$rest[0]+$rest[1];
1335: if (&hidden_button_check() eq 'yes') {
1336: if ($idx == 21 ||$idx == 23) {
1337: $buttons.=&switch('','',@rest);
1338: } else {
1339: $buttons.=&clear(@rest);
1340: }
1341: } else {
1342: if ($command eq 's') {
1343: $buttons.=&switch('','',@rest);
1344: } else {
1345: $buttons.=&clear(@rest);
1346: }
1347: }
1348: }
1349: my ($showprogress,$linkprotout);
1350: if (($crstype eq 'Placement') && (!$env{'request.role.adv'})) {
1351: $showprogress = &placement_progress();
1352: }
1353: if ($env{'request.deeplink.login'}) {
1354: $linkprotout = &linkprot_exit();
1355: }
1356:
1357: my $addremote=0;
1358: foreach (@inlineremote) { if ($_ ne '') { $addremote=1; last;} }
1359:
1360: if ($addremote) {
1361: my ($countdown,$buttonshide);
1362: if ($env{'request.filename'} =~ /\.page$/) {
1363: my %breadcrumb_tools = &Apache::lonhtmlcommon::current_breadcrumb_tools();
1364: if (ref($breadcrumb_tools{'tools'}) eq 'ARRAY') {
1365: $countdown = $breadcrumb_tools{'tools'}->[0];
1366: }
1367: $buttonshide = $pagebuttonshide;
1368: } else {
1369: $countdown = &countdown_timer();
1370: $buttonshide = &hidden_button_check();
1371: }
1372: &Apache::lonhtmlcommon::clear_breadcrumb_tools();
1373:
1374: &Apache::lonhtmlcommon::add_breadcrumb_tool(
1375: 'navigation', @inlineremote[21,23]);
1376:
1377: if ($buttonshide eq 'yes') {
1378: if ($countdown) {
1379: &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$countdown);
1380: }
1381: if ($linkprotout) {
1382: &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$linkprotout);
1383: }
1384: if ($showprogress) {
1385: &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$showprogress);
1386: }
1387: } else {
1388: my @tools = @inlineremote[93,91,81,82,83];
1389: if ($countdown) {
1390: unshift(@tools,$countdown);
1391: }
1392: if ($linkprotout) {
1393: unshift(@tools,$linkprotout);
1394: }
1395: &Apache::lonhtmlcommon::add_breadcrumb_tool(
1396: 'tools',@tools);
1397:
1398: #publish button in construction space
1399: if ($env{'request.state'} eq 'construct'){
1400: &Apache::lonhtmlcommon::add_breadcrumb_tool(
1401: 'advtools', $inlineremote[63]);
1402: } else {
1403: &Apache::lonhtmlcommon::add_breadcrumb_tool(
1404: 'tools', $inlineremote[63]);
1405: }
1406: &advtools_crumbs(@inlineremote);
1407: }
1408: } else {
1409: if ($showprogress) {
1410: &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$showprogress);
1411: }
1412: if ($linkprotout) {
1413: &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$linkprotout);
1414: }
1415: }
1416: my ($topic_help,$topic_help_text);
1417: if ($is_const_dir == 2) {
1418: if ((($ENV{'SERVER_PORT'} == 443) ||
1419: ($Apache::lonnet::protocol{$Apache::lonnet::perlvar{'lonHostID'}} eq 'https')) &&
1420: (&Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},'webdav'))) {
1421: $topic_help = 'Authoring_WebDAV,Authoring_WebDAV_Mac_10v6,Authoring_WebDAV_Mac_10v10,'.
1422: 'Authoring_WebDAV_Windows_v7,Authoring_WebDAV_Linux_Centos';
1423: $topic_help_text = 'About WebDAV access';
1424: }
1425: }
1426: if (ref($showncrumbsref)) {
1427: $$showncrumbsref = 1;
1428: }
1429: return &Apache::lonhtmlcommon::scripttag('', 'start')
1430: . &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0,'','','','',$topic_help,$topic_help_text)
1431: . &Apache::lonhtmlcommon::scripttag('', 'end');
1432: }
1433:
1434: sub get_editbutton {
1435: my ($cfile,$home,$switchserver,$forceedit,$forceview,$forcereg,$hostname) = @_;
1436: my $jscall;
1437: if (($forceview) && ($env{'form.todocs'})) {
1438: my ($folderpath,$command,$navmap);
1439: if ($env{'request.symb'}) {
1440: $folderpath = &Apache::loncommon::symb_to_docspath($env{'request.symb'},\$navmap);
1441: } elsif ($env{'form.folderpath'} =~ /^supplemental/) {
1442: $folderpath = $env{'form.folderpath'};
1443: $command = '&forcesupplement=1';
1444: }
1445: $folderpath = &escape(&HTML::Entities::encode(&escape($folderpath),'<>&"'));
1446: $jscall = "go('/adm/coursedocs?folderpath=$folderpath$command')";
1447: } else {
1448: my $suppanchor;
1449: if ($env{'form.folderpath'}) {
1450: $suppanchor = $env{'form.anchor'};
1451: }
1452: my $shownsymb;
1453: if ($env{'request.symb'}) {
1454: $shownsymb = &Apache::lonenc::check_encrypt($env{'request.symb'});
1455: }
1456: $jscall = &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,$switchserver,
1457: $forceedit,$forcereg,$env{'request.symb'},$shownsymb,
1458: &escape($env{'form.folderpath'}),
1459: &escape($env{'form.title'}),$hostname,
1460: $env{'form.idx'},&escape($env{'form.suppurl'}),
1461: $env{'form.todocs'},$suppanchor);
1462: }
1463: if ($jscall) {
1464: my $icon = 'pcstr.png';
1465: my $label = 'Edit';
1466: if ($forceview) {
1467: $icon = 'tolastloc.png';
1468: $label = 'Exit Editing';
1469: }
1470: &switch('','',6,1,$icon,$label,'resource[_2]',
1471: $jscall,"Edit this resource");
1472: return 1;
1473: }
1474: return;
1475: }
1476:
1477: sub prepare_functions {
1478: my ($resurl,$forcereg,$group,$bread_crumbs,$advtools,$docscrumbs,$hostname) = @_;
1479: unless ($env{'request.registered'}) {
1480: undef(@inlineremote);
1481: }
1482: my ($cdom,$cnum,%perms,$cfile,$switchserver,$home,$forceedit,
1483: $forceview);
1484:
1485: if ($env{'request.course.id'}) {
1486: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1487: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1488: $perms{'mdc'} = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
1489: }
1490:
1491: my $editbutton = '';
1492: my $viewsrcbutton = '';
1493: my $clientip = &Apache::lonnet::get_requestor_ip();
1494: #
1495: # Determine whether or not to display 'Edit' or 'View Source' icon/button
1496: #
1497: if ($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) {
1498: my $blocked = &Apache::loncommon::blocking_status('about',$clientip,$2,$1);
1499: my $file=&Apache::lonnet::declutter($env{'request.filename'});
1500: ($cfile,$home,$switchserver,$forceedit,$forceview) =
1501: &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
1502: &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
1503: if (($cfile) && ($home ne '') && ($home ne 'no_host') && (!$blocked)) {
1504: $editbutton = &get_editbutton($cfile,$home,$switchserver,
1505: $forceedit,$forceview,$forcereg);
1506: }
1507: } elsif ((!$env{'request.course.id'}) &&
1508: ($env{'user.author'}) && ($env{'request.filename'}) &&
1509: ($env{'request.role'} !~/^(aa|ca|au)/)) {
1510: #
1511: # Currently do not have the role of author or co-author.
1512: # Do we have authoring privileges for the resource?
1513: #
1514: my $file=&Apache::lonnet::declutter($env{'request.filename'});
1515: ($cfile,$home,$switchserver,$forceedit,$forceview) =
1516: &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
1517: &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
1518: if (($cfile) && ($home ne '') && ($home ne 'no_host')) {
1519: $editbutton = &get_editbutton($cfile,$home,$switchserver,
1520: $forceedit,$forceview,$forcereg);
1521: }
1522: } elsif ($env{'request.course.id'}) {
1523: #
1524: # This applies in course context
1525: #
1526: if (($perms{'mdc'}) &&
1527: (($resurl =~ m{^/?public/$cdom/$cnum/syllabus}) ||
1528: ($resurl =~ m{^/?uploaded/$cdom/$cnum/portfolio/syllabus/}) ||
1529: (($resurl =~ m{^/?uploaded/$cdom/$cnum/default_\d+\.sequence$}) && ($env{'form.navmap'})))) {
1530: if ($resurl =~ m{^/}) {
1531: $cfile = $resurl;
1532: } else {
1533: $cfile = "/$resurl";
1534: }
1535: $home = &Apache::lonnet::homeserver($cnum,$cdom);
1536: if ($env{'form.forceedit'}) {
1537: $forceview = 1;
1538: } else {
1539: $forceedit = 1;
1540: }
1541: if ($cfile =~ m{^/uploaded/$cdom/$cnum/default_\d+\.sequence$}) {
1542: my $text = 'Edit Folder';
1543: &switch('','',7,4,'docs-22x22.png','Edit Folder','parms[_2]',
1544: "gocmd('/adm/coursedocs','direct')",
1545: 'Folder/Page Content');
1546: $editbutton = 1;
1547: } else {
1548: $editbutton = &get_editbutton($cfile,$home,$switchserver,
1549: $forceedit,$forceview,$forcereg,
1550: $hostname);
1551: }
1552: } elsif (($resurl eq '/adm/extresedit') &&
1553: (($env{'form.symb'}) || ($env{'form.folderpath'}))) {
1554: ($cfile,$home,$switchserver,$forceedit,$forceview) =
1555: &Apache::lonnet::can_edit_resource($resurl,$cnum,$cdom,$resurl,
1556: $env{'form.symb'});
1557: if ($cfile ne '') {
1558: $editbutton = &get_editbutton($cfile,$home,$switchserver,
1559: $forceedit,$forceview,$forcereg);
1560: }
1561: } elsif (($resurl =~ m{^/?adm/viewclasslist$}) &&
1562: (&Apache::lonnet::allowed('opa',$env{'request.course.id'}))) {
1563: ($cfile,$home,$switchserver,$forceedit,$forceview) =
1564: &Apache::lonnet::can_edit_resource($resurl,$cnum,$cdom,$resurl,
1565: $env{'form.symb'});
1566: $editbutton = &get_editbutton($cfile,$home,$switchserver,
1567: $forceedit,$forceview,$forcereg);
1568: } elsif (($resurl !~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) &&
1569: ($resurl ne '/cgi-bin/printout.pl')) {
1570: if ($env{'request.filename'}) {
1571: my $file=&Apache::lonnet::declutter($env{'request.filename'});
1572: ($cfile,$home,$switchserver,$forceedit,$forceview) =
1573: &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
1574: &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
1575: if ($cfile ne '') {
1576: $editbutton = &get_editbutton($cfile,$home,$switchserver,
1577: $forceedit,$forceview,$forcereg,
1578: $hostname);
1579: }
1580: if ((($cfile eq '') || (!$editbutton)) &&
1581: ($resurl =~ /$LONCAPA::assess_re/)) {
1582: my $showurl = &Apache::lonnet::clutter($resurl);
1583: my $crs_sec = $env{'request.course.id'} . (($env{'request.course.sec'} ne '')
1584: ? "/$env{'request.course.sec'}"
1585: : '');
1586: if ((&Apache::lonnet::allowed('cre','/')) &&
1587: (&Apache::lonnet::metadata($resurl,'sourceavail') eq 'open')) {
1588: $viewsrcbutton = 1;
1589: } elsif (&Apache::lonnet::allowed('vxc',$crs_sec)) {
1590: if ($showurl =~ m{^\Q/res/$cdom/\E($match_username)/}) {
1591: my $auname = $1;
1592: if (($env{'request.course.adhocsrcaccess'} ne '') &&
1593: (grep(/^\Q$auname\E$/,split(/,/,$env{'request.course.adhocsrcaccess'})))) {
1594: $viewsrcbutton = 1;
1595: } elsif ((&Apache::lonnet::metadata($resurl,'sourceavail') eq 'open') &&
1596: (&Apache::lonnet::allowed('bre',$crs_sec))) {
1597: $viewsrcbutton = 1;
1598: }
1599: }
1600: }
1601: if ($viewsrcbutton) {
1602: &switch('','',6,1,'pcstr.png','View Source','resource[_2]','open_source()',
1603: 'View source code');
1604: }
1605: }
1606: }
1607: }
1608: }
1609: # End determination of 'Edit' icon/button display
1610:
1611: if ($env{'request.course.id'}) {
1612: # This applies to about me page for users in a course
1613: if ($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) {
1614: my ($sdom,$sname) = ($1,$2);
1615: unless (&Apache::lonnet::is_course($sdom,$sname)) {
1616: my $blocked = &Apache::loncommon::blocking_status('about',$clientip,$sname,$sdom);
1617: unless ($blocked) {
1618: &switch('','',6,4,'mail-message-new-22x22.png','Message to user',
1619: '',
1620: "go('/adm/email?compose=individual&recname=$sname&recdom=$sdom')",
1621: 'Send message to specific user');
1622: }
1623: }
1624: my $hideprivileged = 1;
1625: if (&Apache::lonnet::in_course($sdom,$sname,$cdom,$cnum,undef,
1626: $hideprivileged)) {
1627: foreach my $priv ('vsa','vgr','srm') {
1628: $perms{$priv} = &Apache::lonnet::allowed($priv,$env{'request.course.id'});
1629: if (!$perms{$priv} && $env{'request.course.sec'} ne '') {
1630: $perms{$priv} =
1631: &Apache::lonnet::allowed($priv,"$env{'request.course.id'}/$env{'request.course.sec'}");
1632: }
1633: }
1634: if ($perms{'vsa'}) {
1635: &switch('','',6,5,'trck-22x22.png','Activity',
1636: '',
1637: "go('/adm/trackstudent?selected_student=$sname:$sdom')",
1638: 'View recent activity by this person');
1639: }
1640: if ($perms{'vgr'}) {
1641: &switch('','',6,6,'rsrv-22x22.png','Reservations',
1642: '',
1643: "go('/adm/slotrequest?command=showresv&origin=aboutme&uname=$sname&udom=$sdom')",
1644: 'Slot reservation history');
1645: }
1646: if ($perms{'srm'}) {
1647: &switch('','',6,7,'contact-new-22x22.png','Records',
1648: '',
1649: "go('/adm/email?recordftf=retrieve&recname=$sname&recdom=$sdom')",
1650: 'Add records');
1651: }
1652: }
1653: }
1654: if (($env{'form.folderpath'} =~ /^supplemental/) &&
1655: (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) &&
1656: (($resurl =~ m{^/adm/wrapper/ext/}) ||
1657: ($resurl =~ m{^/adm/$cdom/$cnum/\d+/ext\.tool$}) ||
1658: ($resurl =~ m{^/uploaded/$cdom/$cnum/supplemental/}) ||
1659: ($resurl eq '/adm/supplemental') ||
1660: ($resurl =~ m{^/public/$cdom/$cnum/syllabus$}) ||
1661: ($resurl =~ m{^/adm/$match_domain/$match_username/aboutme$}))) {
1662: my @folders=split('&',$env{'form.folderpath'});
1663: if ((@folders > 2) || ($resurl ne '/adm/supplemental')) {
1664: my $suppanchor;
1665: if ($resurl =~ m{^/adm/wrapper/ext/}) {
1666: $suppanchor = $env{'form.anchor'};
1667: }
1668: my $esc_path=&escape(&HTML::Entities::encode(&escape($env{'form.folderpath'}),'<>&"'));
1669: my $link = '/adm/coursedocs?command=direct&forcesupplement=1&supppath='.
1670: "$esc_path&anchor=$suppanchor";
1671: if ($env{'request.use_absolute'} ne '') {
1672: $link = $env{'request.use_absolute'}.$link;
1673: }
1674: &switch('','',7,4,'docs-22x22.png','Edit Folder','parms[_2]',
1675: "location.href='$link'",'Folder/Page Content');
1676: }
1677: }
1678: }
1679:
1680: # End checking for items for about me page for users in a course
1681: if ($docscrumbs) {
1682: &Apache::lonhtmlcommon::clear_breadcrumb_tools();
1683: &advtools_crumbs(@inlineremote);
1684: return $editbutton;
1685: } elsif ($env{'request.registered'}) {
1686: return $editbutton || $viewsrcbutton;
1687: } else {
1688: if (ref($bread_crumbs) eq 'ARRAY') {
1689: if (@inlineremote > 0) {
1690: if (ref($advtools) eq 'ARRAY') {
1691: @{$advtools} = @inlineremote;
1692: }
1693: }
1694: return;
1695: } elsif (@inlineremote > 0) {
1696: &Apache::lonhtmlcommon::clear_breadcrumb_tools();
1697: &advtools_crumbs(@inlineremote);
1698: return &Apache::lonhtmlcommon::scripttag('', 'start')
1699: . &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0)
1700: . &Apache::lonhtmlcommon::scripttag('', 'end');
1701: }
1702: }
1703: }
1704:
1705: sub advtools_crumbs {
1706: my @funcs = @_;
1707: if ($env{'request.noversionuri'} =~ m{^/adm/$match_domain/$match_username/aboutme$}) {
1708: &Apache::lonhtmlcommon::add_breadcrumb_tool(
1709: 'advtools', @funcs[61,64,65,66,67,74]);
1710: } elsif ($env{'request.noversionuri'} !~ m{^/adm/(navmaps|viewclasslist)(\?|$)}) {
1711: if ($env{'request.state'} eq 'construct') {
1712: &Apache::lonhtmlcommon::add_breadcrumb_tool(
1713: 'advtools', @funcs[61,73,74,71,72]);
1714: } else {
1715: &Apache::lonhtmlcommon::add_breadcrumb_tool(
1716: 'advtools', @funcs[61,71,72,73,74,75,92]);
1717: }
1718: } elsif ($env{'request.noversionuri'} eq '/adm/viewclasslist') {
1719: &Apache::lonhtmlcommon::add_breadcrumb_tool(
1720: 'advtools', $funcs[61]);
1721: }
1722: return;
1723: }
1724:
1725: # ================================================================== Raw Config
1726:
1727: sub clear {
1728: my ($row,$col)=@_;
1729: $inlineremote[10*$row+$col]='';
1730: return '';
1731: }
1732:
1733: # ============================================ Switch a button or create a link
1734: # Switch acts on the javascript that is executed when a button is clicked.
1735: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
1736:
1737: sub switch {
1738: my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat,$nobreak,$form)=@_;
1739: $act=~s/\$uname/$uname/g;
1740: $act=~s/\$udom/$udom/g;
1741: $top=&mt($top);
1742: $bot=&mt($bot);
1743: $desc=&mt($desc);
1744: my $idx=10*$row+$col;
1745: $category_members{$cat}.=':'.$idx;
1746:
1747: # Inline Menu
1748: if ($nobreak==2) { return ''; }
1749: my $text=$top.' '.$bot;
1750: $text=~s/\s*\-\s*//gs;
1751:
1752: my $pic=
1753: '<img alt="'.$text.'" src="'.
1754: &Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$img).
1755: '" align="'.($nobreak==3?'right':'left').'" class="LC_icon" />';
1756: if ($env{'browser.interface'} eq 'faketextual') {
1757: # Main Menu
1758: if ($nobreak==3) {
1759: $inlineremote[$idx]="\n".
1760: '<td class="LC_menubuttons_text" align="right">'.$text.
1761: '</td><td align="left">'.
1762: '<a href="javascript:'.$act.';">'.$pic.'</a></td></tr>';
1763: } elsif ($nobreak) {
1764: $inlineremote[$idx]="\n<tr>".
1765: '<td align="left">'.
1766: '<a href="javascript:'.$act.';">'.$pic.'</a></td>
1767: <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>';
1768: } else {
1769: $inlineremote[$idx]="\n<tr>".
1770: '<td align="left">'.
1771: '<a href="javascript:'.$act.';">'.$pic.
1772: '</a></td><td class="LC_menubuttons_text" colspan="3">'.
1773: '<a class="LC_menubuttons_link" href="javascript:'.$act.';"><span class="LC_menubuttons_inline_text">'.$desc.'</span></a></td></tr>';
1774: }
1775: } else {
1776: # Inline Menu
1777: my @tools = (93,91,81,82,83);
1778: unless ($env{'request.state'} eq 'construct') {
1779: push(@tools,63);
1780: }
1781: if ((($env{'environment.icons'} eq 'iconsonly') ||
1782: ($env{'environment.icons'} eq '') && ($env{'request.lti.login'})) &&
1783: (grep(/^$idx$/,@tools))) {
1784: $inlineremote[$idx] =
1785: '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.'</a>';
1786: } else {
1787: $inlineremote[$idx] =
1788: '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.
1789: '<span class="LC_menubuttons_inline_text">'.$top.' </span></a>'.$form;
1790: }
1791: }
1792: return '';
1793: }
1794:
1795: sub secondlevel {
1796: my $output='';
1797: my
1798: ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat)=@_;
1799: if ($prt eq 'any') {
1800: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1801: } elsif ($prt=~/^r(\w+)/) {
1802: if ($rol eq $1) {
1803: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1804: }
1805: }
1806: return $output;
1807: }
1808:
1809: sub inlinemenu {
1810: undef(@inlineremote);
1811: undef(%category_members);
1812: # calling rawconfig with "1" will evaluate mydesk.tab, even if there is no active remote control
1813: &rawconfig(1);
1814: my $output='<table><tr>';
1815: for (my $col=1; $col<=2; $col++) {
1816: $output.='<td class="LC_mainmenu_col_fieldset">';
1817: for (my $row=1; $row<=8; $row++) {
1818: foreach my $cat (keys(%category_members)) {
1819: if ($category_positions{$cat} ne "$col,$row") { next; }
1820: #$output.='<table><tr><td colspan="4" class="LC_menubuttons_category">'.&mt($category_names{$cat}).'</td></tr>';
1821: $output.='<div class="LC_Box LC_400Box">';
1822: $output.='<h3 class="LC_hcell">'.&mt($category_names{$cat}).'</h3>';
1823: $output.='<table>';
1824: my %active=();
1825: foreach my $menu_item (split(/\:/,$category_members{$cat})) {
1826: if ($inlineremote[$menu_item]) {
1827: $active{$menu_item}=1;
1828: }
1829: }
1830: foreach my $item (sort(keys(%active))) {
1831: $output.=$inlineremote[$item];
1832: }
1833: $output.='</table>';
1834: $output.='</div>';
1835: }
1836: }
1837: $output.="</td>";
1838: }
1839: $output.="</tr></table>";
1840: return $output;
1841: }
1842:
1843: sub rawconfig {
1844: #
1845: # This evaluates mydesk.tab
1846: # Need to add more positions and more privileges to deal with all
1847: # menu items.
1848: #
1849: my $textualoverride=shift;
1850: my $output='';
1851: return '' unless $textualoverride;
1852: my $uname=$env{'user.name'};
1853: my $udom=$env{'user.domain'};
1854: my $adv=$env{'user.adv'};
1855: my $show_course=&Apache::loncommon::show_course();
1856: my $author=$env{'user.author'};
1857: my $crs='';
1858: my $crstype='';
1859: if ($env{'request.course.id'}) {
1860: $crs='/'.$env{'request.course.id'};
1861: if ($env{'request.course.sec'}) {
1862: $crs.='_'.$env{'request.course.sec'};
1863: }
1864: $crs=~s/\_/\//g;
1865: $crstype = &Apache::loncommon::course_type();
1866: }
1867: my $pub=($env{'request.state'} eq 'published');
1868: my $con=($env{'request.state'} eq 'construct');
1869: my $rol=$env{'request.role'};
1870: my $requested_domain;
1871: if ($rol) {
1872: $requested_domain = $env{'request.role.domain'};
1873: }
1874: foreach my $line (@desklines) {
1875: my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc,$cat)=split(/\:/,$line);
1876: $prt=~s/\$uname/$uname/g;
1877: $prt=~s/\$udom/$udom/g;
1878: if ($prt =~ /\$crs/) {
1879: next unless ($env{'request.course.id'});
1880: next if ($crstype eq 'Community');
1881: $prt=~s/\$crs/$crs/g;
1882: } elsif ($prt =~ /\$cmty/) {
1883: next unless ($env{'request.course.id'});
1884: next if ($crstype ne 'Community');
1885: $prt=~s/\$cmty/$crs/g;
1886: }
1887: if ($prt =~ m/\$requested_domain/) {
1888: if ((!$requested_domain) && ($pro eq 'pbre') && ($env{'user.adv'})) {
1889: $prt=~s/\$requested_domain/$env{'user.domain'}/g;
1890: } else {
1891: $prt=~s/\$requested_domain/$requested_domain/g;
1892: }
1893: }
1894: if ($category_names{$cat}!~/\w/) { $cat='oth'; }
1895: if ($pro eq 'clear') {
1896: $output.=&clear($row,$col);
1897: } elsif ($pro eq 'any') {
1898: $output.=&secondlevel(
1899: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1900: } elsif ($pro eq 'smp') {
1901: unless ($adv) {
1902: $output.=&secondlevel(
1903: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1904: }
1905: } elsif ($pro eq 'adv') {
1906: if ($adv) {
1907: $output.=&secondlevel(
1908: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1909: }
1910: } elsif ($pro eq 'shc') {
1911: if ($show_course) {
1912: $output.=&secondlevel(
1913: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1914: }
1915: } elsif ($pro eq 'nsc') {
1916: if (!$show_course) {
1917: $output.=&secondlevel(
1918: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1919: }
1920: } elsif (($pro=~/^p(\w+)/) && ($prt)) {
1921: my $priv = $1;
1922: if ($priv =~ /^mdc(Course|Community)/) {
1923: if ($crstype eq $1) {
1924: $priv = 'mdc';
1925: } else {
1926: next;
1927: }
1928: }
1929: if ((($priv eq 'bre') && (&Apache::lonnet::allowed($priv,$prt) eq 'F')) ||
1930: (($priv ne 'bre') && (&Apache::lonnet::allowed($priv,$prt)))) {
1931: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1932: }
1933: } elsif ($pro eq 'course') {
1934: if (($env{'request.course.fn'}) && ($crstype ne 'Community')) {
1935: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1936: }
1937: } elsif ($pro eq 'community') {
1938: if (($env{'request.course.fn'}) && ($crstype eq 'Community')) {
1939: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1940: }
1941: } elsif ($pro =~ /^courseenv_(.*)$/) {
1942: my $key = $1;
1943: if ($crstype ne 'Community') {
1944: my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
1945: if ($key eq 'canuse_pdfforms') {
1946: if ($env{'request.course.id'} && $coursepref eq '') {
1947: my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
1948: $coursepref = $domdefs{'canuse_pdfforms'};
1949: }
1950: }
1951: if ($coursepref) {
1952: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1953: }
1954: }
1955: } elsif ($pro =~ /^communityenv_(.*)$/) {
1956: my $key = $1;
1957: if ($crstype eq 'Community') {
1958: my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
1959: if ($key eq 'canuse_pdfforms') {
1960: if ($env{'request.course.id'} && $coursepref eq '') {
1961: my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
1962: $coursepref = $domdefs{'canuse_pdfforms'};
1963: }
1964: }
1965: if ($coursepref) {
1966: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1967: }
1968: }
1969: } elsif ($pro =~ /^course_(.*)$/) {
1970: # Check for permissions inside of a course
1971: if (($env{'request.course.id'}) && ($crstype ne 'Community') &&
1972: (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
1973: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
1974: )) {
1975: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1976: }
1977: } elsif ($pro =~ /^community_(.*)$/) {
1978: # Check for permissions inside of a community
1979: if (($env{'request.course.id'}) && ($crstype eq 'Community') &&
1980: (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
1981: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
1982: )) {
1983: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1984: }
1985: } elsif ($pro eq 'author') {
1986: if ($author) {
1987: if ((($prt eq 'rca') && ($env{'request.role'}=~/^ca/)) ||
1988: (($prt eq 'raa') && ($env{'request.role'}=~/^aa/)) ||
1989: (($prt eq 'rau') && ($env{'request.role'}=~/^au/))) {
1990: # Check that we are on the correct machine
1991: my $cadom=$requested_domain;
1992: my $caname=$env{'user.name'};
1993: if (($prt eq 'rca') || ($prt eq 'raa')) {
1994: ($cadom,$caname)=
1995: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1996: }
1997: $act =~ s/\$caname/$caname/g;
1998: $act =~ s/\$cadom/$cadom/g;
1999: my $home = &Apache::lonnet::homeserver($caname,$cadom);
2000: my $allowed=0;
2001: my @ids=&Apache::lonnet::current_machine_ids();
2002: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
2003: if ($allowed) {
2004: $output.=&switch($caname,$cadom,
2005: $row,$col,$img,$top,$bot,$act,$desc,$cat);
2006: }
2007: }
2008: }
2009: } elsif ($pro eq 'tools') {
2010: my @tools = ('aboutme','blog','portfolio');
2011: if (grep(/^\Q$prt\E$/,@tools)) {
2012: if (!&Apache::lonnet::usertools_access($env{'user.name'},
2013: $env{'user.domain'},
2014: $prt,undef,'tools')) {
2015: $output.=&clear($row,$col);
2016: next;
2017: }
2018: } elsif (($prt eq 'reqcrsnsc') || ($prt eq 'reqcrsshc')) {
2019: if (($prt eq 'reqcrsnsc') && ($show_course)) {
2020: next;
2021: }
2022: if (($prt eq 'reqcrsshc') && (!$show_course)) {
2023: next;
2024: }
2025: my $showreqcrs = &check_for_rcrs();
2026: if (!$showreqcrs) {
2027: $output.=&clear($row,$col);
2028: next;
2029: }
2030: }
2031: $prt='any';
2032: $output.=&secondlevel(
2033: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
2034: }
2035: }
2036: return $output;
2037: }
2038:
2039: sub check_for_rcrs {
2040: my $showreqcrs = 0;
2041: my @reqtypes = ('official','unofficial','community','textbook','placement');
2042: foreach my $type (@reqtypes) {
2043: if (&Apache::lonnet::usertools_access($env{'user.name'},
2044: $env{'user.domain'},
2045: $type,undef,'requestcourses')) {
2046: $showreqcrs = 1;
2047: last;
2048: }
2049: }
2050: if (!$showreqcrs) {
2051: foreach my $type (@reqtypes) {
2052: if ($env{'environment.reqcrsotherdom.'.$type} ne '') {
2053: my @domains = split(',',$env{'environment.reqcrsotherdom.'.$type});
2054: foreach my $entry (@domains) {
2055: my ($extdom,$extopt) = split(':',$entry);
2056: if (&Apache::lonnet::will_trust('reqcrs',$env{'user.domain'},$extdom)) {
2057: $showreqcrs = 1;
2058: last;
2059: }
2060: }
2061: if ($showreqcrs) {
2062: last;
2063: }
2064: }
2065: }
2066: }
2067: return $showreqcrs;
2068: }
2069:
2070: sub dc_popup_js {
2071: my %lt = &Apache::lonlocal::texthash(
2072: more => '(More ...)',
2073: less => '(Less ...)',
2074: );
2075: return <<"END";
2076:
2077: function showCourseID() {
2078: document.getElementById('dccid').style.display='block';
2079: document.getElementById('dccid').style.textAlign='left';
2080: document.getElementById('dccid').style.textFace='normal';
2081: document.getElementById('dccidtext').innerHTML ='<a href="javascript:hideCourseID();" class="LC_menubuttons_link">$lt{'less'}</a>';
2082: return;
2083: }
2084:
2085: function hideCourseID() {
2086: document.getElementById('dccid').style.display='none';
2087: document.getElementById('dccidtext').innerHTML ='<a href="javascript:showCourseID()" class="LC_menubuttons_link">$lt{'more'}</a>';
2088: return;
2089: }
2090:
2091: END
2092:
2093: }
2094:
2095: sub countdown_toggle_js {
2096: return <<"END";
2097:
2098: function toggleCountdown() {
2099: var countdownid = document.getElementById('duedatecountdown');
2100: var currstyle = countdownid.style.display;
2101: if (currstyle == 'inline') {
2102: countdownid.style.display = 'none';
2103: document.getElementById('ddcountcollapse').innerHTML='';
2104: document.getElementById('ddcountexpand').innerHTML='◄ ';
2105: } else {
2106: countdownid.style.display = 'inline';
2107: document.getElementById('ddcountcollapse').innerHTML='► ';
2108: document.getElementById('ddcountexpand').innerHTML='';
2109: }
2110: return;
2111: }
2112:
2113: END
2114: }
2115:
2116: # This creates a "done button" for timed events. The confirmation box is a jQuery
2117: # dialog widget. If the interval parameter requires a proctor key for the timed
2118: # event to be marked done, there will also be a textbox where that can be entered.
2119: # Clicking OK will set the value of LC_interval_done to 'true', and, if needed will
2120: # set the value of LC_interval_done_proctorpass to the text entered in that box,
2121: # and submit the corresponding form.
2122: #
2123: # The &zero_time() routine in lonhomework.pm is called when a page is rendered if
2124: # LC_interval_done is true.
2125: #
2126: sub done_button_js {
2127: my ($type,$width,$height,$proctor,$donebuttontext) = @_;
2128: return unless (($type eq 'map') || ($type eq 'resource'));
2129: my %lt = &Apache::lonlocal::texthash(
2130: title => 'WARNING!',
2131: preamble => 'You are trying to end this timed event early.',
2132: map => 'Confirming that you are done will cause the time to expire and prevent you from changing any answers in the current folder.',
2133: resource => 'Confirming that you are done will cause the time to expire for this question, and prevent you from changing your answer(s).',
2134: okdone => 'Click "OK" if you are completely finished.',
2135: cancel => 'Click "Cancel" to continue working.',
2136: proctor => 'Ask a proctor to enter the key, then click "OK" if you are completely finished.',
2137: ok => 'OK',
2138: exit => 'Cancel',
2139: key => 'Key:',
2140: nokey => 'A proctor key is required',
2141: );
2142: my $shownsymb = &HTML::Entities::encode(&Apache::lonenc::check_encrypt($env{'request.symb'}));
2143: my $navmap = Apache::lonnavmaps::navmap->new();
2144: my ($missing,$tried) = (0,0);
2145: if (ref($navmap)) {
2146: my @resources=();
2147: if ($type eq 'map') {
2148: my ($mapurl,$rid,$resurl)=&Apache::lonnet::decode_symb($env{'request.symb'});
2149: if ($env{'request.symb'} =~ /\.page$/) {
2150: @resources=$navmap->retrieveResources($resurl,sub { $_[0]->is_problem() });
2151: } else {
2152: @resources=$navmap->retrieveResources($mapurl,sub { $_[0]->is_problem() });
2153: }
2154: } else {
2155: my $res = $navmap->getBySymb($env{'request.symb'});
2156: if (ref($res)) {
2157: if ($res->is_problem()) {
2158: push(@resources,$res);
2159: }
2160: }
2161: }
2162: foreach my $res (@resources) {
2163: if (ref($res->parts()) eq 'ARRAY') {
2164: foreach my $part (@{$res->parts()}) {
2165: if (!$res->tries($part)) {
2166: $missing++;
2167: } else {
2168: $tried++;
2169: }
2170: }
2171: }
2172: }
2173: }
2174: if ($missing) {
2175: $lt{'miss'} .= '<p class="LC_error">';
2176: if ($type eq 'map') {
2177: $lt{'miss'} .= &mt('Submissions are missing for [quant,_1,question part,question parts] in this folder.',$missing);
2178: } else {
2179: $lt{'miss'} .= &mt('Submissions are missing for [quant,_1,part] in this question.',$missing);
2180: }
2181: if ($missing > 1) {
2182: $lt{'miss'} .= ' '.&mt('If you confirm you are done you will be unable to submit answers for them.').'</span>';
2183: } else {
2184: $lt{'miss'} .= ' '.&mt('If you confirm you are done you will be unable to submit an answer for it.').'</p>';
2185: }
2186: }
2187: $donebuttontext = &HTML::Entities::encode($donebuttontext,'<>&"');
2188: if ($proctor) {
2189: if ($height !~ /^\d+$/) {
2190: $height = 400;
2191: if ($missing) {
2192: $height += 60;
2193: }
2194: }
2195: if ($width !~ /^\d+$/) {
2196: $width = 400;
2197: if ($missing) {
2198: $width += 60;
2199: }
2200: }
2201: return <<END;
2202: <form method="post" name="LCdoneButton" action="">
2203: <input type="hidden" name="LC_interval_done" value="" />
2204: <input type="hidden" name="LC_interval_done_proctorpass" value="" />
2205: <input type="hidden" name="symb" value="$shownsymb" />
2206: <button id="LC_done-confirm-opener" type="button">$donebuttontext</button>
2207: </form>
2208:
2209: <div id="LC_done-confirm" title="$lt{'title'}">
2210: <p>$lt{'preamble'} $lt{$type}</p>
2211: $lt{'miss'}
2212: <p>$lt{'proctor'}</p>
2213: <form name="LCdoneButtonProctor" action="">
2214: <label>$lt{'key'}<input type="password" name="LC_interval_done_proctorkey" value="" /></label>
2215: <input type="submit" tabindex="-1" style="position:absolute; top:-1000px" />
2216: </form>
2217: <p>$lt{'cancel'}</p>
2218: </div>
2219:
2220: <script type="text/javascript">
2221: // <![CDATA[
2222: \$( "#LC_done-confirm" ).dialog({ autoOpen: false });
2223: \$( "#LC_done-confirm-opener" ).on("click", function() {
2224: \$( "#LC_done-confirm" ).dialog("open");
2225: \$( "#LC_done-confirm" ).dialog({
2226: height: $height,
2227: width: $width,
2228: modal: true,
2229: resizable: false,
2230: buttons: [
2231: {
2232: text: "$lt{'ok'}",
2233: click: function() {
2234: var proctorkey = \$( '[name="LC_interval_done_proctorkey"]' )[0].value;
2235: if ((proctorkey == '') || (proctorkey == null)) {
2236: alert("$lt{'nokey'}");
2237: } else {
2238: \$( '[name="LC_interval_done"]' )[0].value = 'true';
2239: \$( '[name="LC_interval_done_proctorpass"]' )[0].value = proctorkey;
2240: \$( '[name="LCdoneButton"]' )[0].submit();
2241: }
2242: },
2243: },
2244: {
2245: text: "$lt{'exit'}",
2246: click: function() {
2247: \$("#LC_done-confirm").dialog( "close" );
2248: }
2249: }
2250: ],
2251: close: function() {
2252: \$( '[name="LC_interval_done_proctorkey"]' )[0].value = '';
2253: }
2254: });
2255: \$( "#LC_done-confirm" ).find( "form" ).on( "submit", function( event ) {
2256: event.preventDefault();
2257: \$( '[name="LC_interval_done"]' )[0].value = 'true';
2258: \$( '[name="LC_interval_done_proctorpass"]' )[0].value = \$( '[name="LC_interval_done_proctorkey"]' )[0].value;
2259: \$( '[name="LCdoneButton"]' )[0].submit();
2260: });
2261: });
2262:
2263: // ]]>
2264: </script>
2265:
2266: END
2267: } else {
2268: if ($height !~ /^\d+$/) {
2269: $height = 320;
2270: if ($missing) {
2271: $height += 60;
2272: }
2273: }
2274: if ($width !~ /^\d+$/) {
2275: $width = 320;
2276: if ($missing) {
2277: $width += 60;
2278: }
2279: }
2280: if ($missing) {
2281: $lt{'miss'} = '</p>'.$lt{'miss'}.'<p>';
2282: }
2283: return <<END;
2284:
2285: <form method="post" name="LCdoneButton" action="">
2286: <input type="hidden" name="LC_interval_done" value="" />
2287: <input type="hidden" name="symb" value="$shownsymb" />
2288: <button id="LC_done-confirm-opener" type="button">$donebuttontext</button>
2289: </form>
2290:
2291: <div id="LC_done-confirm" title="$lt{'title'}">
2292: <p>$lt{'preamble'} $lt{$type} $lt{'miss'} $lt{'okdone'} $lt{'cancel'}</p>
2293: </div>
2294:
2295: <script type="text/javascript">
2296: // <![CDATA[
2297: \$( "#LC_done-confirm" ).dialog({ autoOpen: false });
2298: \$( "#LC_done-confirm-opener" ).click(function() {
2299: \$( "#LC_done-confirm" ).dialog( "open" );
2300: \$( "#LC_done-confirm" ).dialog({
2301: resizable: false,
2302: height: $height,
2303: width: $width,
2304: modal: true,
2305: buttons: [
2306: {
2307: text: "$lt{'ok'}",
2308: click: function() {
2309: \$( this ).dialog( "close" );
2310: \$( '[name="LC_interval_done"]' )[0].value = 'true';
2311: \$( '[name="LCdoneButton"]' )[0].submit();
2312: },
2313: },
2314: {
2315: text: "$lt{'exit'}",
2316: click: function() {
2317: \$( this ).dialog( "close" );
2318: },
2319: },
2320: ],
2321: });
2322: });
2323: // ]]>
2324: </script>
2325:
2326: END
2327: }
2328: }
2329:
2330: sub view_as_js {
2331: my ($url,$symb) = @_;
2332: my %lt = &Apache::lonlocal::texthash(
2333: ente => 'Enter a username or a student/employee ID',
2334: info => 'Information you entered does not match a valid course user',
2335: );
2336: &js_escape(\%lt);
2337: return <<"END";
2338:
2339: function toggleViewAsUser(change) {
2340: var seluserid = document.getElementById('LC_selectuser');
2341: var currstyle = seluserid.style.display;
2342: if (change == 'off') {
2343: document.userview.elements['LC_viewas'].value = '';
2344: document.userview.elements['vuname'].value = '';
2345: document.userview.elements['vid'].value = '';
2346: document.userview.submit();
2347: return;
2348: }
2349: if (currstyle == 'inline') {
2350: seluserid.style.display = 'none';
2351: document.getElementById('usexpand').innerHTML='► ';
2352: document.getElementById('uscollapse').innerHTML='';
2353: } else {
2354: seluserid.style.display = 'inline';
2355: document.getElementById('usexpand').innerHTML='';
2356: document.getElementById('uscollapse').innerHTML='◄ ';
2357: }
2358: return;
2359: }
2360:
2361: function validCourseUser(form,change) {
2362: var possuname = form.elements['vuname'].value;
2363: var possuid = form.elements['vid'].value;
2364: var possudom = form.elements['vudom'].options[form.elements['vudom'].selectedIndex].value;
2365: if ((possuname == '') && (possuid == '')) {
2366: if (change == 'off') {
2367: form.elements['LC_viewas'].value = '';
2368: form.submit();
2369: } else {
2370: alert("$lt{'ente'}");
2371: }
2372: return;
2373: }
2374: var http = new XMLHttpRequest();
2375: var url = "/adm/courseuser";
2376: var params = "uname="+possuname+"&uid="+possuid+"&udom="+possudom;
2377: http.open("POST", url, true);
2378: http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
2379: http.onreadystatechange = function() {
2380: if (http.readyState == 4 && http.status == 200) {
2381: var data = JSON.parse(http.responseText);
2382: if (Array.isArray(data.match)) {
2383: var len = data.match.length;
2384: if (len == 2) {
2385: if (data.match[0] != '' && data.match[1] != '') {
2386: form.elements['LC_viewas'].value = data.match[0]+':'+data.match[1];
2387: form.submit();
2388: }
2389: } else {
2390: alert("$lt{'info'}");
2391: }
2392: }
2393: }
2394: return;
2395: }
2396: http.send(params);
2397: return false;
2398: }
2399:
2400: END
2401: }
2402:
2403: sub utilityfunctions {
2404: my ($httphost) = @_;
2405: my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
2406: my $currentsymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
2407: if ($currenturl =~ m{^/adm/wrapper/ext/}) {
2408: if ($env{'request.external.querystring'}) {
2409: $currenturl .= ($currenturl=~/\?/)?'&':'?'.$env{'request.external.querystring'};
2410: }
2411: my ($anchor) = ($env{'request.symb'} =~ /(\#[^\#]+)$/);
2412: if (($anchor) && ($currenturl !~ /\Q$anchor\E$/)) {
2413: $currenturl .= $1;
2414: }
2415: }
2416: $currenturl=&Apache::lonenc::check_encrypt(&unescape($currenturl));
2417:
2418: my $dc_popup_cid;
2419: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
2420: $env{'course.'.$env{'request.course.id'}.
2421: '.domain'}.'/'})) {
2422: $dc_popup_cid = &dc_popup_js();
2423: }
2424:
2425: my $start_page_annotate =
2426: &Apache::loncommon::start_page('Annotator',undef,
2427: {'only_body' => 1,
2428: 'js_ready' => 1,
2429: 'bgcolor' => '#BBBBBB',
2430: 'add_entries' => {
2431: 'onload' => 'javascript:document.goannotate.submit();'}});
2432:
2433: my $end_page_annotate =
2434: &Apache::loncommon::end_page({'js_ready' => 1});
2435:
2436: my $jumptores = &Apache::lonhtmlcommon::javascript_jumpto_resource();
2437:
2438: my $esc_url=&escape($currenturl);
2439: my $esc_symb=&escape($currentsymb);
2440: my $newname = &mt('New Name');
2441:
2442: my $countdown = &countdown_toggle_js();
2443:
2444: my $viewuser;
2445: if (($env{'request.course.id'}) &&
2446: ($env{'request.symb'} ne '') &&
2447: ($env{'request.filename'}=~/$LONCAPA::assess_re/)) {
2448: my $canview;
2449: foreach my $priv ('msg','vgr') {
2450: $canview = &Apache::lonnet::allowed($priv,$env{'request.course.id'});
2451: if (!$canview && $env{'request.course.sec'} ne '') {
2452: $canview =
2453: &Apache::lonnet::allowed($priv,"$env{'request.course.id'}/$env{'request.course.sec'}");
2454: }
2455: last if ($canview);
2456: }
2457: if ($canview) {
2458: $viewuser = &view_as_js($esc_url,$esc_symb);
2459: }
2460: }
2461:
2462: my ($ltitarget,$deeplinktarget);
2463: if ($env{'request.lti.login'}) {
2464: $ltitarget = $env{'request.lti.target'};
2465: }
2466: if ($env{'request.deeplink.login'}) {
2467: $deeplinktarget = $env{'request.deeplink.target'};
2468: }
2469:
2470: my $annotateurl = '/adm/annotation';
2471: if ($httphost) {
2472: $annotateurl = '/adm/annotations';
2473: }
2474: my $hostvar = '
2475: function setLCHost() {
2476: var lcHostname="";
2477: ';
2478: if ($httphost =~ m{^https?\://}) {
2479: $hostvar .= ' var lcServer="'.$httphost.'";'."\n".
2480: ' var hostReg = /^https?:\/\/([^\/]+)$/i;'."\n".
2481: ' var match = hostReg.exec(lcServer);'."\n".
2482: ' if (match.length) {'."\n".
2483: ' if (match[1] == location.hostname) {'."\n".
2484: ' lcHostname=lcServer;'."\n".
2485: ' }'."\n".
2486: ' }'."\n";
2487: }
2488:
2489: $hostvar .= ' return lcHostname;'."\n".
2490: '}'."\n";
2491:
2492: return (<<ENDUTILITY)
2493: $hostvar
2494: var currentURL=unescape("$esc_url");
2495: var reloadURL=unescape("$esc_url");
2496: var currentSymb=unescape("$esc_symb");
2497:
2498: $dc_popup_cid
2499:
2500: $jumptores
2501:
2502: function gopost(url,postdata) {
2503: if (url!='') {
2504: var lcHostname = setLCHost();
2505: this.document.server.action=lcHostname+url;
2506: this.document.server.postdata.value=postdata;
2507: this.document.server.command.value='';
2508: this.document.server.url.value='';
2509: this.document.server.symb.value='';
2510: this.document.server.submit();
2511: }
2512: }
2513:
2514: function gocmd(url,cmd) {
2515: if (url!='') {
2516: var lcHostname = setLCHost();
2517: this.document.server.action=lcHostname+url;
2518: this.document.server.postdata.value='';
2519: this.document.server.command.value=cmd;
2520: this.document.server.url.value=currentURL;
2521: this.document.server.symb.value=currentSymb;
2522: this.document.server.submit();
2523: }
2524: }
2525:
2526: function gocstr(url,filename) {
2527: if (url == '/adm/cfile?action=delete') {
2528: this.document.cstrdelete.filename.value = filename
2529: this.document.cstrdelete.submit();
2530: return;
2531: }
2532: if ((url == '/adm/cfile?action=copy') || (url == '/adm/cfile?action=rename')) {
2533: this.document.cstrcopy.filename.value = filename;
2534: var oldname = filename.substring(filename.lastIndexOf("/") + 1);
2535: var newname=prompt('$newname',oldname);
2536: if (newname == "" || !newname || newname == oldname) {
2537: return;
2538: }
2539: if (url == '/adm/cfile?action=rename') {
2540: this.document.cstrcopy.action.value = 'rename';
2541: } else {
2542: this.document.cstrcopy.action.value = 'copy';
2543: }
2544: this.document.cstrcopy.newfilename.value = newname;
2545: this.document.cstrcopy.submit();
2546: return;
2547: }
2548: if (url == '/adm/printout') {
2549: this.document.cstrprint.postdata.value = filename
2550: this.document.cstrprint.curseed.value = 0;
2551: this.document.cstrprint.problemtype.value = 0;
2552: if (this.document.lonhomework) {
2553: if ((this.document.lonhomework.rndseed) && (this.document.lonhomework.rndseed.value != null) && (this.document.lonhomework.rndseed.value != '')) {
2554: this.document.cstrprint.curseed.value = this.document.lonhomework.rndseed.value
2555: }
2556: if (this.document.lonhomework.problemtype) {
2557: if (this.document.lonhomework.problemtype.value) {
2558: this.document.cstrprint.problemtype.value =
2559: this.document.lonhomework.problemtype.value;
2560: } else if (this.document.lonhomework.problemtype.options) {
2561: for (var i=0; i<this.document.lonhomework.problemtype.options.length; i++) {
2562: if (this.document.lonhomework.problemtype.options[i].selected) {
2563: if (this.document.lonhomework.problemtype.options[i].value != null && this.document.lonhomework.problemtype.options[i].value != '') {
2564: this.document.cstrprint.problemtype.value = this.document.lonhomework.problemtype.options[i].value
2565: }
2566: }
2567: }
2568: }
2569: }
2570: }
2571: this.document.cstrprint.submit();
2572: return;
2573: }
2574: if (url !='') {
2575: this.document.constspace.filename.value = filename;
2576: this.document.constspace.action = url;
2577: this.document.constspace.submit();
2578: }
2579: }
2580:
2581: function golist(url) {
2582: if (url!='' && url!= null) {
2583: currentURL = null;
2584: currentSymb= null;
2585: var lcHostname = setLCHost();
2586: var ltitarget = '$ltitarget';
2587: var deeplinktarget = '$deeplinktarget';
2588: if ((ltitarget == 'iframe') || (deeplinktarget == '_self')) {
2589: document.location.href=lcHostname+url;
2590: } else {
2591: top.location.href=lcHostname+url;
2592: }
2593: }
2594: }
2595:
2596:
2597:
2598: function catalog_info(url,isMobile) {
2599: if (isMobile == 1) {
2600: openMyModal(url+'.meta?modal=1',500,400,'yes');
2601: } else {
2602: loncatinfo=window.open(url+'.meta',"LONcatInfo",'height=500,width=400,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
2603: }
2604: }
2605:
2606: function chat_win() {
2607: var lcHostname = setLCHost();
2608: lonchat=window.open(lcHostname+'/res/adm/pages/chatroom.html',"LONchat",'height=320,width=480,resizable=yes,location=no,menubar=no,toolbar=no');
2609: }
2610:
2611: function group_chat(group) {
2612: var lcHostname = setLCHost();
2613: var url = lcHostname+'/adm/groupchat?group='+group;
2614: var winName = 'LONchat_'+group;
2615: grpchat=window.open(url,winName,'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
2616: }
2617:
2618: function annotate() {
2619: w_Annotator_flag=1;
2620: annotator=window.open('','Annotator','width=365,height=265,scrollbars=0');
2621: annotator.document.write(
2622: '$start_page_annotate'
2623: +"<form name='goannotate' target='Annotator' method='post' "
2624: +"action='$annotateurl'>"
2625: +"<input type='hidden' name='symbnew' value='"+currentSymb+"' />"
2626: +"<\\/form>"
2627: +'$end_page_annotate');
2628: annotator.document.close();
2629: }
2630:
2631: function open_StoredLinks_Import(rat) {
2632: var newWin;
2633: var lcHostname = setLCHost();
2634: if (rat) {
2635: newWin = window.open(lcHostname+'/adm/wishlist?inhibitmenu=yes&mode=import&rat='+rat,
2636: 'wishlistImport','scrollbars=1,resizable=1,menubar=0');
2637: }
2638: else {
2639: newWin = window.open(lcHostname+'/adm/wishlist?inhibitmenu=yes&mode=import',
2640: 'wishlistImport','scrollbars=1,resizable=1,menubar=0');
2641: }
2642: newWin.focus();
2643: }
2644:
2645: function open_source() {
2646: sourcewin=window.open('/adm/source?inhibitmenu=yes&viewonly=1&filename='+currentURL,'LONsource',
2647: 'height=500,width=600,resizable=yes,location=no,menubar=no,toolbar=no,scrollbars=yes');
2648: }
2649:
2650: function open_aboutLC() {
2651: var isMobile = "$env{'browser.mobile'}";
2652: var url = '/adm/about.html';
2653: if (isMobile == 1) {
2654: openMyModal(url,600,400,'yes');
2655: } else {
2656: window.open(url,"aboutLONCAPA","height=400,width=600,scrollbars=1,resizable=1,menubar=0,location=1");
2657: }
2658: return;
2659: }
2660:
2661:
2662: (function (\$) {
2663: \$(document).ready(function () {
2664: \$.single=function(a){return function(b){a[0]=b;return a}}(\$([1]));
2665: /*\@cc_on
2666: if (!window.XMLHttpRequest) {
2667: \$('.LC_hoverable').each(function () {
2668: this.attachEvent('onmouseenter', function (evt) { \$.single(evt.srcElement).addClass('hover'); });
2669: this.attachEvent('onmouseleave', function (evt) { \$.single(evt.srcElement).removeClass('hover'); });
2670: });
2671: }
2672: \@*/
2673: });
2674: }(jQuery));
2675:
2676: $countdown
2677:
2678: $viewuser
2679:
2680: ENDUTILITY
2681: }
2682:
2683: sub serverform {
2684: my $target;
2685: unless (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {
2686: $target = ' target="_top"';
2687: }
2688: if (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self')) {
2689: $target = ' target="_self"';
2690: }
2691: return(<<ENDSERVERFORM);
2692: <form name="server" action="/adm/logout" method="post"$target>
2693: <input type="hidden" name="postdata" value="none" />
2694: <input type="hidden" name="command" value="none" />
2695: <input type="hidden" name="url" value="none" />
2696: <input type="hidden" name="symb" value="none" />
2697: </form>
2698: ENDSERVERFORM
2699: }
2700:
2701: sub constspaceform {
2702: my ($frameset) = @_;
2703: my ($target,$printtarget);
2704: if ($frameset) {
2705: $target = ' target="_parent"';
2706: $printtarget = ' target="_parent"';
2707: } else {
2708: unless ((($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) ||
2709: (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self'))) {
2710: $target = ' target="_top"';
2711: $printtarget = ' target="_top"';
2712: }
2713: }
2714: return(<<ENDCONSTSPACEFORM);
2715: <form name="constspace" action="/adm/logout" method="post"$target>
2716: <input type="hidden" name="filename" value="" />
2717: </form>
2718: <form name="cstrdelete" action="/adm/cfile" method="post"$target>
2719: <input type="hidden" name="action" value="delete" />
2720: <input type="hidden" name="filename" value="" />
2721: </form>
2722: <form name="cstrprint" action="/adm/printout" method="post"$printtarget>
2723: <input type="hidden" name="postdata" value="" />
2724: <input type="hidden" name="curseed" value="" />
2725: <input type="hidden" name="problemtype" value="" />
2726: </form>
2727: <form name="cstrcopy" action="/adm/cfile" method="post"$target>
2728: <input type="hidden" name="action" value="copy" />
2729: <input type="hidden" name="filename" value="" />
2730: <input type="hidden" name="newfilename" value="" />
2731: </form>
2732:
2733: ENDCONSTSPACEFORM
2734: }
2735:
2736: sub hidden_button_check {
2737: if ( $env{'request.course.id'} eq ''
2738: || $env{'request.role.adv'} ) {
2739:
2740: return;
2741: }
2742: my $buttonshide = &Apache::lonnet::EXT('resource.0.buttonshide');
2743: return $buttonshide;
2744: }
2745:
2746: sub roles_selector {
2747: my ($cdom,$cnum,$httphost,$target,$menucoll,$menuref) = @_;
2748: my $crstype = &Apache::loncommon::course_type();
2749: my $now = time;
2750: my (%courseroles,%seccount,%courseprivs,%roledesc);
2751: my $is_cc;
2752: my ($js,$form,$switcher,$has_opa_priv);
2753: my $ccrole;
2754: if ($crstype eq 'Community') {
2755: $ccrole = 'co';
2756: } else {
2757: $ccrole = 'cc';
2758: }
2759: my ($privref,$gotsymb,$destsymb);
2760: my $destinationurl = $ENV{'REQUEST_URI'};
2761: if ($destinationurl =~ /(\?|\&)symb=/) {
2762: $gotsymb = 1;
2763: } elsif ($destinationurl =~ m{^/enc/}) {
2764: my $plainurl = &Apache::lonenc::unencrypted($destinationurl);
2765: if ($plainurl =~ /(\?|\&)symb=/) {
2766: $gotsymb = 1;
2767: }
2768: }
2769: unless ($gotsymb) {
2770: $destsymb = &Apache::lonnet::symbread();
2771: if ($destsymb ne '') {
2772: $destsymb = &Apache::lonenc::check_encrypt($destsymb);
2773: }
2774: }
2775: my $reqprivs = &required_privs();
2776: if (ref($reqprivs) eq 'HASH') {
2777: my $destination = $destinationurl;
2778: $destination =~ s/(\?.*)$//;
2779: if (exists($reqprivs->{$destination})) {
2780: if ($reqprivs->{$destination} =~ /,/) {
2781: @{$privref} = split(/,/,$reqprivs->{$destination});
2782: } else {
2783: $privref = [$reqprivs->{$destination}];
2784: }
2785: }
2786: }
2787: if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) {
2788: my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum});
2789: if ((($start) && ($start<0)) ||
2790: (($end) && ($end<$now)) ||
2791: (($start) && ($now<$start))) {
2792: $is_cc = 0;
2793: } else {
2794: $is_cc = 1;
2795: }
2796: }
2797: if ($is_cc) {
2798: &get_all_courseroles($cdom,$cnum,\%courseroles,\%seccount,\%courseprivs);
2799: } elsif ($env{'request.role'} =~ m{^\Qcr/$cdom/$cdom-domainconfig/\E(\w+)\.\Q/$cdom/$cnum\E}) {
2800: &get_customadhoc_roles($cdom,$cnum,\%courseroles,\%seccount,\%courseprivs,\%roledesc,$privref);
2801: } else {
2802: my %gotnosection;
2803: foreach my $item (keys(%env)) {
2804: if ($item =~ m-^user\.role\.([^.]+)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
2805: my $role = $1;
2806: my $sec = $2;
2807: next if ($role eq 'gr');
2808: my ($start,$end) = split(/\./,$env{$item});
2809: next if (($start && $start > $now) || ($end && $end < $now));
2810: if ($sec eq '') {
2811: if (!$gotnosection{$role}) {
2812: $seccount{$role} ++;
2813: $gotnosection{$role} = 1;
2814: }
2815: }
2816: if ((ref($privref) eq 'ARRAY') && (@{$privref} > 0)) {
2817: my $cnumsec = $cnum;
2818: if ($sec ne '') {
2819: $cnumsec .= "/$sec";
2820: }
2821: $courseprivs{"$role./$cdom/$cnumsec./"} =
2822: $env{"user.priv.$role./$cdom/$cnumsec./"};
2823: $courseprivs{"$role./$cdom/$cnumsec./$cdom/"} =
2824: $env{"user.priv.$role./$cdom/$cnumsec./$cdom/"};
2825: $courseprivs{"$role./$cdom/$cnumsec./$cdom/$cnumsec"} =
2826: $env{"user.priv.$role./$cdom/$cnumsec./$cdom/$cnumsec"};
2827: }
2828: if (ref($courseroles{$role}) eq 'ARRAY') {
2829: if ($sec ne '') {
2830: if (!grep(/^\Q$sec\E$/,@{$courseroles{$role}})) {
2831: push(@{$courseroles{$role}},$sec);
2832: $seccount{$role} ++;
2833: }
2834: }
2835: } else {
2836: @{$courseroles{$role}} = ();
2837: if ($sec ne '') {
2838: $seccount{$role} ++;
2839: push(@{$courseroles{$role}},$sec);
2840: }
2841: }
2842: }
2843: }
2844: }
2845: my @roles_order = ($ccrole,'in','ta','ep','ad','st');
2846: my $numdiffsec;
2847: if (keys(%seccount) == 1) {
2848: foreach my $key (keys(%seccount)) {
2849: $numdiffsec = $seccount{$key};
2850: }
2851: }
2852: if ((keys(%seccount) > 1) || ($numdiffsec > 1)) {
2853: my $targetattr;
2854: if ($target ne '') {
2855: $targetattr = ' target="'.$target.'"';
2856: }
2857: my @submenu;
2858: $js = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles,\%courseprivs,
2859: \%roledesc,$privref,$menucoll,$menuref);
2860: $form =
2861: '<form name="rolechooser" method="post" action="'.$httphost.'/adm/roles"'.$targetattr.'>'."\n".
2862: ' <input type="hidden" name="destinationurl" value="'.
2863: &HTML::Entities::encode($destinationurl).'" />'."\n".
2864: ' <input type="hidden" name="gotorole" value="1" />'."\n".
2865: ' <input type="hidden" name="selectrole" value="" />'."\n".
2866: ' <input type="hidden" name="switchrole" value="" />'."\n";
2867: if ($destsymb ne '') {
2868: $form .= ' <input type="hidden" name="destsymb" value="'.
2869: &HTML::Entities::encode($destsymb).'" />'."\n";
2870: }
2871: $form .= '</form>'."\n";
2872: foreach my $role (@roles_order) {
2873: my $include;
2874: if (defined($courseroles{$role})) {
2875: if ($env{'request.role'} =~ m{^\Q$role\E}) {
2876: if ($seccount{$role} > 1) {
2877: $include = 1;
2878: } else {
2879: if ($env{'user.priv.'.$env{'request.role'}."./$cdom/$cnum"} =~/opa\&([^\:]*)/) {
2880: $has_opa_priv = 1;
2881: }
2882: }
2883: } else {
2884: $include = 1;
2885: }
2886: }
2887: if ($include) {
2888: if ($env{"user.priv.$role./$cdom/$cnum./$cdom/$cnum"} =~/opa\&([^\:]*)/) {
2889: $has_opa_priv = 1;
2890: }
2891: push(@submenu,['javascript:adhocRole('."'$role'".')',
2892: &Apache::lonnet::plaintext($role,$crstype)]);
2893: }
2894: }
2895: foreach my $role (sort(keys(%courseroles))) {
2896: if ($role =~ /^cr/) {
2897: my $include;
2898: if ($env{'request.role'} =~ m{^\Q$role\E}) {
2899: if ($seccount{$role} > 1) {
2900: $include = 1;
2901: }
2902: } else {
2903: $include = 1;
2904: }
2905: if ($include) {
2906: my $rolename;
2907: if ($role =~ m{^cr/$cdom/$cdom\-domainconfig/(\w+)(?:/\w+|$)}) {
2908: $rolename = $roledesc{$role};
2909: if ($rolename eq '') {
2910: $rolename = &mt('Helpdesk [_1]',$1);
2911: }
2912: } else {
2913: $rolename = &Apache::lonnet::plaintext($role);
2914: }
2915: if ($env{"user.priv.$role./$cdom/$cnum./$cdom/$cnum"} =~/opa\&([^\:]*)/) {
2916: $has_opa_priv = 1;
2917: }
2918: push(@submenu,['javascript:adhocRole('."'$role'".')',
2919: $rolename]);
2920: }
2921: }
2922: }
2923: if (@submenu > 0) {
2924: $switcher = &create_submenu('#',$target,&mt('Switch role'),\@submenu);
2925: }
2926: }
2927: return ($js,$form,$switcher,$has_opa_priv);
2928: }
2929:
2930: sub get_all_courseroles {
2931: my ($cdom,$cnum,$courseroles,$seccount,$courseprivs) = @_;
2932: unless ((ref($courseroles) eq 'HASH') && (ref($seccount) eq 'HASH') &&
2933: (ref($courseprivs) eq 'HASH')) {
2934: return;
2935: }
2936: my ($result,$cached) =
2937: &Apache::lonnet::is_cached_new('getcourseroles',$cdom.'_'.$cnum);
2938: if (defined($cached)) {
2939: if (ref($result) eq 'HASH') {
2940: if ((ref($result->{'roles'}) eq 'HASH') &&
2941: (ref($result->{'seccount'}) eq 'HASH') &&
2942: (ref($result->{'privs'}) eq 'HASH')) {
2943: %{$courseroles} = %{$result->{'roles'}};
2944: %{$seccount} = %{$result->{'seccount'}};
2945: %{$courseprivs} = %{$result->{'privs'}};
2946: return;
2947: }
2948: }
2949: }
2950: my %gotnosection;
2951: my %adv_roles =
2952: &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
2953: foreach my $role (keys(%adv_roles)) {
2954: my ($urole,$usec) = split(/:/,$role);
2955: if (!$gotnosection{$urole}) {
2956: $seccount->{$urole} ++;
2957: $gotnosection{$urole} = 1;
2958: }
2959: if (ref($courseroles->{$urole}) eq 'ARRAY') {
2960: if ($usec ne '') {
2961: if (!grep(/^Q$usec\E$/,@{$courseroles->{$urole}})) {
2962: push(@{$courseroles->{$urole}},$usec);
2963: $seccount->{$urole} ++;
2964: }
2965: }
2966: } else {
2967: @{$courseroles->{$urole}} = ();
2968: if ($usec ne '') {
2969: $seccount->{$urole} ++;
2970: push(@{$courseroles->{$urole}},$usec);
2971: }
2972: }
2973: my $area = '/'.$cdom.'/'.$cnum;
2974: if ($usec ne '') {
2975: $area .= '/'.$usec;
2976: }
2977: if ($role =~ /^cr\//) {
2978: &Apache::lonnet::custom_roleprivs($courseprivs,$urole,$cdom,$cnum,$urole.'.'.$area,$area);
2979: } else {
2980: &Apache::lonnet::standard_roleprivs($courseprivs,$urole,$cdom,$urole.'.'.$area,$cnum,$area);
2981: }
2982: }
2983: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum,['st']);
2984: @{$courseroles->{'st'}} = ();
2985: &Apache::lonnet::standard_roleprivs($courseprivs,'st',$cdom,"st./$cdom/$cnum",$cnum,"/$cdom/$cnum");
2986: if (keys(%sections_count) > 0) {
2987: push(@{$courseroles->{'st'}},keys(%sections_count));
2988: $seccount->{'st'} = scalar(keys(%sections_count));
2989: }
2990: $seccount->{'st'} ++; # Increment for a section-less student role.
2991: my $rolehash = {
2992: 'roles' => $courseroles,
2993: 'seccount' => $seccount,
2994: 'privs' => $courseprivs,
2995: };
2996: &Apache::lonnet::do_cache_new('getcourseroles',$cdom.'_'.$cnum,$rolehash);
2997: return;
2998: }
2999:
3000: sub get_customadhoc_roles {
3001: my ($cdom,$cnum,$courseroles,$seccount,$courseprivs,$roledesc,$privref) = @_;
3002: unless ((ref($courseroles) eq 'HASH') && (ref($seccount) eq 'HASH') &&
3003: (ref($courseprivs) eq 'HASH') && (ref($roledesc) eq 'HASH')) {
3004: return;
3005: }
3006: my $is_helpdesk = 0;
3007: my $now = time;
3008: foreach my $role ('dh','da') {
3009: if ($env{"user.role.$role./$cdom/"}) {
3010: my ($start,$end)=split(/\./,$env{"user.role.$role./$cdom/"});
3011: if (!($start && ($now<$start)) && !($end && ($now>$end))) {
3012: $is_helpdesk = 1;
3013: last;
3014: }
3015: }
3016: }
3017: if ($is_helpdesk) {
3018: my ($possroles,$description) = &Apache::lonnet::get_my_adhocroles($cdom.'_'.$cnum);
3019: my %available;
3020: if (ref($possroles) eq 'ARRAY') {
3021: map { $available{$_} = 1; } @{$possroles};
3022: }
3023: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
3024: if (ref($domdefaults{'adhocroles'}) eq 'HASH') {
3025: if (keys(%{$domdefaults{'adhocroles'}})) {
3026: my $numsec = 1;
3027: my @sections;
3028: my ($allseclist,$cached) =
3029: &Apache::lonnet::is_cached_new('courseseclist',$cdom.'_'.$cnum);
3030: if (defined($cached)) {
3031: if ($allseclist ne '') {
3032: @sections = split(/,/,$allseclist);
3033: $numsec += scalar(@sections);
3034: }
3035: } else {
3036: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
3037: @sections = sort(keys(%sections_count));
3038: $numsec += scalar(@sections);
3039: $allseclist = join(',',@sections);
3040: &Apache::lonnet::do_cache_new('courseseclist',$cdom.'_'.$cnum,$allseclist);
3041: }
3042: my (%adhoc,$gotprivs);
3043: my $prefix = "cr/$cdom/$cdom".'-domainconfig';
3044: foreach my $role (keys(%{$domdefaults{'adhocroles'}})) {
3045: next if (($role eq '') || ($role =~ /\W/));
3046: $seccount->{"$prefix/$role"} = $numsec;
3047: $roledesc->{"$prefix/$role"} = $description->{$role};
3048: if ((ref($privref) eq 'ARRAY') && (@{$privref} > 0)) {
3049: if (exists($env{"user.priv.$prefix/$role./$cdom/$cnum./"})) {
3050: $courseprivs->{"$prefix/$role./$cdom/$cnum./"} =
3051: $env{"user.priv.$prefix/$role./$cdom/$cnum./"};
3052: $courseprivs->{"$prefix/$role./$cdom/$cnum./$cdom/"} =
3053: $env{"user.priv.$prefix/$role./$cdom/$cnum./$cdom/"};
3054: $courseprivs->{"$prefix/$role./$cdom/$cnum./$cdom/$cnum"} =
3055: $env{"user.priv.$prefix/$role./$cdom/$cnum./$cdom/$cnum"};
3056: } else {
3057: unless ($gotprivs) {
3058: my ($adhocroles,$privscached) =
3059: &Apache::lonnet::is_cached_new('adhocroles',$cdom);
3060: if ((defined($privscached)) && (ref($adhocroles) eq 'HASH')) {
3061: %adhoc = %{$adhocroles};
3062: } else {
3063: my $confname = &Apache::lonnet::get_domainconfiguser($cdom);
3064: my %roledefs = &Apache::lonnet::dump('roles',$cdom,$confname,'rolesdef_');
3065: foreach my $key (keys(%roledefs)) {
3066: (undef,my $rolename) = split(/_/,$key);
3067: if ($rolename ne '') {
3068: my ($systempriv,$domainpriv,$coursepriv) = split(/\_/,$roledefs{$key});
3069: $coursepriv = &Apache::lonnet::course_adhocrole_privs($rolename,$cdom,$cnum,$coursepriv);
3070: $adhoc{$rolename} = join('_',($systempriv,$domainpriv,$coursepriv));
3071: }
3072: }
3073: &Apache::lonnet::do_cache_new('adhocroles',$cdom,\%adhoc);
3074: }
3075: $gotprivs = 1;
3076: }
3077: ($courseprivs->{"$prefix/$role./$cdom/$cnum./"},
3078: $courseprivs->{"$prefix/$role./$cdom/$cnum./$cdom/"},
3079: $courseprivs->{"$prefix/$role./$cdom/$cnum./$cdom/$cnum"}) =
3080: split(/\_/,$adhoc{$role});
3081: }
3082: }
3083: if ($available{$role}) {
3084: $courseroles->{"$prefix/$role"} = \@sections;
3085: }
3086: }
3087: }
3088: }
3089: }
3090: return;
3091: }
3092:
3093: sub jump_to_role {
3094: my ($cdom,$cnum,$seccount,$courseroles,$courseprivs,$roledesc,$privref,
3095: $menucoll,$menuref) = @_;
3096: my %lt = &Apache::lonlocal::texthash(
3097: this => 'This role has section(s) associated with it.',
3098: ente => 'Enter a specific section.',
3099: orlb => 'Enter a specific section, or leave blank for no section.',
3100: avai => 'Available sections are:',
3101: youe => 'You entered an invalid section choice:',
3102: plst => 'Please try again.',
3103: role => 'The role you selected is not permitted to view the current page.',
3104: swit => 'Switch role, but display Main Menu page instead?',
3105: );
3106: &js_escape(\%lt);
3107: my $js;
3108: if (ref($courseroles) eq 'HASH') {
3109: $js = ' var secpick = new Array("'.$lt{'ente'}.'","'.$lt{'orlb'}.'");'."\n".
3110: ' var numsec = new Array();'."\n".
3111: ' var rolesections = new Array();'."\n".
3112: ' var rolenames = new Array();'."\n".
3113: ' var roleseclist = new Array();'."\n";
3114: my @items = keys(%{$courseroles});
3115: for (my $i=0; $i<@items; $i++) {
3116: $js .= ' rolenames['.$i.'] = "'.$items[$i].'";'."\n";
3117: my ($secs,$secstr);
3118: if (ref($courseroles->{$items[$i]}) eq 'ARRAY') {
3119: my @sections = sort { $a <=> $b } @{$courseroles->{$items[$i]}};
3120: $secs = join('","',@sections);
3121: $secstr = join(', ',@sections);
3122: }
3123: $js .= ' rolesections['.$i.'] = new Array("'.$secs.'");'."\n".
3124: ' roleseclist['.$i.'] = "'.$secstr.'";'."\n".
3125: ' numsec['.$i.'] = "'.$seccount->{$items[$i]}.'";'."\n";
3126: }
3127: }
3128: my $checkroles = 0;
3129: my $fallback = '/adm/menu';
3130: my $displaymsg = $lt{'swit'};
3131: if ((ref($privref) eq 'ARRAY') && (@{$privref} > 0) && (ref($courseprivs) eq 'HASH')) {
3132: my %disallowed;
3133: foreach my $role (sort(keys(%{$courseprivs}))) {
3134: my $trole;
3135: if ($role =~ m{^(.+?)\Q./$cdom/$cnum\E}) {
3136: $trole = $1;
3137: }
3138: if (($trole ne '') && ($trole ne 'cm')) {
3139: $disallowed{$trole} = 1;
3140: foreach my $priv (@{$privref}) {
3141: if ($courseprivs->{$role} =~ /\Q:$priv\E($|:|\&\w+)/) {
3142: delete($disallowed{$trole});
3143: last;
3144: }
3145: }
3146: }
3147: }
3148: if (keys(%disallowed) > 0) {
3149: $checkroles = 1;
3150: $js .= " var disallow = new Array('".join("','",keys(%disallowed))."');\n".
3151: " var rolecheck = 1;\n";
3152: if ($menucoll) {
3153: if (ref($menuref) eq 'HASH') {
3154: if ($menuref->{'main'} eq 'n') {
3155: $fallback = '/adm/navmaps';
3156: if (&Apache::loncommon::course_type() eq 'Community') {
3157: $displaymsg = &mt('Switch role, but display Community Contents page instead?');
3158: } else {
3159: $displaymsg = &mt('Switch role, but display Course Contents page instead?');
3160: }
3161: &js_escape(\$displaymsg);
3162: }
3163: }
3164: }
3165: }
3166: }
3167: &js_escape(\$fallback);
3168: if (!$checkroles) {
3169: $js .= " var disallow = new Array();\n".
3170: " rolecheck = 0;\n";
3171: }
3172: return <<"END";
3173: <script type="text/javascript">
3174: //<![CDATA[
3175: function adhocRole(newrole) {
3176: $js
3177: if (newrole == '') {
3178: return;
3179: }
3180: var fullrole = newrole+'./$cdom/$cnum';
3181: var selidx = '';
3182: for (var i=0; i<rolenames.length; i++) {
3183: if (rolenames[i] == newrole) {
3184: selidx = i;
3185: }
3186: }
3187: if (rolecheck > 0) {
3188: for (var i=0; i<disallow.length; i++) {
3189: if (disallow[i] == newrole) {
3190: if (confirm("$lt{'role'}\\n$displaymsg")) {
3191: document.rolechooser.destinationurl.value = '$fallback';
3192: } else {
3193: return;
3194: }
3195: }
3196: }
3197: }
3198: var secok = 1;
3199: var secchoice = '';
3200: if (selidx >= 0) {
3201: if (numsec[selidx] > 1) {
3202: secok = 0;
3203: var numrolesec = rolesections[selidx].length;
3204: var msgidx = numsec[selidx] - numrolesec;
3205: secchoice = prompt("$lt{'this'} "+secpick[msgidx]+"\\n$lt{'avai'} "+roleseclist[selidx],"");
3206: if (secchoice == '') {
3207: if (msgidx > 0) {
3208: secok = 1;
3209: }
3210: } else {
3211: for (var j=0; j<rolesections[selidx].length; j++) {
3212: if (rolesections[selidx][j] == secchoice) {
3213: secok = 1;
3214: }
3215: }
3216: }
3217: } else {
3218: if (rolesections[selidx].length == 1) {
3219: secchoice = rolesections[selidx][0];
3220: }
3221: }
3222: }
3223: if (secok == 1) {
3224: if (secchoice != '') {
3225: fullrole += '/'+secchoice;
3226: }
3227: } else {
3228: if (secchoice != null) {
3229: alert("$lt{'youe'} \\""+secchoice+"\\".\\n $lt{'plst'}");
3230: }
3231: return;
3232: }
3233: if (fullrole == "$env{'request.role'}") {
3234: return;
3235: }
3236: itemid = retrieveIndex('gotorole');
3237: if (itemid != -1) {
3238: document.rolechooser.elements[itemid].name = fullrole;
3239: }
3240: document.rolechooser.switchrole.value = fullrole;
3241: document.rolechooser.selectrole.value = '1';
3242: document.rolechooser.submit();
3243: return;
3244: }
3245:
3246: function retrieveIndex(item) {
3247: for (var i=0;i<document.rolechooser.elements.length;i++) {
3248: if (document.rolechooser.elements[i].name == item) {
3249: return i;
3250: }
3251: }
3252: return -1;
3253: }
3254: // ]]>
3255: </script>
3256: END
3257: }
3258:
3259: sub required_privs {
3260: my $privs = {
3261: '/adm/parmset' => 'opa,vpa',
3262: '/adm/courseprefs' => 'opa,vpa',
3263: '/adm/whatsnew' => 'whn',
3264: '/adm/populate' => 'cst,vpa,vcl',
3265: '/adm/trackstudent' => 'vsa',
3266: '/adm/statistics' => 'mgr,vgr',
3267: '/adm/setblock' => 'dcm,vcb',
3268: '/adm/coursedocs' => 'mdc',
3269: };
3270: unless ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'spreadsheet') {
3271: $privs->{'/adm/classcalc'} = 'vgr',
3272: $privs->{'/adm/assesscalc'} = 'vgr',
3273: $privs->{'/adm/studentcalc'} = 'vgr';
3274: }
3275: return $privs;
3276: }
3277:
3278: sub countdown_timer {
3279: if (($env{'request.course.id'}) && ($env{'request.symb'} ne '') &&
3280: (($env{'request.filename'}=~/$LONCAPA::assess_re/) ||
3281: (($env{'request.symb'} =~ /ext\.tool$/) &&
3282: (&Apache::lonnet::EXT('resource.0.gradable',$env{'request.symb'}) =~ /^yes$/i)))) {
3283: my ($type,$hastimeleft,$slothastime);
3284: my $now = time;
3285: if ($env{'request.filename'} =~ /\.task$/) {
3286: $type = 'Task';
3287: } elsif ($env{'request.symb'} =~ /ext\.tool$/) {
3288: $type = 'tool';
3289: } else {
3290: $type = 'problem';
3291: }
3292: my ($status,$accessmsg,$slot_name,$slot);
3293: if ($type eq 'tool') {
3294: ($status,$accessmsg,$slot_name,$slot) =
3295: &Apache::lonhomework::check_slot_access('0',$type,$env{'request.symb'},['0']);
3296: } else {
3297: ($status,$accessmsg,$slot_name,$slot) =
3298: &Apache::lonhomework::check_slot_access('0',$type);
3299: }
3300: if ($slot_name ne '') {
3301: if (ref($slot) eq 'HASH') {
3302: if (($slot->{'starttime'} < $now) &&
3303: ($slot->{'endtime'} > $now)) {
3304: $slothastime = 1;
3305: }
3306: }
3307: }
3308: if ($status ne 'CAN_ANSWER') {
3309: return;
3310: }
3311: my $duedate = &Apache::lonnet::EXT("resource.0.duedate");
3312: my @interval=&Apache::lonnet::EXT("resource.0.interval");
3313: my ($timelimit,$usesdone,$donebuttontext,$proctor,$secret);
3314: if (@interval > 1) {
3315: ($timelimit,my $donesuffix) = split(/_/,$interval[0],2);
3316: if ($donesuffix =~ /^done\:([^\:]+)\:(.*)$/) {
3317: $usesdone = 'done';
3318: $donebuttontext = $1;
3319: (undef,$proctor,$secret) = split(/_/,$2);
3320: } elsif ($donesuffix =~ /^done(|_.+)$/) {
3321: $donebuttontext = &mt('Done');
3322: ($usesdone,$proctor,$secret) = split(/_/,$donesuffix);
3323: }
3324: my $first_access=&Apache::lonnet::get_first_access($interval[1]);
3325: if ($first_access > 0) {
3326: if ($first_access+$timelimit > time) {
3327: $hastimeleft = 1;
3328: }
3329: }
3330: }
3331: if (($duedate && $duedate > time) ||
3332: (!$duedate && $hastimeleft) ||
3333: ($slot_name ne '' && $slothastime)) {
3334: my ($collapse,$expand,$alttxt,$title,$currdisp,$donebutton);
3335: if ((@interval > 1 && $hastimeleft) ||
3336: ($type eq 'Task' && $slothastime)) {
3337: $currdisp = 'inline';
3338: $collapse = '► ';
3339: if ((@interval > 1) && ($hastimeleft)) {
3340: if ($usesdone eq 'done') {
3341: $donebutton = &done_button_js($interval[1],'','',$proctor,$donebuttontext);
3342: }
3343: }
3344: } else {
3345: $currdisp = 'none';
3346: $expand = '◄ ';
3347: }
3348: unless ($env{'environment.icons'} eq 'iconsonly') {
3349: $alttxt = &mt('Timer');
3350: $title = $alttxt.' ';
3351: }
3352: my $desc = &mt('Countdown to due date/time');
3353:
3354: return <<END;
3355: $donebutton
3356: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
3357: <span id="ddcountcollapse" class="LC_menubuttons_inline_text">
3358: $collapse
3359: </span></a>
3360: <span id="duedatecountdown" class="LC_menubuttons_inline_text" style="display: $currdisp;"></span>
3361: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
3362: <span id="ddcountexpand" class="LC_menubuttons_inline_text" >$expand</span>
3363: <img src="/res/adm/pages/timer.png" title="$desc" class="LC_icon" alt="$alttxt" /><span class="LC_menubuttons_inline_text">$title</span></a>
3364: END
3365: }
3366: }
3367: return;
3368: }
3369:
3370: sub placement_progress {
3371: my ($totalpoints,$incomplete) = &Apache::lonplacementtest::check_completion(undef,undef,1);
3372: my $complete = 100 - $incomplete;
3373: return '<span class="LC_placement_prog">'.
3374: &mt('Test is [_1]% complete',$complete).'</span>';
3375: }
3376:
3377: sub linkprot_exit {
3378: if (($env{'request.course.id'}) && ($env{'request.deeplink.login'})) {
3379: my ($deeplink_symb,$deeplink);
3380: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
3381: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3382: if (($cnum ne '') && ($cdom ne '')) {
3383: $deeplink_symb = &Apache::loncommon::deeplink_login_symb($cnum,$cdom);
3384: if ($deeplink_symb) {
3385: if ($deeplink_symb =~ /\.(page|sequence)$/) {
3386: my $mapname = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($deeplink_symb))[2]);
3387: my $navmap = Apache::lonnavmaps::navmap->new();
3388: if (ref($navmap)) {
3389: $deeplink = $navmap->get_mapparam(undef,$mapname,'0.deeplink');
3390: }
3391: } else {
3392: $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$deeplink_symb);
3393: }
3394: if ($deeplink ne '') {
3395: my ($state,$others,$listed,$scope,$protect,$display,$target,$exit) = split(/,/,$deeplink);
3396: my %lt = &Apache::lonlocal::texthash(
3397: title => 'Exit Tool',
3398: okdone => 'Click "OK" to exit embedded tool',
3399: cancel => 'Click "Cancel" to continue working.',
3400: ok => 'OK',
3401: exit => 'Cancel',
3402: );
3403: if ($exit) {
3404: my ($show,$text) = split(/:/,$exit);
3405: unless ($show eq 'no') {
3406: my $height = 250;
3407: my $width = 300;
3408: my $exitbuttontext;
3409: if ($text eq '') {
3410: $exitbuttontext = &mt('Exit Tool');
3411: } else {
3412: $exitbuttontext = $text;
3413: }
3414: return <<END;
3415: <form method="post" name="LCexitButton" action="/adm/linkexit">
3416: <input type="hidden" name="LC_deeplink_exit" value="" />
3417: <button id="LC_exit-confirm-opener" type="button">$exitbuttontext</button>
3418: </form>
3419:
3420: <div id="LC_exit-confirm" title="$lt{'title'}">
3421: <p>$lt{'okdone'} $lt{'cancel'}</p>
3422: </div>
3423:
3424: <script type="text/javascript">
3425: // <![CDATA[
3426: \$( "#LC_exit-confirm" ).dialog({ autoOpen: false });
3427: \$( "#LC_exit-confirm-opener" ).click(function() {
3428: \$( "#LC_exit-confirm" ).dialog( "open" );
3429: \$( "#LC_exit-confirm" ).dialog({
3430: resizable: false,
3431: height: $height,
3432: width: $width,
3433: modal: true,
3434: buttons: [
3435: {
3436: text: "$lt{'ok'}",
3437: click: function() {
3438: \$( this ).dialog( "close" );
3439: \$( '[name="LC_deeplink_exit"]' )[0].value = 'true';
3440: \$( '[name="LCexitButton"]' )[0].submit();
3441: },
3442: },
3443: {
3444: text: "$lt{'exit'}",
3445: click: function() {
3446: \$( this ).dialog( "close" );
3447: },
3448: },
3449: ],
3450: });
3451: });
3452: // ]]>
3453: </script>
3454:
3455: END
3456: }
3457: }
3458: }
3459: }
3460: }
3461: }
3462: return;
3463: }
3464:
3465: # ================================================================ Main Program
3466:
3467: BEGIN {
3468: if (! defined($readdesk)) {
3469: {
3470: my $tabfile = $Apache::lonnet::perlvar{'lonTabDir'}.'/mydesk.tab';
3471: if ( CORE::open( my $config,"<$tabfile") ) {
3472: while (my $configline=<$config>) {
3473: $configline=(split(/\#/,$configline))[0];
3474: $configline=~s/^\s+//;
3475: chomp($configline);
3476: if ($configline=~/^cat\:/) {
3477: my @entries=split(/\:/,$configline);
3478: $category_positions{$entries[2]}=$entries[1];
3479: $category_names{$entries[2]}=$entries[3];
3480: } elsif ($configline=~/^prim\:/) {
3481: my @entries = (split(/\:/, $configline))[1..7];
3482: push(@primary_menu,\@entries);
3483: } elsif ($configline=~/^primsub\:/) {
3484: my ($parent,@entries) = (split(/\:/, $configline))[1..5];
3485: push(@{$primary_submenu{$parent}},\@entries);
3486: } elsif ($configline=~/^scnd\:/) {
3487: my @entries = (split(/\:/, $configline))[1..6];
3488: push(@secondary_menu,\@entries);
3489: } elsif ($configline=~/^scndsub\:/) {
3490: my ($parent,@entries) = (split(/\:/, $configline))[1..4];
3491: push(@{$secondary_submenu{$parent}},\@entries);
3492: } elsif ($configline) {
3493: push(@desklines,$configline);
3494: }
3495: }
3496: CORE::close($config);
3497: }
3498: }
3499: $readdesk='done';
3500: }
3501: }
3502:
3503: 1;
3504: __END__
3505:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>