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