Annotation of loncom/interface/lonmenu.pm, revision 1.369.2.83.2.6
1.1 www 1: # The LearningOnline Network with CAPA
2: # Routines to control the menu
3: #
1.369.2.83.2. (raeburn 4:): # $Id: lonmenu.pm,v 1.369.2.83.2.5 2022/09/19 19:39:48 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.369.2.3 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.369.2.3 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.369.2.3 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.369.2.83.2. (raeburn 102:): =item prep_menuitems(\@menuitem,$target,$listclass,$linkattr)
1.314 droeschl 103:
104: This routine wraps a menuitem in proper HTML. It is used by primary_menu() and
105: secondary_menu().
106:
107: =item primary_menu()
108:
1.369.2.42 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.369.2.42 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.369.2.6 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.369.2.57 raeburn 127: Inputs: 6 - (a) link and (b) target for anchor href in top level item,
1.369.2.6 raeburn 128: (c) title for text wrapped by anchor tag in top level item.
129: (d) reference to array of arrays of sub-menu items.
1.369.2.57 raeburn 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.
134:
1.369.2.58 raeburn 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.369.2.6 raeburn 162:
1.244 jms 163: =item innerregister()
164:
1.320 droeschl 165: This gets called in order to register a URL in the body of the document
1.244 jms 166:
1.369.2.17 raeburn 167: =item loadevents()
168:
169: =item unloadevents()
170:
171: =item startupremote()
172:
173: =item setflags()
174:
175: =item maincall()
176:
177: =item load_remote_msg()
178:
179: =item get_menu_name()
180:
181: =item reopenmenu()
182:
183: =item open()
184:
185: Open the menu
186:
1.244 jms 187: =item clear()
188:
189: =item switch()
190:
191: Switch a button or create a link
192: Switch acts on the javascript that is executed when a button is clicked.
193: The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
194:
195: =item secondlevel()
196:
197: =item openmenu()
198:
199: =item inlinemenu()
200:
201: =item rawconfig()
202:
203: =item utilityfunctions()
204:
1.369.2.6 raeburn 205: Output from this routine is a number of javascript functions called by
206: items in the inline menu, and in some cases items in the Main Menu page.
207:
1.244 jms 208: =item serverform()
209:
210: =item constspaceform()
211:
212: =item get_nav_status()
213:
214: =item hidden_button_check()
215:
216: =item roles_selector()
217:
218: =item jump_to_role()
219:
220: =back
221:
222: =cut
223:
1.1 www 224: package Apache::lonmenu;
225:
226: use strict;
1.152 albertel 227: use Apache::lonnet;
1.47 matthew 228: use Apache::lonhtmlcommon();
1.115 albertel 229: use Apache::loncommon();
1.127 albertel 230: use Apache::lonenc();
1.88 www 231: use Apache::lonlocal;
1.361 raeburn 232: use Apache::lonmsg();
1.207 foxr 233: use LONCAPA qw(:DEFAULT :match);
1.282 amueller 234: use HTML::Entities();
1.369.2.8 raeburn 235: use Apache::lonwishlist();
1.88 www 236:
1.283 droeschl 237: use vars qw(@desklines %category_names %category_members %category_positions
1.369.2.5 raeburn 238: $readdesk @primary_menu %primary_submenu @secondary_menu %secondary_submenu);
1.88 www 239:
1.56 www 240: my @inlineremote;
1.38 www 241:
1.283 droeschl 242: sub prep_menuitem {
1.369.2.83.2. (raeburn 243:): my ($menuitem,$target,$listclass,$linkattr) = @_;
1.291 raeburn 244: return '' unless(ref($menuitem) eq 'ARRAY');
1.369.2.83.2. (raeburn 245:): my ($link,$targetattr);
1.283 droeschl 246: if ($$menuitem[1]) { # graphical Link
247: $link = "<img class=\"LC_noBorder\""
1.291 raeburn 248: . " src=\"" . &Apache::loncommon::lonhttpdurl($$menuitem[1]) . "\""
249: . " alt=\"" . &mt($$menuitem[2]) . "\" />";
1.283 droeschl 250: } else { # textual Link
1.291 raeburn 251: $link = &mt($$menuitem[3]);
252: }
1.369.2.83.2. (raeburn 253:): if ($target ne '') {
254:): $targetattr = ' target="'.$target.'"';
255:): }
1.369.2.83 raeburn 256: return ($listclass?'<li class="'.$listclass.'">':'<li>').'<a'
1.316 droeschl 257: # highlighting for new messages
258: . ( $$menuitem[4] eq 'newmsg' ? ' class="LC_new_message"' : '')
1.369.2.83.2. (raeburn 259:): . qq| href="$$menuitem[0]"$targetattr $linkattr>$link</a></li>|;
1.283 droeschl 260: }
261:
1.369.2.42 raeburn 262: # primary_menu() evaluates @primary_menu and returns a two item array,
263: # with the array elements containing XHTML for the left and right sides of
264: # the menu that contains the following links:
265: # Personal, About, Message, Roles, Help, Logout
1.283 droeschl 266: # @primary_menu is filled within the BEGIN block of this module with
267: # entries from mydesk.tab
268: sub primary_menu {
1.369.2.83.2. (raeburn 269:): my ($crstype,$ltimenu,$menucoll,$menuref,$links_disabled,$links_target) = @_;
270:): my (%menu,%menuopts);
1.283 droeschl 271: # each element of @primary contains following array:
1.369.2.42 raeburn 272: # (link url, icon path, alt text, link text, condition, position)
1.319 raeburn 273: my $public;
274: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
275: || (($env{'user.name'} eq '') && ($env{'user.domain'} eq ''))) {
276: $public = 1;
277: }
1.369.2.83.2. (raeburn 278:): my ($listclass,$linkattr,$target);
279:): if ($links_disabled) {
280:): $listclass = 'LCisDisabled';
281:): $linkattr = 'aria-disabled="true"';
282:): }
283:): if ($links_target ne '') {
284:): $target = $links_target;
285:): } else {
286:): my $deeplinktarget;
287:): if ($env{'request.deeplink.login'}) {
288:): $deeplinktarget = $env{'request.deeplink.target'};
289:): }
290:): if ($deeplinktarget eq '_self') {
291:): $target = '_self';
292:): } else {
293:): $target = '_top';
294:): }
295:): }
296:): if (($menucoll) && (ref($menuref) eq 'HASH')) {
297:): %menuopts = %{$menuref};
298:): }
1.283 droeschl 299: foreach my $menuitem (@primary_menu) {
300: # evaluate conditions
1.296 droeschl 301: next if ref($menuitem) ne 'ARRAY'; #
1.283 droeschl 302: next if $$menuitem[4] eq 'nonewmsg' # show links depending on
1.291 raeburn 303: && &Apache::lonmsg::mynewmail(); # whether a new msg
1.283 droeschl 304: next if $$menuitem[4] eq 'newmsg' # arrived or not
1.291 raeburn 305: && !&Apache::lonmsg::mynewmail(); #
1.319 raeburn 306: next if $$menuitem[4] !~ /public/ ##we've a public user,
307: && $public; ##who should not see all
308: ##links
1.283 droeschl 309: next if $$menuitem[4] eq 'onlypublic'# hide links which are
1.319 raeburn 310: && !$public; # only visible to public
311: # users
1.283 droeschl 312: next if $$menuitem[4] eq 'roles' ##show links depending on
1.291 raeburn 313: && &Apache::loncommon::show_course(); ##term 'Courses' or
1.283 droeschl 314: next if $$menuitem[4] eq 'courses' ##'Roles' wanted
1.291 raeburn 315: && !&Apache::loncommon::show_course(); ##
316:
1.369.2.3 raeburn 317: my $title = $menuitem->[3];
1.369.2.42 raeburn 318: my $position = $menuitem->[5];
319: if ($position eq '') {
320: $position = 'right';
321: }
1.369.2.83.2. (raeburn 322:): if ($env{'request.course.id'} && $menucoll) {
323:): if (($menuitem->[6]) && (!$menuopts{$menuitem->[6]})) {
324:): if ($menuitem->[6] eq 'pers') {
325:): if ($menuopts{'name'} &&
326:): $env{'user.name'} && $env{'user.domain'}) {
327:): $menu{$position} .= '<li><a href="#">'.
328:): &Apache::loncommon::plainname($env{'user.name'},
329:): $env{'user.domain'}).'</a></li>';
330:): next;
331:): } else {
332:): next;
333:): }
334:): } else {
335:): next;
336:): }
337:): }
338:): }
1.369.2.3 raeburn 339: if (defined($primary_submenu{$title})) {
1.369.2.83.2. (raeburn 340:): my $link;
1.369.2.3 raeburn 341: if ($menuitem->[0] ne '') {
342: $link = $menuitem->[0];
343: } else {
344: $link = '#';
345: }
1.369.2.6 raeburn 346: my @primsub;
1.369.2.3 raeburn 347: if (ref($primary_submenu{$title}) eq 'ARRAY') {
1.369.2.6 raeburn 348: foreach my $item (@{$primary_submenu{$title}}) {
1.369.2.16 raeburn 349: next if (($item->[2] eq 'wishlist') && (!$env{'user.adv'}));
1.369.2.6 raeburn 350: next if ((($item->[2] eq 'portfolio') ||
351: ($item->[2] eq 'blog')) &&
352: (!&Apache::lonnet::usertools_access('','',$item->[2],
353: undef,'tools')));
1.369.2.83.2. (raeburn 354:): if ($env{'request.course.id'} && $menucoll) {
355:): next if ($item->[3]) && (!$menuopts{$item->[3]});
356:): }
1.369.2.6 raeburn 357: push(@primsub,$item);
358: }
1.369.2.83.2. (raeburn 359:): if ($title eq 'Personal') {
360:): if ($env{'user.name'} && $env{'user.domain'}) {
361:): unless (($env{'request.course.id'}) && ($menucoll) && (!$menuopts{'name'})) {
362:): $title = &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'});
363:): }
364:): }
365:): next if (($env{'request.course.id'}) && ($menucoll) && ($title eq 'Personal') &&
366:): (!@primsub));
367:): if ($title eq 'Personal') {
1.369.2.59 raeburn 368: $title = &mt($title);
369: }
1.369.2.83.2. (raeburn 370:): } else {
371:): $title = &mt($title);
372:): }
373:): if (@primsub > 0) {
1.369.2.83 raeburn 374: $menu{$position} .= &create_submenu($link,$target,$title,\@primsub,1,undef,$listclass,$linkattr);
1.369.2.6 raeburn 375: } elsif ($link) {
1.369.2.83 raeburn 376: $menu{$position} .= ($listclass?'<li class="'.$listclass.'">':'<li>').
1.369.2.83.2. (raeburn 377:): '<a href="'.$link.'" target="'.$target.'" '.$linkattr.'>'.$title.'</a></li>';
1.369.2.3 raeburn 378: }
379: }
380: } elsif ($$menuitem[3] eq 'Help') { # special treatment for helplink
1.340 raeburn 381: if ($public) {
382: my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
383: my $defdom = &Apache::lonnet::default_login_domain();
384: my $to = &Apache::loncommon::build_recipient_list(undef,
385: 'helpdeskmail',
386: $defdom,$origmail);
387: if ($to ne '') {
1.369.2.83.2. (raeburn 388:): $menu{$position} .= &prep_menuitem($menuitem,$target,$listclass,$linkattr);
1.340 raeburn 389: }
390: } else {
1.369.2.83 raeburn 391: $menu{$position} .= ($listclass?'<li class="'.$listclass.'">':'<li>').
392: &Apache::loncommon::top_nav_help('Help',$linkattr).
393: '</li>';
1.340 raeburn 394: }
1.369.2.83 raeburn 395: } elsif ($$menuitem[3] eq 'Log In') {
396: if ($public) {
397: if (&Apache::lonnet::get_saml_landing()) {
398: $$menuitem[0] = '/adm/login';
399: }
400: }
1.369.2.83.2. (raeburn 401:): $menu{$position} .= prep_menuitem($menuitem,$target,$listclass,$linkattr);
1.283 droeschl 402: } else {
1.369.2.83.2. (raeburn 403:): $menu{$position} .= prep_menuitem($menuitem,$target,$listclass,$linkattr);
1.283 droeschl 404: }
1.291 raeburn 405: }
1.369.2.48 raeburn 406: my @output = ('','');
407: if ($menu{'left'} ne '') {
408: $output[0] = "<ol class=\"LC_primary_menu LC_floatleft\">$menu{'left'}</ol>";
409: }
410: if ($menu{'right'} ne '') {
411: $output[1] = "<ol class=\"LC_primary_menu LC_floatright LC_right\">$menu{'right'}</ol>";
412: }
413: return @output;
1.283 droeschl 414: }
415:
1.329 droeschl 416: #returns hashref {user=>'',dom=>''} containing:
417: # own name, domain if user is au
418: # name, domain of parent author if user is ca or aa
419: #empty return if user is not an author or not on homeserver
420: #
421: #TODO this should probably be moved somewhere more central
422: #since it can be used by different parts of the system
423: sub getauthor{
424: return unless $env{'request.role'}=~/^(ca|aa|au)/; #nothing to do if user isn't some kind of author
425:
426: #co- or assistent author?
427: my ($dom, $user) = ($env{'request.role'} =~ /^(?:ca|aa)\.\/($match_domain)\/($match_username)$/)
428: ? ($1, $2) #domain, username of the parent author
429: : @env{ ('request.role.domain', 'user.name') }; #own domain, username
430:
431: # current server == home server?
432: my $home = &Apache::lonnet::homeserver($user,$dom);
433: foreach (&Apache::lonnet::current_machine_ids()){
434: return {user => $user, dom => $dom} if $_ eq $home;
435: }
436:
437: # if wrong server
438: return;
439: }
1.283 droeschl 440:
441: sub secondary_menu {
1.369.2.83.2. (raeburn 442:): my ($httphost,$ltiscope,$ltimenu,$noprimary,$menucoll,$menuref,
443:): $links_disabled,$links_target) = @_;
1.283 droeschl 444: my $menu;
445:
1.286 raeburn 446: my $crstype = &Apache::loncommon::course_type();
1.327 droeschl 447: my $crs_sec = $env{'request.course.id'} . ($env{'request.course.sec'}
448: ? "/$env{'request.course.sec'}"
449: : '');
450: my $canedit = &Apache::lonnet::allowed('mdc', $env{'request.course.id'});
1.369.2.67 raeburn 451: my $canvieweditor = &Apache::lonnet::allowed('cev', $env{'request.course.id'});
1.369.2.5 raeburn 452: my $canviewroster = $env{'course.'.$env{'request.course.id'}.'.student_classlist_view'};
1.369.2.44 raeburn 453: if ($canviewroster eq 'disabled') {
454: undef($canviewroster);
455: }
1.369.2.5 raeburn 456: my $canviewgrps = &Apache::lonnet::allowed('vcg', $crs_sec);
457: my $canmodifyuser = &Apache::lonnet::allowed('cst', $crs_sec);
1.369.2.59 raeburn 458: my $canviewusers = &Apache::lonnet::allowed('vcl', $crs_sec);
1.369.2.5 raeburn 459: my $canviewwnew = &Apache::lonnet::allowed('whn', $crs_sec);
1.369.2.59 raeburn 460: my $canviewpara = &Apache::lonnet::allowed('vpa', $crs_sec);
1.341 www 461: my $canmodpara = &Apache::lonnet::allowed('opa', $crs_sec);
1.343 www 462: my $canvgr = &Apache::lonnet::allowed('vgr', $crs_sec);
1.369.2.5 raeburn 463: my $canmgr = &Apache::lonnet::allowed('mgr', $crs_sec);
1.369.2.83.2. (raeburn 464:): my $canplc = &Apache::lonnet::allowed('plc', $crs_sec);
1.343 www 465: my $author = &getauthor();
1.327 droeschl 466:
1.369.2.83.2. (raeburn 467:): my ($cdom,$cnum,$showsyllabus,$showfeeds,$showresv,$grouptools,%menuopts);
1.369.2.76 raeburn 468: $grouptools = 0;
1.369.2.39 raeburn 469: if ($env{'request.course.id'}) {
470: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
471: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.369.2.67 raeburn 472: unless ($canedit || $canvieweditor) {
1.369.2.39 raeburn 473: unless (&Apache::lonnet::is_on_map("public/$cdom/$cnum/syllabus")) {
474: if (($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'}) ||
475: ($env{'course.'.$env{'request.course.id'}.'.uploadedsyllabus'}) ||
476: ($env{'course.'.$env{'request.course.id'}.'.updatedsyllabus'}) ||
477: ($env{'request.course.syllabustime'})) {
478: $showsyllabus = 1;
479: }
480: }
481: if ($env{'request.course.feeds'}) {
482: $showfeeds = 1;
483: }
484: }
1.369.2.67 raeburn 485: unless ($canmgr || $canvgr) {
1.369.2.45 raeburn 486: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
487: if (keys(%slots) > 0) {
488: $showresv = 1;
489: }
490: }
1.369.2.76 raeburn 491: if ($env{'request.course.groups'} ne '') {
1.369.2.77 raeburn 492: foreach my $group (split(/:/,$env{'request.course.groups'})) {
1.369.2.76 raeburn 493: next unless ($group =~ /^\w+$/);
494: my @privs = split(/:/,$env{"user.priv.$env{'request.role'}./$cdom/$cnum/$group"});
495: shift(@privs);
496: if (@privs) {
497: $grouptools ++;
498: }
499: }
500: }
1.369.2.39 raeburn 501: }
1.369.2.83.2. (raeburn 502:): if (($menucoll) && (ref($menuref) eq 'HASH')) {
503:): %menuopts = %{$menuref};
504:): }
1.369.2.39 raeburn 505:
1.369.2.83.2. (raeburn 506:): my ($listclass,$linkattr,$target);
1.369.2.83 raeburn 507: if ($links_disabled) {
508: $listclass = 'LCisDisabled';
509: $linkattr = 'aria-disabled="true"';
510: }
511:
1.369.2.31 raeburn 512: my ($canmodifycoauthor);
513: if ($env{'request.role'} eq "au./$env{'user.domain'}/") {
514: my $extent = "$env{'user.domain'}/$env{'user.name'}";
515: if ((&Apache::lonnet::allowed('cca',$extent)) ||
516: (&Apache::lonnet::allowed('caa',$extent))) {
517: $canmodifycoauthor = 1;
518: }
519: }
520:
1.369.2.30 raeburn 521: my ($roleswitcher_js,$roleswitcher_form);
1.369.2.83.2. (raeburn 522:): if ($links_target ne '') {
523:): $target = $links_target;
524:): } else {
525:): my $deeplinktarget;
526:): if ($env{'request.deeplink.login'}) {
527:): $deeplinktarget = $env{'request.deeplink.target'};
528:): }
529:): if ($deeplinktarget eq '_self') {
530:): $target = '_self';
531:): } else {
532:): $target = '_top';
533:): }
534:): }
1.369.2.30 raeburn 535:
1.283 droeschl 536: foreach my $menuitem (@secondary_menu) {
537: # evaluate conditions
1.296 droeschl 538: next if ref($menuitem) ne 'ARRAY';
1.283 droeschl 539: next if $$menuitem[4] ne 'always'
1.369.2.31 raeburn 540: && ($$menuitem[4] ne 'author' && $$menuitem[4] ne 'cca')
1.283 droeschl 541: && !$env{'request.course.id'};
1.369.2.67 raeburn 542: next if $$menuitem[4] =~ /^crsedit/
543: && (!$canedit && !$canvieweditor);
544: next if $$menuitem[4] eq 'crseditCourse'
1.369.2.5 raeburn 545: && ($crstype eq 'Community');
1.369.2.67 raeburn 546: next if $$menuitem[4] eq 'crseditCommunity'
1.369.2.5 raeburn 547: && ($crstype eq 'Course');
1.341 www 548: next if $$menuitem[4] eq 'nvgr'
549: && $canvgr;
550: next if $$menuitem[4] eq 'vgr'
551: && !$canvgr;
1.369.2.60 raeburn 552: next if $$menuitem[4] eq 'viewusers'
1.369.2.59 raeburn 553: && !$canmodifyuser && !$canviewusers;
1.369.2.60 raeburn 554: next if $$menuitem[4] eq 'noviewusers'
555: && ($canmodifyuser || $canviewusers || !$canviewroster);
1.343 www 556: next if $$menuitem[4] eq 'mgr'
557: && !$canmgr;
1.369.2.45 raeburn 558: next if $$menuitem[4] eq 'showresv'
559: && !$showresv;
1.327 droeschl 560: next if $$menuitem[4] eq 'whn'
561: && !$canviewwnew;
1.369.2.59 raeburn 562: next if $$menuitem[4] eq 'params'
563: && (!$canmodpara && !$canviewpara);
1.369.2.5 raeburn 564: next if $$menuitem[4] eq 'nvcg'
1.369.2.76 raeburn 565: && ($canviewgrps || !$grouptools);
1.369.2.39 raeburn 566: next if $$menuitem[4] eq 'showsyllabus'
567: && !$showsyllabus;
568: next if $$menuitem[4] eq 'showfeeds'
569: && !$showfeeds;
1.369.2.83.2. (raeburn 570:): next if $$menuitem[4] eq 'plc'
571:): && !$canplc;
1.329 droeschl 572: next if $$menuitem[4] eq 'author'
573: && !$author;
1.369.2.31 raeburn 574: next if $$menuitem[4] eq 'cca'
575: && !$canmodifycoauthor;
1.283 droeschl 576:
1.369.2.5 raeburn 577: my $title = $menuitem->[3];
1.369.2.83.2. (raeburn 578:): if ($env{'request.course.id'} && $menucoll) {
579:): if ($$menuitem[5] eq 'main') {
580:): next if ($menuopts{$$menuitem[5]} eq 'n');
581:): } elsif ($$menuitem[5] ne 'roles') {
582:): next if (($$menuitem[5]) && (!$menuopts{$$menuitem[5]}));
583:): }
584:): }
1.369.2.5 raeburn 585: if (defined($secondary_submenu{$title})) {
1.369.2.83.2. (raeburn 586:): my $link;
1.369.2.5 raeburn 587: if ($menuitem->[0] ne '') {
588: $link = $menuitem->[0];
589: } else {
590: $link = '#';
591: }
1.369.2.43 raeburn 592: my @scndsub;
1.369.2.5 raeburn 593: if (ref($secondary_submenu{$title}) eq 'ARRAY') {
594: foreach my $item (@{$secondary_submenu{$title}}) {
595: if (ref($item) eq 'ARRAY') {
596: next if ($item->[2] eq 'vgr' && !$canvgr);
597: next if ($item->[2] eq 'opa' && !$canmodpara);
1.369.2.59 raeburn 598: next if ($item->[2] eq 'vpa' && !$canviewpara);
1.369.2.60 raeburn 599: next if ($item->[2] eq 'viewusers' && !($canmodifyuser || $canviewusers));
1.369.2.5 raeburn 600: next if ($item->[2] eq 'mgr' && !$canmgr);
601: next if ($item->[2] eq 'vcg' && !$canviewgrps);
1.369.2.67 raeburn 602: next if ($item->[2] eq 'crsedit' && !$canedit && !$canvieweditor);
1.369.2.74 raeburn 603: next if ($item->[2] eq 'params' && !$canmodpara && !$canviewpara);
1.369.2.72 raeburn 604: next if ($item->[2] eq 'author' && !$author);
605: next if ($item->[2] eq 'cca' && !$canmodifycoauthor);
1.369.2.5 raeburn 606: push(@scndsub,$item);
607: }
608: }
1.369.2.6 raeburn 609: if (@scndsub > 0) {
1.369.2.83 raeburn 610: $menu .= &create_submenu($link,$target,&mt($title),\@scndsub,1,undef,
611: $listclass,$linkattr);
1.369.2.41 raeburn 612: } elsif ($link ne '#') {
1.369.2.83 raeburn 613: $menu .= ($listclass?'<li class="'.$listclass.'">':'<li>').
614: '<a href="'.$link.'" target="'.$target.'" '.$linkattr.'>'.
615: &mt($title).'</a></li>';
1.369.2.5 raeburn 616: }
617: }
618: } elsif ($$menuitem[3] eq 'Roles' && $env{'request.course.id'}) {
1.283 droeschl 619: # special treatment for role selector
1.369.2.83.2. (raeburn 620:): my ($switcher,$has_opa_priv);
621:): ($roleswitcher_js,$roleswitcher_form,$switcher,$has_opa_priv) =
1.369.2.30 raeburn 622: &roles_selector(
1.283 droeschl 623: $env{'course.' . $env{'request.course.id'} . '.domain'},
1.369.2.47 raeburn 624: $env{'course.' . $env{'request.course.id'} . '.num'},
1.369.2.83.2. (raeburn 625:): $httphost,$target,$menucoll,$menuref
1.369.2.30 raeburn 626: );
1.369.2.83.2. (raeburn 627:): if (($$menuitem[5]) && (!$menuopts{$$menuitem[5]})) {
628:): next unless ($has_opa_priv);
629:): }
1.369.2.30 raeburn 630: $menu .= $switcher;
1.296 droeschl 631: } else {
1.369.2.39 raeburn 632: if ($$menuitem[3] eq 'Syllabus' && $env{'request.course.id'}) {
633: my $url = $$menuitem[0];
634: $url =~ s{\[cdom\]/\[cnum\]}{$cdom/$cnum};
635: if (&Apache::lonnet::is_on_map($url)) {
1.369.2.75 raeburn 636: unless ($$menuitem[0] =~ /(\?|\&)register=1/) {
637: $$menuitem[0] .= (($$menuitem[0]=~/\?/)? '&' : '?').'register=1';
1.369.2.39 raeburn 638: }
639: } else {
1.369.2.75 raeburn 640: $$menuitem[0] =~ s{\&?register=1}{};
641: }
642: if ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://}) {
643: if (($ENV{'SERVER_PORT'} == 443) || ($env{'request.use_absolute'} =~ m{^https://})) {
1.369.2.83 raeburn 644: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl())) {
1.369.2.75 raeburn 645: unless ($$menuitem[0] =~ m{^https?://}) {
646: $$menuitem[0] = 'http://'.$ENV{'SERVER_NAME'}.$$menuitem[0];
647: }
648: unless ($$menuitem[0] =~ /(\&|\?)usehttp=1/) {
649: $$menuitem[0] .= (($$menuitem[0]=~/\?/) ? '&' : '?').'usehttp=1';
650: }
651: }
652: }
1.369.2.39 raeburn 653: }
1.369.2.72 raeburn 654: $$menuitem[0] = &HTML::Entities::encode($$menuitem[0],'&<>"');
1.369.2.39 raeburn 655: }
1.369.2.83.2. (raeburn 656:): $menu .= &prep_menuitem(\@$menuitem,$target,$listclass,$linkattr);
1.283 droeschl 657: }
658: }
659: if ($menu =~ /\[url\].*\[symb\]/) {
1.291 raeburn 660: my $escurl = &escape( &Apache::lonenc::check_encrypt(
661: $env{'request.noversionuri'}));
1.283 droeschl 662:
1.291 raeburn 663: my $escsymb = &escape( &Apache::lonenc::check_encrypt(
664: $env{'request.symb'}));
1.283 droeschl 665:
666: if ( $env{'request.state'} eq 'construct'
667: and ( $env{'request.noversionuri'} eq ''
668: || !defined($env{'request.noversionuri'})))
669: {
1.359 raeburn 670: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
671: ($escurl = $env{'request.filename'}) =~ s{^\Q$londocroot\E}{};
1.291 raeburn 672: $escurl = &escape($escurl);
1.369.2.72 raeburn 673: }
1.283 droeschl 674: $menu =~ s/\[url\]/$escurl/g;
675: $menu =~ s/\[symb\]/$escsymb/g;
676: }
1.329 droeschl 677: $menu =~ s/\[uname\]/$$author{user}/g;
678: $menu =~ s/\[udom\]/$$author{dom}/g;
1.369.2.83.2. (raeburn 679:): $menu =~ s/\[javascript\]/javascript:/g;
1.369.2.41 raeburn 680: if ($env{'request.course.id'}) {
1.369.2.40 raeburn 681: $menu =~ s/\[cnum\]/$cnum/g;
682: $menu =~ s/\[cdom\]/$cdom/g;
683: }
1.369.2.22 raeburn 684: if ($menu) {
685: $menu = "<ul id=\"LC_secondary_menu\">$menu</ul>";
686: }
1.369.2.30 raeburn 687: if ($roleswitcher_form) {
688: $menu .= "\n$roleswitcher_js\n$roleswitcher_form";
689: }
1.369.2.22 raeburn 690: return $menu;
1.283 droeschl 691: }
692:
1.369.2.6 raeburn 693: sub create_submenu {
1.369.2.83 raeburn 694: my ($link,$target,$title,$submenu,$translate,$addclass,$listclass,$linkattr) = @_;
1.369.2.6 raeburn 695: return unless (ref($submenu) eq 'ARRAY');
1.369.2.83.2. (raeburn 696:): my $targetattr;
697:): if (($target ne '') && ($link ne '#')) {
698:): $targetattr = ' target="'.$target.'"';
1.369.2.11 raeburn 699: }
1.369.2.57 raeburn 700: my $menu = '<li class="LC_hoverable '.$addclass.'">'.
1.369.2.83.2. (raeburn 701:): '<a href="'.$link.'"'.$targetattr.'>'.
1.369.2.58 raeburn 702: '<span class="LC_nobreak">'.$title.
1.369.2.6 raeburn 703: '<span class="LC_fontsize_small" style="font-weight:normal;">'.
704: ' ▼</span></span></a>'.
705: '<ul>';
1.369.2.58 raeburn 706:
707: # $link and $title are only used in the initial string written in $menu
708: # as seen above, not needed for nested submenus
1.369.2.83 raeburn 709: $menu .= &build_submenu($target, $submenu, $translate, '1', $listclass, $linkattr);
1.369.2.58 raeburn 710: $menu .= '</ul></li>';
711:
712: return $menu;
713: }
714:
715: # helper routine for create_submenu
716: # build the dropdown (and nested submenus) recursively
717: # see perldoc create_submenu documentation for further information
718: sub build_submenu {
1.369.2.83 raeburn 719: my ($target, $submenu, $translate, $first_level, $listclass, $linkattr) = @_;
1.369.2.58 raeburn 720: unless (@{$submenu}) {
721: return '';
722: }
723:
724: my $menu = '';
1.369.2.6 raeburn 725: my $count = 0;
726: my $numsub = scalar(@{$submenu});
727: foreach my $item (@{$submenu}) {
728: $count ++;
729: if (ref($item) eq 'ARRAY') {
1.369.2.43 raeburn 730: my $href = $item->[0];
1.369.2.58 raeburn 731: my $bordertop;
1.369.2.6 raeburn 732: my $borderbot;
1.369.2.58 raeburn 733: my $title;
734:
1.369.2.46 raeburn 735: if ($translate) {
1.369.2.58 raeburn 736: $title = &mt($item->[1]);
1.369.2.46 raeburn 737: } else {
1.369.2.58 raeburn 738: $title = $item->[1];
739: }
740:
741: if ($count == 1 && !$first_level) {
742: $bordertop = 'border-top: 1px solid black;';
743: }
744: if ($count == $numsub) {
745: $borderbot = 'border-bottom: 1px solid black;';
746: }
747:
748: # href is a reference to another submenu
749: if (ref($href) eq 'ARRAY') {
750: $menu .= '<li style="margin:0;padding:0;'.$bordertop . $borderbot . '">';
751: $menu .= '<p><span class="LC_primary_menu_innertitle">'
752: . $title . '</span><span class="LC_primary_menu_innerarrow">▶</span></p>';
753: $menu .= '<ul>';
754: $menu .= &build_submenu($target, $href, $translate);
755: $menu .= '</ul>';
756: $menu .= '</li>';
757: } else { # href is the actual hyperlink and does not represent another submenu
758: # for the current menu title
759: if ($href =~ /(aboutme|rss\.html)$/) {
760: next unless (($env{'user.name'} ne '') && ($env{'user.domain'} ne ''));
761: $href =~ s/\[domain\]/$env{'user.domain'}/g;
762: $href =~ s/\[user\]/$env{'user.name'}/g;
1.369.2.72 raeburn 763: } elsif (($href =~ m{^/adm/preferences\?}) && ($href =~ /\[returnurl\]/)) {
764: my $returnurl = $ENV{'REQUEST_URI'};
765: if ($ENV{'REQUEST_URI'} =~ m{/adm/preferences\?action=(?:changedomcoord|authorsettings)\&returnurl=([^\&]+)$}) {
766: $returnurl = $1;
767: }
768: if (($returnurl =~ m{^/adm/createuser($|\?action=)}) ||
769: ($returnurl =~ m{^/priv/$match_domain/$match_username}) ||
770: ($returnurl =~ m{^/res(/?$|/$match_domain/$match_username)})) {
771: $returnurl =~ s{\?.*$}{};
772: $returnurl = '&returnurl='.&HTML::Entities::encode($returnurl,'"<>&\'');
773: } else {
774: undef($returnurl);
775: }
776: $href =~ s/\[returnurl\]/$returnurl/;
1.369.2.58 raeburn 777: }
1.369.2.83.2. (raeburn 778:): my $targetattr;
1.369.2.58 raeburn 779: unless (($href eq '') || ($href =~ /^\#/)) {
1.369.2.83.2. (raeburn 780:): if ($target ne '') {
781:): $targetattr = ' target="'.$target.'"';
782:): }
1.369.2.58 raeburn 783: }
784:
1.369.2.83 raeburn 785: $menu .= '<li ';
786: $menu .= ($listclass?'class="'.$listclass.'" ':'');
787: $menu .= 'style="margin:0;padding:0;'. $bordertop . $borderbot .'">';
1.369.2.83.2. (raeburn 788:): $menu .= '<a href="'.$href.'"'.$targetattr.' '.$linkattr.'>' . $title . '</a>';
1.369.2.58 raeburn 789: $menu .= '</li>';
1.369.2.46 raeburn 790: }
1.369.2.6 raeburn 791: }
792: }
793: return $menu;
794: }
795:
1.369.2.17 raeburn 796: sub registerurl {
797: my ($forcereg) = @_;
798: my $result = '';
799: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
800: my $force_title='';
801: if ($env{'request.state'} eq 'construct') {
802: $force_title=&Apache::lonxml::display_title();
803: }
1.369.2.25 raeburn 804: if (($env{'environment.remote'} ne 'on') ||
1.369.2.17 raeburn 805: ((($env{'request.publicaccess'}) ||
806: (!&Apache::lonnet::is_on_map(
807: &unescape($env{'request.noversionuri'})))) &&
808: (!$forcereg))) {
809: return
810: $result
811: .'<script type="text/javascript">'."\n"
812: .'// <![CDATA['."\n"
813: .'function LONCAPAreg(){;} function LONCAPAstale(){}'."\n"
814: .'// ]]>'."\n"
815: .'</script>'
816: .$force_title;
817: }
818: # Graphical display after login only
819: if ($env{'request.registered'} && !$forcereg) { return ''; }
820: $result.=&innerregister($forcereg);
821: return $result.$force_title;
822: }
823:
1.40 www 824: sub innerregister {
1.369.2.83.2. (raeburn 825:): my ($forcereg,$bread_crumbs,$group,$pagebuttonshide,$hostname,
826:): $ltiscope,$ltiuri,$showncrumbsref) = @_;
1.152 albertel 827: my $const_space = ($env{'request.state'} eq 'construct');
1.131 raeburn 828: my $is_const_dir = 0;
1.120 raeburn 829:
1.175 albertel 830: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
1.40 www 831:
1.174 albertel 832: $env{'request.registered'} = 1;
1.40 www 833:
1.369.2.25 raeburn 834: my $noremote = ($env{'environment.remote'} ne 'on');
1.369.2.17 raeburn 835:
1.177 albertel 836: undef(@inlineremote);
1.56 www 837:
1.369.2.17 raeburn 838: my $reopen=&Apache::lonmenu::reopenmenu();
839:
840: my $newmail='';
841:
842: if (&Apache::lonmsg::newmail() && !$noremote) {
843: # We have new mail and remote is up
844: $newmail= 'swmenu.setstatus("you have","messages");';
845: }
846:
1.369.2.78 raeburn 847: my ($mapurl,$resurl,$crstype,$navmap);
1.369.2.26 raeburn 848:
1.369.2.27 raeburn 849: if ($env{'request.course.id'}) {
1.369.2.75 raeburn 850: #
851: #course_type: Course or Community
852: #
853: $crstype = &Apache::loncommon::course_type();
1.369.2.27 raeburn 854: if ($env{'request.symb'}) {
1.369.2.78 raeburn 855: my $ignorenull;
856: unless ($env{'request.noversionuri'} eq '/adm/navmaps') {
857: $ignorenull = 1;
858: }
859: my $symb = &Apache::lonnet::symbread('','',$ignorenull);
860: ($mapurl, my $rid, $resurl) = &Apache::lonnet::decode_symb($symb);
1.369.2.27 raeburn 861: my $coursetitle = $env{'course.'.$env{'request.course.id'}.'.description'};
1.267 droeschl 862:
1.369.2.27 raeburn 863: my $maptitle = &Apache::lonnet::gettitle($mapurl);
1.369.2.78 raeburn 864: my $restitle = &Apache::lonnet::gettitle($symb);
1.267 droeschl 865:
1.369.2.78 raeburn 866: my (@crumbs,@mapcrumbs);
867: if (($env{'request.noversionuri'} ne '/adm/navmaps') && ($mapurl ne '') &&
868: ($mapurl ne $env{'course.'.$env{'request.course.id'}.'.url'})) {
869: $navmap = Apache::lonnavmaps::navmap->new();
870: if (ref($navmap)) {
871: @mapcrumbs = $navmap->recursed_crumbs($mapurl,$restitle);
872: }
873: }
1.369.2.27 raeburn 874: unless (($forcereg) &&
875: ($env{'request.noversionuri'} eq '/adm/navmaps') &&
876: ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'})) {
1.369.2.75 raeburn 877: @crumbs = ({text => $crstype.' Contents',
1.369.2.27 raeburn 878: href => "Javascript:gopost('/adm/navmaps','')"});
879: }
880: if ($mapurl ne $env{'course.'.$env{'request.course.id'}.'.url'}) {
1.369.2.78 raeburn 881: if (@mapcrumbs) {
882: push(@crumbs,@mapcrumbs);
883: } else {
884: push(@crumbs, {text => '...',
885: no_mt => 1});
886: }
1.369.2.27 raeburn 887: }
888:
1.369.2.78 raeburn 889: unless ((@mapcrumbs) || (!$maptitle) || ($maptitle eq 'default.sequence') ||
890: ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'})) {
891: push @crumbs, {text => $maptitle, no_mt => 1,
892: href => &Apache::lonnet::clutter($mapurl).'?navmap=1'};
893: }
894: if ($restitle && !@mapcrumbs) {
895: push(@crumbs,{text => $restitle, no_mt => 1});
896: }
1.369.2.56 raeburn 897: my @tools;
898: if ($env{'request.filename'} =~ /\.page$/) {
899: my %breadcrumb_tools = &Apache::lonhtmlcommon::current_breadcrumb_tools();
900: if (ref($breadcrumb_tools{'tools'}) eq 'ARRAY') {
901: @tools = @{$breadcrumb_tools{'tools'}};
902: }
903: }
1.369.2.27 raeburn 904: &Apache::lonhtmlcommon::clear_breadcrumbs();
905: &Apache::lonhtmlcommon::add_breadcrumb(@crumbs);
1.369.2.56 raeburn 906: if (@tools) {
907: &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',@tools);
908: }
1.369.2.27 raeburn 909: } else {
910: $resurl = $env{'request.noversionuri'};
911: my $courseurl = &Apache::lonnet::courseid_to_courseurl($env{'request.course.id'});
912: my $title = &mt('View Resource');
913: if ($resurl =~ m{^\Q/uploaded$courseurl/supplemental/\E(default|\d+)/}) {
914: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['folderpath','title']);
915: &Apache::lonhtmlcommon::clear_breadcrumbs();
916: if ($env{'form.title'}) {
917: $title = $env{'form.title'};
918: }
1.369.2.83.2. (raeburn 919:): my ($trail,$cnum,$cdom);
920:): if ($env{'form.folderpath'}) {
921:): $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
922:): $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
923:): &Apache::loncommon::validate_folderpath(1,'',$cnum,$cdom);
924:): }
1.369.2.27 raeburn 925: if ($env{'form.folderpath'}) {
1.369.2.75 raeburn 926: &prepare_functions($resurl,$forcereg,$group,undef,undef,1,$hostname);
1.369.2.83.2. (raeburn 927:): $title = &HTML::Entities::encode($title,'\'"<>&');
1.369.2.27 raeburn 928: ($trail) =
1.369.2.83.2. (raeburn 929:): &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1,1);
1.369.2.27 raeburn 930: } else {
931: &Apache::lonhtmlcommon::add_breadcrumb(
932: {text => "Supplemental $crstype Content",
933: href => "javascript:gopost('/adm/supplemental','')"});
1.369.2.83.2. (raeburn 934:): $title = &HTML::Entities::encode(&mt('View Resource'),'\'"<>&');
1.369.2.27 raeburn 935: ($trail) =
1.369.2.83.2. (raeburn 936:): &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1,1);
937:): }
938:): if (ref($showncrumbsref)) {
939:): $$showncrumbsref = 1;
1.369.2.27 raeburn 940: }
941: return $trail;
1.369.2.39 raeburn 942: } elsif ($resurl =~ m{^\Q/uploaded$courseurl/portfolio/syllabus/}) {
943: &Apache::lonhtmlcommon::clear_breadcrumbs();
944: &prepare_functions('/public'.$courseurl."/syllabus",
1.369.2.75 raeburn 945: $forcereg,$group,undef,undef,1,$hostname);
1.369.2.83.2. (raeburn 946:): $title = &HTML::Entities::encode(&mt('Syllabus File'),'\'"<>&');
1.369.2.39 raeburn 947: my ($trail) =
1.369.2.83.2. (raeburn 948:): &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1,1);
949:): if (ref($showncrumbsref)) {
950:): $$showncrumbsref = 1;
951:): }
1.369.2.39 raeburn 952: return $trail;
1.369.2.27 raeburn 953: }
954: unless ($env{'request.state'} eq 'construct') {
955: &Apache::lonhtmlcommon::clear_breadcrumbs();
956: &Apache::lonhtmlcommon::add_breadcrumb({text => 'View Resource'});
957: }
958: }
1.369.2.26 raeburn 959: } elsif (! $const_space){
1.328 droeschl 960: #a situation when we're looking at a resource outside of context of a
961: #course or construction space (e.g. with cumulative rights)
962: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.369.2.26 raeburn 963: unless ($env{'request.noversionuri'} =~ m{^/adm/$match_domain/$match_username/aboutme$}) {
964: &Apache::lonhtmlcommon::add_breadcrumb({text => 'View Resource'});
965: }
1.65 www 966: }
1.369.2.17 raeburn 967: my $timesync = ( $noremote ? '' : 'swmenu.syncclock(1000*'.time.');' );
1.41 www 968: # =============================================================================
969: # ============================ This is for URLs that actually can be registered
1.369.2.18 raeburn 970: if ( ($env{'request.noversionuri'}!~m{^/(res/)*adm/})
1.369.2.17 raeburn 971: || ($forcereg)) {
1.369.2.28 raeburn 972:
973: my %swtext;
974: if ($noremote) {
975: %swtext = &get_inline_text();
976: } else {
977: %swtext = &get_rc_text();
978: }
979: my $hwkadd='';
980:
981: my ($cdom,$cnum,%perms,$cfile,$switchserver,$home,$forceedit,
982: $forceview,$editbutton);
983: if (($resurl =~ m{^/adm/($match_domain)/($match_username)/aboutme$}) ||
984: ($env{'request.role'} !~/^(aa|ca|au)/)) {
1.369.2.37 raeburn 985: if (($env{'environment.remote'} eq 'on') && ($env{'request.symb'})) {
986: &Apache::lonhtmlcommon::clear_breadcrumbs();
987: }
1.369.2.75 raeburn 988: $editbutton = &prepare_functions($resurl,$forcereg,$group,'','','',$hostname);
1.369.2.28 raeburn 989: }
990: if ($editbutton eq '') {
1.369.2.29 raeburn 991: $editbutton = &clear(6,1);
1.369.2.28 raeburn 992: }
1.369.2.26 raeburn 993:
994: #
995: # This applies in course context
996: #
1.369.2.28 raeburn 997: if ($env{'request.course.id'}) {
998: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
999: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1000: $perms{'mdc'} = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
1.369.2.66 raeburn 1001: $perms{'cev'} = &Apache::lonnet::allowed('cev',$env{'request.course.id'});
1.369.2.28 raeburn 1002: my @privs;
1003: if ($env{'request.symb'} ne '') {
1004: if ($env{'request.filename'}=~/$LONCAPA::assess_re/) {
1005: push(@privs,('mgr','vgr'));
1006: }
1.369.2.59 raeburn 1007: push(@privs,('opa','vpa'));
1.369.2.28 raeburn 1008: }
1009: foreach my $priv (@privs) {
1010: $perms{$priv} = &Apache::lonnet::allowed($priv,$env{'request.course.id'});
1011: if (!$perms{$priv} && $env{'request.course.sec'} ne '') {
1012: $perms{$priv} =
1013: &Apache::lonnet::allowed($priv,"$env{'request.course.id'}/$env{'request.course.sec'}");
1014: }
1.258 raeburn 1015: }
1.369.2.26 raeburn 1016: #
1017: # Determine whether or not to show Grades and Submissions buttons
1018: #
1.369.2.28 raeburn 1019: if ($env{'request.symb'} ne '' &&
1020: $env{'request.filename'}=~/$LONCAPA::assess_re/) {
1021: if ($perms{'mgr'}) {
1022: $hwkadd.= &switch('','',7,2,'pgrd.png','Content Grades',
1023: 'grades[_4]',
1024: "gocmd('/adm/grades','gradingmenu')",
1025: 'Content Grades');
1026: } elsif ($perms{'vgr'}) {
1027: $hwkadd .= &switch('','',7,2,'subm.png','Content Submissions',
1028: 'missions[_1]',
1029: "gocmd('/adm/grades','submission')",
1030: 'Content Submissions');
1031: }
1032: }
1.369.2.59 raeburn 1033: if (($env{'request.symb'} ne '') && (($perms{'opa'}) || ($perms{'vpa'}))) {
1.369.2.28 raeburn 1034: $hwkadd .= &switch('','',7,3,'pparm.png','Content Settings',
1035: 'parms[_2]',"gocmd('/adm/parmset','set')",
1036: 'Content Settings');
1037: }
1.369.2.26 raeburn 1038: # End grades/submissions check
1039:
1040: #
1041: # This applies to items inside a folder/page modifiable in the course.
1042: #
1.369.2.66 raeburn 1043: if (($env{'request.symb'}=~/^uploaded/) && (($perms{'mdc'}) || ($perms{'cev'}))) {
1.369.2.28 raeburn 1044: my $text = 'Edit Folder';
1045: if (($mapurl =~ /\.page$/) ||
1046: ($env{'request.symb'}=~
1047: m{uploaded/$cdom/$cnum/default_\d+\.page$})) {
1048: $text = 'Edit Page';
1049: }
1050: $hwkadd .= &switch('','',7,4,'docs-22x22.png',$text,'parms[_2]',
1051: "gocmd('/adm/coursedocs','direct')",
1052: 'Folder/Page Content');
1053: }
1.369.2.26 raeburn 1054: # End modifiable folder/page container check
1.369.2.28 raeburn 1055: }
1.369.2.26 raeburn 1056: # End course context
1057:
1.41 www 1058: # Prepare the rest of the buttons
1.369.2.21 raeburn 1059: my ($menuitems,$got_prt,$got_wishlist,$cstritems);
1.120 raeburn 1060: if ($const_space) {
1.274 www 1061: #
1062: # We are in construction space
1063: #
1.353 www 1064:
1.355 raeburn 1065: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.353 www 1066: my ($udom,$uname,$thisdisfn) =
1.355 raeburn 1067: ($env{'request.filename'}=~m{^\Q$londocroot/priv/\E([^/]+)/([^/]+)/(.*)$});
1.353 www 1068: my $currdir = '/priv/'.$udom.'/'.$uname.'/'.$thisdisfn;
1.131 raeburn 1069: if ($currdir =~ m-/$-) {
1070: $is_const_dir = 1;
1.369.2.55 raeburn 1071: if ($thisdisfn eq '') {
1072: $is_const_dir = 2;
1073: }
1.131 raeburn 1074: } else {
1.267 droeschl 1075: $currdir =~ s|[^/]+$||;
1.200 foxr 1076: my $cleandisfn = &Apache::loncommon::escape_single($thisdisfn);
1.208 albertel 1077: my $esc_currdir = &Apache::loncommon::escape_single($currdir);
1.274 www 1078: #
1079: # Probably should be in mydesk.tab
1080: #
1.131 raeburn 1081: $menuitems=(<<ENDMENUITEMS);
1.369.2.21 raeburn 1082: s&6&1&list.png&Directory&dir[_1]&golist('$esc_currdir')&List current directory
1083: s&6&2&rtrv.png&Retrieve&version[_1]&gocstr('/adm/retrieve','/priv/$udom/$uname/$cleandisfn')&Retrieve old version
1084: s&6&3&pub.png&Publish&resource[_3]&gocstr('/adm/publish','/priv/$udom/$uname/$cleandisfn')&Publish this resource
1085: s&7&1&del.png&Delete&resource[_2]&gocstr('/adm/cfile?action=delete','/priv/$udom/$uname/$cleandisfn')&Delete this resource
1086: s&7&2&prt.png&Print&printout[_1]&gocstr('/adm/printout','/priv/$udom/$uname/$cleandisfn')&Prepare a printable document
1.120 raeburn 1087: ENDMENUITEMS
1.369.2.21 raeburn 1088: unless ($noremote) {
1089: $cstritems = $menuitems;
1090: undef($menuitems);
1091: }
1.131 raeburn 1092: }
1.369.2.28 raeburn 1093: if (ref($bread_crumbs) eq 'ARRAY') {
1094: &Apache::lonhtmlcommon::clear_breadcrumbs();
1095: foreach my $crumb (@{$bread_crumbs}){
1096: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
1.308 raeburn 1097: }
1.369.2.28 raeburn 1098: }
1.203 foxr 1099: } elsif ( defined($env{'request.course.id'}) &&
1100: $env{'request.symb'} ne '' ) {
1.274 www 1101: #
1.369.2.16 raeburn 1102: # We are in a course and looking at a registered URL
1.274 www 1103: # Should probably be in mydesk.tab
1104: #
1.369.2.19 raeburn 1105:
1.120 raeburn 1106: $menuitems=(<<ENDMENUITEMS);
1.41 www 1107: c&3&1
1.369.2.19 raeburn 1108: s&2&1&back.png&$swtext{'back'}&&gopost('/adm/flip','back:'+currentURL)&Previous content resource&&1
1109: s&2&3&forw.png&$swtext{'forw'}&&gopost('/adm/flip','forward:'+currentURL)&Next content resource&&3
1.77 www 1110: c&6&3
1111: c&8&1
1112: c&8&2
1.369.2.19 raeburn 1113: s&8&3&prt.png&$swtext{'prt'}&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
1.41 www 1114: ENDMENUITEMS
1.369.2.16 raeburn 1115: $got_prt = 1;
1116: if (($env{'user.adv'}) && ($env{'request.uri'} =~ /^\/res/)
1117: && (!$env{'request.enc'})) {
1.369.2.8 raeburn 1118: # wishlist is only available for users with access to resource-pool
1119: # and links can only be set for resources within the resource-pool
1120: $menuitems .= (<<ENDMENUITEMS);
1.369.2.54 raeburn 1121: s&9&1&alnk.png&$swtext{'alnk'}&linkstor[_1]&set_wishlistlink('',currentURL)&Save a link for this resource in my personal Stored Links repository&&1
1.369.2.8 raeburn 1122: ENDMENUITEMS
1.369.2.16 raeburn 1123: $got_wishlist = 1;
1.369.2.8 raeburn 1124: }
1.216 albertel 1125:
1.243 tempelho 1126: my $currentURL = &Apache::loncommon::get_symb();
1127: my ($symb_old,$symb_old_enc) = &Apache::loncommon::clean_symb($currentURL);
1128: my $annotation = &Apache::loncommon::get_annotation($symb_old,$symb_old_enc);
1129: $menuitems.="s&9&3&";
1130: if(length($annotation) > 0){
1.317 droeschl 1131: $menuitems.="anot2.png";
1.243 tempelho 1132: }else{
1.317 droeschl 1133: $menuitems.="anot.png";
1.243 tempelho 1134: }
1.369.2.19 raeburn 1135: $menuitems.="&$swtext{'anot'}&tations[_1]&annotate()&";
1.243 tempelho 1136: $menuitems.="Make notes and annotations about this resource&&1\n";
1.369.2.52 raeburn 1137: my $is_mobile;
1138: if ($env{'browser.mobile'}) {
1139: $is_mobile = 1;
1140: }
1.243 tempelho 1141:
1.323 raeburn 1142: unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme|viewclasslist|portfolio)(\?|$)/) {
1.369.2.80 raeburn 1143: if ((!$env{'request.enc'}) && ($env{'request.noversionuri'} !~ m{^/adm/wrapper/ext/}) &&
1.369.2.83.2. (raeburn 1144:): ($env{'request.noversionuri'} !~ m{^/uploaded/$match_domain/$match_courseid/(docs/|default_\d+\.page$)}) &&
1145:): ($env{'request.noversionuri'} !~ m{^/adm/.+/ext\.tool$})) {
1.216 albertel 1146: $menuitems.=(<<ENDREALRES);
1.369.2.83.2. (raeburn 1147:): s&6&3&catalog.png&$swtext{'catalog'}&info[_1]&catalog_info(currentURL,'$is_mobile')&Show Metadata
1.216 albertel 1148: ENDREALRES
1149: }
1.369.2.80 raeburn 1150: unless (($env{'request.noversionuri'} =~ m{^/uploaded/$match_domain/$match_courseid/(docs/|default_\d+\.page$)}) ||
1.369.2.83.2. (raeburn 1151:): ($env{'request.noversionuri'} =~ m{^\Q/adm/wrapper/\E(ext|uploaded)/}) ||
1152:): ($env{'request.noversionuri'} =~ m{^/adm/.+/ext\.tool$})) {
1.369.2.14 raeburn 1153: $menuitems.=(<<ENDREALRES);
1.369.2.19 raeburn 1154: s&8&1&eval.png&$swtext{'eval'}&this[_1]&gopost('/adm/evaluate',currentURL,1)&Provide my evaluation of this resource
1.369.2.14 raeburn 1155: ENDREALRES
1156: }
1.369.2.48 raeburn 1157: unless ($env{'request.noversionuri'} =~ m{^\Q/adm/wrapper/\E(ext|uploaded)/}) {
1158: $menuitems.=(<<ENDREALRES);
1.369.2.19 raeburn 1159: s&8&2&fdbk.png&$swtext{'fdbk'}&discuss[_1]&gopost('/adm/feedback',currentURL,1)&Provide feedback messages or contribute to the course discussion about this resource
1.77 www 1160: ENDREALRES
1.369.2.48 raeburn 1161: }
1.120 raeburn 1162: }
1163: }
1.203 foxr 1164: if ($env{'request.uri'} =~ /^\/res/) {
1.369.2.16 raeburn 1165: unless ($got_prt) {
1166: $menuitems .= (<<ENDMENUITEMS);
1.369.2.19 raeburn 1167: s&8&3&prt.png&$swtext{'prt'}&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
1.203 foxr 1168: ENDMENUITEMS
1.369.2.16 raeburn 1169: $got_prt = 1;
1170: }
1171: unless ($got_wishlist) {
1172: if (($env{'user.adv'}) && (!$env{'request.enc'})) {
1173: # wishlist is only available for users with access to resource-pool
1174: $menuitems .= (<<ENDMENUITEMS);
1.369.2.54 raeburn 1175: s&9&1&alnk.png&$swtext{'alnk'}&linkstor[_1]&set_wishlistlink('',currentURL)&Save a link for this resource in your personal Stored Links repository&&1
1.369.2.8 raeburn 1176: ENDMENUITEMS
1.369.2.16 raeburn 1177: $got_wishlist = 1;
1.369.2.17 raeburn 1178: }
1.369.2.8 raeburn 1179: }
1.203 foxr 1180: }
1.369.2.20 raeburn 1181: unless ($got_prt) {
1182: $menuitems .= (<<ENDMENUITEMS);
1183: c&8&3
1184: ENDMENUITEMS
1185: }
1186: unless ($got_wishlist) {
1187: $menuitems .= (<<ENDMENUITEMS);
1188: c&9&1
1189: ENDMENUITEMS
1190: }
1.41 www 1191: my $buttons='';
1192: foreach (split(/\n/,$menuitems)) {
1193: my ($command,@rest)=split(/\&/,$_);
1.220 raeburn 1194: my $idx=10*$rest[0]+$rest[1];
1195: if (&hidden_button_check() eq 'yes') {
1196: if ($idx == 21 ||$idx == 23) {
1197: $buttons.=&switch('','',@rest);
1198: } else {
1199: $buttons.=&clear(@rest);
1200: }
1201: } else {
1202: if ($command eq 's') {
1203: $buttons.=&switch('','',@rest);
1204: } else {
1205: $buttons.=&clear(@rest);
1206: }
1.41 www 1207: }
1208: }
1.369.2.83.2. (raeburn 1209:): my $linkprotout;
1210:): if ($env{'request.deeplink.login'}) {
1211:): $linkprotout = &linkprot_exit();
1212:): }
1.369.2.17 raeburn 1213: if ($noremote) {
1.148 albertel 1214: my $addremote=0;
1.267 droeschl 1215: foreach (@inlineremote) { if ($_ ne '') { $addremote=1; last;} }
1.369.2.17 raeburn 1216: if ($addremote) {
1.369.2.63 raeburn 1217: my ($countdown,$buttonshide);
1.369.2.56 raeburn 1218: if ($env{'request.filename'} =~ /\.page$/) {
1219: my %breadcrumb_tools = &Apache::lonhtmlcommon::current_breadcrumb_tools();
1220: if (ref($breadcrumb_tools{'tools'}) eq 'ARRAY') {
1.369.2.63 raeburn 1221: $countdown = $breadcrumb_tools{'tools'}->[0];
1.369.2.56 raeburn 1222: }
1.369.2.63 raeburn 1223: $buttonshide = $pagebuttonshide;
1.369.2.56 raeburn 1224: } else {
1225: $countdown = &countdown_timer();
1.369.2.63 raeburn 1226: $buttonshide = &hidden_button_check();
1.369.2.56 raeburn 1227: }
1.369.2.62 raeburn 1228:
1229: &Apache::lonhtmlcommon::clear_breadcrumb_tools();
1230:
1231: &Apache::lonhtmlcommon::add_breadcrumb_tool(
1232: 'navigation', @inlineremote[21,23]);
1233:
1.369.2.63 raeburn 1234: if ($buttonshide eq 'yes') {
1.369.2.17 raeburn 1235: if ($countdown) {
1236: &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$countdown);
1237: }
1.369.2.83.2. (raeburn 1238:): if ($linkprotout) {
1239:): &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$linkprotout);
1240:): }
1.369.2.17 raeburn 1241: } else {
1242: my @tools = @inlineremote[93,91,81,82,83];
1243: if ($countdown) {
1244: unshift(@tools,$countdown);
1245: }
1.369.2.83.2. (raeburn 1246:): if ($linkprotout) {
1247:): unshift(@tools,$linkprotout);
1248:): }
1.369.2.17 raeburn 1249: &Apache::lonhtmlcommon::add_breadcrumb_tool(
1250: 'tools',@tools);
1.312 droeschl 1251:
1.369.2.17 raeburn 1252: #publish button in construction space
1253: if ($env{'request.state'} eq 'construct'){
1254: &Apache::lonhtmlcommon::add_breadcrumb_tool(
1255: 'advtools', $inlineremote[63]);
1256: } else {
1257: &Apache::lonhtmlcommon::add_breadcrumb_tool(
1258: 'tools', $inlineremote[63]);
1259: }
1.369.2.26 raeburn 1260: &advtools_crumbs(@inlineremote);
1.369.2.17 raeburn 1261: }
1.369.2.83.2. (raeburn 1262:): } else {
1263:): if ($linkprotout) {
1264:): &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$linkprotout);
1265:): }
1.369.2.10 raeburn 1266: }
1.369.2.55 raeburn 1267: my ($topic_help,$topic_help_text);
1268: if ($is_const_dir == 2) {
1269: if ((($ENV{'SERVER_PORT'} == 443) ||
1270: ($Apache::lonnet::protocol{$Apache::lonnet::perlvar{'lonHostID'}} eq 'https')) &&
1271: (&Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},'webdav'))) {
1272: $topic_help = 'Authoring_WebDAV,Authoring_WebDAV_Mac_10v6,Authoring_WebDAV_Mac_10v10,'.
1273: 'Authoring_WebDAV_Windows_v7,Authoring_WebDAV_Linux_Centos';
1274: $topic_help_text = 'About WebDAV access';
1275: }
1276: }
1.369.2.83.2. (raeburn 1277:): if (ref($showncrumbsref)) {
1278:): $$showncrumbsref = 1;
1279:): }
1.369.2.18 raeburn 1280: return &Apache::lonhtmlcommon::scripttag('', 'start')
1.369.2.55 raeburn 1281: . &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0,'','','','',$topic_help,$topic_help_text)
1.369.2.18 raeburn 1282: . &Apache::lonhtmlcommon::scripttag('', 'end');
1283:
1.369.2.10 raeburn 1284: } else {
1.369.2.21 raeburn 1285: my $cstrcrumbs;
1286: if ($const_space) {
1287: foreach (split(/\n/,$cstritems)) {
1288: my ($command,@rest)=split(/\&/,$_);
1289: my $idx=10*$rest[0]+$rest[1];
1290: &switch('','',@rest);
1291: }
1292: &Apache::lonhtmlcommon::add_breadcrumb_tool('advtools',
1293: @inlineremote[63,61,71,72]);
1294:
1295: $cstrcrumbs = &Apache::lonhtmlcommon::scripttag('', 'start')
1296: .&Apache::lonhtmlcommon::breadcrumbs(undef,undef,0)
1297: .&Apache::lonhtmlcommon::scripttag('', 'end');
1298: }
1.369.2.17 raeburn 1299: my $requri=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
1300: $requri=&Apache::lonenc::check_encrypt(&unescape($requri));
1301: my $cursymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
1302: my $navstatus=&get_nav_status();
1303: my $clearcstr;
1.313 droeschl 1304:
1.369.2.17 raeburn 1305: if ($env{'user.adv'}) { $clearcstr='clearbut(6,1)'; }
1306: return <<ENDREGTHIS;
1307:
1308: <script type="text/javascript">
1309: // <![CDATA[
1310: // BEGIN LON-CAPA Internal
1311: var swmenu=null;
1312:
1313: function LONCAPAreg() {
1314: swmenu=$reopen;
1315: swmenu.clearTimeout(swmenu.menucltim);
1316: $timesync
1317: $newmail
1318: $buttons
1319: swmenu.currentURL="$requri";
1320: swmenu.reloadURL=swmenu.currentURL+window.location.search;
1321: swmenu.currentSymb="$cursymb";
1322: swmenu.reloadSymb="$cursymb";
1323: swmenu.currentStale=0;
1324: $navstatus
1325: $hwkadd
1326: $editbutton
1327: }
1328:
1329: function LONCAPAstale() {
1330: swmenu=$reopen
1331: swmenu.currentStale=1;
1332: if (swmenu.reloadURL!='' && swmenu.reloadURL!= null) {
1333: swmenu.switchbutton
1334: (3,1,'reload.gif','return','location','go(reloadURL)','Return to the last known location in the course sequence');
1335: }
1336: swmenu.clearbut(7,2);
1337: swmenu.clearbut(7,3);
1338: swmenu.menucltim=swmenu.setTimeout(
1339: 'clearbut(2,1);clearbut(2,3);clearbut(8,1);clearbut(8,2);clearbut(8,3);'+
1340: 'clearbut(9,1);clearbut(9,3);clearbut(6,3);$clearcstr',
1341: 2000);
1342: }
1343:
1344: // END LON-CAPA Internal
1345: // ]]>
1346: </script>
1.369.2.21 raeburn 1347:
1348: $cstrcrumbs
1.369.2.17 raeburn 1349: ENDREGTHIS
1.301 droeschl 1350: }
1.369.2.18 raeburn 1351: } else {
1352: unless ($noremote) {
1353: # Not registered, graphical
1354: return (<<ENDDONOTREGTHIS);
1355:
1356: <script type="text/javascript">
1357: // <![CDATA[
1358: // BEGIN LON-CAPA Internal
1359: var swmenu=null;
1.38 www 1360:
1.369.2.18 raeburn 1361: function LONCAPAreg() {
1362: swmenu=$reopen
1363: $timesync
1364: swmenu.currentStale=1;
1365: swmenu.clearbut(2,1);
1366: swmenu.clearbut(2,3);
1367: swmenu.clearbut(8,1);
1368: swmenu.clearbut(8,2);
1369: swmenu.clearbut(8,3);
1.369.2.20 raeburn 1370: swmenu.clearbut(9,1);
1.369.2.18 raeburn 1371: if (swmenu.currentURL) {
1372: swmenu.switchbutton
1373: (3,1,'reload.gif','return','location','go(currentURL)');
1374: } else {
1375: swmenu.clearbut(3,1);
1376: }
1377: }
1378:
1379: function LONCAPAstale() {
1380: }
1381:
1382: // END LON-CAPA Internal
1383: // ]]>
1384: </script>
1385: ENDDONOTREGTHIS
1386:
1387: }
1388: return '';
1389: }
1.38 www 1390: }
1391:
1.369.2.19 raeburn 1392: sub get_inline_text {
1393: my %text = (
1394: pgrd => 'Content Grades',
1395: subm => 'Content Submissions',
1396: pparm => 'Content Settings',
1397: docs => 'Folder/Page Content',
1398: pcstr => 'Edit',
1399: prt => 'Print',
1400: alnk => 'Stored Links',
1401: anot => 'Notes',
1402: catalog => 'Info',
1403: eval => 'Evaluate',
1404: fdbk => 'Feedback',
1405: );
1406: return %text;
1407: }
1408:
1409: sub get_rc_text {
1410: my %text = (
1411: pgrd => 'problem[_1]',
1412: subm => 'view sub-[_1]',
1413: pparm => 'problem[_2]',
1414: pcstr => 'edit[_1]',
1415: prt => 'prepare[_1]',
1416: back => 'backward[_1]',
1417: forw => 'forward[_1]',
1418: alnk => 'add to[_1]',
1419: anot => 'anno-[_1]',
1420: catalog => 'catalog[_2]',
1421: eval => 'evaluate[_1]',
1422: fdbk => 'feedback[_1]',
1423: );
1424: return %text;
1425: }
1426:
1.369.2.17 raeburn 1427: sub loadevents() {
1428: if ($env{'request.state'} eq 'construct' ||
1429: $env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
1430: return 'LONCAPAreg();';
1431: }
1432:
1433: sub unloadevents() {
1434: if ($env{'request.state'} eq 'construct' ||
1435: $env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
1436: return 'LONCAPAstale();';
1437: }
1438:
1.369.2.1 raeburn 1439: sub startupremote {
1440: my ($lowerurl)=@_;
1.369.2.17 raeburn 1441: unless ($env{'environment.remote'} eq 'on') {
1442: return ('<meta HTTP-EQUIV="Refresh" CONTENT="0.5; url='.$lowerurl.'" />');
1.369.2.1 raeburn 1443: }
1444: #
1445: # The Remote actually gets launched!
1446: #
1447: my $configmenu=&rawconfig();
1448: my $esclowerurl=&escape($lowerurl);
1449: my $message=&mt('"Waiting for Remote Control window to load: "+[_1]','waited');
1450: return(<<ENDREMOTESTARTUP);
1451: <script type="text/javascript">
1452: // <![CDATA[
1453: var timestart;
1454: function wheelswitch() {
1455: if (typeof(document.wheel) != 'undefined') {
1456: if (typeof(document.wheel.spin) != 'undefined') {
1457: var date=new Date();
1458: var waited=Math.round(30-((date.getTime()-timestart)/1000));
1459: document.wheel.spin.value=$message;
1460: }
1461: }
1462: if (window.status=='|') {
1463: window.status='/';
1464: } else {
1465: if (window.status=='/') {
1466: window.status='-';
1467: } else {
1468: if (window.status=='-') {
1469: window.status='\\\\';
1470: } else {
1471: if (window.status=='\\\\') { window.status='|'; }
1472: }
1473: }
1474: }
1475: }
1476:
1477: // ---------------------------------------------------------- The wait function
1478: var canceltim;
1479: function wait() {
1480: if ((menuloaded==1) || (tim==1)) {
1481: window.status='Done.';
1482: if (tim==0) {
1483: clearTimeout(canceltim);
1484: $configmenu
1485: window.location='$lowerurl';
1486: } else {
1487: window.location='/adm/remote?action=collapse&url=$esclowerurl';
1488: }
1489: } else {
1490: wheelswitch();
1491: setTimeout('wait();',200);
1492: }
1493: }
1494:
1495: function main() {
1496: canceltim=setTimeout('tim=1;',30000);
1497: window.status='-';
1498: var date=new Date();
1499: timestart=date.getTime();
1500: wait();
1501: }
1502:
1503: // ]]>
1504: </script>
1505: ENDREMOTESTARTUP
1506: }
1507:
1508: sub setflags() {
1509: return(<<ENDSETFLAGS);
1510: <script type="text/javascript">
1511: // <![CDATA[
1512: menuloaded=0;
1513: tim=0;
1514: // ]]>
1515: </script>
1516: ENDSETFLAGS
1517: }
1518:
1519: sub maincall() {
1.369.2.17 raeburn 1520: unless ($env{'environment.remote'} eq 'on') { return ''; }
1.369.2.1 raeburn 1521: return(<<ENDMAINCALL);
1522: <script type="text/javascript">
1523: // <![CDATA[
1524: main();
1525: // ]]>
1526: </script>
1527: ENDMAINCALL
1528: }
1529:
1530: sub load_remote_msg {
1531: my ($lowerurl)=@_;
1532:
1.369.2.17 raeburn 1533: unless ($env{'environment.remote'} eq 'on') { return ''; }
1.369.2.1 raeburn 1534:
1535: my $esclowerurl=&escape($lowerurl);
1536: my $link=&mt('[_1]Continue[_2] on in Inline Menu mode'
1537: ,'<a href="/adm/remote?action=collapse&url='.$esclowerurl.'">'
1538: ,'</a>');
1539: return(<<ENDREMOTEFORM);
1540: <p>
1541: <form name="wheel">
1542: <input name="spin" type="text" size="60" />
1543: </form>
1544: </p>
1545: <p>$link</p>
1546: ENDREMOTEFORM
1547: }
1548:
1549: sub get_menu_name {
1550: my $hostid = $Apache::lonnet::perlvar{'lonHostID'};
1551: $hostid =~ s/\W//g;
1552: return 'LCmenu'.$hostid;
1553: }
1554:
1555:
1556: sub reopenmenu {
1.369.2.17 raeburn 1557: unless ($env{'environment.remote'} eq 'on') { return ''; }
1.369.2.1 raeburn 1558: my $menuname = &get_menu_name();
1559: my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
1560: return('window.open('.$nothing.',"'.$menuname.'","",false);');
1561: }
1562:
1563:
1564: sub open {
1565: my $returnval='';
1.369.2.17 raeburn 1566: unless ($env{'environment.remote'} eq 'on') {
1.369.2.1 raeburn 1567: return
1568: '<script type="text/javascript">'."\n"
1569: .'// <![CDATA['."\n"
1570: .'self.name="loncapaclient";'."\n"
1571: .'// ]]>'."\n"
1572: .'</script>';
1573: }
1574: my $menuname = &get_menu_name();
1575:
1576: # unless (shift eq 'unix') {
1577: # resizing does not work on linux because of virtual desktop sizes
1578: # $returnval.=(<<ENDRESIZE);
1579: #if (window.screen) {
1580: # self.resizeTo(screen.availWidth-215,screen.availHeight-55);
1581: # self.moveTo(190,15);
1582: #}
1583: #ENDRESIZE
1584: # }
1585: $returnval=(<<ENDOPEN);
1586: // <![CDATA[
1587: window.status='Opening LON-CAPA Remote Control';
1588: var menu=window.open("/res/adm/pages/menu.html?inhibitmenu=yes","$menuname",
1589: "height=375,width=150,scrollbars=no,menubar=no,top=5,left=5,screenX=5,screenY=5");
1590: self.name='loncapaclient';
1591: // ]]>
1592: ENDOPEN
1593: return '<script type="text/javascript">'.$returnval.'</script>';
1594: }
1595:
1.369.2.26 raeburn 1596: sub get_editbutton {
1.369.2.75 raeburn 1597: my ($cfile,$home,$switchserver,$forceedit,$forceview,$forcereg,$hostname) = @_;
1.369.2.27 raeburn 1598: my $jscall;
1599: if (($forceview) && ($env{'form.todocs'})) {
1.369.2.66 raeburn 1600: my ($folderpath,$command,$navmap);
1.369.2.27 raeburn 1601: if ($env{'request.symb'}) {
1.369.2.66 raeburn 1602: $folderpath = &Apache::loncommon::symb_to_docspath($env{'request.symb'},\$navmap);
1.369.2.27 raeburn 1603: } elsif ($env{'form.folderpath'} =~ /^supplemental/) {
1604: $folderpath = $env{'form.folderpath'};
1605: $command = '&forcesupplement=1';
1606: }
1607: $folderpath = &escape(&HTML::Entities::encode(&escape($folderpath),'<>&"'));
1608: $jscall = "go('/adm/coursedocs?folderpath=$folderpath$command')";
1609: } else {
1.369.2.64 raeburn 1610: my $suppanchor;
1611: if ($env{'form.folderpath'}) {
1612: $suppanchor = $env{'form.anchor'};
1613: }
1.369.2.83.2. (raeburn 1614:): my $shownsymb;
1615:): if ($env{'request.symb'}) {
1616:): $shownsymb = &Apache::lonenc::check_encrypt($env{'request.symb'});
1617:): }
1.369.2.27 raeburn 1618: $jscall = &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,$switchserver,
1.369.2.83.2. (raeburn 1619:): $forceedit,$forcereg,$env{'request.symb'},$shownsymb,
1.369.2.27 raeburn 1620: &escape($env{'form.folderpath'}),
1.369.2.75 raeburn 1621: &escape($env{'form.title'}),$hostname,
1622: $env{'form.idx'},&escape($env{'form.suppurl'}),
1623: $env{'form.todocs'},$suppanchor);
1.369.2.27 raeburn 1624: }
1.369.2.26 raeburn 1625: if ($jscall) {
1626: my $icon = 'pcstr.png';
1627: my $label = 'Edit';
1628: if ($forceview) {
1629: $icon = 'tolastloc.png';
1630: $label = 'Exit Editing';
1631: }
1.369.2.37 raeburn 1632: my $infunc = 1;
1633: my $clearbutton;
1634: if ($env{'environment.remote'} eq 'on') {
1635: if ($cfile =~ m{^/priv/}) {
1636: undef($infunc);
1637: $label = 'edit';
1638: } else {
1639: $clearbutton = 1;
1640: }
1641: }
1642: my $editor = &switch('','',6,1,$icon,$label,'resource[_2]',
1643: $jscall,"Edit this resource",'','',$infunc);
1644: if ($infunc) {
1645: return 1;
1646: } elsif ($clearbutton) {
1647: return &clear(6,1);
1648: } else {
1649: return $editor;
1650: }
1.369.2.26 raeburn 1651: }
1652: return;
1653: }
1654:
1655: sub prepare_functions {
1.369.2.75 raeburn 1656: my ($resurl,$forcereg,$group,$bread_crumbs,$advtools,$docscrumbs,$hostname,$forbodytag) = @_;
1.369.2.26 raeburn 1657: unless ($env{'request.registered'}) {
1658: undef(@inlineremote);
1659: }
1660: my ($cdom,$cnum,%perms,$cfile,$switchserver,$home,$forceedit,
1661: $forceview);
1662:
1663: if ($env{'request.course.id'}) {
1664: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1665: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1666: $perms{'mdc'} = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
1667: }
1668:
1669: my $editbutton = '';
1.369.2.73 raeburn 1670: my $viewsrcbutton = '';
1.369.2.83 raeburn 1671: my $clientip = &Apache::lonnet::get_requestor_ip();
1.369.2.26 raeburn 1672: #
1.369.2.73 raeburn 1673: # Determine whether or not to display 'Edit' or 'View Source' icon/button
1.369.2.26 raeburn 1674: #
1675: if ($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) {
1.369.2.83 raeburn 1676: my $blocked = &Apache::loncommon::blocking_status('about',$clientip,$2,$1);
1.369.2.26 raeburn 1677: my $file=&Apache::lonnet::declutter($env{'request.filename'});
1.369.2.27 raeburn 1678: ($cfile,$home,$switchserver,$forceedit,$forceview) =
1679: &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
1680: &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
1.369.2.83 raeburn 1681: if (($cfile) && ($home ne '') && ($home ne 'no_host') && (!$blocked)) {
1.369.2.27 raeburn 1682: $editbutton = &get_editbutton($cfile,$home,$switchserver,
1.369.2.26 raeburn 1683: $forceedit,$forceview,$forcereg);
1684: }
1.369.2.27 raeburn 1685: } elsif ((!$env{'request.course.id'}) &&
1.369.2.26 raeburn 1686: ($env{'user.author'}) && ($env{'request.filename'}) &&
1687: ($env{'request.role'} !~/^(aa|ca|au)/)) {
1688: #
1689: # Currently do not have the role of author or co-author.
1690: # Do we have authoring privileges for the resource?
1691: #
1692: my $file=&Apache::lonnet::declutter($env{'request.filename'});
1693: ($cfile,$home,$switchserver,$forceedit,$forceview) =
1694: &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
1695: &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
1696: if (($cfile) && ($home ne '') && ($home ne 'no_host')) {
1697: $editbutton = &get_editbutton($cfile,$home,$switchserver,
1698: $forceedit,$forceview,$forcereg);
1699: }
1700: } elsif ($env{'request.course.id'}) {
1701: #
1702: # This applies in course context
1703: #
1.369.2.39 raeburn 1704: if (($perms{'mdc'}) &&
1.369.2.70 raeburn 1705: (($resurl =~ m{^/?public/$cdom/$cnum/syllabus}) ||
1.369.2.78 raeburn 1706: ($resurl =~ m{^/?uploaded/$cdom/$cnum/portfolio/syllabus/}) ||
1707: (($resurl =~ m{^/?uploaded/$cdom/$cnum/default_\d+\.sequence$}) && ($env{'form.navmap'})))) {
1.369.2.71 raeburn 1708: if ($resurl =~ m{^/}) {
1709: $cfile = $resurl;
1710: } else {
1711: $cfile = "/$resurl";
1712: }
1.369.2.39 raeburn 1713: $home = &Apache::lonnet::homeserver($cnum,$cdom);
1714: if ($env{'form.forceedit'}) {
1715: $forceview = 1;
1.369.2.26 raeburn 1716: } else {
1.369.2.39 raeburn 1717: $forceedit = 1;
1.369.2.26 raeburn 1718: }
1.369.2.78 raeburn 1719: if ($cfile =~ m{^/uploaded/$cdom/$cnum/default_\d+\.sequence$}) {
1720: my $text = 'Edit Folder';
1721: &switch('','',7,4,'docs-22x22.png','Edit Folder','parms[_2]',
1722: "gocmd('/adm/coursedocs','direct')",
1723: 'Folder/Page Content');
1724: $editbutton = 1;
1725: } else {
1726: $editbutton = &get_editbutton($cfile,$home,$switchserver,
1727: $forceedit,$forceview,$forcereg,
1728: $hostname);
1729: }
1.369.2.27 raeburn 1730: } elsif (($resurl eq '/adm/extresedit') &&
1731: (($env{'form.symb'}) || ($env{'form.folderpath'}))) {
1732: ($cfile,$home,$switchserver,$forceedit,$forceview) =
1733: &Apache::lonnet::can_edit_resource($resurl,$cnum,$cdom,$resurl,
1734: $env{'form.symb'});
1735: if ($cfile ne '') {
1736: $editbutton = &get_editbutton($cfile,$home,$switchserver,
1737: $forceedit,$forceview,$forcereg,
1738: $env{'form.title'},$env{'form.suppurl'});
1739: }
1.369.2.32 raeburn 1740: } elsif (($resurl =~ m{^/?adm/viewclasslist$}) &&
1741: (&Apache::lonnet::allowed('opa',$env{'request.course.id'}))) {
1742: ($cfile,$home,$switchserver,$forceedit,$forceview) =
1743: &Apache::lonnet::can_edit_resource($resurl,$cnum,$cdom,$resurl,
1744: $env{'form.symb'});
1745: $editbutton = &get_editbutton($cfile,$home,$switchserver,
1746: $forceedit,$forceview,$forcereg);
1.369.2.31 raeburn 1747: } elsif (($resurl !~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) &&
1748: ($resurl ne '/cgi-bin/printout.pl')) {
1.369.2.26 raeburn 1749: if ($env{'request.filename'}) {
1750: my $file=&Apache::lonnet::declutter($env{'request.filename'});
1751: ($cfile,$home,$switchserver,$forceedit,$forceview) =
1752: &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
1753: &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
1754: if ($cfile ne '') {
1755: $editbutton = &get_editbutton($cfile,$home,$switchserver,
1756: $forceedit,$forceview,$forcereg);
1757: }
1.369.2.73 raeburn 1758: if ((($cfile eq '') || (!$editbutton)) &&
1759: ($resurl =~ /$LONCAPA::assess_re/)) {
1760: my $showurl = &Apache::lonnet::clutter($resurl);
1.369.2.80 raeburn 1761: my $crs_sec = $env{'request.course.id'} . (($env{'request.course.sec'} ne '')
1762: ? "/$env{'request.course.sec'}"
1763: : '');
1.369.2.73 raeburn 1764: if ((&Apache::lonnet::allowed('cre','/')) &&
1765: (&Apache::lonnet::metadata($resurl,'sourceavail') eq 'open')) {
1766: $viewsrcbutton = 1;
1.369.2.80 raeburn 1767: } elsif (&Apache::lonnet::allowed('vxc',$crs_sec)) {
1.369.2.73 raeburn 1768: if ($showurl =~ m{^\Q/res/$cdom/\E($match_username)/}) {
1769: my $auname = $1;
1770: if (($env{'request.course.adhocsrcaccess'} ne '') &&
1771: (grep(/^\Q$auname\E$/,split(/,/,$env{'request.course.adhocsrcaccess'})))) {
1772: $viewsrcbutton = 1;
1773: } elsif ((&Apache::lonnet::metadata($resurl,'sourceavail') eq 'open') &&
1.369.2.80 raeburn 1774: (&Apache::lonnet::allowed('bre',$crs_sec))) {
1.369.2.73 raeburn 1775: $viewsrcbutton = 1;
1776: }
1777: }
1778: }
1779: if ($viewsrcbutton) {
1780: &switch('','',6,1,'pcstr.png','View Source','resource[_2]','open_source()',
1781: 'View source code');
1782: }
1783: }
1.369.2.26 raeburn 1784: }
1785: }
1786: }
1787: # End determination of 'Edit' icon/button display
1788:
1789: if ($env{'request.course.id'}) {
1.369.2.27 raeburn 1790: # This applies to about me page for users in a course
1.369.2.29 raeburn 1791: if ($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) {
1.369.2.26 raeburn 1792: my ($sdom,$sname) = ($1,$2);
1793: unless (&Apache::lonnet::is_course($sdom,$sname)) {
1.369.2.83 raeburn 1794: my $blocked = &Apache::loncommon::blocking_status('about',$clientip,$sname,$sdom);
1795: unless ($blocked) {
1796: &switch('','',6,4,'mail-message-new-22x22.png','Message to user',
1797: '',
1798: "go('/adm/email?compose=individual&recname=$sname&recdom=$sdom')",
1799: 'Send message to specific user','','',1);
1800: }
1.369.2.26 raeburn 1801: }
1.369.2.27 raeburn 1802: my $hideprivileged = 1;
1803: if (&Apache::lonnet::in_course($sdom,$sname,$cdom,$cnum,undef,
1804: $hideprivileged)) {
1.369.2.26 raeburn 1805: foreach my $priv ('vsa','vgr','srm') {
1806: $perms{$priv} = &Apache::lonnet::allowed($priv,$env{'request.course.id'});
1807: if (!$perms{$priv} && $env{'request.course.sec'} ne '') {
1808: $perms{$priv} =
1809: &Apache::lonnet::allowed($priv,"$env{'request.course.id'}/$env{'request.course.sec'}");
1810: }
1811: }
1812: if ($perms{'vsa'}) {
1813: &switch('','',6,5,'trck-22x22.png','Activity',
1814: '',
1815: "go('/adm/trackstudent?selected_student=$sname:$sdom')",
1.369.2.37 raeburn 1816: 'View recent activity by this person','','',1);
1.369.2.26 raeburn 1817: }
1818: if ($perms{'vgr'}) {
1819: &switch('','',6,6,'rsrv-22x22.png','Reservations',
1820: '',
1.369.2.42 raeburn 1821: "go('/adm/slotrequest?command=showresv&origin=aboutme&uname=$sname&udom=$sdom')",
1.369.2.37 raeburn 1822: 'Slot reservation history','','',1);
1.369.2.26 raeburn 1823: }
1824: if ($perms{'srm'}) {
1825: &switch('','',6,7,'contact-new-22x22.png','Records',
1826: '',
1.369.2.42 raeburn 1827: "go('/adm/email?recordftf=retrieve&recname=$sname&recdom=$sdom')",
1.369.2.37 raeburn 1828: 'Add records','','',1);
1.369.2.26 raeburn 1829: }
1830: }
1.369.2.27 raeburn 1831: }
1832: if (($env{'form.folderpath'} =~ /^supplemental/) &&
1833: (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) &&
1834: (($resurl =~ m{^/adm/wrapper/ext/}) ||
1.369.2.83.2. (raeburn 1835:): ($resurl =~ m{^/adm/$cdom/$cnum/\d+/ext\.tool$}) ||
1.369.2.27 raeburn 1836: ($resurl =~ m{^/uploaded/$cdom/$cnum/supplemental/}) ||
1837: ($resurl eq '/adm/supplemental') ||
1838: ($resurl =~ m{^/public/$cdom/$cnum/syllabus$}) ||
1839: ($resurl =~ m{^/adm/$match_domain/$match_username/aboutme$}))) {
1840: my @folders=split('&',$env{'form.folderpath'});
1841: if ((@folders > 2) || ($resurl ne '/adm/supplemental')) {
1.369.2.64 raeburn 1842: my $suppanchor;
1843: if ($resurl =~ m{^/adm/wrapper/ext/}) {
1844: $suppanchor = $env{'form.anchor'};
1845: }
1.369.2.27 raeburn 1846: my $esc_path=&escape(&HTML::Entities::encode(&escape($env{'form.folderpath'}),'<>&"'));
1.369.2.75 raeburn 1847: my $link = '/adm/coursedocs?command=direct&forcesupplement=1&supppath='.
1848: "$esc_path&anchor=$suppanchor";
1849: if ($env{'request.use_absolute'} ne '') {
1850: $link = $env{'request.use_absolute'}.$link;
1851: }
1.369.2.27 raeburn 1852: &switch('','',7,4,'docs-22x22.png','Edit Folder','parms[_2]',
1.369.2.75 raeburn 1853: "location.href='$link'",'Folder/Page Content');
1.369.2.27 raeburn 1854: }
1.369.2.26 raeburn 1855: }
1856: }
1857:
1858: # End checking for items for about me page for users in a course
1.369.2.27 raeburn 1859: if ($docscrumbs) {
1860: &Apache::lonhtmlcommon::clear_breadcrumb_tools();
1861: &advtools_crumbs(@inlineremote);
1862: return $editbutton;
1.369.2.37 raeburn 1863: } elsif (($env{'request.registered'}) && (!ref($forbodytag))) {
1.369.2.79 raeburn 1864: return $editbutton || $viewsrcbutton;
1.369.2.26 raeburn 1865: } else {
1866: if (ref($bread_crumbs) eq 'ARRAY') {
1867: if (@inlineremote > 0) {
1868: if (ref($advtools) eq 'ARRAY') {
1869: @{$advtools} = @inlineremote;
1870: }
1871: }
1872: return;
1873: } elsif (@inlineremote > 0) {
1874: &Apache::lonhtmlcommon::clear_breadcrumb_tools();
1875: &advtools_crumbs(@inlineremote);
1.369.2.37 raeburn 1876: if (ref($forbodytag)) {
1877: $$forbodytag =
1878: &Apache::lonhtmlcommon::scripttag('', 'start')
1879: .&Apache::lonhtmlcommon::breadcrumbs(undef,undef,0)
1880: .&Apache::lonhtmlcommon::scripttag('', 'end');
1881: }
1882: return;
1.369.2.26 raeburn 1883: }
1884: }
1885: }
1886:
1887: sub advtools_crumbs {
1888: my @funcs = @_;
1889: if ($env{'request.noversionuri'} =~ m{^/adm/$match_domain/$match_username/aboutme$}) {
1890: &Apache::lonhtmlcommon::add_breadcrumb_tool(
1891: 'advtools', @funcs[61,64,65,66,67,74]);
1892: } elsif ($env{'request.noversionuri'} !~ m{^/adm/(navmaps|viewclasslist)(\?|$)}) {
1893: &Apache::lonhtmlcommon::add_breadcrumb_tool(
1894: 'advtools', @funcs[61,71,72,73,74,92]);
1.369.2.27 raeburn 1895: } elsif ($env{'request.noversionuri'} eq '/adm/viewclasslist') {
1896: &Apache::lonhtmlcommon::add_breadcrumb_tool(
1.369.2.33 raeburn 1897: 'advtools', $funcs[61]);
1.369.2.26 raeburn 1898: }
1899: }
1.369.2.1 raeburn 1900:
1.2 www 1901: # ================================================================== Raw Config
1902:
1.3 www 1903: sub clear {
1904: my ($row,$col)=@_;
1.369.2.17 raeburn 1905: if ($env{'environment.remote'} eq 'on') {
1906: if (($row<1) || ($row>13)) { return ''; }
1907: return "\n".qq(window.status+='.';swmenu.clearbut($row,$col););
1908: } else {
1909: $inlineremote[10*$row+$col]='';
1910: return '';
1911: }
1.3 www 1912: }
1913:
1.40 www 1914: # ============================================ Switch a button or create a link
1.25 matthew 1915: # Switch acts on the javascript that is executed when a button is clicked.
1916: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
1.40 www 1917:
1.2 www 1918: sub switch {
1.369.2.37 raeburn 1919: my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat,$nobreak,$infunc)=@_;
1.2 www 1920: $act=~s/\$uname/$uname/g;
1921: $act=~s/\$udom/$udom/g;
1.88 www 1922: $top=&mt($top);
1923: $bot=&mt($bot);
1924: $desc=&mt($desc);
1.209 www 1925: my $idx=10*$row+$col;
1926: $category_members{$cat}.=':'.$idx;
1927:
1.369.2.37 raeburn 1928: if (($env{'environment.remote'} eq 'on') && (!$infunc)) {
1.369.2.17 raeburn 1929: if (($row<1) || ($row>13)) { return ''; }
1.369.2.21 raeburn 1930: if ($env{'request.state'} eq 'construct') {
1931: my $text = $top.' '.$bot;
1932: $text=~s/\s*\-\s*//gs;
1933: my $pic = '<img alt="'.$text.'" src="'.
1934: &Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$img).
1935: '" align="'.($nobreak==3?'right':'left').'" class="LC_icon" />';
1936: $inlineremote[$idx] =
1937: '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.
1938: $pic.'<span class="LC_menubuttons_inline_text">'.$top.' </span></a>';
1939: }
1.369.2.17 raeburn 1940: # Remote
1941: $img=~s/\.png$/\.gif/;
1942: return "\n".
1943: qq(window.status+='.';swmenu.switchbutton($row,$col,"$img","$top","$bot","$act","$desc"););
1944: }
1945:
1.320 droeschl 1946: # Inline Menu
1.317 droeschl 1947: if ($nobreak==2) { return ''; }
1948: my $text=$top.' '.$bot;
1949: $text=~s/\s*\-\s*//gs;
1.105 www 1950:
1.317 droeschl 1951: my $pic=
1.225 albertel 1952: '<img alt="'.$text.'" src="'.
1953: &Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$img).
1.303 droeschl 1954: '" align="'.($nobreak==3?'right':'left').'" class="LC_icon" />';
1.317 droeschl 1955: if ($env{'browser.interface'} eq 'faketextual') {
1.274 www 1956: # Main Menu
1.103 www 1957: if ($nobreak==3) {
1.209 www 1958: $inlineremote[$idx]="\n".
1.177 albertel 1959: '<td class="LC_menubuttons_text" align="right">'.$text.
1.247 harmsja 1960: '</td><td align="left">'.
1.103 www 1961: '<a href="javascript:'.$act.';">'.$pic.'</a></td></tr>';
1962: } elsif ($nobreak) {
1.209 www 1963: $inlineremote[$idx]="\n<tr>".
1.247 harmsja 1964: '<td align="left">'.
1.177 albertel 1965: '<a href="javascript:'.$act.';">'.$pic.'</a></td>
1.215 www 1966: <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 1967: } else {
1.209 www 1968: $inlineremote[$idx]="\n<tr>".
1.247 harmsja 1969: '<td align="left">'.
1.103 www 1970: '<a href="javascript:'.$act.';">'.$pic.
1.177 albertel 1971: '</a></td><td class="LC_menubuttons_text" colspan="3">'.
1.215 www 1972: '<a class="LC_menubuttons_link" href="javascript:'.$act.';"><span class="LC_menubuttons_inline_text">'.$desc.'</span></a></td></tr>';
1.103 www 1973: }
1.317 droeschl 1974: } else {
1.103 www 1975: # Inline Menu
1.369.2.10 raeburn 1976: my @tools = (93,91,81,82,83);
1977: unless ($env{'request.state'} eq 'construct') {
1978: push(@tools,63);
1979: }
1980: if (($env{'environment.icons'} eq 'iconsonly') &&
1981: (grep(/^$idx$/,@tools))) {
1982: $inlineremote[$idx] =
1983: '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.'</a>';
1984: } else {
1985: $inlineremote[$idx] =
1.317 droeschl 1986: '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.
1.344 www 1987: '<span class="LC_menubuttons_inline_text">'.$top.' </span></a>';
1.369.2.10 raeburn 1988: }
1.317 droeschl 1989: }
1.56 www 1990: return '';
1.2 www 1991: }
1992:
1993: sub secondlevel {
1994: my $output='';
1995: my
1.209 www 1996: ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat)=@_;
1.2 www 1997: if ($prt eq 'any') {
1.209 www 1998: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.2 www 1999: } elsif ($prt=~/^r(\w+)/) {
2000: if ($rol eq $1) {
1.209 www 2001: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.2 www 2002: }
2003: }
2004: return $output;
2005: }
2006:
1.369.2.17 raeburn 2007: sub openmenu {
2008: my $menuname = &get_menu_name();
2009: unless ($env{'environment.remote'} eq 'on') { return ''; }
2010: my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
2011: return "window.open(".$nothing.",'".$menuname."');";
2012: }
2013:
1.56 www 2014: sub inlinemenu {
1.210 albertel 2015: undef(@inlineremote);
2016: undef(%category_members);
1.275 www 2017: # calling rawconfig with "1" will evaluate mydesk.tab, even if there is no active remote control
1.56 www 2018: &rawconfig(1);
1.309 bisitz 2019: my $output='<table><tr>';
1.209 www 2020: for (my $col=1; $col<=2; $col++) {
1.241 riegler 2021: $output.='<td class="LC_mainmenu_col_fieldset">';
1.209 www 2022: for (my $row=1; $row<=8; $row++) {
2023: foreach my $cat (keys(%category_members)) {
2024: if ($category_positions{$cat} ne "$col,$row") { next; }
1.247 harmsja 2025: #$output.='<table><tr><td colspan="4" class="LC_menubuttons_category">'.&mt($category_names{$cat}).'</td></tr>';
1.309 bisitz 2026: $output.='<div class="LC_Box LC_400Box">';
2027: $output.='<h3 class="LC_hcell">'.&mt($category_names{$cat}).'</h3>';
1.247 harmsja 2028: $output.='<table>';
1.240 riegler 2029: my %active=();
2030: foreach my $menu_item (split(/\:/,$category_members{$cat})) {
2031: if ($inlineremote[$menu_item]) {
2032: $active{$menu_item}=1;
2033: }
2034: }
2035: foreach my $item (sort(keys(%active))) {
2036: $output.=$inlineremote[$item];
2037: }
2038: $output.='</table>';
1.245 harmsja 2039: $output.='</div>';
1.240 riegler 2040: }
2041: }
2042: $output.="</td>";
2043: }
2044: $output.="</tr></table>";
2045: return $output;
2046: }
2047:
1.2 www 2048: sub rawconfig {
1.274 www 2049: #
2050: # This evaluates mydesk.tab
2051: # Need to add more positions and more privileges to deal with all
2052: # menu items.
2053: #
1.34 www 2054: my $textualoverride=shift;
2055: my $output='';
1.369.2.17 raeburn 2056: if ($env{'environment.remote'} eq 'on') {
2057: $output.=
2058: "window.status='Opening Remote Control';var swmenu=".&openmenu().
2059: "\nwindow.status='Configuring Remote Control ';";
2060: } else {
2061: unless ($textualoverride) { return ''; }
2062: }
1.152 albertel 2063: my $uname=$env{'user.name'};
2064: my $udom=$env{'user.domain'};
2065: my $adv=$env{'user.adv'};
1.266 raeburn 2066: my $show_course=&Apache::loncommon::show_course();
1.152 albertel 2067: my $author=$env{'user.author'};
1.5 www 2068: my $crs='';
1.295 raeburn 2069: my $crstype='';
1.152 albertel 2070: if ($env{'request.course.id'}) {
2071: $crs='/'.$env{'request.course.id'};
2072: if ($env{'request.course.sec'}) {
2073: $crs.='_'.$env{'request.course.sec'};
1.7 www 2074: }
1.8 www 2075: $crs=~s/\_/\//g;
1.295 raeburn 2076: $crstype = &Apache::loncommon::course_type();
1.5 www 2077: }
1.152 albertel 2078: my $pub=($env{'request.state'} eq 'published');
2079: my $con=($env{'request.state'} eq 'construct');
2080: my $rol=$env{'request.role'};
1.369.2.51 raeburn 2081: my $requested_domain;
2082: if ($rol) {
2083: $requested_domain = $env{'request.role.domain'};
2084: }
1.184 raeburn 2085: foreach my $line (@desklines) {
1.209 www 2086: my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc,$cat)=split(/\:/,$line);
1.3 www 2087: $prt=~s/\$uname/$uname/g;
2088: $prt=~s/\$udom/$udom/g;
1.295 raeburn 2089: if ($prt =~ /\$crs/) {
2090: next unless ($env{'request.course.id'});
2091: next if ($crstype eq 'Community');
2092: $prt=~s/\$crs/$crs/g;
2093: } elsif ($prt =~ /\$cmty/) {
2094: next unless ($env{'request.course.id'});
2095: next if ($crstype ne 'Community');
2096: $prt=~s/\$cmty/$crs/g;
2097: }
1.369.2.51 raeburn 2098: if ($prt =~ m/\$requested_domain/) {
2099: if ((!$requested_domain) && ($pro eq 'pbre') && ($env{'user.adv'})) {
2100: $prt=~s/\$requested_domain/$env{'user.domain'}/g;
2101: } else {
2102: $prt=~s/\$requested_domain/$requested_domain/g;
2103: }
2104: }
1.211 www 2105: if ($category_names{$cat}!~/\w/) { $cat='oth'; }
1.3 www 2106: if ($pro eq 'clear') {
1.4 www 2107: $output.=&clear($row,$col);
1.3 www 2108: } elsif ($pro eq 'any') {
1.2 www 2109: $output.=&secondlevel(
1.209 www 2110: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2 www 2111: } elsif ($pro eq 'smp') {
2112: unless ($adv) {
2113: $output.=&secondlevel(
1.209 www 2114: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2 www 2115: }
2116: } elsif ($pro eq 'adv') {
2117: if ($adv) {
2118: $output.=&secondlevel(
1.209 www 2119: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2 www 2120: }
1.231 albertel 2121: } elsif ($pro eq 'shc') {
2122: if ($show_course) {
2123: $output.=&secondlevel(
2124: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
2125: }
2126: } elsif ($pro eq 'nsc') {
2127: if (!$show_course) {
2128: $output.=&secondlevel(
2129: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
2130: }
1.81 matthew 2131: } elsif (($pro=~/^p(\w+)/) && ($prt)) {
1.295 raeburn 2132: my $priv = $1;
2133: if ($priv =~ /^mdc(Course|Community)/) {
2134: if ($crstype eq $1) {
2135: $priv = 'mdc';
2136: } else {
2137: next;
2138: }
2139: }
1.369.2.51 raeburn 2140: if ((($priv eq 'bre') && (&Apache::lonnet::allowed($priv,$prt) eq 'F')) ||
2141: (($priv ne 'bre') && (&Apache::lonnet::allowed($priv,$prt)))) {
2142: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.4 www 2143: }
1.295 raeburn 2144: } elsif ($pro eq 'course') {
2145: if (($env{'request.course.fn'}) && ($crstype ne 'Community')) {
1.209 www 2146: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.81 matthew 2147: }
1.295 raeburn 2148: } elsif ($pro eq 'community') {
2149: if (($env{'request.course.fn'}) && ($crstype eq 'Community')) {
2150: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
2151: }
1.124 matthew 2152: } elsif ($pro =~ /^courseenv_(.*)$/) {
2153: my $key = $1;
1.307 raeburn 2154: if ($crstype ne 'Community') {
2155: my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
2156: if ($key eq 'canuse_pdfforms') {
2157: if ($env{'request.course.id'} && $coursepref eq '') {
2158: my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
2159: $coursepref = $domdefs{'canuse_pdfforms'};
2160: }
2161: }
2162: if ($coursepref) {
2163: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
2164: }
1.295 raeburn 2165: }
2166: } elsif ($pro =~ /^communityenv_(.*)$/) {
2167: my $key = $1;
1.307 raeburn 2168: if ($crstype eq 'Community') {
2169: my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
2170: if ($key eq 'canuse_pdfforms') {
2171: if ($env{'request.course.id'} && $coursepref eq '') {
2172: my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
2173: $coursepref = $domdefs{'canuse_pdfforms'};
2174: }
2175: }
2176: if ($coursepref) {
2177: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
2178: }
1.124 matthew 2179: }
1.81 matthew 2180: } elsif ($pro =~ /^course_(.*)$/) {
2181: # Check for permissions inside of a course
1.295 raeburn 2182: if (($env{'request.course.id'}) && ($crstype ne 'Community') &&
1.152 albertel 2183: (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
2184: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
1.81 matthew 2185: )) {
1.209 www 2186: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.26 www 2187: }
1.295 raeburn 2188: } elsif ($pro =~ /^community_(.*)$/) {
2189: # Check for permissions inside of a community
2190: if (($env{'request.course.id'}) && ($crstype eq 'Community') &&
2191: (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
2192: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
2193: )) {
2194: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
2195: }
1.4 www 2196: } elsif ($pro eq 'author') {
2197: if ($author) {
1.152 albertel 2198: if ((($prt eq 'rca') && ($env{'request.role'}=~/^ca/)) ||
1.234 raeburn 2199: (($prt eq 'raa') && ($env{'request.role'}=~/^aa/)) ||
1.152 albertel 2200: (($prt eq 'rau') && ($env{'request.role'}=~/^au/))) {
1.19 matthew 2201: # Check that we are on the correct machine
1.29 matthew 2202: my $cadom=$requested_domain;
1.152 albertel 2203: my $caname=$env{'user.name'};
1.234 raeburn 2204: if (($prt eq 'rca') || ($prt eq 'raa')) {
1.29 matthew 2205: ($cadom,$caname)=
1.206 albertel 2206: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.29 matthew 2207: }
2208: $act =~ s/\$caname/$caname/g;
1.353 www 2209: $act =~ s/\$cadom/$cadom/g;
1.19 matthew 2210: my $home = &Apache::lonnet::homeserver($caname,$cadom);
1.109 albertel 2211: my $allowed=0;
2212: my @ids=&Apache::lonnet::current_machine_ids();
2213: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
2214: if ($allowed) {
1.209 www 2215: $output.=&switch($caname,$cadom,
2216: $row,$col,$img,$top,$bot,$act,$desc,$cat);
1.19 matthew 2217: }
1.6 www 2218: }
1.2 www 2219: }
1.248 raeburn 2220: } elsif ($pro eq 'tools') {
2221: my @tools = ('aboutme','blog','portfolio');
2222: if (grep(/^\Q$prt\E$/,@tools)) {
1.249 raeburn 2223: if (!&Apache::lonnet::usertools_access($env{'user.name'},
1.251 raeburn 2224: $env{'user.domain'},
2225: $prt,undef,'tools')) {
2226: $output.=&clear($row,$col);
2227: next;
2228: }
1.278 raeburn 2229: } elsif (($prt eq 'reqcrsnsc') || ($prt eq 'reqcrsshc')) {
2230: if (($prt eq 'reqcrsnsc') && ($show_course)) {
2231: next;
2232: }
2233: if (($prt eq 'reqcrsshc') && (!$show_course)) {
2234: next;
2235: }
1.279 raeburn 2236: my $showreqcrs = &check_for_rcrs();
1.251 raeburn 2237: if (!$showreqcrs) {
1.248 raeburn 2238: $output.=&clear($row,$col);
2239: next;
2240: }
2241: }
2242: $prt='any';
2243: $output.=&secondlevel(
2244: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2 www 2245: }
1.13 harris41 2246: }
1.369.2.17 raeburn 2247: if ($env{'environment.remote'} eq 'on') {
2248: $output.="\nwindow.status='Synchronizing Time';swmenu.syncclock(1000*".time.");\nwindow.status='Remote Control Configured.';";
2249: if (&Apache::lonmsg::newmail()) {
2250: $output.='swmenu.setstatus("you have","messages");';
2251: }
2252: }
1.2 www 2253: return $output;
2254: }
2255:
1.279 raeburn 2256: sub check_for_rcrs {
2257: my $showreqcrs = 0;
1.369.2.49 raeburn 2258: my @reqtypes = ('official','unofficial','community','textbook');
1.280 raeburn 2259: foreach my $type (@reqtypes) {
1.279 raeburn 2260: if (&Apache::lonnet::usertools_access($env{'user.name'},
2261: $env{'user.domain'},
2262: $type,undef,'requestcourses')) {
2263: $showreqcrs = 1;
2264: last;
2265: }
2266: }
1.280 raeburn 2267: if (!$showreqcrs) {
2268: foreach my $type (@reqtypes) {
2269: if ($env{'environment.reqcrsotherdom.'.$type} ne '') {
2270: $showreqcrs = 1;
2271: last;
2272: }
2273: }
2274: }
1.279 raeburn 2275: return $showreqcrs;
2276: }
2277:
1.369.2.1 raeburn 2278: # ======================================================================= Close
2279:
2280: sub close {
1.369.2.17 raeburn 2281: unless ($env{'environment.remote'} eq 'on') { return ''; }
1.369.2.1 raeburn 2282: my $menuname = &get_menu_name();
2283: return(<<ENDCLOSE);
2284: <script type="text/javascript">
2285: // <![CDATA[
2286: window.status='Accessing Remote Control';
2287: menu=window.open("/adm/rat/empty.html","$menuname",
2288: "height=350,width=150,scrollbars=no,menubar=no");
2289: window.status='Disabling Remote Control';
2290: menu.active=0;
2291: menu.autologout=0;
2292: window.status='Closing Remote Control';
2293: menu.close();
2294: window.status='Done.';
2295: // ]]>
2296: </script>
2297: ENDCLOSE
2298: }
2299:
1.306 raeburn 2300: sub dc_popup_js {
2301: my %lt = &Apache::lonlocal::texthash(
2302: more => '(More ...)',
2303: less => '(Less ...)',
2304: );
2305: return <<"END";
2306:
2307: function showCourseID() {
2308: document.getElementById('dccid').style.display='block';
2309: document.getElementById('dccid').style.textAlign='left';
1.307 raeburn 2310: document.getElementById('dccid').style.textFace='normal';
1.369 raeburn 2311: document.getElementById('dccidtext').innerHTML ='<a href="javascript:hideCourseID();" class="LC_menubuttons_link">$lt{'less'}</a>';
1.306 raeburn 2312: return;
2313: }
2314:
2315: function hideCourseID() {
2316: document.getElementById('dccid').style.display='none';
1.369 raeburn 2317: document.getElementById('dccidtext').innerHTML ='<a href="javascript:showCourseID()" class="LC_menubuttons_link">$lt{'more'}</a>';
1.306 raeburn 2318: return;
2319: }
2320:
2321: END
2322:
2323: }
2324:
1.369.2.10 raeburn 2325: sub countdown_toggle_js {
2326: return <<"END";
2327:
2328: function toggleCountdown() {
2329: var countdownid = document.getElementById('duedatecountdown');
2330: var currstyle = countdownid.style.display;
2331: if (currstyle == 'inline') {
2332: countdownid.style.display = 'none';
2333: document.getElementById('ddcountcollapse').innerHTML='';
2334: document.getElementById('ddcountexpand').innerHTML='◄ ';
2335: } else {
2336: countdownid.style.display = 'inline';
2337: document.getElementById('ddcountcollapse').innerHTML='► ';
2338: document.getElementById('ddcountexpand').innerHTML='';
2339: }
2340: return;
2341: }
2342:
2343: END
2344: }
2345:
1.369.2.83.2. (raeburn 2346:): # This creates a "done button" for timed events. The confirmation box is a jQuery
2347:): # dialog widget. If the interval parameter requires a proctor key for the timed
2348:): # event to be marked done, there will also be a textbox where that can be entered.
2349:): # Clicking OK will set the value of LC_interval_done to 'true', and, if needed will
2350:): # set the value of LC_interval_done_proctorpass to the text entered in that box,
2351:): # and submit the corresponding form.
2352:): #
2353:): # The &zero_time() routine in lonhomework.pm is called when a page is rendered if
2354:): # LC_interval_done is true.
2355:): #
2356:): sub done_button_js {
2357:): my ($type,$width,$height,$proctor,$donebuttontext) = @_;
2358:): return unless (($type eq 'map') || ($type eq 'resource'));
2359:): my %lt = &Apache::lonlocal::texthash(
2360:): title => 'WARNING!',
2361:): preamble => 'You are trying to end this timed event early.',
2362:): map => 'Confirming that you are done will cause the time to expire and prevent you from changing any answers in the current folder.',
2363:): resource => 'Confirming that you are done will cause the time to expire for this question, and prevent you from changing your answer(s).',
2364:): okdone => 'Click "OK" if you are completely finished.',
2365:): cancel => 'Click "Cancel" to continue working.',
2366:): proctor => 'Ask a proctor to enter the key, then click "OK" if you are completely finished.',
2367:): ok => 'OK',
2368:): exit => 'Cancel',
2369:): key => 'Key:',
2370:): nokey => 'A proctor key is required',
2371:): );
2372:): my $shownsymb = &HTML::Entities::encode(&Apache::lonenc::check_encrypt($env{'request.symb'}));
2373:): my $navmap = Apache::lonnavmaps::navmap->new();
2374:): my ($missing,$tried) = (0,0);
2375:): if (ref($navmap)) {
2376:): my @resources=();
2377:): if ($type eq 'map') {
2378:): my ($mapurl,$rid,$resurl)=&Apache::lonnet::decode_symb($env{'request.symb'});
2379:): if ($env{'request.symb'} =~ /\.page$/) {
2380:): @resources=$navmap->retrieveResources($resurl,sub { $_[0]->is_problem() });
2381:): } else {
2382:): @resources=$navmap->retrieveResources($mapurl,sub { $_[0]->is_problem() });
2383:): }
2384:): } else {
2385:): my $res = $navmap->getBySymb($env{'request.symb'});
2386:): if (ref($res)) {
2387:): if ($res->is_problem()) {
2388:): push(@resources,$res);
2389:): }
2390:): }
2391:): }
2392:): foreach my $res (@resources) {
2393:): if (ref($res->parts()) eq 'ARRAY') {
2394:): foreach my $part (@{$res->parts()}) {
2395:): if (!$res->tries($part)) {
2396:): $missing++;
2397:): } else {
2398:): $tried++;
2399:): }
2400:): }
2401:): }
2402:): }
2403:): }
2404:): if ($missing) {
2405:): $lt{'miss'} .= '<p class="LC_error">';
2406:): if ($type eq 'map') {
2407:): $lt{'miss'} .= &mt('Submissions are missing for [quant,_1,question part,question parts] in this folder.',$missing);
2408:): } else {
2409:): $lt{'miss'} .= &mt('Submissions are missing for [quant,_1,part] in this question.',$missing);
2410:): }
2411:): if ($missing > 1) {
2412:): $lt{'miss'} .= ' '.&mt('If you confirm you are done you will be unable to submit answers for them.').'</span>';
2413:): } else {
2414:): $lt{'miss'} .= ' '.&mt('If you confirm you are done you will be unable to submit an answer for it.').'</p>';
2415:): }
2416:): }
2417:): $donebuttontext = &HTML::Entities::encode($donebuttontext,'<>&"');
2418:): if ($proctor) {
2419:): if ($height !~ /^\d+$/) {
2420:): $height = 400;
2421:): if ($missing) {
2422:): $height += 60;
2423:): }
2424:): }
2425:): if ($width !~ /^\d+$/) {
2426:): $width = 400;
2427:): if ($missing) {
2428:): $width += 60;
2429:): }
2430:): }
2431:): return <<END;
2432:): <form method="post" name="LCdoneButton" action="">
2433:): <input type="hidden" name="LC_interval_done" value="" />
2434:): <input type="hidden" name="LC_interval_done_proctorpass" value="" />
2435:): <input type="hidden" name="symb" value="$shownsymb" />
2436:): <button id="LC_done-confirm-opener" type="button">$donebuttontext</button>
2437:): </form>
2438:):
2439:): <div id="LC_done-confirm" title="$lt{'title'}">
2440:): <p>$lt{'preamble'} $lt{$type}</p>
2441:): $lt{'miss'}
2442:): <p>$lt{'proctor'}</p>
2443:): <form name="LCdoneButtonProctor" action="">
2444:): <label>$lt{'key'}<input type="password" name="LC_interval_done_proctorkey" value="" /></label>
2445:): <input type="submit" tabindex="-1" style="position:absolute; top:-1000px" />
2446:): </form>
2447:): <p>$lt{'cancel'}</p>
2448:): </div>
2449:):
2450:): <script type="text/javascript">
2451:): // <![CDATA[
2452:): \$( "#LC_done-confirm" ).dialog({ autoOpen: false });
2453:): \$( "#LC_done-confirm-opener" ).on("click", function() {
2454:): \$( "#LC_done-confirm" ).dialog("open");
2455:): \$( "#LC_done-confirm" ).dialog({
2456:): height: $height,
2457:): width: $width,
2458:): modal: true,
2459:): resizable: false,
2460:): buttons: [
2461:): {
2462:): text: "$lt{'ok'}",
2463:): click: function() {
2464:): var proctorkey = \$( '[name="LC_interval_done_proctorkey"]' )[0].value;
2465:): if ((proctorkey == '') || (proctorkey == null)) {
2466:): alert("$lt{'nokey'}");
2467:): } else {
2468:): \$( '[name="LC_interval_done"]' )[0].value = 'true';
2469:): \$( '[name="LC_interval_done_proctorpass"]' )[0].value = proctorkey;
2470:): \$( '[name="LCdoneButton"]' )[0].submit();
2471:): }
2472:): },
2473:): },
2474:): {
2475:): text: "$lt{'exit'}",
2476:): click: function() {
2477:): \$("#LC_done-confirm").dialog( "close" );
2478:): }
2479:): }
2480:): ],
2481:): close: function() {
2482:): \$( '[name="LC_interval_done_proctorkey"]' )[0].value = '';
2483:): }
2484:): });
2485:): \$( "#LC_done-confirm" ).find( "form" ).on( "submit", function( event ) {
2486:): event.preventDefault();
2487:): \$( '[name="LC_interval_done"]' )[0].value = 'true';
2488:): \$( '[name="LC_interval_done_proctorpass"]' )[0].value = \$( '[name="LC_interval_done_proctorkey"]' )[0].value;
2489:): \$( '[name="LCdoneButton"]' )[0].submit();
2490:): });
2491:): });
2492:):
2493:): // ]]>
2494:): </script>
2495:):
2496:): END
2497:): } else {
2498:): if ($height !~ /^\d+$/) {
2499:): $height = 320;
2500:): if ($missing) {
2501:): $height += 60;
2502:): }
2503:): }
2504:): if ($width !~ /^\d+$/) {
2505:): $width = 320;
2506:): if ($missing) {
2507:): $width += 60;
2508:): }
2509:): }
2510:): if ($missing) {
2511:): $lt{'miss'} = '</p>'.$lt{'miss'}.'<p>';
2512:): }
2513:): return <<END;
2514:):
2515:): <form method="post" name="LCdoneButton" action="">
2516:): <input type="hidden" name="LC_interval_done" value="" />
2517:): <input type="hidden" name="symb" value="$shownsymb" />
2518:): <button id="LC_done-confirm-opener" type="button">$donebuttontext</button>
2519:): </form>
2520:):
2521:): <div id="LC_done-confirm" title="$lt{'title'}">
2522:): <p>$lt{'preamble'} $lt{$type} $lt{'miss'} $lt{'okdone'} $lt{'cancel'}</p>
2523:): </div>
2524:):
2525:): <script type="text/javascript">
2526:): // <![CDATA[
2527:): \$( "#LC_done-confirm" ).dialog({ autoOpen: false });
2528:): \$( "#LC_done-confirm-opener" ).click(function() {
2529:): \$( "#LC_done-confirm" ).dialog( "open" );
2530:): \$( "#LC_done-confirm" ).dialog({
2531:): resizable: false,
2532:): height: $height,
2533:): width: $width,
2534:): modal: true,
2535:): buttons: [
2536:): {
2537:): text: "$lt{'ok'}",
2538:): click: function() {
2539:): \$( this ).dialog( "close" );
2540:): \$( '[name="LC_interval_done"]' )[0].value = 'true';
2541:): \$( '[name="LCdoneButton"]' )[0].submit();
2542:): },
2543:): },
2544:): {
2545:): text: "$lt{'exit'}",
2546:): click: function() {
2547:): \$( this ).dialog( "close" );
2548:): },
2549:): },
2550:): ],
2551:): });
2552:): });
2553:): // ]]>
2554:): </script>
2555:):
2556:): END
2557:): }
2558:): }
2559:):
1.42 www 2560: sub utilityfunctions {
1.369.2.47 raeburn 2561: my ($httphost) = @_;
1.152 albertel 2562: my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
1.369.2.75 raeburn 2563: my $currentsymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
2564: if ($currenturl =~ m{^/adm/wrapper/ext/}) {
2565: if ($env{'request.external.querystring'}) {
1.293 raeburn 2566: $currenturl .= ($currenturl=~/\?/)?'&':'?'.$env{'request.external.querystring'};
1.369.2.75 raeburn 2567: }
2568: my ($anchor) = ($env{'request.symb'} =~ /(\#[^\#]+)$/);
2569: if (($anchor) && ($currenturl !~ /\Q$anchor\E$/)) {
2570: $currenturl .= $1;
2571: }
1.293 raeburn 2572: }
1.183 www 2573: $currenturl=&Apache::lonenc::check_encrypt(&unescape($currenturl));
1.125 albertel 2574:
1.306 raeburn 2575: my $dc_popup_cid;
2576: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
2577: $env{'course.'.$env{'request.course.id'}.
2578: '.domain'}.'/'})) {
2579: $dc_popup_cid = &dc_popup_js();
2580: }
2581:
1.175 albertel 2582: my $start_page_annotate =
2583: &Apache::loncommon::start_page('Annotator',undef,
2584: {'only_body' => 1,
2585: 'js_ready' => 1,
2586: 'bgcolor' => '#BBBBBB',
2587: 'add_entries' => {
2588: 'onload' => 'javascript:document.goannotate.submit();'}});
2589:
1.205 albertel 2590: my $end_page_annotate =
2591: &Apache::loncommon::end_page({'js_ready' => 1});
2592:
1.369.2.26 raeburn 2593: my $jumptores = &Apache::lonhtmlcommon::javascript_jumpto_resource();
1.336 raeburn 2594:
1.368 www 2595: my $esc_url=&escape($currenturl);
2596: my $esc_symb=&escape($currentsymb);
1.332 wenzelju 2597:
1.369.2.10 raeburn 2598: my $countdown = &countdown_toggle_js();
2599:
1.369.2.83.2. (raeburn 2600:): my $deeplinktarget;
2601:): if ($env{'request.deeplink.login'}) {
2602:): $deeplinktarget = $env{'request.deeplink.target'};
2603:): }
2604:):
1.369.2.75 raeburn 2605: my $annotateurl = '/adm/annotation';
2606: if ($httphost) {
2607: $annotateurl = '/adm/annotations';
2608: }
1.369.2.53 raeburn 2609: my $hostvar = '
2610: function setLCHost() {
2611: var lcHostname="";
2612: ';
2613: if ($httphost =~ m{^https?\://}) {
2614: $hostvar .= ' var lcServer="'.$httphost.'";'."\n".
2615: ' var hostReg = /^https?:\/\/([^\/]+)$/i;'."\n".
2616: ' var match = hostReg.exec(lcServer);'."\n".
2617: ' if (match.length) {'."\n".
2618: ' if (match[1] == location.hostname) {'."\n".
2619: ' lcHostname=lcServer;'."\n".
2620: ' }'."\n".
2621: ' }'."\n";
2622: }
2623:
2624: $hostvar .= ' return lcHostname;'."\n".
2625: '}'."\n";
2626:
1.42 www 2627: return (<<ENDUTILITY)
1.369.2.53 raeburn 2628: $hostvar
1.368 www 2629: var currentURL=unescape("$esc_url");
2630: var reloadURL=unescape("$esc_url");
2631: var currentSymb=unescape("$esc_symb");
1.42 www 2632:
1.306 raeburn 2633: $dc_popup_cid
1.114 albertel 2634:
1.369.2.26 raeburn 2635: $jumptores
1.336 raeburn 2636:
1.42 www 2637: function gopost(url,postdata) {
2638: if (url!='') {
1.369.2.53 raeburn 2639: var lcHostname = setLCHost();
2640: this.document.server.action=lcHostname+url;
1.42 www 2641: this.document.server.postdata.value=postdata;
2642: this.document.server.command.value='';
2643: this.document.server.url.value='';
2644: this.document.server.symb.value='';
2645: this.document.server.submit();
2646: }
2647: }
2648:
2649: function gocmd(url,cmd) {
2650: if (url!='') {
1.369.2.53 raeburn 2651: var lcHostname = setLCHost();
2652: this.document.server.action=lcHostname+url;
1.42 www 2653: this.document.server.postdata.value='';
2654: this.document.server.command.value=cmd;
2655: this.document.server.url.value=currentURL;
2656: this.document.server.symb.value=currentSymb;
2657: this.document.server.submit();
2658: }
1.57 www 2659: }
2660:
1.121 raeburn 2661: function gocstr(url,filename) {
2662: if (url == '/adm/cfile?action=delete') {
2663: this.document.cstrdelete.filename.value = filename
2664: this.document.cstrdelete.submit();
2665: return;
2666: }
1.137 raeburn 2667: if (url == '/adm/printout') {
2668: this.document.cstrprint.postdata.value = filename
2669: this.document.cstrprint.curseed.value = 0;
2670: this.document.cstrprint.problemtype.value = 0;
1.138 raeburn 2671: if (this.document.lonhomework) {
2672: if ((this.document.lonhomework.rndseed) && (this.document.lonhomework.rndseed.value != null) && (this.document.lonhomework.rndseed.value != '')) {
2673: this.document.cstrprint.curseed.value = this.document.lonhomework.rndseed.value
2674: }
2675: if (this.document.lonhomework.problemtype) {
1.164 albertel 2676: if (this.document.lonhomework.problemtype.value) {
2677: this.document.cstrprint.problemtype.value =
2678: this.document.lonhomework.problemtype.value;
2679: } else if (this.document.lonhomework.problemtype.options) {
2680: for (var i=0; i<this.document.lonhomework.problemtype.options.length; i++) {
2681: if (this.document.lonhomework.problemtype.options[i].selected) {
2682: if (this.document.lonhomework.problemtype.options[i].value != null && this.document.lonhomework.problemtype.options[i].value != '') {
2683: this.document.cstrprint.problemtype.value = this.document.lonhomework.problemtype.options[i].value
2684: }
2685: }
2686: }
2687: }
2688: }
2689: }
1.137 raeburn 2690: this.document.cstrprint.submit();
2691: return;
2692: }
1.121 raeburn 2693: if (url !='') {
2694: this.document.constspace.filename.value = filename;
2695: this.document.constspace.action = url;
2696: this.document.constspace.submit();
2697: }
2698: }
2699:
1.131 raeburn 2700: function golist(url) {
2701: if (url!='' && url!= null) {
2702: currentURL = null;
2703: currentSymb= null;
1.369.2.53 raeburn 2704: var lcHostname = setLCHost();
1.369.2.83.2. (raeburn 2705:): var deeplinktarget = '$deeplinktarget';
2706:): if (deeplinktarget == '_self') {
2707:): document.location.href=lcHostname+url;
2708:): } else {
2709:): top.location.href=lcHostname+url;
2710:): }
1.131 raeburn 2711: }
2712: }
2713:
2714:
1.121 raeburn 2715:
1.369.2.83.2. (raeburn 2716:): function catalog_info(url,isMobile) {
1.369.2.52 raeburn 2717: if (isMobile == 1) {
1.369.2.83.2. (raeburn 2718:): openMyModal(url+'.meta?modal=1',500,400,'yes');
1.369.2.52 raeburn 2719: } else {
1.369.2.83.2. (raeburn 2720:): loncatinfo=window.open(url+'.meta',"LONcatInfo",'height=500,width=400,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
1.369.2.52 raeburn 2721: }
1.57 www 2722: }
2723:
2724: function chat_win() {
1.369.2.53 raeburn 2725: var lcHostname = setLCHost();
2726: 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 2727: }
1.169 raeburn 2728:
2729: function group_chat(group) {
1.369.2.53 raeburn 2730: var lcHostname = setLCHost();
2731: var url = lcHostname+'/adm/groupchat?group='+group;
1.169 raeburn 2732: var winName = 'LONchat_'+group;
2733: grpchat=window.open(url,winName,'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
2734: }
1.175 albertel 2735:
2736: function annotate() {
2737: w_Annotator_flag=1;
2738: annotator=window.open('','Annotator','width=365,height=265,scrollbars=0');
2739: annotator.document.write(
2740: '$start_page_annotate'
2741: +"<form name='goannotate' target='Annotator' method='post' "
1.369.2.75 raeburn 2742: +"action='$annotateurl'>"
1.217 albertel 2743: +"<input type='hidden' name='symbnew' value='"+currentSymb+"' />"
1.181 albertel 2744: +"<\\/form>"
1.205 albertel 2745: +'$end_page_annotate');
1.175 albertel 2746: annotator.document.close();
2747: }
2748:
1.369.2.8 raeburn 2749: function open_StoredLinks_Import(rat) {
2750: var newWin;
1.369.2.53 raeburn 2751: var lcHostname = setLCHost();
1.369.2.8 raeburn 2752: if (rat) {
1.369.2.53 raeburn 2753: newWin = window.open(lcHostname+'/adm/wishlist?inhibitmenu=yes&mode=import&rat='+rat,
1.369.2.8 raeburn 2754: 'wishlistImport','scrollbars=1,resizable=1,menubar=0');
2755: }
2756: else {
1.369.2.53 raeburn 2757: newWin = window.open(lcHostname+'/adm/wishlist?inhibitmenu=yes&mode=import',
1.369.2.8 raeburn 2758: 'wishlistImport','scrollbars=1,resizable=1,menubar=0');
2759: }
2760: newWin.focus();
2761: }
2762:
1.369.2.79 raeburn 2763: function open_source() {
2764: sourcewin=window.open('/adm/source?inhibitmenu=yes&viewonly=1&filename='+currentURL,'LONsource',
2765: 'height=500,width=600,resizable=yes,location=no,menubar=no,toolbar=no,scrollbars=yes');
2766: }
2767:
1.369.2.4 raeburn 2768: (function (\$) {
2769: \$(document).ready(function () {
2770: \$.single=function(a){return function(b){a[0]=b;return a}}(\$([1]));
2771: /*\@cc_on
2772: if (!window.XMLHttpRequest) {
2773: \$('.LC_hoverable').each(function () {
2774: this.attachEvent('onmouseenter', function (evt) { \$.single(evt.srcElement).addClass('hover'); });
2775: this.attachEvent('onmouseleave', function (evt) { \$.single(evt.srcElement).removeClass('hover'); });
2776: });
2777: }
2778: \@*/
2779: });
2780: }(jQuery));
2781:
1.369.2.10 raeburn 2782: $countdown
2783:
1.42 www 2784: ENDUTILITY
2785: }
2786:
2787: sub serverform {
1.369.2.83.2. (raeburn 2788:): my $target;
2789:): if (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self')) {
2790:): $target = ' target="_self"';
2791:): } else {
2792:): $target = ' target="_top"';
2793:): }
1.42 www 2794: return(<<ENDSERVERFORM);
1.369.2.83.2. (raeburn 2795:): <form name="server" action="/adm/logout" method="post"$target>
1.42 www 2796: <input type="hidden" name="postdata" value="none" />
2797: <input type="hidden" name="command" value="none" />
2798: <input type="hidden" name="url" value="none" />
2799: <input type="hidden" name="symb" value="none" />
2800: </form>
2801: ENDSERVERFORM
2802: }
1.113 albertel 2803:
1.121 raeburn 2804: sub constspaceform {
1.369.2.83.2. (raeburn 2805:): my ($frameset) = @_;
2806:): my ($target,$printtarget);
2807:): if ($frameset) {
2808:): $target = ' target="_parent"';
2809:): $printtarget = ' target="_parent"';
2810:): } else {
2811:): unless (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self')) {
2812:): $target = ' target="_top"';
2813:): $printtarget = ' target="_top"';
2814:): }
2815:): }
1.121 raeburn 2816: return(<<ENDCONSTSPACEFORM);
1.369.2.83.2. (raeburn 2817:): <form name="constspace" action="/adm/logout" method="post"$target>
1.121 raeburn 2818: <input type="hidden" name="filename" value="" />
2819: </form>
1.369.2.83.2. (raeburn 2820:): <form name="cstrdelete" action="/adm/cfile" method="post"$target>
1.121 raeburn 2821: <input type="hidden" name="action" value="delete" />
2822: <input type="hidden" name="filename" value="" />
2823: </form>
1.369.2.83.2. (raeburn 2824:): <form name="cstrprint" action="/adm/printout" method="post"$printtarget>
1.137 raeburn 2825: <input type="hidden" name="postdata" value="" />
2826: <input type="hidden" name="curseed" value="" />
2827: <input type="hidden" name="problemtype" value="" />
2828: </form>
2829:
1.121 raeburn 2830: ENDCONSTSPACEFORM
2831: }
2832:
1.369.2.17 raeburn 2833: sub get_nav_status {
2834: my $navstatus="swmenu.w_loncapanav_flag=";
2835: if ($env{'environment.remotenavmap'} eq 'on') {
2836: $navstatus.="1";
2837: } else {
2838: $navstatus.="-1";
2839: }
2840: return $navstatus;
2841: }
2842:
1.220 raeburn 2843: sub hidden_button_check {
1.317 droeschl 2844: if ( $env{'request.course.id'} eq ''
2845: || $env{'request.role.adv'} ) {
2846:
1.220 raeburn 2847: return;
2848: }
1.232 raeburn 2849: my $buttonshide = &Apache::lonnet::EXT('resource.0.buttonshide');
2850: return $buttonshide;
1.220 raeburn 2851: }
1.184 raeburn 2852:
1.235 raeburn 2853: sub roles_selector {
1.369.2.83.2. (raeburn 2854:): my ($cdom,$cnum,$httphost,$target,$menucoll,$menuref) = @_;
1.298 raeburn 2855: my $crstype = &Apache::loncommon::course_type();
1.235 raeburn 2856: my $now = time;
1.369.2.68 raeburn 2857: my (%courseroles,%seccount,%courseprivs,%roledesc);
1.235 raeburn 2858: my $is_cc;
1.369.2.83.2. (raeburn 2859:): my ($js,$form,$switcher,$has_opa_priv);
1.298 raeburn 2860: my $ccrole;
2861: if ($crstype eq 'Community') {
2862: $ccrole = 'co';
2863: } else {
2864: $ccrole = 'cc';
1.350 raeburn 2865: }
1.369.2.61 raeburn 2866: my ($privref,$gotsymb,$destsymb);
1.350 raeburn 2867: my $destinationurl = $ENV{'REQUEST_URI'};
1.369.2.75 raeburn 2868: if ($destinationurl =~ /(\?|\&)symb=/) {
1.369.2.23 raeburn 2869: $gotsymb = 1;
2870: } elsif ($destinationurl =~ m{^/enc/}) {
2871: my $plainurl = &Apache::lonenc::unencrypted($destinationurl);
1.369.2.75 raeburn 2872: if ($plainurl =~ /(\?|\&)symb=/) {
1.369.2.23 raeburn 2873: $gotsymb = 1;
2874: }
2875: }
2876: unless ($gotsymb) {
2877: $destsymb = &Apache::lonnet::symbread();
2878: if ($destsymb ne '') {
2879: $destsymb = &Apache::lonenc::check_encrypt($destsymb);
2880: }
2881: }
1.350 raeburn 2882: my $reqprivs = &required_privs();
2883: if (ref($reqprivs) eq 'HASH') {
2884: my $destination = $destinationurl;
2885: $destination =~ s/(\?.*)$//;
2886: if (exists($reqprivs->{$destination})) {
1.369.2.61 raeburn 2887: if ($reqprivs->{$destination} =~ /,/) {
2888: @{$privref} = split(/,/,$reqprivs->{$destination});
2889: } else {
2890: $privref = [$reqprivs->{$destination}];
2891: }
1.350 raeburn 2892: }
2893: }
1.298 raeburn 2894: if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) {
2895: my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum});
1.235 raeburn 2896: if ((($start) && ($start<0)) ||
2897: (($end) && ($end<$now)) ||
2898: (($start) && ($now<$start))) {
2899: $is_cc = 0;
2900: } else {
2901: $is_cc = 1;
2902: }
2903: }
2904: if ($is_cc) {
1.369.2.61 raeburn 2905: &get_all_courseroles($cdom,$cnum,\%courseroles,\%seccount,\%courseprivs);
2906: } elsif ($env{'request.role'} =~ m{^\Qcr/$cdom/$cdom-domainconfig/\E(\w+)\.\Q/$cdom/$cnum\E}) {
1.369.2.68 raeburn 2907: &get_customadhoc_roles($cdom,$cnum,\%courseroles,\%seccount,\%courseprivs,\%roledesc,$privref);
1.235 raeburn 2908: } else {
1.262 raeburn 2909: my %gotnosection;
1.235 raeburn 2910: foreach my $item (keys(%env)) {
1.239 raeburn 2911: if ($item =~ m-^user\.role\.([^.]+)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
1.235 raeburn 2912: my $role = $1;
2913: my $sec = $2;
2914: next if ($role eq 'gr');
2915: my ($start,$end) = split(/\./,$env{$item});
2916: next if (($start && $start > $now) || ($end && $end < $now));
2917: if ($sec eq '') {
1.239 raeburn 2918: if (!$gotnosection{$role}) {
2919: $seccount{$role} ++;
2920: $gotnosection{$role} = 1;
2921: }
1.235 raeburn 2922: }
1.369.2.61 raeburn 2923: if ((ref($privref) eq 'ARRAY') && (@{$privref} > 0)) {
1.350 raeburn 2924: my $cnumsec = $cnum;
2925: if ($sec ne '') {
2926: $cnumsec .= "/$sec";
2927: }
2928: $courseprivs{"$role./$cdom/$cnumsec./"} =
2929: $env{"user.priv.$role./$cdom/$cnumsec./"};
2930: $courseprivs{"$role./$cdom/$cnumsec./$cdom/"} =
2931: $env{"user.priv.$role./$cdom/$cnumsec./$cdom/"};
2932: $courseprivs{"$role./$cdom/$cnumsec./$cdom/$cnumsec"} =
2933: $env{"user.priv.$role./$cdom/$cnumsec./$cdom/$cnumsec"};
2934: }
1.235 raeburn 2935: if (ref($courseroles{$role}) eq 'ARRAY') {
1.239 raeburn 2936: if ($sec ne '') {
1.264 raeburn 2937: if (!grep(/^\Q$sec\E$/,@{$courseroles{$role}})) {
1.239 raeburn 2938: push(@{$courseroles{$role}},$sec);
2939: $seccount{$role} ++;
2940: }
2941: }
2942: } else {
2943: @{$courseroles{$role}} = ();
2944: if ($sec ne '') {
2945: $seccount{$role} ++;
1.235 raeburn 2946: push(@{$courseroles{$role}},$sec);
2947: }
2948: }
2949: }
2950: }
2951: }
1.298 raeburn 2952: my @roles_order = ($ccrole,'in','ta','ep','ad','st');
1.369.2.30 raeburn 2953: my $numdiffsec;
2954: if (keys(%seccount) == 1) {
2955: foreach my $key (keys(%seccount)) {
2956: $numdiffsec = $seccount{$key};
2957: }
2958: }
2959: if ((keys(%seccount) > 1) || ($numdiffsec > 1)) {
1.369.2.83.2. (raeburn 2960:): my $targetattr;
2961:): if ($target ne '') {
2962:): $targetattr = ' target="'.$target.'"';
2963:): }
1.369.2.30 raeburn 2964: my @submenu;
1.369.2.83.2. (raeburn 2965:): $js = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles,\%courseprivs,
2966:): \%roledesc,$privref,$menucoll,$menuref);
1.369.2.30 raeburn 2967: $form =
1.369.2.83.2. (raeburn 2968:): '<form name="rolechooser" method="post" action="'.$httphost.'/adm/roles"'.$targetattr.'>'."\n".
1.369.2.30 raeburn 2969: ' <input type="hidden" name="destinationurl" value="'.
2970: &HTML::Entities::encode($destinationurl).'" />'."\n".
2971: ' <input type="hidden" name="gotorole" value="1" />'."\n".
2972: ' <input type="hidden" name="selectrole" value="" />'."\n".
2973: ' <input type="hidden" name="switchrole" value="" />'."\n";
2974: if ($destsymb ne '') {
2975: $form .= ' <input type="hidden" name="destsymb" value="'.
2976: &HTML::Entities::encode($destsymb).'" />'."\n";
2977: }
2978: $form .= '</form>'."\n";
1.235 raeburn 2979: foreach my $role (@roles_order) {
1.369.2.30 raeburn 2980: my $include;
1.235 raeburn 2981: if (defined($courseroles{$role})) {
1.369.2.30 raeburn 2982: if ($env{'request.role'} =~ m{^\Q$role\E}) {
2983: if ($seccount{$role} > 1) {
2984: $include = 1;
1.369.2.83.2. (raeburn 2985:): } else {
2986:): if ($env{'user.priv.'.$env{'request.role'}."./$cdom/$cnum"} =~/opa\&([^\:]*)/) {
2987:): $has_opa_priv = 1;
2988:): }
1.369.2.30 raeburn 2989: }
2990: } else {
2991: $include = 1;
2992: }
2993: }
2994: if ($include) {
1.369.2.83.2. (raeburn 2995:): if ($env{"user.priv.$role./$cdom/$cnum./$cdom/$cnum"} =~/opa\&([^\:]*)/) {
2996:): $has_opa_priv = 1;
2997:): }
1.369.2.30 raeburn 2998: push(@submenu,['javascript:adhocRole('."'$role'".')',
2999: &Apache::lonnet::plaintext($role,$crstype)]);
1.235 raeburn 3000: }
3001: }
3002: foreach my $role (sort(keys(%courseroles))) {
3003: if ($role =~ /^cr/) {
1.369.2.30 raeburn 3004: my $include;
3005: if ($env{'request.role'} =~ m{^\Q$role\E}) {
3006: if ($seccount{$role} > 1) {
3007: $include = 1;
3008: }
3009: } else {
3010: $include = 1;
3011: }
3012: if ($include) {
1.369.2.65 raeburn 3013: my $rolename;
3014: if ($role =~ m{^cr/$cdom/$cdom\-domainconfig/(\w+)(?:/\w+|$)}) {
1.369.2.68 raeburn 3015: $rolename = $roledesc{$role};
3016: if ($rolename eq '') {
3017: $rolename = &mt('Helpdesk [_1]',$1);
3018: }
1.369.2.65 raeburn 3019: } else {
3020: $rolename = &Apache::lonnet::plaintext($role);
3021: }
1.369.2.83.2. (raeburn 3022:): if ($env{"user.priv.$role./$cdom/$cnum./$cdom/$cnum"} =~/opa\&([^\:]*)/) {
3023:): $has_opa_priv = 1;
3024:): }
1.369.2.30 raeburn 3025: push(@submenu,['javascript:adhocRole('."'$role'".')',
1.369.2.65 raeburn 3026: $rolename]);
1.369.2.30 raeburn 3027: }
1.235 raeburn 3028: }
3029: }
1.369.2.30 raeburn 3030: if (@submenu > 0) {
1.369.2.83.2. (raeburn 3031:): $switcher = &create_submenu('#',$target,&mt('Switch role'),\@submenu);
1.369.2.23 raeburn 3032: }
1.235 raeburn 3033: }
1.369.2.83.2. (raeburn 3034:): return ($js,$form,$switcher,$has_opa_priv);
1.235 raeburn 3035: }
3036:
1.262 raeburn 3037: sub get_all_courseroles {
1.350 raeburn 3038: my ($cdom,$cnum,$courseroles,$seccount,$courseprivs) = @_;
1.351 raeburn 3039: unless ((ref($courseroles) eq 'HASH') && (ref($seccount) eq 'HASH') &&
1.350 raeburn 3040: (ref($courseprivs) eq 'HASH')) {
1.262 raeburn 3041: return;
3042: }
3043: my ($result,$cached) =
3044: &Apache::lonnet::is_cached_new('getcourseroles',$cdom.'_'.$cnum);
3045: if (defined($cached)) {
3046: if (ref($result) eq 'HASH') {
3047: if ((ref($result->{'roles'}) eq 'HASH') &&
1.350 raeburn 3048: (ref($result->{'seccount'}) eq 'HASH') &&
3049: (ref($result->{'privs'}) eq 'HASH')) {
1.262 raeburn 3050: %{$courseroles} = %{$result->{'roles'}};
3051: %{$seccount} = %{$result->{'seccount'}};
1.350 raeburn 3052: %{$courseprivs} = %{$result->{'privs'}};
1.262 raeburn 3053: return;
3054: }
3055: }
3056: }
3057: my %gotnosection;
3058: my %adv_roles =
3059: &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
3060: foreach my $role (keys(%adv_roles)) {
3061: my ($urole,$usec) = split(/:/,$role);
3062: if (!$gotnosection{$urole}) {
3063: $seccount->{$urole} ++;
3064: $gotnosection{$urole} = 1;
3065: }
3066: if (ref($courseroles->{$urole}) eq 'ARRAY') {
3067: if ($usec ne '') {
3068: if (!grep(/^Q$usec\E$/,@{$courseroles->{$urole}})) {
3069: push(@{$courseroles->{$urole}},$usec);
3070: $seccount->{$urole} ++;
3071: }
3072: }
3073: } else {
3074: @{$courseroles->{$urole}} = ();
3075: if ($usec ne '') {
3076: $seccount->{$urole} ++;
3077: push(@{$courseroles->{$urole}},$usec);
3078: }
3079: }
1.350 raeburn 3080: my $area = '/'.$cdom.'/'.$cnum;
3081: if ($usec ne '') {
3082: $area .= '/'.$usec;
3083: }
3084: if ($role =~ /^cr\//) {
3085: &Apache::lonnet::custom_roleprivs($courseprivs,$urole,$cdom,$cnum,$urole.'.'.$area,$area);
3086: } else {
3087: &Apache::lonnet::standard_roleprivs($courseprivs,$urole,$cdom,$urole.'.'.$area,$cnum,$area);
3088: }
1.262 raeburn 3089: }
3090: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum,['st']);
3091: @{$courseroles->{'st'}} = ();
1.350 raeburn 3092: &Apache::lonnet::standard_roleprivs($courseprivs,'st',$cdom,"st./$cdom/$cnum",$cnum,"/$cdom/$cnum");
1.262 raeburn 3093: if (keys(%sections_count) > 0) {
3094: push(@{$courseroles->{'st'}},keys(%sections_count));
1.350 raeburn 3095: $seccount->{'st'} = scalar(keys(%sections_count));
1.262 raeburn 3096: }
1.369.2.38 raeburn 3097: $seccount->{'st'} ++; # Increment for a section-less student role.
1.262 raeburn 3098: my $rolehash = {
3099: 'roles' => $courseroles,
3100: 'seccount' => $seccount,
1.350 raeburn 3101: 'privs' => $courseprivs,
1.262 raeburn 3102: };
3103: &Apache::lonnet::do_cache_new('getcourseroles',$cdom.'_'.$cnum,$rolehash);
3104: return;
3105: }
3106:
1.369.2.61 raeburn 3107: sub get_customadhoc_roles {
1.369.2.68 raeburn 3108: my ($cdom,$cnum,$courseroles,$seccount,$courseprivs,$roledesc,$privref) = @_;
1.369.2.61 raeburn 3109: unless ((ref($courseroles) eq 'HASH') && (ref($seccount) eq 'HASH') &&
1.369.2.68 raeburn 3110: (ref($courseprivs) eq 'HASH') && (ref($roledesc) eq 'HASH')) {
1.369.2.61 raeburn 3111: return;
3112: }
1.369.2.69 raeburn 3113: my $is_helpdesk = 0;
3114: my $now = time;
3115: foreach my $role ('dh','da') {
3116: if ($env{"user.role.$role./$cdom/"}) {
3117: my ($start,$end)=split(/\./,$env{"user.role.$role./$cdom/"});
3118: if (!($start && ($now<$start)) && !($end && ($now>$end))) {
3119: $is_helpdesk = 1;
3120: last;
3121: }
3122: }
3123: }
3124: if ($is_helpdesk) {
3125: my ($possroles,$description) = &Apache::lonnet::get_my_adhocroles($cdom.'_'.$cnum);
3126: my %available;
3127: if (ref($possroles) eq 'ARRAY') {
3128: map { $available{$_} = 1; } @{$possroles};
3129: }
3130: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
3131: if (ref($domdefaults{'adhocroles'}) eq 'HASH') {
3132: if (keys(%{$domdefaults{'adhocroles'}})) {
3133: my $numsec = 1;
3134: my @sections;
3135: my ($allseclist,$cached) =
3136: &Apache::lonnet::is_cached_new('courseseclist',$cdom.'_'.$cnum);
3137: if (defined($cached)) {
3138: if ($allseclist ne '') {
3139: @sections = split(/,/,$allseclist);
1.369.2.68 raeburn 3140: $numsec += scalar(@sections);
1.369.2.61 raeburn 3141: }
1.369.2.69 raeburn 3142: } else {
3143: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
3144: @sections = sort(keys(%sections_count));
3145: $numsec += scalar(@sections);
3146: $allseclist = join(',',@sections);
3147: &Apache::lonnet::do_cache_new('courseseclist',$cdom.'_'.$cnum,$allseclist);
3148: }
3149: my (%adhoc,$gotprivs);
3150: my $prefix = "cr/$cdom/$cdom".'-domainconfig';
3151: foreach my $role (keys(%{$domdefaults{'adhocroles'}})) {
3152: next if (($role eq '') || ($role =~ /\W/));
3153: $seccount->{"$prefix/$role"} = $numsec;
3154: $roledesc->{"$prefix/$role"} = $description->{$role};
3155: if ((ref($privref) eq 'ARRAY') && (@{$privref} > 0)) {
3156: if (exists($env{"user.priv.$prefix/$role./$cdom/$cnum./"})) {
3157: $courseprivs->{"$prefix/$role./$cdom/$cnum./"} =
3158: $env{"user.priv.$prefix/$role./$cdom/$cnum./"};
3159: $courseprivs->{"$prefix/$role./$cdom/$cnum./$cdom/"} =
3160: $env{"user.priv.$prefix/$role./$cdom/$cnum./$cdom/"};
3161: $courseprivs->{"$prefix/$role./$cdom/$cnum./$cdom/$cnum"} =
3162: $env{"user.priv.$prefix/$role./$cdom/$cnum./$cdom/$cnum"};
3163: } else {
3164: unless ($gotprivs) {
3165: my ($adhocroles,$privscached) =
3166: &Apache::lonnet::is_cached_new('adhocroles',$cdom);
3167: if ((defined($privscached)) && (ref($adhocroles) eq 'HASH')) {
3168: %adhoc = %{$adhocroles};
3169: } else {
3170: my $confname = &Apache::lonnet::get_domainconfiguser($cdom);
3171: my %roledefs = &Apache::lonnet::dump('roles',$cdom,$confname,'rolesdef_');
3172: foreach my $key (keys(%roledefs)) {
3173: (undef,my $rolename) = split(/_/,$key);
3174: if ($rolename ne '') {
3175: my ($systempriv,$domainpriv,$coursepriv) = split(/\_/,$roledefs{$key});
3176: $coursepriv = &Apache::lonnet::course_adhocrole_privs($rolename,$cdom,$cnum,$coursepriv);
3177: $adhoc{$rolename} = join('_',($systempriv,$domainpriv,$coursepriv));
1.369.2.61 raeburn 3178: }
3179: }
1.369.2.69 raeburn 3180: &Apache::lonnet::do_cache_new('adhocroles',$cdom,\%adhoc);
1.369.2.61 raeburn 3181: }
1.369.2.69 raeburn 3182: $gotprivs = 1;
1.369.2.61 raeburn 3183: }
1.369.2.69 raeburn 3184: ($courseprivs->{"$prefix/$role./$cdom/$cnum./"},
3185: $courseprivs->{"$prefix/$role./$cdom/$cnum./$cdom/"},
3186: $courseprivs->{"$prefix/$role./$cdom/$cnum./$cdom/$cnum"}) =
3187: split(/\_/,$adhoc{$role});
1.369.2.61 raeburn 3188: }
1.369.2.69 raeburn 3189: }
3190: if ($available{$role}) {
3191: $courseroles->{"$prefix/$role"} = \@sections;
1.369.2.61 raeburn 3192: }
3193: }
3194: }
3195: }
3196: }
3197: return;
3198: }
3199:
1.235 raeburn 3200: sub jump_to_role {
1.369.2.83.2. (raeburn 3201:): my ($cdom,$cnum,$seccount,$courseroles,$courseprivs,$roledesc,$privref,
3202:): $menucoll,$menuref) = @_;
1.239 raeburn 3203: my %lt = &Apache::lonlocal::texthash(
3204: this => 'This role has section(s) associated with it.',
3205: ente => 'Enter a specific section.',
3206: orlb => 'Enter a specific section, or leave blank for no section.',
3207: avai => 'Available sections are:',
3208: youe => 'You entered an invalid section choice:',
1.352 raeburn 3209: plst => 'Please try again.',
1.350 raeburn 3210: role => 'The role you selected is not permitted to view the current page.',
3211: swit => 'Switch role, but display Main Menu page instead?',
1.239 raeburn 3212: );
1.369.2.83.2. (raeburn 3213:): &js_escape(\%lt);
1.239 raeburn 3214: my $js;
3215: if (ref($courseroles) eq 'HASH') {
3216: $js = ' var secpick = new Array("'.$lt{'ente'}.'","'.$lt{'orlb'}.'");'."\n".
3217: ' var numsec = new Array();'."\n".
3218: ' var rolesections = new Array();'."\n".
3219: ' var rolenames = new Array();'."\n".
3220: ' var roleseclist = new Array();'."\n";
3221: my @items = keys(%{$courseroles});
3222: for (my $i=0; $i<@items; $i++) {
3223: $js .= ' rolenames['.$i.'] = "'.$items[$i].'";'."\n";
3224: my ($secs,$secstr);
3225: if (ref($courseroles->{$items[$i]}) eq 'ARRAY') {
3226: my @sections = sort { $a <=> $b } @{$courseroles->{$items[$i]}};
3227: $secs = join('","',@sections);
3228: $secstr = join(', ',@sections);
3229: }
3230: $js .= ' rolesections['.$i.'] = new Array("'.$secs.'");'."\n".
3231: ' roleseclist['.$i.'] = "'.$secstr.'";'."\n".
3232: ' numsec['.$i.'] = "'.$seccount->{$items[$i]}.'";'."\n";
3233: }
3234: }
1.350 raeburn 3235: my $checkroles = 0;
1.369.2.83.2. (raeburn 3236:): my $fallback = '/adm/menu';
3237:): my $displaymsg = $lt{'swit'};
1.369.2.61 raeburn 3238: if ((ref($privref) eq 'ARRAY') && (@{$privref} > 0) && (ref($courseprivs) eq 'HASH')) {
3239: my %disallowed;
1.350 raeburn 3240: foreach my $role (sort(keys(%{$courseprivs}))) {
3241: my $trole;
3242: if ($role =~ m{^(.+?)\Q./$cdom/$cnum\E}) {
3243: $trole = $1;
3244: }
3245: if (($trole ne '') && ($trole ne 'cm')) {
1.369.2.61 raeburn 3246: $disallowed{$trole} = 1;
3247: foreach my $priv (@{$privref}) {
3248: if ($courseprivs->{$role} =~ /\Q:$priv\E($|:|\&\w+)/) {
3249: delete($disallowed{$trole});
3250: last;
3251: }
1.350 raeburn 3252: }
3253: }
3254: }
1.369.2.61 raeburn 3255: if (keys(%disallowed) > 0) {
1.350 raeburn 3256: $checkroles = 1;
1.369.2.61 raeburn 3257: $js .= " var disallow = new Array('".join("','",keys(%disallowed))."');\n".
1.350 raeburn 3258: " var rolecheck = 1;\n";
1.369.2.83.2. (raeburn 3259:): if ($menucoll) {
3260:): if (ref($menuref) eq 'HASH') {
3261:): if ($menuref->{'main'} eq 'n') {
3262:): $fallback = '/adm/navmaps';
3263:): if (&Apache::loncommon::course_type() eq 'Community') {
3264:): $displaymsg = &mt('Switch role, but display Community Contents page instead?');
3265:): } else {
3266:): $displaymsg = &mt('Switch role, but display Course Contents page instead?');
3267:): }
3268:): &js_escape(\$displaymsg);
3269:): }
3270:): }
3271:): }
1.350 raeburn 3272: }
3273: }
1.369.2.83.2. (raeburn 3274:): &js_escape(\$fallback);
1.350 raeburn 3275: if (!$checkroles) {
3276: $js .= " var disallow = new Array();\n".
3277: " rolecheck = 0;\n";
3278: }
1.273 droeschl 3279: return <<"END";
1.235 raeburn 3280: <script type="text/javascript">
1.273 droeschl 3281: //<![CDATA[
1.369.2.30 raeburn 3282: function adhocRole(newrole) {
1.239 raeburn 3283: $js
1.235 raeburn 3284: if (newrole == '') {
1.350 raeburn 3285: return;
1.235 raeburn 3286: }
1.239 raeburn 3287: var fullrole = newrole+'./$cdom/$cnum';
3288: var selidx = '';
3289: for (var i=0; i<rolenames.length; i++) {
3290: if (rolenames[i] == newrole) {
3291: selidx = i;
3292: }
3293: }
1.350 raeburn 3294: if (rolecheck > 0) {
3295: for (var i=0; i<disallow.length; i++) {
3296: if (disallow[i] == newrole) {
1.369.2.83.2. (raeburn 3297:): if (confirm("$lt{'role'}\\n$displaymsg")) {
3298:): document.rolechooser.destinationurl.value = '$fallback';
1.350 raeburn 3299: } else {
3300: return;
3301: }
3302: }
3303: }
3304: }
1.239 raeburn 3305: var secok = 1;
3306: var secchoice = '';
3307: if (selidx >= 0) {
3308: if (numsec[selidx] > 1) {
3309: secok = 0;
3310: var numrolesec = rolesections[selidx].length;
3311: var msgidx = numsec[selidx] - numrolesec;
1.339 raeburn 3312: secchoice = prompt("$lt{'this'} "+secpick[msgidx]+"\\n$lt{'avai'} "+roleseclist[selidx],"");
1.239 raeburn 3313: if (secchoice == '') {
3314: if (msgidx > 0) {
3315: secok = 1;
3316: }
3317: } else {
3318: for (var j=0; j<rolesections[selidx].length; j++) {
3319: if (rolesections[selidx][j] == secchoice) {
3320: secok = 1;
3321: }
3322: }
3323: }
3324: } else {
3325: if (rolesections[selidx].length == 1) {
3326: secchoice = rolesections[selidx][0];
3327: }
3328: }
3329: }
3330: if (secok == 1) {
3331: if (secchoice != '') {
3332: fullrole += '/'+secchoice;
3333: }
3334: } else {
3335: document.rolechooser.elements[roleitem].selectedIndex = 0;
3336: if (secchoice != null) {
3337: alert("$lt{'youe'} \\""+secchoice+"\\".\\n $lt{'plst'}");
3338: }
3339: return;
3340: }
3341: if (fullrole == "$env{'request.role'}") {
1.235 raeburn 3342: return;
3343: }
3344: itemid = retrieveIndex('gotorole');
3345: if (itemid != -1) {
1.239 raeburn 3346: document.rolechooser.elements[itemid].name = fullrole;
1.235 raeburn 3347: }
1.369.2.30 raeburn 3348: document.rolechooser.switchrole.value = fullrole;
1.235 raeburn 3349: document.rolechooser.selectrole.value = '1';
3350: document.rolechooser.submit();
3351: return;
3352: }
3353:
3354: function retrieveIndex(item) {
3355: for (var i=0;i<document.rolechooser.elements.length;i++) {
3356: if (document.rolechooser.elements[i].name == item) {
3357: return i;
3358: }
3359: }
3360: return -1;
3361: }
1.273 droeschl 3362: // ]]>
1.235 raeburn 3363: </script>
3364: END
3365: }
3366:
1.350 raeburn 3367: sub required_privs {
3368: my $privs = {
1.369.2.61 raeburn 3369: '/adm/parmset' => 'opa,vpa',
3370: '/adm/courseprefs' => 'opa,vpa',
1.350 raeburn 3371: '/adm/whatsnew' => 'whn',
1.369.2.65 raeburn 3372: '/adm/populate' => 'cst,vpa,vcl',
1.350 raeburn 3373: '/adm/trackstudent' => 'vsa',
1.369.2.61 raeburn 3374: '/adm/statistics' => 'mgr,vgr',
3375: '/adm/setblock' => 'dcm,vcb',
1.367 raeburn 3376: '/adm/coursedocs' => 'mdc',
1.350 raeburn 3377: };
3378: unless ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'spreadsheet') {
1.364 raeburn 3379: $privs->{'/adm/classcalc'} = 'vgr',
3380: $privs->{'/adm/assesscalc'} = 'vgr',
3381: $privs->{'/adm/studentcalc'} = 'vgr';
1.350 raeburn 3382: }
3383: return $privs;
3384: }
1.235 raeburn 3385:
1.369.2.10 raeburn 3386: sub countdown_timer {
3387: if (($env{'request.course.id'}) && ($env{'request.symb'} ne '') &&
1.369.2.24 raeburn 3388: ($env{'request.filename'}=~/$LONCAPA::assess_re/)) {
3389: my ($type,$hastimeleft,$slothastime);
3390: my $now = time;
3391: if ($env{'request.filename'} =~ /\.task$/) {
3392: $type = 'Task';
3393: } else {
3394: $type = 'problem';
3395: }
3396: my ($status,$accessmsg,$slot_name,$slot) =
3397: &Apache::lonhomework::check_slot_access('0',$type);
3398: if ($slot_name ne '') {
3399: if (ref($slot) eq 'HASH') {
3400: if (($slot->{'starttime'} < $now) &&
3401: ($slot->{'endtime'} > $now)) {
3402: $slothastime = 1;
3403: }
3404: }
3405: }
3406: if ($status ne 'CAN_ANSWER') {
3407: return;
3408: }
1.369.2.10 raeburn 3409: my $duedate = &Apache::lonnet::EXT("resource.0.duedate");
1.369.2.12 raeburn 3410: my @interval=&Apache::lonnet::EXT("resource.0.interval");
1.369.2.83.2. (raeburn 3411:): my ($timelimit,$usesdone,$donebuttontext,$proctor,$secret);
1.369.2.13 raeburn 3412: if (@interval > 1) {
1.369.2.83.2. (raeburn 3413:): ($timelimit,my $donesuffix) = split(/_/,$interval[0],2);
3414:): if ($donesuffix =~ /^done\:([^\:]+)\:(.*)$/) {
3415:): $usesdone = 'done';
3416:): $donebuttontext = $1;
3417:): (undef,$proctor,$secret) = split(/_/,$2);
3418:): } elsif ($donesuffix =~ /^done(|_.+)$/) {
3419:): $donebuttontext = &mt('Done');
3420:): ($usesdone,$proctor,$secret) = split(/_/,$donesuffix);
3421:): }
1.369.2.13 raeburn 3422: my $first_access=&Apache::lonnet::get_first_access($interval[1]);
3423: if ($first_access > 0) {
1.369.2.83.2. (raeburn 3424:): if ($first_access+$timelimit > time) {
1.369.2.13 raeburn 3425: $hastimeleft = 1;
3426: }
3427: }
3428: }
1.369.2.12 raeburn 3429: if (($duedate && $duedate > time) ||
1.369.2.24 raeburn 3430: (!$duedate && $hastimeleft) ||
3431: ($slot_name ne '' && $slothastime)) {
1.369.2.83.2. (raeburn 3432:): my ($collapse,$expand,$alttxt,$title,$currdisp,$donebutton);
1.369.2.24 raeburn 3433: if ((@interval > 1 && $hastimeleft) ||
3434: ($type eq 'Task' && $slothastime)) {
1.369.2.10 raeburn 3435: $currdisp = 'inline';
3436: $collapse = '► ';
1.369.2.83.2. (raeburn 3437:): if ((@interval > 1) && ($hastimeleft)) {
3438:): if ($usesdone eq 'done') {
3439:): $donebutton = &done_button_js($interval[1],'','',$proctor,$donebuttontext);
3440:): }
3441:): }
1.369.2.10 raeburn 3442: } else {
3443: $currdisp = 'none';
3444: $expand = '◄ ';
3445: }
3446: unless ($env{'environment.icons'} eq 'iconsonly') {
1.369.2.11 raeburn 3447: $alttxt = &mt('Timer');
3448: $title = $alttxt.' ';
1.369.2.10 raeburn 3449: }
3450: my $desc = &mt('Countdown to due date/time');
3451: return <<END;
1.369.2.83.2. (raeburn 3452:): $donebutton
1.369.2.10 raeburn 3453: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
3454: <span id="ddcountcollapse" class="LC_menubuttons_inline_text">
3455: $collapse
1.369.2.11 raeburn 3456: </span></a>
1.369.2.10 raeburn 3457: <span id="duedatecountdown" class="LC_menubuttons_inline_text" style="display: $currdisp;"></span>
3458: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
3459: <span id="ddcountexpand" class="LC_menubuttons_inline_text" >$expand</span>
1.369.2.11 raeburn 3460: <img src="/res/adm/pages/timer.png" title="$desc" class="LC_icon" alt="$alttxt" /><span class="LC_menubuttons_inline_text">$title</span></a>
1.369.2.10 raeburn 3461: END
3462: }
3463: }
3464: return;
3465: }
3466:
1.369.2.83.2. (raeburn 3467:): sub linkprot_exit {
3468:): if (($env{'request.course.id'}) && ($env{'request.deeplink.login'})) {
3469:): my ($deeplink_symb,$deeplink);
3470:): my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
3471:): my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3472:): if (($cnum ne '') && ($cdom ne '')) {
3473:): $deeplink_symb = &Apache::loncommon::deeplink_login_symb($cnum,$cdom);
3474:): if ($deeplink_symb) {
3475:): if ($deeplink_symb =~ /\.(page|sequence)$/) {
3476:): my $mapname = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($deeplink_symb))[2]);
3477:): my $navmap = Apache::lonnavmaps::navmap->new();
3478:): if (ref($navmap)) {
3479:): $deeplink = $navmap->get_mapparam(undef,$mapname,'0.deeplink');
3480:): }
3481:): } else {
3482:): $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$deeplink_symb);
3483:): }
3484:): if ($deeplink ne '') {
3485:): my ($state,$others,$listed,$scope,$protect,$display,$target,$exit) = split(/,/,$deeplink);
3486:): my %lt = &Apache::lonlocal::texthash(
3487:): title => 'Exit Tool',
3488:): okdone => 'Click "OK" to exit embedded tool',
3489:): cancel => 'Click "Cancel" to continue working.',
3490:): ok => 'OK',
3491:): exit => 'Cancel',
3492:): );
3493:): if ($exit) {
3494:): my ($show,$text) = split(/:/,$exit);
3495:): unless ($show eq 'no') {
3496:): my $height = 250;
3497:): my $width = 300;
3498:): my $exitbuttontext;
3499:): if ($text eq '') {
3500:): $exitbuttontext = &mt('Exit Tool');
3501:): } else {
3502:): $exitbuttontext = $text;
3503:): }
3504:): return <<END;
3505:): <form method="post" name="LCexitButton" action="/adm/linkexit">
3506:): <input type="hidden" name="LC_deeplink_exit" value="" />
3507:): <button id="LC_exit-confirm-opener" type="button">$exitbuttontext</button>
3508:): </form>
3509:):
3510:): <div id="LC_exit-confirm" title="$lt{'title'}">
3511:): <p>$lt{'okdone'} $lt{'cancel'}</p>
3512:): </div>
3513:):
3514:): <script type="text/javascript">
3515:): // <![CDATA[
3516:): \$( "#LC_exit-confirm" ).dialog({ autoOpen: false });
3517:): \$( "#LC_exit-confirm-opener" ).click(function() {
3518:): \$( "#LC_exit-confirm" ).dialog( "open" );
3519:): \$( "#LC_exit-confirm" ).dialog({
3520:): resizable: false,
3521:): height: $height,
3522:): width: $width,
3523:): modal: true,
3524:): buttons: [
3525:): {
3526:): text: "$lt{'ok'}",
3527:): click: function() {
3528:): \$( this ).dialog( "close" );
3529:): \$( '[name="LC_deeplink_exit"]' )[0].value = 'true';
3530:): \$( '[name="LCexitButton"]' )[0].submit();
3531:): },
3532:): },
3533:): {
3534:): text: "$lt{'exit'}",
3535:): click: function() {
3536:): \$( this ).dialog( "close" );
3537:): },
3538:): },
3539:): ],
3540:): });
3541:): });
3542:): // ]]>
3543:): </script>
3544:):
3545:): END
3546:): }
3547:): }
3548:): }
3549:): }
3550:): }
3551:): }
3552:): return;
3553:): }
3554:):
1.2 www 3555: # ================================================================ Main Program
3556:
1.16 harris41 3557: BEGIN {
1.166 albertel 3558: if (! defined($readdesk)) {
1.283 droeschl 3559: {
3560: my $tabfile = $Apache::lonnet::perlvar{'lonTabDir'}.'/mydesk.tab';
3561: if ( CORE::open( my $config,"<$tabfile") ) {
3562: while (my $configline=<$config>) {
3563: $configline=(split(/\#/,$configline))[0];
3564: $configline=~s/^\s+//;
3565: chomp($configline);
1.209 www 3566: if ($configline=~/^cat\:/) {
1.283 droeschl 3567: my @entries=split(/\:/,$configline);
3568: $category_positions{$entries[2]}=$entries[1];
3569: $category_names{$entries[2]}=$entries[3];
3570: } elsif ($configline=~/^prim\:/) {
1.369.2.83.2. (raeburn 3571:): my @entries = (split(/\:/, $configline))[1..7];
1.369.2.30 raeburn 3572: push(@primary_menu,\@entries);
1.369.2.3 raeburn 3573: } elsif ($configline=~/^primsub\:/) {
1.369.2.83.2. (raeburn 3574:): my ($parent,@entries) = (split(/\:/, $configline))[1..5];
1.369.2.30 raeburn 3575: push(@{$primary_submenu{$parent}},\@entries);
1.283 droeschl 3576: } elsif ($configline=~/^scnd\:/) {
1.369.2.83.2. (raeburn 3577:): my @entries = (split(/\:/, $configline))[1..6];
1.369.2.30 raeburn 3578: push(@secondary_menu,\@entries);
1.369.2.5 raeburn 3579: } elsif ($configline=~/^scndsub\:/) {
3580: my ($parent,@entries) = (split(/\:/, $configline))[1..4];
1.369.2.30 raeburn 3581: push(@{$secondary_submenu{$parent}},\@entries);
1.283 droeschl 3582: } elsif ($configline) {
3583: push(@desklines,$configline);
3584: }
3585: }
3586: CORE::close($config);
3587: }
3588: }
3589: $readdesk='done';
1.2 www 3590: }
3591: }
1.30 www 3592:
1.1 www 3593: 1;
3594: __END__
3595:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>