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