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