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