1: # The LearningOnline Network with CAPA
2: # Routines to control the menu
3: #
4: # $Id: lonmenu.pm,v 1.369.2.83.2.10 2023/09/06 16:05:23 raeburn Exp $
5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: #
29:
30: =head1 NAME
31:
32: Apache::lonmenu
33:
34: =head1 SYNOPSIS
35:
36: Loads contents of /home/httpd/lonTabs/mydesk.tab,
37: used to generate inline menu, and Main Menu page.
38:
39: This is part of the LearningOnline Network with CAPA project
40: described at http://www.lon-capa.org.
41:
42: =head1 GLOBAL VARIABLES
43:
44: =over
45:
46: =item @desklines
47:
48: Each element of this array contains a line of mydesk.tab that doesn't start with
49: cat, prim or scnd.
50: It gets filled in the BEGIN block of this module.
51:
52: =item %category_names
53:
54: The keys of this hash are the abbreviations used in mydesk.tab in those lines that
55: start with cat, the values are strings representing titles.
56: It gets filled in the BEGIN block of this module.
57:
58: =item %category_members
59:
60: TODO
61:
62: =item %category_positions
63:
64: The keys of this hash are the abbreviations used in mydesk.tab in those lines that
65: start with cat, its values are position vectors (column, row).
66: It gets filled in the BEGIN block of this module.
67:
68: =item $readdesk
69:
70: Indicates that mydesk.tab has been read.
71: It is set to 'done' in the BEGIN block of this module.
72:
73: =item @primary_menu
74:
75: The elements of this array reference arrays that are made up of the components
76: of those lines of mydesk.tab that start with prim:.
77: It is used by primary_menu() to generate the corresponding menu.
78: It gets filled in the BEGIN block of this module.
79:
80: =item %primary_sub_menu
81:
82: The keys of this hash reference are the names of items in the primary_menu array
83: which have sub-menus. For each key, the corresponding value is a reference to
84: an array containing components extracted from lines in mydesk.tab which begin
85: with primsub:.
86: This hash, which is used by primary_menu to generate sub-menus, is populated in
87: the BEGIN block.
88:
89: =item @secondary_menu
90:
91: The elements of this array reference arrays that are made up of the components
92: of those lines of mydesk.tab that start with scnd.
93: It is used by secondary_menu() to generate the corresponding menu.
94: It gets filled in the BEGIN block of this module.
95:
96: =back
97:
98: =head1 SUBROUTINES
99:
100: =over
101:
102: =item prep_menuitems(\@menuitem,$target,$listclass,$linkattr)
103:
104: This routine wraps a menuitem in proper HTML. It is used by primary_menu() and
105: secondary_menu().
106:
107: =item primary_menu()
108:
109: This routine evaluates @primary_menu and returns a two item array,
110: with the array elements containing XHTML for the left and right sides of
111: the menu that contains the following links: About, Message, Roles, Help, Logout
112: @primary_menu is filled within the BEGIN block of this module with
113: entries from mydesk.tab
114:
115: =item secondary_menu()
116:
117: Same as primary_menu() but operates on @secondary_menu.
118:
119: =item create_submenu()
120:
121: Creates XHTML for unordered list of sub-menu items which belong to a
122: particular top-level menu item. Uses hover pseudo class in css to display
123: dropdown list when mouse hovers over top-level item. Support for IE6
124: (no hover psuedo class) via LC_hoverable class for <li> tag for top-
125: level item, which employs jQuery to handle behavior on mouseover.
126:
127: Inputs: 6 - (a) link and (b) target for anchor href in top level item,
128: (c) title for text wrapped by anchor tag in top level item.
129: (d) reference to array of arrays of sub-menu items.
130: (e) boolean to indicate whether to call &mt() to translate
131: name of menu item,
132: (f) optional class for <li> element in primary menu, for which
133: sub menu is being generated.
134:
135: The underlying datastructure used in (d) contains data from mydesk.tab.
136: It consists of an array which has an array for each item appearing in
137: the menu (e.g. [["link", "title", "condition"]] for a single-item menu).
138: create_submenu() supports also the creation of XHTML for nested dropdown
139: menus represented by unordered lists. This is done by replacing the
140: scalar used for the link with an arrayreference containing the menuitems
141: for the nested menu. This can be done recursively so that the next menu
142: may also contain nested submenus.
143:
144: Example:
145: [ # begin of datastructure
146: ["/home/", "Home", "condition1"], # 1st item of the 1st layer menu
147: [ # 2nd item of the 1st layer menu
148: [ # anon. array for nested menu
149: ["/path1", "Path1", undef], # 1st item of the 2nd layer menu
150: ["/path2", "Path2", undef], # 2nd item of the 2nd layer menu
151: [ # 3rd item of the 2nd layer menu
152: [[...], [...], ..., [...]], # containing another menu layer
153: "Sub-Sub-Menu", # title for this container
154: undef
155: ]
156: ], # end of array/nested menu
157: "Sub-Menu", # title for the container item
158: undef
159: ] # end of 2nd item of the 1st layer menu
160: ]
161:
162:
163: =item innerregister()
164:
165: This gets called in order to register a URL in the body of the document
166:
167: =item loadevents()
168:
169: =item unloadevents()
170:
171: =item startupremote()
172:
173: =item setflags()
174:
175: =item maincall()
176:
177: =item load_remote_msg()
178:
179: =item get_menu_name()
180:
181: =item reopenmenu()
182:
183: =item open()
184:
185: Open the menu
186:
187: =item clear()
188:
189: =item switch()
190:
191: Switch a button or create a link
192: Switch acts on the javascript that is executed when a button is clicked.
193: The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
194:
195: =item secondlevel()
196:
197: =item openmenu()
198:
199: =item inlinemenu()
200:
201: =item rawconfig()
202:
203: =item utilityfunctions()
204:
205: Output from this routine is a number of javascript functions called by
206: items in the inline menu, and in some cases items in the Main Menu page.
207:
208: =item serverform()
209:
210: =item constspaceform()
211:
212: =item get_nav_status()
213:
214: =item hidden_button_check()
215:
216: =item roles_selector()
217:
218: =item jump_to_role()
219:
220: =back
221:
222: =cut
223:
224: package Apache::lonmenu;
225:
226: use strict;
227: use Apache::lonnet;
228: use Apache::lonhtmlcommon();
229: use Apache::loncommon();
230: use Apache::lonenc();
231: use Apache::lonlocal;
232: use Apache::lonmsg();
233: use LONCAPA qw(:DEFAULT :match);
234: use HTML::Entities();
235: use Apache::lonwishlist();
236:
237: use vars qw(@desklines %category_names %category_members %category_positions
238: $readdesk @primary_menu %primary_submenu @secondary_menu %secondary_submenu);
239:
240: my @inlineremote;
241:
242: sub prep_menuitem {
243: my ($menuitem,$target,$listclass,$linkattr) = @_;
244: return '' unless(ref($menuitem) eq 'ARRAY');
245: my ($link,$targetattr);
246: if ($$menuitem[1]) { # graphical Link
247: $link = "<img class=\"LC_noBorder\""
248: . " src=\"" . &Apache::loncommon::lonhttpdurl($$menuitem[1]) . "\""
249: . " alt=\"" . &mt($$menuitem[2]) . "\" />";
250: } else { # textual Link
251: $link = &mt($$menuitem[3]);
252: }
253: if ($target ne '') {
254: $targetattr = ' target="'.$target.'"';
255: }
256: return ($listclass?'<li class="'.$listclass.'">':'<li>').'<a'
257: # highlighting for new messages
258: . ( $$menuitem[4] eq 'newmsg' ? ' class="LC_new_message"' : '')
259: . qq| href="$$menuitem[0]"$targetattr $linkattr>$link</a></li>|;
260: }
261:
262: # primary_menu() evaluates @primary_menu and returns a two item array,
263: # with the array elements containing XHTML for the left and right sides of
264: # the menu that contains the following links:
265: # Personal, About, Message, Roles, Help, Logout
266: # @primary_menu is filled within the BEGIN block of this module with
267: # entries from mydesk.tab
268: sub primary_menu {
269: my ($crstype,$ltimenu,$menucoll,$menuref,$links_disabled,$links_target) = @_;
270: my (%menu,%ltiexc,%menuopts);
271: # each element of @primary contains following array:
272: # (link url, icon path, alt text, link text, condition, position)
273: my $public;
274: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
275: || (($env{'user.name'} eq '') && ($env{'user.domain'} eq ''))) {
276: $public = 1;
277: }
278: my $lti;
279: if ($env{'request.lti.login'}) {
280: $lti = 1;
281: if (ref($ltimenu) eq 'HASH') {
282: foreach my $item ('fullname','logout') {
283: unless ($ltimenu->{$item}) {
284: $ltiexc{$item} = 1;
285: }
286: }
287: }
288: }
289: my ($listclass,$linkattr,$target);
290: if ($links_disabled) {
291: $listclass = 'LCisDisabled';
292: $linkattr = 'aria-disabled="true"';
293: }
294: if ($links_target ne '') {
295: $target = $links_target;
296: } else {
297: my ($ltitarget,$deeplinktarget);
298: if ($env{'request.lti.login'}) {
299: $ltitarget = $env{'request.lti.target'};
300: }
301: if ($env{'request.deeplink.login'}) {
302: $deeplinktarget = $env{'request.deeplink.target'};
303: }
304: if (($ltitarget eq 'iframe') || ($deeplinktarget eq '_self')) {
305: $target = '_self';
306: } else {
307: $target = '_top';
308: }
309: }
310: if (($menucoll) && (ref($menuref) eq 'HASH')) {
311: %menuopts = %{$menuref};
312: }
313: foreach my $menuitem (@primary_menu) {
314: # evaluate conditions
315: next if ref($menuitem) ne 'ARRAY'; #
316: next if $$menuitem[4] eq 'nonewmsg' # show links depending on
317: && &Apache::lonmsg::mynewmail(); # whether a new msg
318: next if $$menuitem[4] eq 'newmsg' # arrived or not
319: && !&Apache::lonmsg::mynewmail(); #
320: next if $$menuitem[4] !~ /public/ ##we've a public user,
321: && $public; ##who should not see all
322: ##links
323: next if $$menuitem[4] eq 'onlypublic'# hide links which are
324: && !$public; # only visible to public
325: # users
326: next if $$menuitem[4] eq 'roles' ##show links depending on
327: && (&Apache::loncommon::show_course() ##term 'Courses' or
328: || $lti); ##'Roles' wanted
329: next if $$menuitem[4] eq 'courses' ##and not LTI access
330: && (!&Apache::loncommon::show_course()
331: || $lti);
332: next if $$menuitem[4] eq 'notlti'
333: && $lti;
334: next if $$menuitem[4] eq 'ltiexc'
335: && exists($ltiexc{lc($menuitem->[3])});
336: my $title = $menuitem->[3];
337: my $position = $menuitem->[5];
338: if ($position eq '') {
339: $position = 'right';
340: }
341: if ($env{'request.course.id'} && $menucoll) {
342: if (($menuitem->[6]) && (!$menuopts{$menuitem->[6]})) {
343: if ($menuitem->[6] eq 'pers') {
344: if ($menuopts{'name'} && !$ltiexc{'fullname'} &&
345: $env{'user.name'} && $env{'user.domain'}) {
346: $menu{$position} .= '<li><a href="#">'.
347: &Apache::loncommon::plainname($env{'user.name'},
348: $env{'user.domain'}).'</a></li>';
349: next;
350: } else {
351: next;
352: }
353: } else {
354: next;
355: }
356: }
357: }
358: if (defined($primary_submenu{$title})) {
359: my $link;
360: if ($menuitem->[0] ne '') {
361: $link = $menuitem->[0];
362: } else {
363: $link = '#';
364: }
365: my @primsub;
366: if (ref($primary_submenu{$title}) eq 'ARRAY') {
367: foreach my $item (@{$primary_submenu{$title}}) {
368: next if (($item->[2] eq 'wishlist') && (!$env{'user.adv'}));
369: next if ((($item->[2] eq 'portfolio') ||
370: ($item->[2] eq 'blog')) &&
371: (!&Apache::lonnet::usertools_access('','',$item->[2],
372: undef,'tools')));
373: if ($env{'request.course.id'} && $menucoll) {
374: next if ($item->[3]) && (!$menuopts{$item->[3]});
375: }
376: push(@primsub,$item);
377: }
378: if ($title eq 'Personal') {
379: if ($env{'user.name'} && $env{'user.domain'} && !$ltiexc{'fullname'}) {
380: unless (($env{'request.course.id'}) && ($menucoll) && (!$menuopts{'name'})) {
381: $title = &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'});
382: }
383: }
384: next if (($env{'request.course.id'}) && ($menucoll) && ($title eq 'Personal') &&
385: (!@primsub));
386: if ($title eq 'Personal') {
387: $title = &mt($title);
388: }
389: } else {
390: $title = &mt($title);
391: }
392: if (@primsub > 0) {
393: $menu{$position} .= &create_submenu($link,$target,$title,\@primsub,1,undef,$listclass,$linkattr);
394: } elsif ($link) {
395: $menu{$position} .= ($listclass?'<li class="'.$listclass.'">':'<li>').
396: '<a href="'.$link.'" target="'.$target.'" '.$linkattr.'>'.$title.'</a></li>';
397: }
398: }
399: } elsif ($$menuitem[3] eq 'Help') { # special treatment for helplink
400: if ($public) {
401: my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
402: my $defdom = &Apache::lonnet::default_login_domain();
403: my $to = &Apache::loncommon::build_recipient_list(undef,
404: 'helpdeskmail',
405: $defdom,$origmail);
406: if ($to ne '') {
407: $menu{$position} .= &prep_menuitem($menuitem,$target,$listclass,$linkattr);
408: }
409: } else {
410: $menu{$position} .= ($listclass?'<li class="'.$listclass.'">':'<li>').
411: &Apache::loncommon::top_nav_help('Help',$linkattr).
412: '</li>';
413: }
414: } elsif ($$menuitem[3] eq 'Log In') {
415: if ($public) {
416: if (&Apache::lonnet::get_saml_landing()) {
417: $$menuitem[0] = '/adm/login';
418: }
419: }
420: $menu{$position} .= prep_menuitem($menuitem,$target,$listclass,$linkattr);
421: } else {
422: $menu{$position} .= prep_menuitem($menuitem,$target,$listclass,$linkattr);
423: }
424: }
425: my @output = ('','');
426: if ($menu{'left'} ne '') {
427: $output[0] = "<ol class=\"LC_primary_menu LC_floatleft\">$menu{'left'}</ol>";
428: }
429: if ($menu{'right'} ne '') {
430: $output[1] = "<ol class=\"LC_primary_menu LC_floatright LC_right\">$menu{'right'}</ol>";
431: }
432: return @output;
433: }
434:
435: #returns hashref {user=>'',dom=>''} containing:
436: # own name, domain if user is au
437: # name, domain of parent author if user is ca or aa
438: #empty return if user is not an author or not on homeserver
439: #
440: #TODO this should probably be moved somewhere more central
441: #since it can be used by different parts of the system
442: sub getauthor{
443: return unless $env{'request.role'}=~/^(ca|aa|au)/; #nothing to do if user isn't some kind of author
444:
445: #co- or assistent author?
446: my ($dom, $user) = ($env{'request.role'} =~ /^(?:ca|aa)\.\/($match_domain)\/($match_username)$/)
447: ? ($1, $2) #domain, username of the parent author
448: : @env{ ('request.role.domain', 'user.name') }; #own domain, username
449:
450: # current server == home server?
451: my $home = &Apache::lonnet::homeserver($user,$dom);
452: foreach (&Apache::lonnet::current_machine_ids()){
453: return {user => $user, dom => $dom} if $_ eq $home;
454: }
455:
456: # if wrong server
457: return;
458: }
459:
460: sub secondary_menu {
461: my ($httphost,$ltiscope,$ltimenu,$noprimary,$menucoll,$menuref,
462: $links_disabled,$links_target) = @_;
463: my $menu;
464:
465: my $crstype = &Apache::loncommon::course_type();
466: my $crs_sec = $env{'request.course.id'} . ($env{'request.course.sec'}
467: ? "/$env{'request.course.sec'}"
468: : '');
469: my $canedit = &Apache::lonnet::allowed('mdc', $env{'request.course.id'});
470: my $canvieweditor = &Apache::lonnet::allowed('cev', $env{'request.course.id'});
471: my $canviewroster = $env{'course.'.$env{'request.course.id'}.'.student_classlist_view'};
472: if ($canviewroster eq 'disabled') {
473: undef($canviewroster);
474: }
475: my $canviewgrps = &Apache::lonnet::allowed('vcg', $crs_sec);
476: my $canmodifyuser = &Apache::lonnet::allowed('cst', $crs_sec);
477: my $canviewusers = &Apache::lonnet::allowed('vcl', $crs_sec);
478: my $canviewwnew = &Apache::lonnet::allowed('whn', $crs_sec);
479: my $canviewpara = &Apache::lonnet::allowed('vpa', $crs_sec);
480: my $canmodpara = &Apache::lonnet::allowed('opa', $crs_sec);
481: my $canvgr = &Apache::lonnet::allowed('vgr', $crs_sec);
482: my $canmgr = &Apache::lonnet::allowed('mgr', $crs_sec);
483: my $canplc = &Apache::lonnet::allowed('plc', $crs_sec);
484: my $author = &getauthor();
485:
486: my ($cdom,$cnum,$showsyllabus,$showfeeds,$showresv,$grouptools,
487: $lti,$ltimapres,%ltiexc,%menuopts);
488: $grouptools = 0;
489: if ($env{'request.course.id'}) {
490: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
491: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
492: unless ($canedit || $canvieweditor) {
493: unless (&Apache::lonnet::is_on_map("public/$cdom/$cnum/syllabus")) {
494: if (($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'}) ||
495: ($env{'course.'.$env{'request.course.id'}.'.uploadedsyllabus'}) ||
496: ($env{'course.'.$env{'request.course.id'}.'.updatedsyllabus'}) ||
497: ($env{'request.course.syllabustime'})) {
498: $showsyllabus = 1;
499: }
500: }
501: if ($env{'request.course.feeds'}) {
502: $showfeeds = 1;
503: }
504: }
505: unless ($canmgr || $canvgr) {
506: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
507: if (keys(%slots) > 0) {
508: $showresv = 1;
509: }
510: }
511: if ($env{'request.course.groups'} ne '') {
512: foreach my $group (split(/:/,$env{'request.course.groups'})) {
513: next unless ($group =~ /^\w+$/);
514: my @privs = split(/:/,$env{"user.priv.$env{'request.role'}./$cdom/$cnum/$group"});
515: shift(@privs);
516: if (@privs) {
517: $grouptools ++;
518: }
519: }
520: }
521: if ($env{'request.lti.login'}) {
522: $lti = 1;
523: if (ref($ltimenu) eq 'HASH') {
524: foreach my $item ('fullname','coursetitle','role','logout','grades') {
525: unless ($ltimenu->{$item}) {
526: $ltiexc{$item} = 1;
527: }
528: }
529: }
530: if (($ltiscope eq 'map') || ($ltiscope eq 'resource')) {
531: $ltimapres = 1;
532: }
533: }
534: }
535: if (($menucoll) && (ref($menuref) eq 'HASH')) {
536: %menuopts = %{$menuref};
537: }
538:
539: my ($listclass,$linkattr,$target);
540: if ($links_disabled) {
541: $listclass = 'LCisDisabled';
542: $linkattr = 'aria-disabled="true"';
543: }
544:
545: my ($canmodifycoauthor);
546: if ($env{'request.role'} eq "au./$env{'user.domain'}/") {
547: my $extent = "$env{'user.domain'}/$env{'user.name'}";
548: if ((&Apache::lonnet::allowed('cca',$extent)) ||
549: (&Apache::lonnet::allowed('caa',$extent))) {
550: $canmodifycoauthor = 1;
551: }
552: }
553:
554: my ($roleswitcher_js,$roleswitcher_form);
555: if ($links_target ne '') {
556: $target = $links_target;
557: } else {
558: my ($ltitarget,$deeplinktarget);
559: if ($env{'request.lti.login'}) {
560: $ltitarget = $env{'request.lti.target'};
561: }
562: if ($env{'request.deeplink.login'}) {
563: $deeplinktarget = $env{'request.deeplink.target'};
564: }
565: if (($ltitarget eq 'iframe') || ($deeplinktarget eq '_self')) {
566: $target = '_self';
567: } else {
568: $target = '_top';
569: }
570: }
571:
572: foreach my $menuitem (@secondary_menu) {
573: # evaluate conditions
574: next if ref($menuitem) ne 'ARRAY';
575: next if $$menuitem[4] ne 'always'
576: && ($$menuitem[4] ne 'author' && $$menuitem[4] ne 'cca')
577: && !$env{'request.course.id'};
578: next if $$menuitem[4] =~ /^crsedit/
579: && (!$canedit && !$canvieweditor);
580: next if $$menuitem[4] eq 'crseditCourse'
581: && ($crstype eq 'Community');
582: next if $$menuitem[4] eq 'crseditCommunity'
583: && ($crstype eq 'Course');
584: next if $$menuitem[4] eq 'nvgr'
585: && ($canvgr || $ltiexc{'grades'});
586: next if $$menuitem[4] eq 'vgr'
587: && !$canvgr;
588: next if $$menuitem[4] eq 'viewusers'
589: && !$canmodifyuser && !$canviewusers;
590: next if $$menuitem[4] eq 'noviewusers'
591: && ($canmodifyuser || $canviewusers || !$canviewroster);
592: next if $$menuitem[4] eq 'mgr'
593: && !$canmgr;
594: next if $$menuitem[4] eq 'showresv'
595: && !$showresv;
596: next if $$menuitem[4] eq 'whn'
597: && !$canviewwnew;
598: next if $$menuitem[4] eq 'params'
599: && (!$canmodpara && !$canviewpara);
600: next if $$menuitem[4] eq 'nvcg'
601: && ($canviewgrps || !$grouptools);
602: next if $$menuitem[4] eq 'showsyllabus'
603: && !$showsyllabus;
604: next if $$menuitem[4] eq 'showfeeds'
605: && !$showfeeds;
606: next if $$menuitem[4] eq 'plc'
607: && !$canplc;
608: next if $$menuitem[4] eq 'author'
609: && !$author;
610: next if $$menuitem[4] eq 'cca'
611: && !$canmodifycoauthor;
612: next if $$menuitem[4] eq 'notltimapres'
613: && $ltimapres;
614: next if $$menuitem[4] eq 'notlti'
615: && $lti;
616: next if $$menuitem[4] eq 'lti'
617: && (!$lti || !$noprimary);
618: next if $$menuitem[3] eq 'Logout'
619: && $ltiexc{'logout'};
620:
621: my $title = $menuitem->[3];
622: if ($env{'request.course.id'} && $menucoll) {
623: if ($$menuitem[5] eq 'main') {
624: next if ($menuopts{$$menuitem[5]} eq 'n');
625: } elsif ($$menuitem[5] ne 'roles') {
626: next if (($$menuitem[5]) && (!$menuopts{$$menuitem[5]}));
627: }
628: }
629: if (defined($secondary_submenu{$title})) {
630: my $link;
631: if ($menuitem->[0] ne '') {
632: $link = $menuitem->[0];
633: } else {
634: $link = '#';
635: }
636: my @scndsub;
637: if (ref($secondary_submenu{$title}) eq 'ARRAY') {
638: foreach my $item (@{$secondary_submenu{$title}}) {
639: if (ref($item) eq 'ARRAY') {
640: next if ($item->[2] eq 'vgr' && !$canvgr);
641: next if ($item->[2] eq 'opa' && !$canmodpara);
642: next if ($item->[2] eq 'vpa' && !$canviewpara);
643: next if ($item->[2] eq 'viewusers' && !($canmodifyuser || $canviewusers));
644: next if ($item->[2] eq 'mgr' && !$canmgr);
645: next if ($item->[2] eq 'vcg' && !$canviewgrps);
646: next if ($item->[2] eq 'crsedit' && !$canedit && !$canvieweditor);
647: next if ($item->[2] eq 'params' && !$canmodpara && !$canviewpara);
648: next if ($item->[2] eq 'author' && !$author);
649: next if ($item->[2] eq 'cca' && !$canmodifycoauthor);
650: next if ($item->[2] eq 'lti' && !$lti);
651: if ($item->[2] =~ /^lti(portfolio|wishlist|blog)$/) {
652: my $tool = $1;
653: next if !$lti;
654: next if (!&Apache::lonnet::usertools_access('','',$tool,
655: undef,'tools'));
656: }
657: push(@scndsub,$item);
658: }
659: }
660: if ($title eq 'Personal' && $env{'user.name'} && $env{'user.domain'}) {
661: unless ($ltiexc{'fullname'}) {
662: $title = &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'});
663: }
664: }
665: if (@scndsub > 0) {
666: $menu .= &create_submenu($link,$target,&mt($title),\@scndsub,1,undef,
667: $listclass,$linkattr);
668: } elsif ($link ne '#') {
669: $menu .= ($listclass?'<li class="'.$listclass.'">':'<li>').
670: '<a href="'.$link.'" target="'.$target.'" '.$linkattr.'>'.
671: &mt($title).'</a></li>';
672: }
673: }
674: } elsif ($$menuitem[3] eq 'Roles' && $env{'request.course.id'}) {
675: # special treatment for role selector
676: my ($switcher,$has_opa_priv);
677: ($roleswitcher_js,$roleswitcher_form,$switcher,$has_opa_priv) =
678: &roles_selector(
679: $env{'course.' . $env{'request.course.id'} . '.domain'},
680: $env{'course.' . $env{'request.course.id'} . '.num'},
681: $httphost,$target,$menucoll,$menuref
682: );
683: if (($$menuitem[5]) && (!$menuopts{$$menuitem[5]})) {
684: next unless ($has_opa_priv);
685: }
686: $menu .= $switcher;
687: } else {
688: if ($$menuitem[3] eq 'Syllabus' && $env{'request.course.id'}) {
689: my $url = $$menuitem[0];
690: $url =~ s{\[cdom\]/\[cnum\]}{$cdom/$cnum};
691: if (&Apache::lonnet::is_on_map($url)) {
692: unless ($$menuitem[0] =~ /(\?|\&)register=1/) {
693: $$menuitem[0] .= (($$menuitem[0]=~/\?/)? '&' : '?').'register=1';
694: }
695: } else {
696: $$menuitem[0] =~ s{\&?register=1}{};
697: }
698: if ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://}) {
699: if (($ENV{'SERVER_PORT'} == 443) || ($env{'request.use_absolute'} =~ m{^https://})) {
700: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl())) {
701: unless ($$menuitem[0] =~ m{^https?://}) {
702: $$menuitem[0] = 'http://'.$ENV{'SERVER_NAME'}.$$menuitem[0];
703: }
704: unless ($$menuitem[0] =~ /(\&|\?)usehttp=1/) {
705: $$menuitem[0] .= (($$menuitem[0]=~/\?/) ? '&' : '?').'usehttp=1';
706: }
707: }
708: }
709: }
710: $$menuitem[0] = &HTML::Entities::encode($$menuitem[0],'&<>"');
711: }
712: $menu .= &prep_menuitem(\@$menuitem,$target,$listclass,$linkattr);
713: }
714: }
715: if ($menu =~ /\[url\].*\[symb\]/) {
716: my $escurl = &escape( &Apache::lonenc::check_encrypt(
717: $env{'request.noversionuri'}));
718:
719: my $escsymb = &escape( &Apache::lonenc::check_encrypt(
720: $env{'request.symb'}));
721:
722: if ( $env{'request.state'} eq 'construct'
723: and ( $env{'request.noversionuri'} eq ''
724: || !defined($env{'request.noversionuri'})))
725: {
726: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
727: ($escurl = $env{'request.filename'}) =~ s{^\Q$londocroot\E}{};
728: $escurl = &escape($escurl);
729: }
730: $menu =~ s/\[url\]/$escurl/g;
731: $menu =~ s/\[symb\]/$escsymb/g;
732: }
733: $menu =~ s/\[uname\]/$$author{user}/g;
734: $menu =~ s/\[udom\]/$$author{dom}/g;
735: $menu =~ s/\[javascript\]/javascript:/g;
736: if ($env{'request.course.id'}) {
737: $menu =~ s/\[cnum\]/$cnum/g;
738: $menu =~ s/\[cdom\]/$cdom/g;
739: }
740: if ($menu) {
741: $menu = "<ul id=\"LC_secondary_menu\">$menu</ul>";
742: }
743: if ($roleswitcher_form) {
744: $menu .= "\n$roleswitcher_js\n$roleswitcher_form";
745: }
746: return $menu;
747: }
748:
749: sub create_submenu {
750: my ($link,$target,$title,$submenu,$translate,$addclass,$listclass,$linkattr) = @_;
751: return unless (ref($submenu) eq 'ARRAY');
752: my $targetattr;
753: if (($target ne '') && ($link ne '#')) {
754: $targetattr = ' target="'.$target.'"';
755: }
756: my $menu = '<li class="LC_hoverable '.$addclass.'">'.
757: '<a href="'.$link.'"'.$targetattr.'>'.
758: '<span class="LC_nobreak">'.$title.
759: '<span class="LC_fontsize_small" style="font-weight:normal;">'.
760: ' ▼</span></span></a>'.
761: '<ul>';
762:
763: # $link and $title are only used in the initial string written in $menu
764: # as seen above, not needed for nested submenus
765: $menu .= &build_submenu($target, $submenu, $translate, '1', $listclass, $linkattr);
766: $menu .= '</ul></li>';
767:
768: return $menu;
769: }
770:
771: # helper routine for create_submenu
772: # build the dropdown (and nested submenus) recursively
773: # see perldoc create_submenu documentation for further information
774: sub build_submenu {
775: my ($target, $submenu, $translate, $first_level, $listclass, $linkattr) = @_;
776: unless (@{$submenu}) {
777: return '';
778: }
779:
780: my $menu = '';
781: my $count = 0;
782: my $numsub = scalar(@{$submenu});
783: foreach my $item (@{$submenu}) {
784: $count ++;
785: if (ref($item) eq 'ARRAY') {
786: my $href = $item->[0];
787: my $bordertop;
788: my $borderbot;
789: my $title;
790:
791: if ($translate) {
792: $title = &mt($item->[1]);
793: } else {
794: $title = $item->[1];
795: }
796:
797: if ($count == 1 && !$first_level) {
798: $bordertop = 'border-top: 1px solid black;';
799: }
800: if ($count == $numsub) {
801: $borderbot = 'border-bottom: 1px solid black;';
802: }
803:
804: # href is a reference to another submenu
805: if (ref($href) eq 'ARRAY') {
806: $menu .= '<li style="margin:0;padding:0;'.$bordertop . $borderbot . '">';
807: $menu .= '<p><span class="LC_primary_menu_innertitle">'
808: . $title . '</span><span class="LC_primary_menu_innerarrow">▶</span></p>';
809: $menu .= '<ul>';
810: $menu .= &build_submenu($target, $href, $translate);
811: $menu .= '</ul>';
812: $menu .= '</li>';
813: } else { # href is the actual hyperlink and does not represent another submenu
814: # for the current menu title
815: if ($href =~ /(aboutme|rss\.html)$/) {
816: next unless (($env{'user.name'} ne '') && ($env{'user.domain'} ne ''));
817: $href =~ s/\[domain\]/$env{'user.domain'}/g;
818: $href =~ s/\[user\]/$env{'user.name'}/g;
819: } elsif (($href =~ m{^/adm/preferences\?}) && ($href =~ /\[returnurl\]/)) {
820: my $returnurl = $ENV{'REQUEST_URI'};
821: if ($ENV{'REQUEST_URI'} =~ m{/adm/preferences\?action=(?:changedomcoord|authorsettings)\&returnurl=([^\&]+)$}) {
822: $returnurl = $1;
823: }
824: if (($returnurl =~ m{^/adm/createuser($|\?action=)}) ||
825: ($returnurl =~ m{^/priv/$match_domain/$match_username}) ||
826: ($returnurl =~ m{^/res(/?$|/$match_domain/$match_username)})) {
827: $returnurl =~ s{\?.*$}{};
828: $returnurl = '&returnurl='.&HTML::Entities::encode($returnurl,'"<>&\'');
829: } else {
830: undef($returnurl);
831: }
832: $href =~ s/\[returnurl\]/$returnurl/;
833: }
834: my $targetattr;
835: unless (($href eq '') || ($href =~ /^\#/)) {
836: if ($target ne '') {
837: $targetattr = ' target="'.$target.'"';
838: }
839: }
840:
841: $menu .= '<li ';
842: $menu .= ($listclass?'class="'.$listclass.'" ':'');
843: $menu .= 'style="margin:0;padding:0;'. $bordertop . $borderbot .'">';
844: $menu .= '<a href="'.$href.'"'.$targetattr.' '.$linkattr.'>' . $title . '</a>';
845: $menu .= '</li>';
846: }
847: }
848: }
849: return $menu;
850: }
851:
852: sub registerurl {
853: my ($forcereg) = @_;
854: my $result = '';
855: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
856: my $force_title='';
857: if ($env{'request.state'} eq 'construct') {
858: $force_title=&Apache::lonxml::display_title();
859: }
860: if (($env{'environment.remote'} ne 'on') ||
861: ((($env{'request.publicaccess'}) ||
862: (!&Apache::lonnet::is_on_map(
863: &unescape($env{'request.noversionuri'})))) &&
864: (!$forcereg))) {
865: return
866: $result
867: .'<script type="text/javascript">'."\n"
868: .'// <![CDATA['."\n"
869: .'function LONCAPAreg(){;} function LONCAPAstale(){}'."\n"
870: .'// ]]>'."\n"
871: .'</script>'
872: .$force_title;
873: }
874: # Graphical display after login only
875: if ($env{'request.registered'} && !$forcereg) { return ''; }
876: $result.=&innerregister($forcereg);
877: return $result.$force_title;
878: }
879:
880: sub innerregister {
881: my ($forcereg,$bread_crumbs,$group,$pagebuttonshide,$hostname,
882: $ltiscope,$ltiuri,$showncrumbsref) = @_;
883: my $const_space = ($env{'request.state'} eq 'construct');
884: my $is_const_dir = 0;
885:
886: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
887:
888: $env{'request.registered'} = 1;
889:
890: my $noremote = ($env{'environment.remote'} ne 'on');
891:
892: undef(@inlineremote);
893:
894: my $reopen=&Apache::lonmenu::reopenmenu();
895:
896: my $newmail='';
897:
898: if (&Apache::lonmsg::newmail() && !$noremote) {
899: # We have new mail and remote is up
900: $newmail= 'swmenu.setstatus("you have","messages");';
901: }
902:
903: my ($mapurl,$resurl,$crstype,$navmap);
904:
905: if ($env{'request.course.id'}) {
906: #
907: #course_type: Course or Community
908: #
909: $crstype = &Apache::loncommon::course_type();
910: if ($env{'request.symb'}) {
911: my $ignorenull;
912: unless ($env{'request.noversionuri'} eq '/adm/navmaps') {
913: $ignorenull = 1;
914: }
915: my $symb = &Apache::lonnet::symbread('','',$ignorenull);
916: ($mapurl, my $rid, $resurl) = &Apache::lonnet::decode_symb($symb);
917: my $coursetitle = $env{'course.'.$env{'request.course.id'}.'.description'};
918:
919: my $maptitle = &Apache::lonnet::gettitle($mapurl);
920: my $restitle = &Apache::lonnet::gettitle($symb);
921:
922: my (@crumbs,@mapcrumbs);
923: if (($env{'request.noversionuri'} ne '/adm/navmaps') && ($mapurl ne '')) {
924: unless ($ltiscope eq 'resource') {
925: if (($mapurl ne $env{'course.'.$env{'request.course.id'}.'.url'}) &&
926: !(($ltiscope eq 'map') && (&Apache::lonnet::clutter($resurl) eq $ltiuri))) {
927: $navmap = Apache::lonnavmaps::navmap->new();
928: if (ref($navmap)) {
929: @mapcrumbs = $navmap->recursed_crumbs($mapurl,$restitle);
930: }
931: }
932: }
933: }
934: unless (($ltiscope eq 'map') || ($ltiscope eq 'resource')) {
935: @crumbs = ({text => $crstype.' Contents',
936: href => "Javascript:gopost('/adm/navmaps','')"});
937: }
938: if ($mapurl ne $env{'course.'.$env{'request.course.id'}.'.url'}) {
939: if (@mapcrumbs) {
940: push(@crumbs,@mapcrumbs);
941: } elsif (($ltiscope ne 'map') && ($ltiscope ne 'resource')) {
942: push(@crumbs, {text => '...',
943: no_mt => 1});
944: }
945: }
946:
947: unless ((@mapcrumbs) || (!$maptitle) || ($maptitle eq 'default.sequence') ||
948: ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'}) ||
949: ($ltiscope eq 'resource')) {
950: push @crumbs, {text => $maptitle, no_mt => 1,
951: href => &Apache::lonnet::clutter($mapurl).'?navmap=1'};
952: }
953: if ($restitle && !@mapcrumbs) {
954: push(@crumbs,{text => $restitle, no_mt => 1});
955: }
956: my @tools;
957: if ($env{'request.filename'} =~ /\.page$/) {
958: my %breadcrumb_tools = &Apache::lonhtmlcommon::current_breadcrumb_tools();
959: if (ref($breadcrumb_tools{'tools'}) eq 'ARRAY') {
960: @tools = @{$breadcrumb_tools{'tools'}};
961: }
962: }
963: &Apache::lonhtmlcommon::clear_breadcrumbs();
964: &Apache::lonhtmlcommon::add_breadcrumb(@crumbs);
965: if (@tools) {
966: &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',@tools);
967: }
968: } else {
969: $resurl = $env{'request.noversionuri'};
970: my $courseurl = &Apache::lonnet::courseid_to_courseurl($env{'request.course.id'});
971: my $title = &mt('View Resource');
972: if ($resurl =~ m{^\Q/uploaded$courseurl/supplemental/\E(default|\d+)/}) {
973: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['folderpath','title']);
974: &Apache::lonhtmlcommon::clear_breadcrumbs();
975: if ($env{'form.title'}) {
976: $title = $env{'form.title'};
977: }
978: my ($trail,$cnum,$cdom);
979: if ($env{'form.folderpath'}) {
980: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
981: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
982: &Apache::loncommon::validate_folderpath(1,'',$cnum,$cdom);
983: }
984: if ($env{'form.folderpath'}) {
985: &prepare_functions($resurl,$forcereg,$group,undef,undef,1,$hostname);
986: $title = &HTML::Entities::encode($title,'\'"<>&');
987: ($trail) =
988: &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1,1);
989: } else {
990: &Apache::lonhtmlcommon::add_breadcrumb(
991: {text => "Supplemental $crstype Content",
992: href => "javascript:gopost('/adm/supplemental','')"});
993: $title = &HTML::Entities::encode(&mt('View Resource'),'\'"<>&');
994: ($trail) =
995: &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1,1);
996: }
997: if (ref($showncrumbsref)) {
998: $$showncrumbsref = 1;
999: }
1000: return $trail;
1001: } elsif ($resurl =~ m{^\Q/uploaded$courseurl/portfolio/syllabus/}) {
1002: &Apache::lonhtmlcommon::clear_breadcrumbs();
1003: &prepare_functions('/public'.$courseurl."/syllabus",
1004: $forcereg,$group,undef,undef,1,$hostname);
1005: $title = &HTML::Entities::encode(&mt('Syllabus File'),'\'"<>&');
1006: my ($trail) =
1007: &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1,1);
1008: if (ref($showncrumbsref)) {
1009: $$showncrumbsref = 1;
1010: }
1011: return $trail;
1012: }
1013: unless ($env{'request.state'} eq 'construct') {
1014: &Apache::lonhtmlcommon::clear_breadcrumbs();
1015: &Apache::lonhtmlcommon::add_breadcrumb({text => 'View Resource'});
1016: }
1017: }
1018: } elsif (! $const_space){
1019: #a situation when we're looking at a resource outside of context of a
1020: #course or construction space (e.g. with cumulative rights)
1021: &Apache::lonhtmlcommon::clear_breadcrumbs();
1022: unless ($env{'request.noversionuri'} =~ m{^/adm/$match_domain/$match_username/aboutme$}) {
1023: &Apache::lonhtmlcommon::add_breadcrumb({text => 'View Resource'});
1024: }
1025: }
1026: my $timesync = ( $noremote ? '' : 'swmenu.syncclock(1000*'.time.');' );
1027: # =============================================================================
1028: # ============================ This is for URLs that actually can be registered
1029: if ( ($env{'request.noversionuri'}!~m{^/(res/)*adm/})
1030: || ($forcereg)) {
1031:
1032: my %swtext;
1033: if ($noremote) {
1034: %swtext = &get_inline_text();
1035: } else {
1036: %swtext = &get_rc_text();
1037: }
1038: my $hwkadd='';
1039:
1040: my ($cdom,$cnum,%perms,$cfile,$switchserver,$home,$forceedit,
1041: $forceview,$editbutton);
1042: if (($resurl =~ m{^/adm/($match_domain)/($match_username)/aboutme$}) ||
1043: ($env{'request.role'} !~/^(aa|ca|au)/)) {
1044: if (($env{'environment.remote'} eq 'on') && ($env{'request.symb'})) {
1045: &Apache::lonhtmlcommon::clear_breadcrumbs();
1046: }
1047: $editbutton = &prepare_functions($resurl,$forcereg,$group,'','','',$hostname);
1048: }
1049: if ($editbutton eq '') {
1050: $editbutton = &clear(6,1);
1051: }
1052:
1053: #
1054: # This applies in course context
1055: #
1056: if ($env{'request.course.id'}) {
1057: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1058: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1059: $perms{'mdc'} = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
1060: $perms{'cev'} = &Apache::lonnet::allowed('cev',$env{'request.course.id'});
1061: my @privs;
1062: my $gradable_exttool;
1063: if ($env{'request.symb'} ne '') {
1064: if ($env{'request.noversionuri'} =~ m{^/adm/$cdom/$cnum/(\d+)/ext\.tool$}) {
1065: if (&Apache::lonnet::EXT('resource.0.gradable') =~ /^yes$/i) {
1066: $gradable_exttool = 1;
1067: push(@privs,('mgr','vgr'));
1068: }
1069: } elsif ($env{'request.filename'}=~/$LONCAPA::assess_re/) {
1070: push(@privs,('mgr','vgr'));
1071: }
1072: push(@privs,('opa','vpa'));
1073: }
1074: foreach my $priv (@privs) {
1075: $perms{$priv} = &Apache::lonnet::allowed($priv,$env{'request.course.id'});
1076: if (!$perms{$priv} && $env{'request.course.sec'} ne '') {
1077: $perms{$priv} =
1078: &Apache::lonnet::allowed($priv,"$env{'request.course.id'}/$env{'request.course.sec'}");
1079: }
1080: }
1081: #
1082: # Determine whether or not to show Grades and Submissions buttons
1083: #
1084: if (($env{'request.symb'} ne '') &&
1085: (($env{'request.filename'}=~/$LONCAPA::assess_re/) || ($gradable_exttool))) {
1086: if ($perms{'mgr'}) {
1087: $hwkadd.= &switch('','',7,2,'pgrd.png','Content Grades',
1088: 'grades[_4]',
1089: "gocmd('/adm/grades','gradingmenu')",
1090: 'Content Grades');
1091: } elsif ($perms{'vgr'}) {
1092: $hwkadd .= &switch('','',7,2,'subm.png','Content Submissions',
1093: 'missions[_1]',
1094: "gocmd('/adm/grades','submission')",
1095: 'Content Submissions');
1096: }
1097: }
1098: if (($env{'request.symb'} ne '') && (($perms{'opa'}) || ($perms{'vpa'}))) {
1099: $hwkadd .= &switch('','',7,3,'pparm.png','Content Settings',
1100: 'parms[_2]',"gocmd('/adm/parmset','set')",
1101: 'Content Settings');
1102: }
1103: # End grades/submissions check
1104:
1105: #
1106: # This applies to items inside a folder/page modifiable in the course.
1107: #
1108: if (($env{'request.symb'}=~/^uploaded/) && (($perms{'mdc'}) || ($perms{'cev'}))) {
1109: my $text = 'Edit Folder';
1110: if (($mapurl =~ /\.page$/) ||
1111: ($env{'request.symb'}=~
1112: m{uploaded/$cdom/$cnum/default_\d+\.page$})) {
1113: $text = 'Edit Page';
1114: }
1115: $hwkadd .= &switch('','',7,4,'docs-22x22.png',$text,'parms[_2]',
1116: "gocmd('/adm/coursedocs','direct')",
1117: 'Folder/Page Content');
1118: }
1119: # End modifiable folder/page container check
1120:
1121: #
1122: # Determine whether to show View As button for shortcut to display problem, answer, and submissions
1123: #
1124:
1125: if (($env{'request.symb'} ne '') &&
1126: ($env{'request.filename'}=~/$LONCAPA::assess_re/) &&
1127: (($perms{'mgr'}) || ($perms{'vgr'}))) {
1128: my ($viewas,$text,$change,$visibility,$vuname,$vudom,$vid,$leftvis,$defdom,$righticon);
1129: my %lt = &Apache::lonlocal::texthash(
1130: view => 'View',
1131: upda => 'Update',
1132: );
1133: if ($env{'request.user_in_effect'} =~ /^($match_username):($match_domain)$/) {
1134: ($vuname,$vudom) = ($1,$2);
1135: unless (&Apache::lonnet::is_advanced_user($vudom,$vuname)) {
1136: $vid = (&Apache::lonnet::idrget($vudom,$vuname))[1];
1137: }
1138: $viewas = $env{'request.user_in_effect'};
1139: $text = $lt{'upda'};
1140: $change = 'off';
1141: $visibility = 'inline';
1142: $leftvis = 'none';
1143: $defdom = $vudom;
1144: $righticon = '✖';
1145: } else {
1146: $text = $lt{'view'};
1147: $change = 'on';
1148: $visibility = 'none';
1149: $leftvis = 'inline';
1150: $defdom = $cdom;
1151: }
1152: my $sellink = &Apache::loncommon::selectstudent_link('userview','vuname','vudom');
1153: my $selscript=&Apache::loncommon::studentbrowser_javascript();
1154: my $shownsymb = &HTML::Entities::encode(&Apache::lonenc::check_encrypt($env{'request.symb'}),'<>&"');
1155: my $input = &mt('User: [_1] or ID: [_2] at: [_3]',
1156: '<input name="vuname" type="text" size="8" value="'.$vuname.'" />',
1157: '<input name="vid" type="text" size="8" value="'.$vid.'" />',
1158: &Apache::loncommon::select_dom_form($defdom,'vudom')).
1159: '<input name="LC_viewas" type="hidden" value="'.$viewas.'" />',
1160: '<input name="symb" type="hidden" value="'.$shownsymb.'" />';
1161: my $chooser = <<END;
1162: $selscript
1163: <a href="javascript:toggleViewAsUser('$change');" class="LC_menubuttons_link">
1164: <span id="usexpand" class="LC_menubuttons_inline_text" style="display:$leftvis">► </span>
1165: </a>
1166: <fieldset id="LC_selectuser" style="display:$visibility">
1167: <form name="userview" action="" method="post" onsubmit="event.preventDefault(); return validCourseUser(this,'$change');">
1168: <span class="LC_menubuttons_inline_text LC_nobreak">
1169: $input
1170: $sellink
1171: </span>
1172: <input type="submit" value="$text" />
1173: </form>
1174: </fieldset>
1175: <a href="javascript:toggleViewAsUser('$change');" class="LC_menubuttons_link">
1176: <span id="uscollapse" class="LC_menubuttons_inline_text">$righticon</span>
1177: </a>
1178: END
1179: &switch('','',7,5,'viewuser.png','View As','user[_1]',
1180: 'toggleViewAsUser('."'$change'".')',
1181: 'View As','','',$chooser);
1182: }
1183: # End view as user check
1184:
1185: }
1186: # End course context
1187:
1188: # Prepare the rest of the buttons
1189: my ($menuitems,$got_prt,$got_wishlist,$cstritems);
1190: if ($const_space) {
1191: #
1192: # We are in construction space
1193: #
1194:
1195: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1196: my ($udom,$uname,$thisdisfn) =
1197: ($env{'request.filename'}=~m{^\Q$londocroot/priv/\E([^/]+)/([^/]+)/(.*)$});
1198: my $currdir = '/priv/'.$udom.'/'.$uname.'/'.$thisdisfn;
1199: if ($currdir =~ m-/$-) {
1200: $is_const_dir = 1;
1201: if ($thisdisfn eq '') {
1202: $is_const_dir = 2;
1203: }
1204: } else {
1205: $currdir =~ s|[^/]+$||;
1206: my $cleandisfn = &Apache::loncommon::escape_single($thisdisfn);
1207: my $esc_currdir = &Apache::loncommon::escape_single($currdir);
1208: #
1209: # Probably should be in mydesk.tab
1210: #
1211: $menuitems=(<<ENDMENUITEMS);
1212: s&6&1&list.png&Directory&dir[_1]&golist('$esc_currdir')&List current directory
1213: s&6&2&rtrv.png&Retrieve&version[_1]&gocstr('/adm/retrieve','/priv/$udom/$uname/$cleandisfn')&Retrieve old version
1214: s&6&3&pub.png&Publish&resource[_3]&gocstr('/adm/publish','/priv/$udom/$uname/$cleandisfn')&Publish this resource
1215: s&7&1&del.png&Delete&resource[_2]&gocstr('/adm/cfile?action=delete','/priv/$udom/$uname/$cleandisfn')&Delete this resource
1216: s&7&2&prt.png&Print&printout[_1]&gocstr('/adm/printout','/priv/$udom/$uname/$cleandisfn')&Prepare a printable document
1217: ENDMENUITEMS
1218: unless ($noremote) {
1219: $cstritems = $menuitems;
1220: undef($menuitems);
1221: }
1222: }
1223: if (ref($bread_crumbs) eq 'ARRAY') {
1224: &Apache::lonhtmlcommon::clear_breadcrumbs();
1225: foreach my $crumb (@{$bread_crumbs}){
1226: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
1227: }
1228: }
1229: } elsif ( defined($env{'request.course.id'}) &&
1230: $env{'request.symb'} ne '' ) {
1231: #
1232: # We are in a course and looking at a registered URL
1233: # Should probably be in mydesk.tab
1234: #
1235: $menuitems = "c&3&1";
1236: if ($ltiscope eq 'resource') {
1237: # Suppress display of backward arrow for LTI Provider if scope is resource.
1238: # Suppress display of forward arrow for LTI Provider if scope is resource.
1239: } elsif ($ltiscope eq 'map') {
1240: # Suppress display of backward arrow for LTI Provider if scope is map and this is first resource.
1241: # Suppress display of forward arrow for LTI Provider if scope is map and this is the last resource.
1242: my $showforw = 1;
1243: my $showback = 1;
1244: my $navmap = Apache::lonnavmaps::navmap->new();
1245: if (ref($navmap)) {
1246: my $mapres = $navmap->getResourceByUrl($ltiuri);
1247: if (ref($mapres)) {
1248: if ($navmap->isLastResource($mapres,$env{'request.symb'})) {
1249: $showforw = 0;
1250: }
1251: if ($navmap->isFirstResource($mapres,$env{'request.symb'})) {
1252: $showback = 0;
1253: }
1254: }
1255: }
1256: if ($showback) {
1257: $menuitems.="
1258: s&2&1&back.png&&&gopost('/adm/flip','back:'+currentURL)&Previous content resource&&1";
1259: }
1260: if ($showforw) {
1261: $menuitems.="
1262: s&2&3&forw.png&&&gopost('/adm/flip','forward:'+currentURL)&Next content resource&&3";
1263: }
1264: } else {
1265: $menuitems.="
1266: s&2&1&back.png&&&gopost('/adm/flip','back:'+currentURL)&Previous content resource&&1
1267: s&2&3&forw.png&&&gopost('/adm/flip','forward:'+currentURL)&Next content resource&&3";
1268: }
1269: $menuitems .= (<<ENDMENUITEMS);
1270: c&6&3
1271: c&8&2
1272: s&8&3&prt.png&$swtext{'prt'}&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
1273: ENDMENUITEMS
1274: $got_prt = 1;
1275: if (($env{'user.adv'}) && ($env{'request.uri'} =~ /^\/res/)
1276: && (!$env{'request.enc'})) {
1277: # wishlist is only available for users with access to resource-pool
1278: # and links can only be set for resources within the resource-pool
1279: $menuitems .= (<<ENDMENUITEMS);
1280: s&9&1&alnk.png&$swtext{'alnk'}&linkstor[_1]&set_wishlistlink('',currentURL)&Save a link for this resource in my personal Stored Links repository&&1
1281: ENDMENUITEMS
1282: $got_wishlist = 1;
1283: }
1284:
1285: my $currentURL = &Apache::loncommon::get_symb();
1286: my ($symb_old,$symb_old_enc) = &Apache::loncommon::clean_symb($currentURL);
1287: my $annotation = &Apache::loncommon::get_annotation($symb_old,$symb_old_enc);
1288: $menuitems.="s&9&3&";
1289: if(length($annotation) > 0){
1290: $menuitems.="anot2.png";
1291: }else{
1292: $menuitems.="anot.png";
1293: }
1294: $menuitems.="&$swtext{'anot'}&tations[_1]&annotate()&";
1295: $menuitems.="Make notes and annotations about this resource&&1\n";
1296: my $is_mobile;
1297: if ($env{'browser.mobile'}) {
1298: $is_mobile = 1;
1299: }
1300:
1301: unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme|viewclasslist|portfolio)(\?|$)/) {
1302: if ((!$env{'request.enc'}) && ($env{'request.noversionuri'} !~ m{^/adm/wrapper/ext/}) &&
1303: ($env{'request.noversionuri'} !~ m{^/uploaded/$match_domain/$match_courseid/(docs/|default_\d+\.page$)}) &&
1304: ($env{'request.noversionuri'} !~ m{^/adm/.+/ext\.tool$})) {
1305: $menuitems.=(<<ENDREALRES);
1306: s&6&3&catalog.png&$swtext{'catalog'}&info[_1]&catalog_info(currentURL,'$is_mobile')&Show Metadata
1307: ENDREALRES
1308: }
1309: unless (($env{'request.noversionuri'} =~ m{^/uploaded/$match_domain/$match_courseid/(docs/|default_\d+\.page$)}) ||
1310: ($env{'request.noversionuri'} =~ m{^\Q/adm/wrapper/\E(ext|uploaded)/}) ||
1311: ($env{'request.noversionuri'} =~ m{^/adm/.+/ext\.tool$})) {
1312: $menuitems.=(<<ENDREALRES);
1313: s&8&1&eval.png&$swtext{'eval'}&this[_1]&gopost('/adm/evaluate',currentURL,1)&Provide my evaluation of this resource
1314: ENDREALRES
1315: }
1316: unless ($env{'request.noversionuri'} =~ m{^\Q/adm/wrapper/\E(ext|uploaded)/}) {
1317: $menuitems.=(<<ENDREALRES);
1318: s&8&2&fdbk.png&$swtext{'fdbk'}&discuss[_1]&gopost('/adm/feedback',currentURL,1)&Provide feedback messages or contribute to the course discussion about this resource
1319: ENDREALRES
1320: }
1321: }
1322: }
1323: if ($env{'request.uri'} =~ /^\/res/) {
1324: unless ($got_prt) {
1325: $menuitems .= (<<ENDMENUITEMS);
1326: s&8&3&prt.png&$swtext{'prt'}&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
1327: ENDMENUITEMS
1328: $got_prt = 1;
1329: }
1330: unless ($got_wishlist) {
1331: if (($env{'user.adv'}) && (!$env{'request.enc'})) {
1332: # wishlist is only available for users with access to resource-pool
1333: $menuitems .= (<<ENDMENUITEMS);
1334: s&9&1&alnk.png&$swtext{'alnk'}&linkstor[_1]&set_wishlistlink('',currentURL)&Save a link for this resource in your personal Stored Links repository&&1
1335: ENDMENUITEMS
1336: $got_wishlist = 1;
1337: }
1338: }
1339: }
1340: unless ($got_prt) {
1341: $menuitems .= (<<ENDMENUITEMS);
1342: c&8&3
1343: ENDMENUITEMS
1344: }
1345: unless ($got_wishlist) {
1346: $menuitems .= (<<ENDMENUITEMS);
1347: c&9&1
1348: ENDMENUITEMS
1349: }
1350: my $buttons='';
1351: foreach (split(/\n/,$menuitems)) {
1352: my ($command,@rest)=split(/\&/,$_);
1353: my $idx=10*$rest[0]+$rest[1];
1354: if (&hidden_button_check() eq 'yes') {
1355: if ($idx == 21 ||$idx == 23) {
1356: $buttons.=&switch('','',@rest);
1357: } else {
1358: $buttons.=&clear(@rest);
1359: }
1360: } else {
1361: if ($command eq 's') {
1362: $buttons.=&switch('','',@rest);
1363: } else {
1364: $buttons.=&clear(@rest);
1365: }
1366: }
1367: }
1368: my $linkprotout;
1369: if ($env{'request.deeplink.login'}) {
1370: $linkprotout = &linkprot_exit();
1371: }
1372: if ($noremote) {
1373: my $addremote=0;
1374: foreach (@inlineremote) { if ($_ ne '') { $addremote=1; last;} }
1375: if ($addremote) {
1376: my ($countdown,$buttonshide);
1377: if ($env{'request.filename'} =~ /\.page$/) {
1378: my %breadcrumb_tools = &Apache::lonhtmlcommon::current_breadcrumb_tools();
1379: if (ref($breadcrumb_tools{'tools'}) eq 'ARRAY') {
1380: $countdown = $breadcrumb_tools{'tools'}->[0];
1381: }
1382: $buttonshide = $pagebuttonshide;
1383: } else {
1384: $countdown = &countdown_timer();
1385: $buttonshide = &hidden_button_check();
1386: }
1387:
1388: &Apache::lonhtmlcommon::clear_breadcrumb_tools();
1389:
1390: &Apache::lonhtmlcommon::add_breadcrumb_tool(
1391: 'navigation', @inlineremote[21,23]);
1392:
1393: if ($buttonshide eq 'yes') {
1394: if ($countdown) {
1395: &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$countdown);
1396: }
1397: if ($linkprotout) {
1398: &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$linkprotout);
1399: }
1400: } else {
1401: my @tools = @inlineremote[93,91,81,82,83];
1402: if ($countdown) {
1403: unshift(@tools,$countdown);
1404: }
1405: if ($linkprotout) {
1406: unshift(@tools,$linkprotout);
1407: }
1408: &Apache::lonhtmlcommon::add_breadcrumb_tool(
1409: 'tools',@tools);
1410:
1411: #publish button in construction space
1412: if ($env{'request.state'} eq 'construct'){
1413: &Apache::lonhtmlcommon::add_breadcrumb_tool(
1414: 'advtools', $inlineremote[63]);
1415: } else {
1416: &Apache::lonhtmlcommon::add_breadcrumb_tool(
1417: 'tools', $inlineremote[63]);
1418: }
1419: &advtools_crumbs(@inlineremote);
1420: }
1421: } else {
1422: if ($linkprotout) {
1423: &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$linkprotout);
1424: }
1425: }
1426: my ($topic_help,$topic_help_text);
1427: if ($is_const_dir == 2) {
1428: if ((($ENV{'SERVER_PORT'} == 443) ||
1429: ($Apache::lonnet::protocol{$Apache::lonnet::perlvar{'lonHostID'}} eq 'https')) &&
1430: (&Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},'webdav'))) {
1431: $topic_help = 'Authoring_WebDAV,Authoring_WebDAV_Mac_10v6,Authoring_WebDAV_Mac_10v10,'.
1432: 'Authoring_WebDAV_Windows_v7,Authoring_WebDAV_Linux_Centos';
1433: $topic_help_text = 'About WebDAV access';
1434: }
1435: }
1436: if (ref($showncrumbsref)) {
1437: $$showncrumbsref = 1;
1438: }
1439: return &Apache::lonhtmlcommon::scripttag('', 'start')
1440: . &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0,'','','','',$topic_help,$topic_help_text)
1441: . &Apache::lonhtmlcommon::scripttag('', 'end');
1442:
1443: } else {
1444: my $cstrcrumbs;
1445: if ($const_space) {
1446: foreach (split(/\n/,$cstritems)) {
1447: my ($command,@rest)=split(/\&/,$_);
1448: my $idx=10*$rest[0]+$rest[1];
1449: &switch('','',@rest);
1450: }
1451: &Apache::lonhtmlcommon::add_breadcrumb_tool('advtools',
1452: @inlineremote[63,61,71,72]);
1453:
1454: $cstrcrumbs = &Apache::lonhtmlcommon::scripttag('', 'start')
1455: .&Apache::lonhtmlcommon::breadcrumbs(undef,undef,0)
1456: .&Apache::lonhtmlcommon::scripttag('', 'end');
1457: }
1458: my $requri=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
1459: $requri=&Apache::lonenc::check_encrypt(&unescape($requri));
1460: my $cursymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
1461: my $navstatus=&get_nav_status();
1462: my $clearcstr;
1463:
1464: if ($env{'user.adv'}) { $clearcstr='clearbut(6,1)'; }
1465: return <<ENDREGTHIS;
1466:
1467: <script type="text/javascript">
1468: // <![CDATA[
1469: // BEGIN LON-CAPA Internal
1470: var swmenu=null;
1471:
1472: function LONCAPAreg() {
1473: swmenu=$reopen;
1474: swmenu.clearTimeout(swmenu.menucltim);
1475: $timesync
1476: $newmail
1477: $buttons
1478: swmenu.currentURL="$requri";
1479: swmenu.reloadURL=swmenu.currentURL+window.location.search;
1480: swmenu.currentSymb="$cursymb";
1481: swmenu.reloadSymb="$cursymb";
1482: swmenu.currentStale=0;
1483: $navstatus
1484: $hwkadd
1485: $editbutton
1486: }
1487:
1488: function LONCAPAstale() {
1489: swmenu=$reopen
1490: swmenu.currentStale=1;
1491: if (swmenu.reloadURL!='' && swmenu.reloadURL!= null) {
1492: swmenu.switchbutton
1493: (3,1,'reload.gif','return','location','go(reloadURL)','Return to the last known location in the course sequence');
1494: }
1495: swmenu.clearbut(7,2);
1496: swmenu.clearbut(7,3);
1497: swmenu.menucltim=swmenu.setTimeout(
1498: 'clearbut(2,1);clearbut(2,3);clearbut(8,1);clearbut(8,2);clearbut(8,3);'+
1499: 'clearbut(9,1);clearbut(9,3);clearbut(6,3);$clearcstr',
1500: 2000);
1501: }
1502:
1503: // END LON-CAPA Internal
1504: // ]]>
1505: </script>
1506:
1507: $cstrcrumbs
1508: ENDREGTHIS
1509: }
1510: } else {
1511: unless ($noremote) {
1512: # Not registered, graphical
1513: return (<<ENDDONOTREGTHIS);
1514:
1515: <script type="text/javascript">
1516: // <![CDATA[
1517: // BEGIN LON-CAPA Internal
1518: var swmenu=null;
1519:
1520: function LONCAPAreg() {
1521: swmenu=$reopen
1522: $timesync
1523: swmenu.currentStale=1;
1524: swmenu.clearbut(2,1);
1525: swmenu.clearbut(2,3);
1526: swmenu.clearbut(8,1);
1527: swmenu.clearbut(8,2);
1528: swmenu.clearbut(8,3);
1529: swmenu.clearbut(9,1);
1530: if (swmenu.currentURL) {
1531: swmenu.switchbutton
1532: (3,1,'reload.gif','return','location','go(currentURL)');
1533: } else {
1534: swmenu.clearbut(3,1);
1535: }
1536: }
1537:
1538: function LONCAPAstale() {
1539: }
1540:
1541: // END LON-CAPA Internal
1542: // ]]>
1543: </script>
1544: ENDDONOTREGTHIS
1545:
1546: }
1547: return '';
1548: }
1549: }
1550:
1551: sub get_inline_text {
1552: my %text = (
1553: pgrd => 'Content Grades',
1554: subm => 'Content Submissions',
1555: pparm => 'Content Settings',
1556: docs => 'Folder/Page Content',
1557: pcstr => 'Edit',
1558: prt => 'Print',
1559: alnk => 'Stored Links',
1560: anot => 'Notes',
1561: catalog => 'Info',
1562: eval => 'Evaluate',
1563: fdbk => 'Feedback',
1564: );
1565: return %text;
1566: }
1567:
1568: sub get_rc_text {
1569: my %text = (
1570: pgrd => 'problem[_1]',
1571: subm => 'view sub-[_1]',
1572: pparm => 'problem[_2]',
1573: pcstr => 'edit[_1]',
1574: prt => 'prepare[_1]',
1575: back => 'backward[_1]',
1576: forw => 'forward[_1]',
1577: alnk => 'add to[_1]',
1578: anot => 'anno-[_1]',
1579: catalog => 'catalog[_2]',
1580: eval => 'evaluate[_1]',
1581: fdbk => 'feedback[_1]',
1582: );
1583: return %text;
1584: }
1585:
1586: sub loadevents() {
1587: if ($env{'request.state'} eq 'construct' ||
1588: $env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
1589: return 'LONCAPAreg();';
1590: }
1591:
1592: sub unloadevents() {
1593: if ($env{'request.state'} eq 'construct' ||
1594: $env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
1595: return 'LONCAPAstale();';
1596: }
1597:
1598: sub startupremote {
1599: my ($lowerurl)=@_;
1600: unless ($env{'environment.remote'} eq 'on') {
1601: return ('<meta HTTP-EQUIV="Refresh" CONTENT="0.5; url='.$lowerurl.'" />');
1602: }
1603: #
1604: # The Remote actually gets launched!
1605: #
1606: my $configmenu=&rawconfig();
1607: my $esclowerurl=&escape($lowerurl);
1608: my $message=&mt('"Waiting for Remote Control window to load: "+[_1]','waited');
1609: return(<<ENDREMOTESTARTUP);
1610: <script type="text/javascript">
1611: // <![CDATA[
1612: var timestart;
1613: function wheelswitch() {
1614: if (typeof(document.wheel) != 'undefined') {
1615: if (typeof(document.wheel.spin) != 'undefined') {
1616: var date=new Date();
1617: var waited=Math.round(30-((date.getTime()-timestart)/1000));
1618: document.wheel.spin.value=$message;
1619: }
1620: }
1621: if (window.status=='|') {
1622: window.status='/';
1623: } else {
1624: if (window.status=='/') {
1625: window.status='-';
1626: } else {
1627: if (window.status=='-') {
1628: window.status='\\\\';
1629: } else {
1630: if (window.status=='\\\\') { window.status='|'; }
1631: }
1632: }
1633: }
1634: }
1635:
1636: // ---------------------------------------------------------- The wait function
1637: var canceltim;
1638: function wait() {
1639: if ((menuloaded==1) || (tim==1)) {
1640: window.status='Done.';
1641: if (tim==0) {
1642: clearTimeout(canceltim);
1643: $configmenu
1644: window.location='$lowerurl';
1645: } else {
1646: window.location='/adm/remote?action=collapse&url=$esclowerurl';
1647: }
1648: } else {
1649: wheelswitch();
1650: setTimeout('wait();',200);
1651: }
1652: }
1653:
1654: function main() {
1655: canceltim=setTimeout('tim=1;',30000);
1656: window.status='-';
1657: var date=new Date();
1658: timestart=date.getTime();
1659: wait();
1660: }
1661:
1662: // ]]>
1663: </script>
1664: ENDREMOTESTARTUP
1665: }
1666:
1667: sub setflags() {
1668: return(<<ENDSETFLAGS);
1669: <script type="text/javascript">
1670: // <![CDATA[
1671: menuloaded=0;
1672: tim=0;
1673: // ]]>
1674: </script>
1675: ENDSETFLAGS
1676: }
1677:
1678: sub maincall() {
1679: unless ($env{'environment.remote'} eq 'on') { return ''; }
1680: return(<<ENDMAINCALL);
1681: <script type="text/javascript">
1682: // <![CDATA[
1683: main();
1684: // ]]>
1685: </script>
1686: ENDMAINCALL
1687: }
1688:
1689: sub load_remote_msg {
1690: my ($lowerurl)=@_;
1691:
1692: unless ($env{'environment.remote'} eq 'on') { return ''; }
1693:
1694: my $esclowerurl=&escape($lowerurl);
1695: my $link=&mt('[_1]Continue[_2] on in Inline Menu mode'
1696: ,'<a href="/adm/remote?action=collapse&url='.$esclowerurl.'">'
1697: ,'</a>');
1698: return(<<ENDREMOTEFORM);
1699: <p>
1700: <form name="wheel">
1701: <input name="spin" type="text" size="60" />
1702: </form>
1703: </p>
1704: <p>$link</p>
1705: ENDREMOTEFORM
1706: }
1707:
1708: sub get_menu_name {
1709: my $hostid = $Apache::lonnet::perlvar{'lonHostID'};
1710: $hostid =~ s/\W//g;
1711: return 'LCmenu'.$hostid;
1712: }
1713:
1714:
1715: sub reopenmenu {
1716: unless ($env{'environment.remote'} eq 'on') { return ''; }
1717: my $menuname = &get_menu_name();
1718: my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
1719: return('window.open('.$nothing.',"'.$menuname.'","",false);');
1720: }
1721:
1722:
1723: sub open {
1724: my $returnval='';
1725: unless ($env{'environment.remote'} eq 'on') {
1726: return
1727: '<script type="text/javascript">'."\n"
1728: .'// <![CDATA['."\n"
1729: .'self.name="loncapaclient";'."\n"
1730: .'// ]]>'."\n"
1731: .'</script>';
1732: }
1733: my $menuname = &get_menu_name();
1734:
1735: # unless (shift eq 'unix') {
1736: # resizing does not work on linux because of virtual desktop sizes
1737: # $returnval.=(<<ENDRESIZE);
1738: #if (window.screen) {
1739: # self.resizeTo(screen.availWidth-215,screen.availHeight-55);
1740: # self.moveTo(190,15);
1741: #}
1742: #ENDRESIZE
1743: # }
1744: $returnval=(<<ENDOPEN);
1745: // <![CDATA[
1746: window.status='Opening LON-CAPA Remote Control';
1747: var menu=window.open("/res/adm/pages/menu.html?inhibitmenu=yes","$menuname",
1748: "height=375,width=150,scrollbars=no,menubar=no,top=5,left=5,screenX=5,screenY=5");
1749: self.name='loncapaclient';
1750: // ]]>
1751: ENDOPEN
1752: return '<script type="text/javascript">'.$returnval.'</script>';
1753: }
1754:
1755: sub get_editbutton {
1756: my ($cfile,$home,$switchserver,$forceedit,$forceview,$forcereg,$hostname) = @_;
1757: my $jscall;
1758: if (($forceview) && ($env{'form.todocs'})) {
1759: my ($folderpath,$command,$navmap);
1760: if ($env{'request.symb'}) {
1761: $folderpath = &Apache::loncommon::symb_to_docspath($env{'request.symb'},\$navmap);
1762: } elsif ($env{'form.folderpath'} =~ /^supplemental/) {
1763: $folderpath = $env{'form.folderpath'};
1764: $command = '&forcesupplement=1';
1765: }
1766: $folderpath = &escape(&HTML::Entities::encode(&escape($folderpath),'<>&"'));
1767: $jscall = "go('/adm/coursedocs?folderpath=$folderpath$command')";
1768: } else {
1769: my $suppanchor;
1770: if ($env{'form.folderpath'}) {
1771: $suppanchor = $env{'form.anchor'};
1772: }
1773: my $shownsymb;
1774: if ($env{'request.symb'}) {
1775: $shownsymb = &Apache::lonenc::check_encrypt($env{'request.symb'});
1776: }
1777: $jscall = &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,$switchserver,
1778: $forceedit,$forcereg,$env{'request.symb'},$shownsymb,
1779: &escape($env{'form.folderpath'}),
1780: &escape($env{'form.title'}),$hostname,
1781: $env{'form.idx'},&escape($env{'form.suppurl'}),
1782: $env{'form.todocs'},$suppanchor);
1783: }
1784: if ($jscall) {
1785: my $icon = 'pcstr.png';
1786: my $label = 'Edit';
1787: if ($forceview) {
1788: $icon = 'tolastloc.png';
1789: $label = 'Exit Editing';
1790: }
1791: my $infunc = 1;
1792: my $clearbutton;
1793: if ($env{'environment.remote'} eq 'on') {
1794: if ($cfile =~ m{^/priv/}) {
1795: undef($infunc);
1796: $label = 'edit';
1797: } else {
1798: $clearbutton = 1;
1799: }
1800: }
1801: my $editor = &switch('','',6,1,$icon,$label,'resource[_2]',
1802: $jscall,"Edit this resource",'','',$infunc);
1803: if ($infunc) {
1804: return 1;
1805: } elsif ($clearbutton) {
1806: return &clear(6,1);
1807: } else {
1808: return $editor;
1809: }
1810: }
1811: return;
1812: }
1813:
1814: sub prepare_functions {
1815: my ($resurl,$forcereg,$group,$bread_crumbs,$advtools,$docscrumbs,$hostname,$forbodytag) = @_;
1816: unless ($env{'request.registered'}) {
1817: undef(@inlineremote);
1818: }
1819: my ($cdom,$cnum,%perms,$cfile,$switchserver,$home,$forceedit,
1820: $forceview);
1821:
1822: if ($env{'request.course.id'}) {
1823: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1824: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1825: $perms{'mdc'} = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
1826: }
1827:
1828: my $editbutton = '';
1829: my $viewsrcbutton = '';
1830: my $clientip = &Apache::lonnet::get_requestor_ip();
1831: #
1832: # Determine whether or not to display 'Edit' or 'View Source' icon/button
1833: #
1834: if ($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) {
1835: my $blocked = &Apache::loncommon::blocking_status('about',$clientip,$2,$1);
1836: my $file=&Apache::lonnet::declutter($env{'request.filename'});
1837: ($cfile,$home,$switchserver,$forceedit,$forceview) =
1838: &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
1839: &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
1840: if (($cfile) && ($home ne '') && ($home ne 'no_host') && (!$blocked)) {
1841: $editbutton = &get_editbutton($cfile,$home,$switchserver,
1842: $forceedit,$forceview,$forcereg);
1843: }
1844: } elsif ((!$env{'request.course.id'}) &&
1845: ($env{'user.author'}) && ($env{'request.filename'}) &&
1846: ($env{'request.role'} !~/^(aa|ca|au)/)) {
1847: #
1848: # Currently do not have the role of author or co-author.
1849: # Do we have authoring privileges for the resource?
1850: #
1851: my $file=&Apache::lonnet::declutter($env{'request.filename'});
1852: ($cfile,$home,$switchserver,$forceedit,$forceview) =
1853: &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
1854: &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
1855: if (($cfile) && ($home ne '') && ($home ne 'no_host')) {
1856: $editbutton = &get_editbutton($cfile,$home,$switchserver,
1857: $forceedit,$forceview,$forcereg);
1858: }
1859: } elsif ($env{'request.course.id'}) {
1860: #
1861: # This applies in course context
1862: #
1863: if (($perms{'mdc'}) &&
1864: (($resurl =~ m{^/?public/$cdom/$cnum/syllabus}) ||
1865: ($resurl =~ m{^/?uploaded/$cdom/$cnum/portfolio/syllabus/}) ||
1866: (($resurl =~ m{^/?uploaded/$cdom/$cnum/default_\d+\.sequence$}) && ($env{'form.navmap'})))) {
1867: if ($resurl =~ m{^/}) {
1868: $cfile = $resurl;
1869: } else {
1870: $cfile = "/$resurl";
1871: }
1872: $home = &Apache::lonnet::homeserver($cnum,$cdom);
1873: if ($env{'form.forceedit'}) {
1874: $forceview = 1;
1875: } else {
1876: $forceedit = 1;
1877: }
1878: if ($cfile =~ m{^/uploaded/$cdom/$cnum/default_\d+\.sequence$}) {
1879: my $text = 'Edit Folder';
1880: &switch('','',7,4,'docs-22x22.png','Edit Folder','parms[_2]',
1881: "gocmd('/adm/coursedocs','direct')",
1882: 'Folder/Page Content');
1883: $editbutton = 1;
1884: } else {
1885: $editbutton = &get_editbutton($cfile,$home,$switchserver,
1886: $forceedit,$forceview,$forcereg,
1887: $hostname);
1888: }
1889: } elsif (($resurl eq '/adm/extresedit') &&
1890: (($env{'form.symb'}) || ($env{'form.folderpath'}))) {
1891: ($cfile,$home,$switchserver,$forceedit,$forceview) =
1892: &Apache::lonnet::can_edit_resource($resurl,$cnum,$cdom,$resurl,
1893: $env{'form.symb'});
1894: if ($cfile ne '') {
1895: $editbutton = &get_editbutton($cfile,$home,$switchserver,
1896: $forceedit,$forceview,$forcereg,
1897: $env{'form.title'},$env{'form.suppurl'});
1898: }
1899: } elsif (($resurl =~ m{^/?adm/viewclasslist$}) &&
1900: (&Apache::lonnet::allowed('opa',$env{'request.course.id'}))) {
1901: ($cfile,$home,$switchserver,$forceedit,$forceview) =
1902: &Apache::lonnet::can_edit_resource($resurl,$cnum,$cdom,$resurl,
1903: $env{'form.symb'});
1904: $editbutton = &get_editbutton($cfile,$home,$switchserver,
1905: $forceedit,$forceview,$forcereg);
1906: } elsif (($resurl !~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) &&
1907: ($resurl ne '/cgi-bin/printout.pl')) {
1908: if ($env{'request.filename'}) {
1909: my $file=&Apache::lonnet::declutter($env{'request.filename'});
1910: ($cfile,$home,$switchserver,$forceedit,$forceview) =
1911: &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
1912: &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
1913: if ($cfile ne '') {
1914: $editbutton = &get_editbutton($cfile,$home,$switchserver,
1915: $forceedit,$forceview,$forcereg);
1916: }
1917: if ((($cfile eq '') || (!$editbutton)) &&
1918: ($resurl =~ /$LONCAPA::assess_re/)) {
1919: my $showurl = &Apache::lonnet::clutter($resurl);
1920: my $crs_sec = $env{'request.course.id'} . (($env{'request.course.sec'} ne '')
1921: ? "/$env{'request.course.sec'}"
1922: : '');
1923: if ((&Apache::lonnet::allowed('cre','/')) &&
1924: (&Apache::lonnet::metadata($resurl,'sourceavail') eq 'open')) {
1925: $viewsrcbutton = 1;
1926: } elsif (&Apache::lonnet::allowed('vxc',$crs_sec)) {
1927: if ($showurl =~ m{^\Q/res/$cdom/\E($match_username)/}) {
1928: my $auname = $1;
1929: if (($env{'request.course.adhocsrcaccess'} ne '') &&
1930: (grep(/^\Q$auname\E$/,split(/,/,$env{'request.course.adhocsrcaccess'})))) {
1931: $viewsrcbutton = 1;
1932: } elsif ((&Apache::lonnet::metadata($resurl,'sourceavail') eq 'open') &&
1933: (&Apache::lonnet::allowed('bre',$crs_sec))) {
1934: $viewsrcbutton = 1;
1935: }
1936: }
1937: }
1938: if ($viewsrcbutton) {
1939: &switch('','',6,1,'pcstr.png','View Source','resource[_2]','open_source()',
1940: 'View source code');
1941: }
1942: }
1943: }
1944: }
1945: }
1946: # End determination of 'Edit' icon/button display
1947:
1948: if ($env{'request.course.id'}) {
1949: # This applies to about me page for users in a course
1950: if ($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) {
1951: my ($sdom,$sname) = ($1,$2);
1952: unless (&Apache::lonnet::is_course($sdom,$sname)) {
1953: my $blocked = &Apache::loncommon::blocking_status('about',$clientip,$sname,$sdom);
1954: unless ($blocked) {
1955: &switch('','',6,4,'mail-message-new-22x22.png','Message to user',
1956: '',
1957: "go('/adm/email?compose=individual&recname=$sname&recdom=$sdom')",
1958: 'Send message to specific user','','',1);
1959: }
1960: }
1961: my $hideprivileged = 1;
1962: if (&Apache::lonnet::in_course($sdom,$sname,$cdom,$cnum,undef,
1963: $hideprivileged)) {
1964: foreach my $priv ('vsa','vgr','srm') {
1965: $perms{$priv} = &Apache::lonnet::allowed($priv,$env{'request.course.id'});
1966: if (!$perms{$priv} && $env{'request.course.sec'} ne '') {
1967: $perms{$priv} =
1968: &Apache::lonnet::allowed($priv,"$env{'request.course.id'}/$env{'request.course.sec'}");
1969: }
1970: }
1971: if ($perms{'vsa'}) {
1972: &switch('','',6,5,'trck-22x22.png','Activity',
1973: '',
1974: "go('/adm/trackstudent?selected_student=$sname:$sdom')",
1975: 'View recent activity by this person','','',1);
1976: }
1977: if ($perms{'vgr'}) {
1978: &switch('','',6,6,'rsrv-22x22.png','Reservations',
1979: '',
1980: "go('/adm/slotrequest?command=showresv&origin=aboutme&uname=$sname&udom=$sdom')",
1981: 'Slot reservation history','','',1);
1982: }
1983: if ($perms{'srm'}) {
1984: &switch('','',6,7,'contact-new-22x22.png','Records',
1985: '',
1986: "go('/adm/email?recordftf=retrieve&recname=$sname&recdom=$sdom')",
1987: 'Add records','','',1);
1988: }
1989: }
1990: }
1991: if (($env{'form.folderpath'} =~ /^supplemental/) &&
1992: (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) &&
1993: (($resurl =~ m{^/adm/wrapper/ext/}) ||
1994: ($resurl =~ m{^/adm/$cdom/$cnum/\d+/ext\.tool$}) ||
1995: ($resurl =~ m{^/uploaded/$cdom/$cnum/supplemental/}) ||
1996: ($resurl eq '/adm/supplemental') ||
1997: ($resurl =~ m{^/public/$cdom/$cnum/syllabus$}) ||
1998: ($resurl =~ m{^/adm/$match_domain/$match_username/aboutme$}))) {
1999: my @folders=split('&',$env{'form.folderpath'});
2000: if ((@folders > 2) || ($resurl ne '/adm/supplemental')) {
2001: my $suppanchor;
2002: if ($resurl =~ m{^/adm/wrapper/ext/}) {
2003: $suppanchor = $env{'form.anchor'};
2004: }
2005: my $esc_path=&escape(&HTML::Entities::encode(&escape($env{'form.folderpath'}),'<>&"'));
2006: my $link = '/adm/coursedocs?command=direct&forcesupplement=1&supppath='.
2007: "$esc_path&anchor=$suppanchor";
2008: if ($env{'request.use_absolute'} ne '') {
2009: $link = $env{'request.use_absolute'}.$link;
2010: }
2011: &switch('','',7,4,'docs-22x22.png','Edit Folder','parms[_2]',
2012: "location.href='$link'",'Folder/Page Content');
2013: }
2014: }
2015: }
2016:
2017: # End checking for items for about me page for users in a course
2018: if ($docscrumbs) {
2019: &Apache::lonhtmlcommon::clear_breadcrumb_tools();
2020: &advtools_crumbs(@inlineremote);
2021: return $editbutton;
2022: } elsif (($env{'request.registered'}) && (!ref($forbodytag))) {
2023: return $editbutton || $viewsrcbutton;
2024: } else {
2025: if (ref($bread_crumbs) eq 'ARRAY') {
2026: if (@inlineremote > 0) {
2027: if (ref($advtools) eq 'ARRAY') {
2028: @{$advtools} = @inlineremote;
2029: }
2030: }
2031: return;
2032: } elsif (@inlineremote > 0) {
2033: &Apache::lonhtmlcommon::clear_breadcrumb_tools();
2034: &advtools_crumbs(@inlineremote);
2035: if (ref($forbodytag)) {
2036: $$forbodytag =
2037: &Apache::lonhtmlcommon::scripttag('', 'start')
2038: .&Apache::lonhtmlcommon::breadcrumbs(undef,undef,0)
2039: .&Apache::lonhtmlcommon::scripttag('', 'end');
2040: }
2041: return;
2042: }
2043: }
2044: }
2045:
2046: sub advtools_crumbs {
2047: my @funcs = @_;
2048: if ($env{'request.noversionuri'} =~ m{^/adm/$match_domain/$match_username/aboutme$}) {
2049: &Apache::lonhtmlcommon::add_breadcrumb_tool(
2050: 'advtools', @funcs[61,64,65,66,67,74]);
2051: } elsif ($env{'request.noversionuri'} !~ m{^/adm/(navmaps|viewclasslist)(\?|$)}) {
2052: &Apache::lonhtmlcommon::add_breadcrumb_tool(
2053: 'advtools', @funcs[61,71,72,73,74,75,92]);
2054: } elsif ($env{'request.noversionuri'} eq '/adm/viewclasslist') {
2055: &Apache::lonhtmlcommon::add_breadcrumb_tool(
2056: 'advtools', $funcs[61]);
2057: }
2058: }
2059:
2060: # ================================================================== Raw Config
2061:
2062: sub clear {
2063: my ($row,$col)=@_;
2064: if ($env{'environment.remote'} eq 'on') {
2065: if (($row<1) || ($row>13)) { return ''; }
2066: return "\n".qq(window.status+='.';swmenu.clearbut($row,$col););
2067: } else {
2068: $inlineremote[10*$row+$col]='';
2069: return '';
2070: }
2071: }
2072:
2073: # ============================================ Switch a button or create a link
2074: # Switch acts on the javascript that is executed when a button is clicked.
2075: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
2076:
2077: sub switch {
2078: my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat,$nobreak,$infunc,$form)=@_;
2079: $act=~s/\$uname/$uname/g;
2080: $act=~s/\$udom/$udom/g;
2081: $top=&mt($top);
2082: $bot=&mt($bot);
2083: $desc=&mt($desc);
2084: my $idx=10*$row+$col;
2085: $category_members{$cat}.=':'.$idx;
2086:
2087: if (($env{'environment.remote'} eq 'on') && (!$infunc)) {
2088: if (($row<1) || ($row>13)) { return ''; }
2089: if ($env{'request.state'} eq 'construct') {
2090: my $text = $top.' '.$bot;
2091: $text=~s/\s*\-\s*//gs;
2092: my $pic = '<img alt="'.$text.'" src="'.
2093: &Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$img).
2094: '" align="'.($nobreak==3?'right':'left').'" class="LC_icon" />';
2095: $inlineremote[$idx] =
2096: '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.
2097: $pic.'<span class="LC_menubuttons_inline_text">'.$top.' </span></a>'.$form;
2098: }
2099: # Remote
2100: $img=~s/\.png$/\.gif/;
2101: return "\n".
2102: qq(window.status+='.';swmenu.switchbutton($row,$col,"$img","$top","$bot","$act","$desc"););
2103: }
2104:
2105: # Inline Menu
2106: if ($nobreak==2) { return ''; }
2107: my $text=$top.' '.$bot;
2108: $text=~s/\s*\-\s*//gs;
2109:
2110: my $pic=
2111: '<img alt="'.$text.'" src="'.
2112: &Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$img).
2113: '" align="'.($nobreak==3?'right':'left').'" class="LC_icon" />';
2114: if ($env{'browser.interface'} eq 'faketextual') {
2115: # Main Menu
2116: if ($nobreak==3) {
2117: $inlineremote[$idx]="\n".
2118: '<td class="LC_menubuttons_text" align="right">'.$text.
2119: '</td><td align="left">'.
2120: '<a href="javascript:'.$act.';">'.$pic.'</a></td></tr>';
2121: } elsif ($nobreak) {
2122: $inlineremote[$idx]="\n<tr>".
2123: '<td align="left">'.
2124: '<a href="javascript:'.$act.';">'.$pic.'</a></td>
2125: <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>';
2126: } else {
2127: $inlineremote[$idx]="\n<tr>".
2128: '<td align="left">'.
2129: '<a href="javascript:'.$act.';">'.$pic.
2130: '</a></td><td class="LC_menubuttons_text" colspan="3">'.
2131: '<a class="LC_menubuttons_link" href="javascript:'.$act.';"><span class="LC_menubuttons_inline_text">'.$desc.'</span></a></td></tr>';
2132: }
2133: } else {
2134: # Inline Menu
2135: my @tools = (93,91,81,82,83);
2136: unless ($env{'request.state'} eq 'construct') {
2137: push(@tools,63);
2138: }
2139: if ((($env{'environment.icons'} eq 'iconsonly') ||
2140: ($env{'environment.icons'} eq '') && ($env{'request.lti.login'})) &&
2141: (grep(/^$idx$/,@tools))) {
2142: $inlineremote[$idx] =
2143: '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.'</a>';
2144: } else {
2145: $inlineremote[$idx] =
2146: '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.
2147: '<span class="LC_menubuttons_inline_text">'.$top.' </span></a>';
2148: }
2149: }
2150: return '';
2151: }
2152:
2153: sub secondlevel {
2154: my $output='';
2155: my
2156: ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat)=@_;
2157: if ($prt eq 'any') {
2158: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
2159: } elsif ($prt=~/^r(\w+)/) {
2160: if ($rol eq $1) {
2161: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
2162: }
2163: }
2164: return $output;
2165: }
2166:
2167: sub openmenu {
2168: my $menuname = &get_menu_name();
2169: unless ($env{'environment.remote'} eq 'on') { return ''; }
2170: my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
2171: return "window.open(".$nothing.",'".$menuname."');";
2172: }
2173:
2174: sub inlinemenu {
2175: undef(@inlineremote);
2176: undef(%category_members);
2177: # calling rawconfig with "1" will evaluate mydesk.tab, even if there is no active remote control
2178: &rawconfig(1);
2179: my $output='<table><tr>';
2180: for (my $col=1; $col<=2; $col++) {
2181: $output.='<td class="LC_mainmenu_col_fieldset">';
2182: for (my $row=1; $row<=8; $row++) {
2183: foreach my $cat (keys(%category_members)) {
2184: if ($category_positions{$cat} ne "$col,$row") { next; }
2185: #$output.='<table><tr><td colspan="4" class="LC_menubuttons_category">'.&mt($category_names{$cat}).'</td></tr>';
2186: $output.='<div class="LC_Box LC_400Box">';
2187: $output.='<h3 class="LC_hcell">'.&mt($category_names{$cat}).'</h3>';
2188: $output.='<table>';
2189: my %active=();
2190: foreach my $menu_item (split(/\:/,$category_members{$cat})) {
2191: if ($inlineremote[$menu_item]) {
2192: $active{$menu_item}=1;
2193: }
2194: }
2195: foreach my $item (sort(keys(%active))) {
2196: $output.=$inlineremote[$item];
2197: }
2198: $output.='</table>';
2199: $output.='</div>';
2200: }
2201: }
2202: $output.="</td>";
2203: }
2204: $output.="</tr></table>";
2205: return $output;
2206: }
2207:
2208: sub rawconfig {
2209: #
2210: # This evaluates mydesk.tab
2211: # Need to add more positions and more privileges to deal with all
2212: # menu items.
2213: #
2214: my $textualoverride=shift;
2215: my $output='';
2216: if ($env{'environment.remote'} eq 'on') {
2217: $output.=
2218: "window.status='Opening Remote Control';var swmenu=".&openmenu().
2219: "\nwindow.status='Configuring Remote Control ';";
2220: } else {
2221: unless ($textualoverride) { return ''; }
2222: }
2223: my $uname=$env{'user.name'};
2224: my $udom=$env{'user.domain'};
2225: my $adv=$env{'user.adv'};
2226: my $show_course=&Apache::loncommon::show_course();
2227: my $author=$env{'user.author'};
2228: my $crs='';
2229: my $crstype='';
2230: if ($env{'request.course.id'}) {
2231: $crs='/'.$env{'request.course.id'};
2232: if ($env{'request.course.sec'}) {
2233: $crs.='_'.$env{'request.course.sec'};
2234: }
2235: $crs=~s/\_/\//g;
2236: $crstype = &Apache::loncommon::course_type();
2237: }
2238: my $pub=($env{'request.state'} eq 'published');
2239: my $con=($env{'request.state'} eq 'construct');
2240: my $rol=$env{'request.role'};
2241: my $requested_domain;
2242: if ($rol) {
2243: $requested_domain = $env{'request.role.domain'};
2244: }
2245: foreach my $line (@desklines) {
2246: my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc,$cat)=split(/\:/,$line);
2247: $prt=~s/\$uname/$uname/g;
2248: $prt=~s/\$udom/$udom/g;
2249: if ($prt =~ /\$crs/) {
2250: next unless ($env{'request.course.id'});
2251: next if ($crstype eq 'Community');
2252: $prt=~s/\$crs/$crs/g;
2253: } elsif ($prt =~ /\$cmty/) {
2254: next unless ($env{'request.course.id'});
2255: next if ($crstype ne 'Community');
2256: $prt=~s/\$cmty/$crs/g;
2257: }
2258: if ($prt =~ m/\$requested_domain/) {
2259: if ((!$requested_domain) && ($pro eq 'pbre') && ($env{'user.adv'})) {
2260: $prt=~s/\$requested_domain/$env{'user.domain'}/g;
2261: } else {
2262: $prt=~s/\$requested_domain/$requested_domain/g;
2263: }
2264: }
2265: if ($category_names{$cat}!~/\w/) { $cat='oth'; }
2266: if ($pro eq 'clear') {
2267: $output.=&clear($row,$col);
2268: } elsif ($pro eq 'any') {
2269: $output.=&secondlevel(
2270: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
2271: } elsif ($pro eq 'smp') {
2272: unless ($adv) {
2273: $output.=&secondlevel(
2274: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
2275: }
2276: } elsif ($pro eq 'adv') {
2277: if ($adv) {
2278: $output.=&secondlevel(
2279: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
2280: }
2281: } elsif ($pro eq 'shc') {
2282: if ($show_course) {
2283: $output.=&secondlevel(
2284: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
2285: }
2286: } elsif ($pro eq 'nsc') {
2287: if (!$show_course) {
2288: $output.=&secondlevel(
2289: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
2290: }
2291: } elsif (($pro=~/^p(\w+)/) && ($prt)) {
2292: my $priv = $1;
2293: if ($priv =~ /^mdc(Course|Community)/) {
2294: if ($crstype eq $1) {
2295: $priv = 'mdc';
2296: } else {
2297: next;
2298: }
2299: }
2300: if ((($priv eq 'bre') && (&Apache::lonnet::allowed($priv,$prt) eq 'F')) ||
2301: (($priv ne 'bre') && (&Apache::lonnet::allowed($priv,$prt)))) {
2302: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
2303: }
2304: } elsif ($pro eq 'course') {
2305: if (($env{'request.course.fn'}) && ($crstype ne 'Community')) {
2306: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
2307: }
2308: } elsif ($pro eq 'community') {
2309: if (($env{'request.course.fn'}) && ($crstype eq 'Community')) {
2310: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
2311: }
2312: } elsif ($pro =~ /^courseenv_(.*)$/) {
2313: my $key = $1;
2314: if ($crstype ne 'Community') {
2315: my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
2316: if ($key eq 'canuse_pdfforms') {
2317: if ($env{'request.course.id'} && $coursepref eq '') {
2318: my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
2319: $coursepref = $domdefs{'canuse_pdfforms'};
2320: }
2321: }
2322: if ($coursepref) {
2323: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
2324: }
2325: }
2326: } elsif ($pro =~ /^communityenv_(.*)$/) {
2327: my $key = $1;
2328: if ($crstype eq 'Community') {
2329: my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
2330: if ($key eq 'canuse_pdfforms') {
2331: if ($env{'request.course.id'} && $coursepref eq '') {
2332: my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
2333: $coursepref = $domdefs{'canuse_pdfforms'};
2334: }
2335: }
2336: if ($coursepref) {
2337: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
2338: }
2339: }
2340: } elsif ($pro =~ /^course_(.*)$/) {
2341: # Check for permissions inside of a course
2342: if (($env{'request.course.id'}) && ($crstype ne 'Community') &&
2343: (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
2344: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
2345: )) {
2346: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
2347: }
2348: } elsif ($pro =~ /^community_(.*)$/) {
2349: # Check for permissions inside of a community
2350: if (($env{'request.course.id'}) && ($crstype eq 'Community') &&
2351: (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
2352: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
2353: )) {
2354: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
2355: }
2356: } elsif ($pro eq 'author') {
2357: if ($author) {
2358: if ((($prt eq 'rca') && ($env{'request.role'}=~/^ca/)) ||
2359: (($prt eq 'raa') && ($env{'request.role'}=~/^aa/)) ||
2360: (($prt eq 'rau') && ($env{'request.role'}=~/^au/))) {
2361: # Check that we are on the correct machine
2362: my $cadom=$requested_domain;
2363: my $caname=$env{'user.name'};
2364: if (($prt eq 'rca') || ($prt eq 'raa')) {
2365: ($cadom,$caname)=
2366: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
2367: }
2368: $act =~ s/\$caname/$caname/g;
2369: $act =~ s/\$cadom/$cadom/g;
2370: my $home = &Apache::lonnet::homeserver($caname,$cadom);
2371: my $allowed=0;
2372: my @ids=&Apache::lonnet::current_machine_ids();
2373: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
2374: if ($allowed) {
2375: $output.=&switch($caname,$cadom,
2376: $row,$col,$img,$top,$bot,$act,$desc,$cat);
2377: }
2378: }
2379: }
2380: } elsif ($pro eq 'tools') {
2381: my @tools = ('aboutme','blog','portfolio');
2382: if (grep(/^\Q$prt\E$/,@tools)) {
2383: if (!&Apache::lonnet::usertools_access($env{'user.name'},
2384: $env{'user.domain'},
2385: $prt,undef,'tools')) {
2386: $output.=&clear($row,$col);
2387: next;
2388: }
2389: } elsif (($prt eq 'reqcrsnsc') || ($prt eq 'reqcrsshc')) {
2390: if (($prt eq 'reqcrsnsc') && ($show_course)) {
2391: next;
2392: }
2393: if (($prt eq 'reqcrsshc') && (!$show_course)) {
2394: next;
2395: }
2396: my $showreqcrs = &check_for_rcrs();
2397: if (!$showreqcrs) {
2398: $output.=&clear($row,$col);
2399: next;
2400: }
2401: }
2402: $prt='any';
2403: $output.=&secondlevel(
2404: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
2405: }
2406: }
2407: if ($env{'environment.remote'} eq 'on') {
2408: $output.="\nwindow.status='Synchronizing Time';swmenu.syncclock(1000*".time.");\nwindow.status='Remote Control Configured.';";
2409: if (&Apache::lonmsg::newmail()) {
2410: $output.='swmenu.setstatus("you have","messages");';
2411: }
2412: }
2413: return $output;
2414: }
2415:
2416: sub check_for_rcrs {
2417: my $showreqcrs = 0;
2418: my @reqtypes = ('official','unofficial','community','textbook');
2419: foreach my $type (@reqtypes) {
2420: if (&Apache::lonnet::usertools_access($env{'user.name'},
2421: $env{'user.domain'},
2422: $type,undef,'requestcourses')) {
2423: $showreqcrs = 1;
2424: last;
2425: }
2426: }
2427: if (!$showreqcrs) {
2428: foreach my $type (@reqtypes) {
2429: if ($env{'environment.reqcrsotherdom.'.$type} ne '') {
2430: $showreqcrs = 1;
2431: last;
2432: }
2433: }
2434: }
2435: return $showreqcrs;
2436: }
2437:
2438: # ======================================================================= Close
2439:
2440: sub close {
2441: unless ($env{'environment.remote'} eq 'on') { return ''; }
2442: my $menuname = &get_menu_name();
2443: return(<<ENDCLOSE);
2444: <script type="text/javascript">
2445: // <![CDATA[
2446: window.status='Accessing Remote Control';
2447: menu=window.open("/adm/rat/empty.html","$menuname",
2448: "height=350,width=150,scrollbars=no,menubar=no");
2449: window.status='Disabling Remote Control';
2450: menu.active=0;
2451: menu.autologout=0;
2452: window.status='Closing Remote Control';
2453: menu.close();
2454: window.status='Done.';
2455: // ]]>
2456: </script>
2457: ENDCLOSE
2458: }
2459:
2460: sub dc_popup_js {
2461: my %lt = &Apache::lonlocal::texthash(
2462: more => '(More ...)',
2463: less => '(Less ...)',
2464: );
2465: return <<"END";
2466:
2467: function showCourseID() {
2468: document.getElementById('dccid').style.display='block';
2469: document.getElementById('dccid').style.textAlign='left';
2470: document.getElementById('dccid').style.textFace='normal';
2471: document.getElementById('dccidtext').innerHTML ='<a href="javascript:hideCourseID();" class="LC_menubuttons_link">$lt{'less'}</a>';
2472: return;
2473: }
2474:
2475: function hideCourseID() {
2476: document.getElementById('dccid').style.display='none';
2477: document.getElementById('dccidtext').innerHTML ='<a href="javascript:showCourseID()" class="LC_menubuttons_link">$lt{'more'}</a>';
2478: return;
2479: }
2480:
2481: END
2482:
2483: }
2484:
2485: sub countdown_toggle_js {
2486: return <<"END";
2487:
2488: function toggleCountdown() {
2489: var countdownid = document.getElementById('duedatecountdown');
2490: var currstyle = countdownid.style.display;
2491: if (currstyle == 'inline') {
2492: countdownid.style.display = 'none';
2493: document.getElementById('ddcountcollapse').innerHTML='';
2494: document.getElementById('ddcountexpand').innerHTML='◄ ';
2495: } else {
2496: countdownid.style.display = 'inline';
2497: document.getElementById('ddcountcollapse').innerHTML='► ';
2498: document.getElementById('ddcountexpand').innerHTML='';
2499: }
2500: return;
2501: }
2502:
2503: END
2504: }
2505:
2506: # This creates a "done button" for timed events. The confirmation box is a jQuery
2507: # dialog widget. If the interval parameter requires a proctor key for the timed
2508: # event to be marked done, there will also be a textbox where that can be entered.
2509: # Clicking OK will set the value of LC_interval_done to 'true', and, if needed will
2510: # set the value of LC_interval_done_proctorpass to the text entered in that box,
2511: # and submit the corresponding form.
2512: #
2513: # The &zero_time() routine in lonhomework.pm is called when a page is rendered if
2514: # LC_interval_done is true.
2515: #
2516: sub done_button_js {
2517: my ($type,$width,$height,$proctor,$donebuttontext) = @_;
2518: return unless (($type eq 'map') || ($type eq 'resource'));
2519: my %lt = &Apache::lonlocal::texthash(
2520: title => 'WARNING!',
2521: preamble => 'You are trying to end this timed event early.',
2522: map => 'Confirming that you are done will cause the time to expire and prevent you from changing any answers in the current folder.',
2523: resource => 'Confirming that you are done will cause the time to expire for this question, and prevent you from changing your answer(s).',
2524: okdone => 'Click "OK" if you are completely finished.',
2525: cancel => 'Click "Cancel" to continue working.',
2526: proctor => 'Ask a proctor to enter the key, then click "OK" if you are completely finished.',
2527: ok => 'OK',
2528: exit => 'Cancel',
2529: key => 'Key:',
2530: nokey => 'A proctor key is required',
2531: );
2532: my $shownsymb = &HTML::Entities::encode(&Apache::lonenc::check_encrypt($env{'request.symb'}));
2533: my $navmap = Apache::lonnavmaps::navmap->new();
2534: my ($missing,$tried) = (0,0);
2535: if (ref($navmap)) {
2536: my @resources=();
2537: if ($type eq 'map') {
2538: my ($mapurl,$rid,$resurl)=&Apache::lonnet::decode_symb($env{'request.symb'});
2539: if ($env{'request.symb'} =~ /\.page$/) {
2540: @resources=$navmap->retrieveResources($resurl,sub { $_[0]->is_problem() });
2541: } else {
2542: @resources=$navmap->retrieveResources($mapurl,sub { $_[0]->is_problem() });
2543: }
2544: } else {
2545: my $res = $navmap->getBySymb($env{'request.symb'});
2546: if (ref($res)) {
2547: if ($res->is_problem()) {
2548: push(@resources,$res);
2549: }
2550: }
2551: }
2552: foreach my $res (@resources) {
2553: if (ref($res->parts()) eq 'ARRAY') {
2554: foreach my $part (@{$res->parts()}) {
2555: if (!$res->tries($part)) {
2556: $missing++;
2557: } else {
2558: $tried++;
2559: }
2560: }
2561: }
2562: }
2563: }
2564: if ($missing) {
2565: $lt{'miss'} .= '<p class="LC_error">';
2566: if ($type eq 'map') {
2567: $lt{'miss'} .= &mt('Submissions are missing for [quant,_1,question part,question parts] in this folder.',$missing);
2568: } else {
2569: $lt{'miss'} .= &mt('Submissions are missing for [quant,_1,part] in this question.',$missing);
2570: }
2571: if ($missing > 1) {
2572: $lt{'miss'} .= ' '.&mt('If you confirm you are done you will be unable to submit answers for them.').'</span>';
2573: } else {
2574: $lt{'miss'} .= ' '.&mt('If you confirm you are done you will be unable to submit an answer for it.').'</p>';
2575: }
2576: }
2577: $donebuttontext = &HTML::Entities::encode($donebuttontext,'<>&"');
2578: if ($proctor) {
2579: if ($height !~ /^\d+$/) {
2580: $height = 400;
2581: if ($missing) {
2582: $height += 60;
2583: }
2584: }
2585: if ($width !~ /^\d+$/) {
2586: $width = 400;
2587: if ($missing) {
2588: $width += 60;
2589: }
2590: }
2591: return <<END;
2592: <form method="post" name="LCdoneButton" action="">
2593: <input type="hidden" name="LC_interval_done" value="" />
2594: <input type="hidden" name="LC_interval_done_proctorpass" value="" />
2595: <input type="hidden" name="symb" value="$shownsymb" />
2596: <button id="LC_done-confirm-opener" type="button">$donebuttontext</button>
2597: </form>
2598:
2599: <div id="LC_done-confirm" title="$lt{'title'}">
2600: <p>$lt{'preamble'} $lt{$type}</p>
2601: $lt{'miss'}
2602: <p>$lt{'proctor'}</p>
2603: <form name="LCdoneButtonProctor" action="">
2604: <label>$lt{'key'}<input type="password" name="LC_interval_done_proctorkey" value="" /></label>
2605: <input type="submit" tabindex="-1" style="position:absolute; top:-1000px" />
2606: </form>
2607: <p>$lt{'cancel'}</p>
2608: </div>
2609:
2610: <script type="text/javascript">
2611: // <![CDATA[
2612: \$( "#LC_done-confirm" ).dialog({ autoOpen: false });
2613: \$( "#LC_done-confirm-opener" ).on("click", function() {
2614: \$( "#LC_done-confirm" ).dialog("open");
2615: \$( "#LC_done-confirm" ).dialog({
2616: height: $height,
2617: width: $width,
2618: modal: true,
2619: resizable: false,
2620: buttons: [
2621: {
2622: text: "$lt{'ok'}",
2623: click: function() {
2624: var proctorkey = \$( '[name="LC_interval_done_proctorkey"]' )[0].value;
2625: if ((proctorkey == '') || (proctorkey == null)) {
2626: alert("$lt{'nokey'}");
2627: } else {
2628: \$( '[name="LC_interval_done"]' )[0].value = 'true';
2629: \$( '[name="LC_interval_done_proctorpass"]' )[0].value = proctorkey;
2630: \$( '[name="LCdoneButton"]' )[0].submit();
2631: }
2632: },
2633: },
2634: {
2635: text: "$lt{'exit'}",
2636: click: function() {
2637: \$("#LC_done-confirm").dialog( "close" );
2638: }
2639: }
2640: ],
2641: close: function() {
2642: \$( '[name="LC_interval_done_proctorkey"]' )[0].value = '';
2643: }
2644: });
2645: \$( "#LC_done-confirm" ).find( "form" ).on( "submit", function( event ) {
2646: event.preventDefault();
2647: \$( '[name="LC_interval_done"]' )[0].value = 'true';
2648: \$( '[name="LC_interval_done_proctorpass"]' )[0].value = \$( '[name="LC_interval_done_proctorkey"]' )[0].value;
2649: \$( '[name="LCdoneButton"]' )[0].submit();
2650: });
2651: });
2652:
2653: // ]]>
2654: </script>
2655:
2656: END
2657: } else {
2658: if ($height !~ /^\d+$/) {
2659: $height = 320;
2660: if ($missing) {
2661: $height += 60;
2662: }
2663: }
2664: if ($width !~ /^\d+$/) {
2665: $width = 320;
2666: if ($missing) {
2667: $width += 60;
2668: }
2669: }
2670: if ($missing) {
2671: $lt{'miss'} = '</p>'.$lt{'miss'}.'<p>';
2672: }
2673: return <<END;
2674:
2675: <form method="post" name="LCdoneButton" action="">
2676: <input type="hidden" name="LC_interval_done" value="" />
2677: <input type="hidden" name="symb" value="$shownsymb" />
2678: <button id="LC_done-confirm-opener" type="button">$donebuttontext</button>
2679: </form>
2680:
2681: <div id="LC_done-confirm" title="$lt{'title'}">
2682: <p>$lt{'preamble'} $lt{$type} $lt{'miss'} $lt{'okdone'} $lt{'cancel'}</p>
2683: </div>
2684:
2685: <script type="text/javascript">
2686: // <![CDATA[
2687: \$( "#LC_done-confirm" ).dialog({ autoOpen: false });
2688: \$( "#LC_done-confirm-opener" ).click(function() {
2689: \$( "#LC_done-confirm" ).dialog( "open" );
2690: \$( "#LC_done-confirm" ).dialog({
2691: resizable: false,
2692: height: $height,
2693: width: $width,
2694: modal: true,
2695: buttons: [
2696: {
2697: text: "$lt{'ok'}",
2698: click: function() {
2699: \$( this ).dialog( "close" );
2700: \$( '[name="LC_interval_done"]' )[0].value = 'true';
2701: \$( '[name="LCdoneButton"]' )[0].submit();
2702: },
2703: },
2704: {
2705: text: "$lt{'exit'}",
2706: click: function() {
2707: \$( this ).dialog( "close" );
2708: },
2709: },
2710: ],
2711: });
2712: });
2713: // ]]>
2714: </script>
2715:
2716: END
2717: }
2718: }
2719:
2720: sub view_as_js {
2721: my ($url,$symb) = @_;
2722: my %lt = &Apache::lonlocal::texthash(
2723: ente => 'Enter a username or a student/employee ID',
2724: info => 'Information you entered does not match a valid course user',
2725: );
2726: &js_escape(\%lt);
2727: return <<"END";
2728:
2729: function toggleViewAsUser(change) {
2730: var seluserid = document.getElementById('LC_selectuser');
2731: var currstyle = seluserid.style.display;
2732: if (change == 'off') {
2733: document.userview.elements['LC_viewas'].value = '';
2734: document.userview.elements['vuname'].value = '';
2735: document.userview.elements['vid'].value = '';
2736: document.userview.submit();
2737: return;
2738: }
2739: if (currstyle == 'inline') {
2740: seluserid.style.display = 'none';
2741: document.getElementById('usexpand').innerHTML='► ';
2742: document.getElementById('uscollapse').innerHTML='';
2743: } else {
2744: seluserid.style.display = 'inline';
2745: document.getElementById('usexpand').innerHTML='';
2746: document.getElementById('uscollapse').innerHTML='◄ ';
2747: }
2748: return;
2749: }
2750:
2751: function validCourseUser(form,change) {
2752: var possuname = form.elements['vuname'].value;
2753: var possuid = form.elements['vid'].value;
2754: var possudom = form.elements['vudom'].options[form.elements['vudom'].selectedIndex].value;
2755: if ((possuname == '') && (possuid == '')) {
2756: if (change == 'off') {
2757: form.elements['LC_viewas'].value = '';
2758: form.submit();
2759: } else {
2760: alert("$lt{'ente'}");
2761: }
2762: return;
2763: }
2764: var http = new XMLHttpRequest();
2765: var url = "/adm/courseuser";
2766: var params = "uname="+possuname+"&uid="+possuid+"&udom="+possudom;
2767: http.open("POST", url, true);
2768: http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
2769: http.onreadystatechange = function() {
2770: if (http.readyState == 4 && http.status == 200) {
2771: var data = JSON.parse(http.responseText);
2772: if (Array.isArray(data.match)) {
2773: var len = data.match.length;
2774: if (len == 2) {
2775: if (data.match[0] != '' && data.match[1] != '') {
2776: form.elements['LC_viewas'].value = data.match[0]+':'+data.match[1];
2777: form.submit();
2778: }
2779: } else {
2780: alert("$lt{'info'}");
2781: }
2782: }
2783: }
2784: return;
2785: }
2786: http.send(params);
2787: return false;
2788: }
2789:
2790: END
2791: }
2792:
2793: sub utilityfunctions {
2794: my ($httphost) = @_;
2795: my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
2796: my $currentsymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
2797: if ($currenturl =~ m{^/adm/wrapper/ext/}) {
2798: if ($env{'request.external.querystring'}) {
2799: $currenturl .= ($currenturl=~/\?/)?'&':'?'.$env{'request.external.querystring'};
2800: }
2801: my ($anchor) = ($env{'request.symb'} =~ /(\#[^\#]+)$/);
2802: if (($anchor) && ($currenturl !~ /\Q$anchor\E$/)) {
2803: $currenturl .= $1;
2804: }
2805: }
2806: $currenturl=&Apache::lonenc::check_encrypt(&unescape($currenturl));
2807:
2808: my $dc_popup_cid;
2809: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
2810: $env{'course.'.$env{'request.course.id'}.
2811: '.domain'}.'/'})) {
2812: $dc_popup_cid = &dc_popup_js();
2813: }
2814:
2815: my $start_page_annotate =
2816: &Apache::loncommon::start_page('Annotator',undef,
2817: {'only_body' => 1,
2818: 'js_ready' => 1,
2819: 'bgcolor' => '#BBBBBB',
2820: 'add_entries' => {
2821: 'onload' => 'javascript:document.goannotate.submit();'}});
2822:
2823: my $end_page_annotate =
2824: &Apache::loncommon::end_page({'js_ready' => 1});
2825:
2826: my $jumptores = &Apache::lonhtmlcommon::javascript_jumpto_resource();
2827:
2828: my $esc_url=&escape($currenturl);
2829: my $esc_symb=&escape($currentsymb);
2830:
2831: my $countdown = &countdown_toggle_js();
2832:
2833: my $viewuser;
2834: if (($env{'request.course.id'}) &&
2835: ($env{'request.symb'} ne '') &&
2836: ($env{'request.filename'}=~/$LONCAPA::assess_re/)) {
2837: my $canview;
2838: foreach my $priv ('msg','vgr') {
2839: $canview = &Apache::lonnet::allowed($priv,$env{'request.course.id'});
2840: if (!$canview && $env{'request.course.sec'} ne '') {
2841: $canview =
2842: &Apache::lonnet::allowed($priv,"$env{'request.course.id'}/$env{'request.course.sec'}");
2843: }
2844: last if ($canview);
2845: }
2846: if ($canview) {
2847: $viewuser = &view_as_js($esc_url,$esc_symb);
2848: }
2849: }
2850:
2851: my ($ltitarget,$deeplinktarget);
2852: if ($env{'request.lti.login'}) {
2853: $ltitarget = $env{'request.lti.target'};
2854: }
2855: if ($env{'request.deeplink.login'}) {
2856: $deeplinktarget = $env{'request.deeplink.target'};
2857: }
2858:
2859: my $annotateurl = '/adm/annotation';
2860: if ($httphost) {
2861: $annotateurl = '/adm/annotations';
2862: }
2863: my $hostvar = '
2864: function setLCHost() {
2865: var lcHostname="";
2866: ';
2867: if ($httphost =~ m{^https?\://}) {
2868: $hostvar .= ' var lcServer="'.$httphost.'";'."\n".
2869: ' var hostReg = /^https?:\/\/([^\/]+)$/i;'."\n".
2870: ' var match = hostReg.exec(lcServer);'."\n".
2871: ' if (match.length) {'."\n".
2872: ' if (match[1] == location.hostname) {'."\n".
2873: ' lcHostname=lcServer;'."\n".
2874: ' }'."\n".
2875: ' }'."\n";
2876: }
2877:
2878: $hostvar .= ' return lcHostname;'."\n".
2879: '}'."\n";
2880:
2881: return (<<ENDUTILITY)
2882: $hostvar
2883: var currentURL=unescape("$esc_url");
2884: var reloadURL=unescape("$esc_url");
2885: var currentSymb=unescape("$esc_symb");
2886:
2887: $dc_popup_cid
2888:
2889: $jumptores
2890:
2891: function gopost(url,postdata) {
2892: if (url!='') {
2893: var lcHostname = setLCHost();
2894: this.document.server.action=lcHostname+url;
2895: this.document.server.postdata.value=postdata;
2896: this.document.server.command.value='';
2897: this.document.server.url.value='';
2898: this.document.server.symb.value='';
2899: this.document.server.submit();
2900: }
2901: }
2902:
2903: function gocmd(url,cmd) {
2904: if (url!='') {
2905: var lcHostname = setLCHost();
2906: this.document.server.action=lcHostname+url;
2907: this.document.server.postdata.value='';
2908: this.document.server.command.value=cmd;
2909: this.document.server.url.value=currentURL;
2910: this.document.server.symb.value=currentSymb;
2911: this.document.server.submit();
2912: }
2913: }
2914:
2915: function gocstr(url,filename) {
2916: if (url == '/adm/cfile?action=delete') {
2917: this.document.cstrdelete.filename.value = filename
2918: this.document.cstrdelete.submit();
2919: return;
2920: }
2921: if (url == '/adm/printout') {
2922: this.document.cstrprint.postdata.value = filename
2923: this.document.cstrprint.curseed.value = 0;
2924: this.document.cstrprint.problemtype.value = 0;
2925: if (this.document.lonhomework) {
2926: if ((this.document.lonhomework.rndseed) && (this.document.lonhomework.rndseed.value != null) && (this.document.lonhomework.rndseed.value != '')) {
2927: this.document.cstrprint.curseed.value = this.document.lonhomework.rndseed.value
2928: }
2929: if (this.document.lonhomework.problemtype) {
2930: if (this.document.lonhomework.problemtype.value) {
2931: this.document.cstrprint.problemtype.value =
2932: this.document.lonhomework.problemtype.value;
2933: } else if (this.document.lonhomework.problemtype.options) {
2934: for (var i=0; i<this.document.lonhomework.problemtype.options.length; i++) {
2935: if (this.document.lonhomework.problemtype.options[i].selected) {
2936: if (this.document.lonhomework.problemtype.options[i].value != null && this.document.lonhomework.problemtype.options[i].value != '') {
2937: this.document.cstrprint.problemtype.value = this.document.lonhomework.problemtype.options[i].value
2938: }
2939: }
2940: }
2941: }
2942: }
2943: }
2944: this.document.cstrprint.submit();
2945: return;
2946: }
2947: if (url !='') {
2948: this.document.constspace.filename.value = filename;
2949: this.document.constspace.action = url;
2950: this.document.constspace.submit();
2951: }
2952: }
2953:
2954: function golist(url) {
2955: if (url!='' && url!= null) {
2956: currentURL = null;
2957: currentSymb= null;
2958: var lcHostname = setLCHost();
2959: var ltitarget = '$ltitarget';
2960: var deeplinktarget = '$deeplinktarget';
2961: if ((ltitarget == 'iframe') || (deeplinktarget == '_self')) {
2962: document.location.href=lcHostname+url;
2963: } else {
2964: top.location.href=lcHostname+url;
2965: }
2966: }
2967: }
2968:
2969:
2970:
2971: function catalog_info(url,isMobile) {
2972: if (isMobile == 1) {
2973: openMyModal(url+'.meta?modal=1',500,400,'yes');
2974: } else {
2975: loncatinfo=window.open(url+'.meta',"LONcatInfo",'height=500,width=400,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
2976: }
2977: }
2978:
2979: function chat_win() {
2980: var lcHostname = setLCHost();
2981: lonchat=window.open(lcHostname+'/res/adm/pages/chatroom.html',"LONchat",'height=320,width=480,resizable=yes,location=no,menubar=no,toolbar=no');
2982: }
2983:
2984: function group_chat(group) {
2985: var lcHostname = setLCHost();
2986: var url = lcHostname+'/adm/groupchat?group='+group;
2987: var winName = 'LONchat_'+group;
2988: grpchat=window.open(url,winName,'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
2989: }
2990:
2991: function annotate() {
2992: w_Annotator_flag=1;
2993: annotator=window.open('','Annotator','width=365,height=265,scrollbars=0');
2994: annotator.document.write(
2995: '$start_page_annotate'
2996: +"<form name='goannotate' target='Annotator' method='post' "
2997: +"action='$annotateurl'>"
2998: +"<input type='hidden' name='symbnew' value='"+currentSymb+"' />"
2999: +"<\\/form>"
3000: +'$end_page_annotate');
3001: annotator.document.close();
3002: }
3003:
3004: function open_StoredLinks_Import(rat) {
3005: var newWin;
3006: var lcHostname = setLCHost();
3007: if (rat) {
3008: newWin = window.open(lcHostname+'/adm/wishlist?inhibitmenu=yes&mode=import&rat='+rat,
3009: 'wishlistImport','scrollbars=1,resizable=1,menubar=0');
3010: }
3011: else {
3012: newWin = window.open(lcHostname+'/adm/wishlist?inhibitmenu=yes&mode=import',
3013: 'wishlistImport','scrollbars=1,resizable=1,menubar=0');
3014: }
3015: newWin.focus();
3016: }
3017:
3018: function open_source() {
3019: sourcewin=window.open('/adm/source?inhibitmenu=yes&viewonly=1&filename='+currentURL,'LONsource',
3020: 'height=500,width=600,resizable=yes,location=no,menubar=no,toolbar=no,scrollbars=yes');
3021: }
3022:
3023: function open_aboutLC() {
3024: var isMobile = "$env{'browser.mobile'}";
3025: var url = '/adm/about.html';
3026: if (isMobile == 1) {
3027: openMyModal(url,600,400,'yes');
3028: } else {
3029: window.open(url,"aboutLONCAPA","height=400,width=600,scrollbars=1,resizable=1,menubar=0,location=1");
3030: }
3031: return;
3032: }
3033:
3034: (function (\$) {
3035: \$(document).ready(function () {
3036: \$.single=function(a){return function(b){a[0]=b;return a}}(\$([1]));
3037: /*\@cc_on
3038: if (!window.XMLHttpRequest) {
3039: \$('.LC_hoverable').each(function () {
3040: this.attachEvent('onmouseenter', function (evt) { \$.single(evt.srcElement).addClass('hover'); });
3041: this.attachEvent('onmouseleave', function (evt) { \$.single(evt.srcElement).removeClass('hover'); });
3042: });
3043: }
3044: \@*/
3045: });
3046: }(jQuery));
3047:
3048: $countdown
3049:
3050: $viewuser
3051:
3052: ENDUTILITY
3053: }
3054:
3055: sub serverform {
3056: my $target;
3057: if (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self')) {
3058: $target = ' target="_self"';
3059: } else {
3060: $target = ' target="_top"';
3061: }
3062: return(<<ENDSERVERFORM);
3063: <form name="server" action="/adm/logout" method="post"$target>
3064: <input type="hidden" name="postdata" value="none" />
3065: <input type="hidden" name="command" value="none" />
3066: <input type="hidden" name="url" value="none" />
3067: <input type="hidden" name="symb" value="none" />
3068: </form>
3069: ENDSERVERFORM
3070: }
3071:
3072: sub constspaceform {
3073: my ($frameset) = @_;
3074: my ($target,$printtarget);
3075: if ($frameset) {
3076: $target = ' target="_parent"';
3077: $printtarget = ' target="_parent"';
3078: } else {
3079: unless ((($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) ||
3080: (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self'))) {
3081: $target = ' target="_top"';
3082: $printtarget = ' target="_top"';
3083: }
3084: }
3085: return(<<ENDCONSTSPACEFORM);
3086: <form name="constspace" action="/adm/logout" method="post"$target>
3087: <input type="hidden" name="filename" value="" />
3088: </form>
3089: <form name="cstrdelete" action="/adm/cfile" method="post"$target>
3090: <input type="hidden" name="action" value="delete" />
3091: <input type="hidden" name="filename" value="" />
3092: </form>
3093: <form name="cstrprint" action="/adm/printout" method="post"$printtarget>
3094: <input type="hidden" name="postdata" value="" />
3095: <input type="hidden" name="curseed" value="" />
3096: <input type="hidden" name="problemtype" value="" />
3097: </form>
3098:
3099: ENDCONSTSPACEFORM
3100: }
3101:
3102: sub get_nav_status {
3103: my $navstatus="swmenu.w_loncapanav_flag=";
3104: if ($env{'environment.remotenavmap'} eq 'on') {
3105: $navstatus.="1";
3106: } else {
3107: $navstatus.="-1";
3108: }
3109: return $navstatus;
3110: }
3111:
3112: sub hidden_button_check {
3113: if ( $env{'request.course.id'} eq ''
3114: || $env{'request.role.adv'} ) {
3115:
3116: return;
3117: }
3118: my $buttonshide = &Apache::lonnet::EXT('resource.0.buttonshide');
3119: return $buttonshide;
3120: }
3121:
3122: sub roles_selector {
3123: my ($cdom,$cnum,$httphost,$target,$menucoll,$menuref) = @_;
3124: my $crstype = &Apache::loncommon::course_type();
3125: my $now = time;
3126: my (%courseroles,%seccount,%courseprivs,%roledesc);
3127: my $is_cc;
3128: my ($js,$form,$switcher,$has_opa_priv);
3129: my $ccrole;
3130: if ($crstype eq 'Community') {
3131: $ccrole = 'co';
3132: } else {
3133: $ccrole = 'cc';
3134: }
3135: my ($privref,$gotsymb,$destsymb);
3136: my $destinationurl = $ENV{'REQUEST_URI'};
3137: if ($destinationurl =~ /(\?|\&)symb=/) {
3138: $gotsymb = 1;
3139: } elsif ($destinationurl =~ m{^/enc/}) {
3140: my $plainurl = &Apache::lonenc::unencrypted($destinationurl);
3141: if ($plainurl =~ /(\?|\&)symb=/) {
3142: $gotsymb = 1;
3143: }
3144: }
3145: unless ($gotsymb) {
3146: $destsymb = &Apache::lonnet::symbread();
3147: if ($destsymb ne '') {
3148: $destsymb = &Apache::lonenc::check_encrypt($destsymb);
3149: }
3150: }
3151: my $reqprivs = &required_privs();
3152: if (ref($reqprivs) eq 'HASH') {
3153: my $destination = $destinationurl;
3154: $destination =~ s/(\?.*)$//;
3155: if (exists($reqprivs->{$destination})) {
3156: if ($reqprivs->{$destination} =~ /,/) {
3157: @{$privref} = split(/,/,$reqprivs->{$destination});
3158: } else {
3159: $privref = [$reqprivs->{$destination}];
3160: }
3161: }
3162: }
3163: if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) {
3164: my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum});
3165: if ((($start) && ($start<0)) ||
3166: (($end) && ($end<$now)) ||
3167: (($start) && ($now<$start))) {
3168: $is_cc = 0;
3169: } else {
3170: $is_cc = 1;
3171: }
3172: }
3173: if ($is_cc) {
3174: &get_all_courseroles($cdom,$cnum,\%courseroles,\%seccount,\%courseprivs);
3175: } elsif ($env{'request.role'} =~ m{^\Qcr/$cdom/$cdom-domainconfig/\E(\w+)\.\Q/$cdom/$cnum\E}) {
3176: &get_customadhoc_roles($cdom,$cnum,\%courseroles,\%seccount,\%courseprivs,\%roledesc,$privref);
3177: } else {
3178: my %gotnosection;
3179: foreach my $item (keys(%env)) {
3180: if ($item =~ m-^user\.role\.([^.]+)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
3181: my $role = $1;
3182: my $sec = $2;
3183: next if ($role eq 'gr');
3184: my ($start,$end) = split(/\./,$env{$item});
3185: next if (($start && $start > $now) || ($end && $end < $now));
3186: if ($sec eq '') {
3187: if (!$gotnosection{$role}) {
3188: $seccount{$role} ++;
3189: $gotnosection{$role} = 1;
3190: }
3191: }
3192: if ((ref($privref) eq 'ARRAY') && (@{$privref} > 0)) {
3193: my $cnumsec = $cnum;
3194: if ($sec ne '') {
3195: $cnumsec .= "/$sec";
3196: }
3197: $courseprivs{"$role./$cdom/$cnumsec./"} =
3198: $env{"user.priv.$role./$cdom/$cnumsec./"};
3199: $courseprivs{"$role./$cdom/$cnumsec./$cdom/"} =
3200: $env{"user.priv.$role./$cdom/$cnumsec./$cdom/"};
3201: $courseprivs{"$role./$cdom/$cnumsec./$cdom/$cnumsec"} =
3202: $env{"user.priv.$role./$cdom/$cnumsec./$cdom/$cnumsec"};
3203: }
3204: if (ref($courseroles{$role}) eq 'ARRAY') {
3205: if ($sec ne '') {
3206: if (!grep(/^\Q$sec\E$/,@{$courseroles{$role}})) {
3207: push(@{$courseroles{$role}},$sec);
3208: $seccount{$role} ++;
3209: }
3210: }
3211: } else {
3212: @{$courseroles{$role}} = ();
3213: if ($sec ne '') {
3214: $seccount{$role} ++;
3215: push(@{$courseroles{$role}},$sec);
3216: }
3217: }
3218: }
3219: }
3220: }
3221: my @roles_order = ($ccrole,'in','ta','ep','ad','st');
3222: my $numdiffsec;
3223: if (keys(%seccount) == 1) {
3224: foreach my $key (keys(%seccount)) {
3225: $numdiffsec = $seccount{$key};
3226: }
3227: }
3228: if ((keys(%seccount) > 1) || ($numdiffsec > 1)) {
3229: my $targetattr;
3230: if ($target ne '') {
3231: $targetattr = ' target="'.$target.'"';
3232: }
3233: my @submenu;
3234: $js = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles,\%courseprivs,
3235: \%roledesc,$privref,$menucoll,$menuref);
3236: $form =
3237: '<form name="rolechooser" method="post" action="'.$httphost.'/adm/roles"'.$targetattr.'>'."\n".
3238: ' <input type="hidden" name="destinationurl" value="'.
3239: &HTML::Entities::encode($destinationurl).'" />'."\n".
3240: ' <input type="hidden" name="gotorole" value="1" />'."\n".
3241: ' <input type="hidden" name="selectrole" value="" />'."\n".
3242: ' <input type="hidden" name="switchrole" value="" />'."\n";
3243: if ($destsymb ne '') {
3244: $form .= ' <input type="hidden" name="destsymb" value="'.
3245: &HTML::Entities::encode($destsymb).'" />'."\n";
3246: }
3247: $form .= '</form>'."\n";
3248: foreach my $role (@roles_order) {
3249: my $include;
3250: if (defined($courseroles{$role})) {
3251: if ($env{'request.role'} =~ m{^\Q$role\E}) {
3252: if ($seccount{$role} > 1) {
3253: $include = 1;
3254: } else {
3255: if ($env{'user.priv.'.$env{'request.role'}."./$cdom/$cnum"} =~/opa\&([^\:]*)/) {
3256: $has_opa_priv = 1;
3257: }
3258: }
3259: } else {
3260: $include = 1;
3261: }
3262: }
3263: if ($include) {
3264: if ($env{"user.priv.$role./$cdom/$cnum./$cdom/$cnum"} =~/opa\&([^\:]*)/) {
3265: $has_opa_priv = 1;
3266: }
3267: push(@submenu,['javascript:adhocRole('."'$role'".')',
3268: &Apache::lonnet::plaintext($role,$crstype)]);
3269: }
3270: }
3271: foreach my $role (sort(keys(%courseroles))) {
3272: if ($role =~ /^cr/) {
3273: my $include;
3274: if ($env{'request.role'} =~ m{^\Q$role\E}) {
3275: if ($seccount{$role} > 1) {
3276: $include = 1;
3277: }
3278: } else {
3279: $include = 1;
3280: }
3281: if ($include) {
3282: my $rolename;
3283: if ($role =~ m{^cr/$cdom/$cdom\-domainconfig/(\w+)(?:/\w+|$)}) {
3284: $rolename = $roledesc{$role};
3285: if ($rolename eq '') {
3286: $rolename = &mt('Helpdesk [_1]',$1);
3287: }
3288: } else {
3289: $rolename = &Apache::lonnet::plaintext($role);
3290: }
3291: if ($env{"user.priv.$role./$cdom/$cnum./$cdom/$cnum"} =~/opa\&([^\:]*)/) {
3292: $has_opa_priv = 1;
3293: }
3294: push(@submenu,['javascript:adhocRole('."'$role'".')',
3295: $rolename]);
3296: }
3297: }
3298: }
3299: if (@submenu > 0) {
3300: $switcher = &create_submenu('#',$target,&mt('Switch role'),\@submenu);
3301: }
3302: }
3303: return ($js,$form,$switcher,$has_opa_priv);
3304: }
3305:
3306: sub get_all_courseroles {
3307: my ($cdom,$cnum,$courseroles,$seccount,$courseprivs) = @_;
3308: unless ((ref($courseroles) eq 'HASH') && (ref($seccount) eq 'HASH') &&
3309: (ref($courseprivs) eq 'HASH')) {
3310: return;
3311: }
3312: my ($result,$cached) =
3313: &Apache::lonnet::is_cached_new('getcourseroles',$cdom.'_'.$cnum);
3314: if (defined($cached)) {
3315: if (ref($result) eq 'HASH') {
3316: if ((ref($result->{'roles'}) eq 'HASH') &&
3317: (ref($result->{'seccount'}) eq 'HASH') &&
3318: (ref($result->{'privs'}) eq 'HASH')) {
3319: %{$courseroles} = %{$result->{'roles'}};
3320: %{$seccount} = %{$result->{'seccount'}};
3321: %{$courseprivs} = %{$result->{'privs'}};
3322: return;
3323: }
3324: }
3325: }
3326: my %gotnosection;
3327: my %adv_roles =
3328: &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
3329: foreach my $role (keys(%adv_roles)) {
3330: my ($urole,$usec) = split(/:/,$role);
3331: if (!$gotnosection{$urole}) {
3332: $seccount->{$urole} ++;
3333: $gotnosection{$urole} = 1;
3334: }
3335: if (ref($courseroles->{$urole}) eq 'ARRAY') {
3336: if ($usec ne '') {
3337: if (!grep(/^Q$usec\E$/,@{$courseroles->{$urole}})) {
3338: push(@{$courseroles->{$urole}},$usec);
3339: $seccount->{$urole} ++;
3340: }
3341: }
3342: } else {
3343: @{$courseroles->{$urole}} = ();
3344: if ($usec ne '') {
3345: $seccount->{$urole} ++;
3346: push(@{$courseroles->{$urole}},$usec);
3347: }
3348: }
3349: my $area = '/'.$cdom.'/'.$cnum;
3350: if ($usec ne '') {
3351: $area .= '/'.$usec;
3352: }
3353: if ($role =~ /^cr\//) {
3354: &Apache::lonnet::custom_roleprivs($courseprivs,$urole,$cdom,$cnum,$urole.'.'.$area,$area);
3355: } else {
3356: &Apache::lonnet::standard_roleprivs($courseprivs,$urole,$cdom,$urole.'.'.$area,$cnum,$area);
3357: }
3358: }
3359: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum,['st']);
3360: @{$courseroles->{'st'}} = ();
3361: &Apache::lonnet::standard_roleprivs($courseprivs,'st',$cdom,"st./$cdom/$cnum",$cnum,"/$cdom/$cnum");
3362: if (keys(%sections_count) > 0) {
3363: push(@{$courseroles->{'st'}},keys(%sections_count));
3364: $seccount->{'st'} = scalar(keys(%sections_count));
3365: }
3366: $seccount->{'st'} ++; # Increment for a section-less student role.
3367: my $rolehash = {
3368: 'roles' => $courseroles,
3369: 'seccount' => $seccount,
3370: 'privs' => $courseprivs,
3371: };
3372: &Apache::lonnet::do_cache_new('getcourseroles',$cdom.'_'.$cnum,$rolehash);
3373: return;
3374: }
3375:
3376: sub get_customadhoc_roles {
3377: my ($cdom,$cnum,$courseroles,$seccount,$courseprivs,$roledesc,$privref) = @_;
3378: unless ((ref($courseroles) eq 'HASH') && (ref($seccount) eq 'HASH') &&
3379: (ref($courseprivs) eq 'HASH') && (ref($roledesc) eq 'HASH')) {
3380: return;
3381: }
3382: my $is_helpdesk = 0;
3383: my $now = time;
3384: foreach my $role ('dh','da') {
3385: if ($env{"user.role.$role./$cdom/"}) {
3386: my ($start,$end)=split(/\./,$env{"user.role.$role./$cdom/"});
3387: if (!($start && ($now<$start)) && !($end && ($now>$end))) {
3388: $is_helpdesk = 1;
3389: last;
3390: }
3391: }
3392: }
3393: if ($is_helpdesk) {
3394: my ($possroles,$description) = &Apache::lonnet::get_my_adhocroles($cdom.'_'.$cnum);
3395: my %available;
3396: if (ref($possroles) eq 'ARRAY') {
3397: map { $available{$_} = 1; } @{$possroles};
3398: }
3399: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
3400: if (ref($domdefaults{'adhocroles'}) eq 'HASH') {
3401: if (keys(%{$domdefaults{'adhocroles'}})) {
3402: my $numsec = 1;
3403: my @sections;
3404: my ($allseclist,$cached) =
3405: &Apache::lonnet::is_cached_new('courseseclist',$cdom.'_'.$cnum);
3406: if (defined($cached)) {
3407: if ($allseclist ne '') {
3408: @sections = split(/,/,$allseclist);
3409: $numsec += scalar(@sections);
3410: }
3411: } else {
3412: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
3413: @sections = sort(keys(%sections_count));
3414: $numsec += scalar(@sections);
3415: $allseclist = join(',',@sections);
3416: &Apache::lonnet::do_cache_new('courseseclist',$cdom.'_'.$cnum,$allseclist);
3417: }
3418: my (%adhoc,$gotprivs);
3419: my $prefix = "cr/$cdom/$cdom".'-domainconfig';
3420: foreach my $role (keys(%{$domdefaults{'adhocroles'}})) {
3421: next if (($role eq '') || ($role =~ /\W/));
3422: $seccount->{"$prefix/$role"} = $numsec;
3423: $roledesc->{"$prefix/$role"} = $description->{$role};
3424: if ((ref($privref) eq 'ARRAY') && (@{$privref} > 0)) {
3425: if (exists($env{"user.priv.$prefix/$role./$cdom/$cnum./"})) {
3426: $courseprivs->{"$prefix/$role./$cdom/$cnum./"} =
3427: $env{"user.priv.$prefix/$role./$cdom/$cnum./"};
3428: $courseprivs->{"$prefix/$role./$cdom/$cnum./$cdom/"} =
3429: $env{"user.priv.$prefix/$role./$cdom/$cnum./$cdom/"};
3430: $courseprivs->{"$prefix/$role./$cdom/$cnum./$cdom/$cnum"} =
3431: $env{"user.priv.$prefix/$role./$cdom/$cnum./$cdom/$cnum"};
3432: } else {
3433: unless ($gotprivs) {
3434: my ($adhocroles,$privscached) =
3435: &Apache::lonnet::is_cached_new('adhocroles',$cdom);
3436: if ((defined($privscached)) && (ref($adhocroles) eq 'HASH')) {
3437: %adhoc = %{$adhocroles};
3438: } else {
3439: my $confname = &Apache::lonnet::get_domainconfiguser($cdom);
3440: my %roledefs = &Apache::lonnet::dump('roles',$cdom,$confname,'rolesdef_');
3441: foreach my $key (keys(%roledefs)) {
3442: (undef,my $rolename) = split(/_/,$key);
3443: if ($rolename ne '') {
3444: my ($systempriv,$domainpriv,$coursepriv) = split(/\_/,$roledefs{$key});
3445: $coursepriv = &Apache::lonnet::course_adhocrole_privs($rolename,$cdom,$cnum,$coursepriv);
3446: $adhoc{$rolename} = join('_',($systempriv,$domainpriv,$coursepriv));
3447: }
3448: }
3449: &Apache::lonnet::do_cache_new('adhocroles',$cdom,\%adhoc);
3450: }
3451: $gotprivs = 1;
3452: }
3453: ($courseprivs->{"$prefix/$role./$cdom/$cnum./"},
3454: $courseprivs->{"$prefix/$role./$cdom/$cnum./$cdom/"},
3455: $courseprivs->{"$prefix/$role./$cdom/$cnum./$cdom/$cnum"}) =
3456: split(/\_/,$adhoc{$role});
3457: }
3458: }
3459: if ($available{$role}) {
3460: $courseroles->{"$prefix/$role"} = \@sections;
3461: }
3462: }
3463: }
3464: }
3465: }
3466: return;
3467: }
3468:
3469: sub jump_to_role {
3470: my ($cdom,$cnum,$seccount,$courseroles,$courseprivs,$roledesc,$privref,
3471: $menucoll,$menuref) = @_;
3472: my %lt = &Apache::lonlocal::texthash(
3473: this => 'This role has section(s) associated with it.',
3474: ente => 'Enter a specific section.',
3475: orlb => 'Enter a specific section, or leave blank for no section.',
3476: avai => 'Available sections are:',
3477: youe => 'You entered an invalid section choice:',
3478: plst => 'Please try again.',
3479: role => 'The role you selected is not permitted to view the current page.',
3480: swit => 'Switch role, but display Main Menu page instead?',
3481: );
3482: &js_escape(\%lt);
3483: my $js;
3484: if (ref($courseroles) eq 'HASH') {
3485: $js = ' var secpick = new Array("'.$lt{'ente'}.'","'.$lt{'orlb'}.'");'."\n".
3486: ' var numsec = new Array();'."\n".
3487: ' var rolesections = new Array();'."\n".
3488: ' var rolenames = new Array();'."\n".
3489: ' var roleseclist = new Array();'."\n";
3490: my @items = keys(%{$courseroles});
3491: for (my $i=0; $i<@items; $i++) {
3492: $js .= ' rolenames['.$i.'] = "'.$items[$i].'";'."\n";
3493: my ($secs,$secstr);
3494: if (ref($courseroles->{$items[$i]}) eq 'ARRAY') {
3495: my @sections = sort { $a <=> $b } @{$courseroles->{$items[$i]}};
3496: $secs = join('","',@sections);
3497: $secstr = join(', ',@sections);
3498: }
3499: $js .= ' rolesections['.$i.'] = new Array("'.$secs.'");'."\n".
3500: ' roleseclist['.$i.'] = "'.$secstr.'";'."\n".
3501: ' numsec['.$i.'] = "'.$seccount->{$items[$i]}.'";'."\n";
3502: }
3503: }
3504: my $checkroles = 0;
3505: my $fallback = '/adm/menu';
3506: my $displaymsg = $lt{'swit'};
3507: if ((ref($privref) eq 'ARRAY') && (@{$privref} > 0) && (ref($courseprivs) eq 'HASH')) {
3508: my %disallowed;
3509: foreach my $role (sort(keys(%{$courseprivs}))) {
3510: my $trole;
3511: if ($role =~ m{^(.+?)\Q./$cdom/$cnum\E}) {
3512: $trole = $1;
3513: }
3514: if (($trole ne '') && ($trole ne 'cm')) {
3515: $disallowed{$trole} = 1;
3516: foreach my $priv (@{$privref}) {
3517: if ($courseprivs->{$role} =~ /\Q:$priv\E($|:|\&\w+)/) {
3518: delete($disallowed{$trole});
3519: last;
3520: }
3521: }
3522: }
3523: }
3524: if (keys(%disallowed) > 0) {
3525: $checkroles = 1;
3526: $js .= " var disallow = new Array('".join("','",keys(%disallowed))."');\n".
3527: " var rolecheck = 1;\n";
3528: if ($menucoll) {
3529: if (ref($menuref) eq 'HASH') {
3530: if ($menuref->{'main'} eq 'n') {
3531: $fallback = '/adm/navmaps';
3532: if (&Apache::loncommon::course_type() eq 'Community') {
3533: $displaymsg = &mt('Switch role, but display Community Contents page instead?');
3534: } else {
3535: $displaymsg = &mt('Switch role, but display Course Contents page instead?');
3536: }
3537: &js_escape(\$displaymsg);
3538: }
3539: }
3540: }
3541: }
3542: }
3543: &js_escape(\$fallback);
3544: if (!$checkroles) {
3545: $js .= " var disallow = new Array();\n".
3546: " rolecheck = 0;\n";
3547: }
3548: return <<"END";
3549: <script type="text/javascript">
3550: //<![CDATA[
3551: function adhocRole(newrole) {
3552: $js
3553: if (newrole == '') {
3554: return;
3555: }
3556: var fullrole = newrole+'./$cdom/$cnum';
3557: var selidx = '';
3558: for (var i=0; i<rolenames.length; i++) {
3559: if (rolenames[i] == newrole) {
3560: selidx = i;
3561: }
3562: }
3563: if (rolecheck > 0) {
3564: for (var i=0; i<disallow.length; i++) {
3565: if (disallow[i] == newrole) {
3566: if (confirm("$lt{'role'}\\n$displaymsg")) {
3567: document.rolechooser.destinationurl.value = '$fallback';
3568: } else {
3569: return;
3570: }
3571: }
3572: }
3573: }
3574: var secok = 1;
3575: var secchoice = '';
3576: if (selidx >= 0) {
3577: if (numsec[selidx] > 1) {
3578: secok = 0;
3579: var numrolesec = rolesections[selidx].length;
3580: var msgidx = numsec[selidx] - numrolesec;
3581: secchoice = prompt("$lt{'this'} "+secpick[msgidx]+"\\n$lt{'avai'} "+roleseclist[selidx],"");
3582: if (secchoice == '') {
3583: if (msgidx > 0) {
3584: secok = 1;
3585: }
3586: } else {
3587: for (var j=0; j<rolesections[selidx].length; j++) {
3588: if (rolesections[selidx][j] == secchoice) {
3589: secok = 1;
3590: }
3591: }
3592: }
3593: } else {
3594: if (rolesections[selidx].length == 1) {
3595: secchoice = rolesections[selidx][0];
3596: }
3597: }
3598: }
3599: if (secok == 1) {
3600: if (secchoice != '') {
3601: fullrole += '/'+secchoice;
3602: }
3603: } else {
3604: document.rolechooser.elements[roleitem].selectedIndex = 0;
3605: if (secchoice != null) {
3606: alert("$lt{'youe'} \\""+secchoice+"\\".\\n $lt{'plst'}");
3607: }
3608: return;
3609: }
3610: if (fullrole == "$env{'request.role'}") {
3611: return;
3612: }
3613: itemid = retrieveIndex('gotorole');
3614: if (itemid != -1) {
3615: document.rolechooser.elements[itemid].name = fullrole;
3616: }
3617: document.rolechooser.switchrole.value = fullrole;
3618: document.rolechooser.selectrole.value = '1';
3619: document.rolechooser.submit();
3620: return;
3621: }
3622:
3623: function retrieveIndex(item) {
3624: for (var i=0;i<document.rolechooser.elements.length;i++) {
3625: if (document.rolechooser.elements[i].name == item) {
3626: return i;
3627: }
3628: }
3629: return -1;
3630: }
3631: // ]]>
3632: </script>
3633: END
3634: }
3635:
3636: sub required_privs {
3637: my $privs = {
3638: '/adm/parmset' => 'opa,vpa',
3639: '/adm/courseprefs' => 'opa,vpa',
3640: '/adm/whatsnew' => 'whn',
3641: '/adm/populate' => 'cst,vpa,vcl',
3642: '/adm/trackstudent' => 'vsa',
3643: '/adm/statistics' => 'mgr,vgr',
3644: '/adm/setblock' => 'dcm,vcb',
3645: '/adm/coursedocs' => 'mdc',
3646: };
3647: unless ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'spreadsheet') {
3648: $privs->{'/adm/classcalc'} = 'vgr',
3649: $privs->{'/adm/assesscalc'} = 'vgr',
3650: $privs->{'/adm/studentcalc'} = 'vgr';
3651: }
3652: return $privs;
3653: }
3654:
3655: sub countdown_timer {
3656: if (($env{'request.course.id'}) && ($env{'request.symb'} ne '') &&
3657: (($env{'request.filename'}=~/$LONCAPA::assess_re/) ||
3658: (($env{'request.symb'} =~ /ext\.tool$/) &&
3659: (&Apache::lonnet::EXT('resource.0.gradable',$env{'request.symb'}) =~ /^yes$/i)))) {
3660: my ($type,$hastimeleft,$slothastime);
3661: my $now = time;
3662: if ($env{'request.filename'} =~ /\.task$/) {
3663: $type = 'Task';
3664: } elsif ($env{'request.symb'} =~ /ext\.tool$/) {
3665: $type = 'tool';
3666: } else {
3667: $type = 'problem';
3668: }
3669: my ($status,$accessmsg,$slot_name,$slot);
3670: if ($type eq 'tool') {
3671: ($status,$accessmsg,$slot_name,$slot) =
3672: &Apache::lonhomework::check_slot_access('0',$type,$env{'request.symb'},['0']);
3673: } else {
3674: ($status,$accessmsg,$slot_name,$slot) =
3675: &Apache::lonhomework::check_slot_access('0',$type);
3676: }
3677: if ($slot_name ne '') {
3678: if (ref($slot) eq 'HASH') {
3679: if (($slot->{'starttime'} < $now) &&
3680: ($slot->{'endtime'} > $now)) {
3681: $slothastime = 1;
3682: }
3683: }
3684: }
3685: if ($status ne 'CAN_ANSWER') {
3686: return;
3687: }
3688: my $duedate = &Apache::lonnet::EXT("resource.0.duedate");
3689: my @interval=&Apache::lonnet::EXT("resource.0.interval");
3690: my ($timelimit,$usesdone,$donebuttontext,$proctor,$secret);
3691: if (@interval > 1) {
3692: ($timelimit,my $donesuffix) = split(/_/,$interval[0],2);
3693: if ($donesuffix =~ /^done\:([^\:]+)\:(.*)$/) {
3694: $usesdone = 'done';
3695: $donebuttontext = $1;
3696: (undef,$proctor,$secret) = split(/_/,$2);
3697: } elsif ($donesuffix =~ /^done(|_.+)$/) {
3698: $donebuttontext = &mt('Done');
3699: ($usesdone,$proctor,$secret) = split(/_/,$donesuffix);
3700: }
3701: my $first_access=&Apache::lonnet::get_first_access($interval[1]);
3702: if ($first_access > 0) {
3703: if ($first_access+$timelimit > time) {
3704: $hastimeleft = 1;
3705: }
3706: }
3707: }
3708: if (($duedate && $duedate > time) ||
3709: (!$duedate && $hastimeleft) ||
3710: ($slot_name ne '' && $slothastime)) {
3711: my ($collapse,$expand,$alttxt,$title,$currdisp,$donebutton);
3712: if ((@interval > 1 && $hastimeleft) ||
3713: ($type eq 'Task' && $slothastime)) {
3714: $currdisp = 'inline';
3715: $collapse = '► ';
3716: if ((@interval > 1) && ($hastimeleft)) {
3717: if ($usesdone eq 'done') {
3718: $donebutton = &done_button_js($interval[1],'','',$proctor,$donebuttontext);
3719: }
3720: }
3721: } else {
3722: $currdisp = 'none';
3723: $expand = '◄ ';
3724: }
3725: unless ($env{'environment.icons'} eq 'iconsonly') {
3726: $alttxt = &mt('Timer');
3727: $title = $alttxt.' ';
3728: }
3729: my $desc = &mt('Countdown to due date/time');
3730: return <<END;
3731: $donebutton
3732: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
3733: <span id="ddcountcollapse" class="LC_menubuttons_inline_text">
3734: $collapse
3735: </span></a>
3736: <span id="duedatecountdown" class="LC_menubuttons_inline_text" style="display: $currdisp;"></span>
3737: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
3738: <span id="ddcountexpand" class="LC_menubuttons_inline_text" >$expand</span>
3739: <img src="/res/adm/pages/timer.png" title="$desc" class="LC_icon" alt="$alttxt" /><span class="LC_menubuttons_inline_text">$title</span></a>
3740: END
3741: }
3742: }
3743: return;
3744: }
3745:
3746: sub linkprot_exit {
3747: if (($env{'request.course.id'}) && ($env{'request.deeplink.login'})) {
3748: my ($deeplink_symb,$deeplink);
3749: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
3750: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3751: if (($cnum ne '') && ($cdom ne '')) {
3752: $deeplink_symb = &Apache::loncommon::deeplink_login_symb($cnum,$cdom);
3753: if ($deeplink_symb) {
3754: if ($deeplink_symb =~ /\.(page|sequence)$/) {
3755: my $mapname = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($deeplink_symb))[2]);
3756: my $navmap = Apache::lonnavmaps::navmap->new();
3757: if (ref($navmap)) {
3758: $deeplink = $navmap->get_mapparam(undef,$mapname,'0.deeplink');
3759: }
3760: } else {
3761: $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$deeplink_symb);
3762: }
3763: if ($deeplink ne '') {
3764: my ($state,$others,$listed,$scope,$protect,$display,$target,$exit) = split(/,/,$deeplink);
3765: my %lt = &Apache::lonlocal::texthash(
3766: title => 'Exit Tool',
3767: okdone => 'Click "OK" to exit embedded tool',
3768: cancel => 'Click "Cancel" to continue working.',
3769: ok => 'OK',
3770: exit => 'Cancel',
3771: );
3772: if ($exit) {
3773: my ($show,$text) = split(/:/,$exit);
3774: unless ($show eq 'no') {
3775: my $height = 250;
3776: my $width = 300;
3777: my $exitbuttontext;
3778: if ($text eq '') {
3779: $exitbuttontext = &mt('Exit Tool');
3780: } else {
3781: $exitbuttontext = $text;
3782: }
3783: return <<END;
3784: <form method="post" name="LCexitButton" action="/adm/linkexit">
3785: <input type="hidden" name="LC_deeplink_exit" value="" />
3786: <button id="LC_exit-confirm-opener" type="button">$exitbuttontext</button>
3787: </form>
3788:
3789: <div id="LC_exit-confirm" title="$lt{'title'}">
3790: <p>$lt{'okdone'} $lt{'cancel'}</p>
3791: </div>
3792:
3793: <script type="text/javascript">
3794: // <![CDATA[
3795: \$( "#LC_exit-confirm" ).dialog({ autoOpen: false });
3796: \$( "#LC_exit-confirm-opener" ).click(function() {
3797: \$( "#LC_exit-confirm" ).dialog( "open" );
3798: \$( "#LC_exit-confirm" ).dialog({
3799: resizable: false,
3800: height: $height,
3801: width: $width,
3802: modal: true,
3803: buttons: [
3804: {
3805: text: "$lt{'ok'}",
3806: click: function() {
3807: \$( this ).dialog( "close" );
3808: \$( '[name="LC_deeplink_exit"]' )[0].value = 'true';
3809: \$( '[name="LCexitButton"]' )[0].submit();
3810: },
3811: },
3812: {
3813: text: "$lt{'exit'}",
3814: click: function() {
3815: \$( this ).dialog( "close" );
3816: },
3817: },
3818: ],
3819: });
3820: });
3821: // ]]>
3822: </script>
3823:
3824: END
3825: }
3826: }
3827: }
3828: }
3829: }
3830: }
3831: return;
3832: }
3833:
3834: # ================================================================ Main Program
3835:
3836: BEGIN {
3837: if (! defined($readdesk)) {
3838: {
3839: my $tabfile = $Apache::lonnet::perlvar{'lonTabDir'}.'/mydesk.tab';
3840: if ( CORE::open( my $config,"<$tabfile") ) {
3841: while (my $configline=<$config>) {
3842: $configline=(split(/\#/,$configline))[0];
3843: $configline=~s/^\s+//;
3844: chomp($configline);
3845: if ($configline=~/^cat\:/) {
3846: my @entries=split(/\:/,$configline);
3847: $category_positions{$entries[2]}=$entries[1];
3848: $category_names{$entries[2]}=$entries[3];
3849: } elsif ($configline=~/^prim\:/) {
3850: my @entries = (split(/\:/, $configline))[1..7];
3851: push(@primary_menu,\@entries);
3852: } elsif ($configline=~/^primsub\:/) {
3853: my ($parent,@entries) = (split(/\:/, $configline))[1..5];
3854: push(@{$primary_submenu{$parent}},\@entries);
3855: } elsif ($configline=~/^scnd\:/) {
3856: my @entries = (split(/\:/, $configline))[1..6];
3857: push(@secondary_menu,\@entries);
3858: } elsif ($configline=~/^scndsub\:/) {
3859: my ($parent,@entries) = (split(/\:/, $configline))[1..4];
3860: push(@{$secondary_submenu{$parent}},\@entries);
3861: } elsif ($configline) {
3862: push(@desklines,$configline);
3863: }
3864: }
3865: CORE::close($config);
3866: }
3867: }
3868: $readdesk='done';
3869: }
3870: }
3871:
3872: 1;
3873: __END__
3874:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>