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