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