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