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