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