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