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