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