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