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