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