File:
[LON-CAPA] /
loncom /
interface /
lonmenu.pm
Revision
1.432:
download - view:
text,
annotated -
select for diffs
Thu Apr 16 10:13:25 2015 UTC (9 years, 4 months ago) by
droeschl
Branches:
MAIN
CVS tags:
HEAD
- rename: Insert Menu -> Templates
- translation of the menu title removed from create_submenu in order to allow more than just (translateable) strings for the menu title (e.g. custom html including images).
The calling function is now responsible for translation of the menu title.
All existing calls to create_submenu have been adjusted.
- moved special treatment of the Personal menu from create_submenu to primary_menu
- added help icon to Help submenu in XML editor.
1: # The LearningOnline Network with CAPA
2: # Routines to control the menu
3: #
4: # $Id: lonmenu.pm,v 1.432 2015/04/16 10:13:25 droeschl 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)
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: 4 - (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:
131: The underlying datastructure used in (d) contains data from mydesk.tab.
132: It consists of an array which has an array for each item appearing in
133: the menu (e.g. [["link", "title", "condition"]] for a single-item menu).
134: create_submenu() supports also the creation of XHTML for nested dropdown
135: menus represented by unordered lists. This is done by replacing the
136: scalar used for the link with an arrayreference containing the menuitems
137: for the nested menu. This can be done recursively so that the next menu
138: may also contain nested submenus.
139:
140: Example:
141: [ # begin of datastructure
142: ["/home/", "Home", "condition1"], # 1st item of the 1st layer menu
143: [ # 2nd item of the 1st layer menu
144: [ # anon. array for nested menu
145: ["/path1", "Path1", undef], # 1st item of the 2nd layer menu
146: ["/path2", "Path2", undef], # 2nd item of the 2nd layer menu
147: [ # 3rd item of the 2nd layer menu
148: [[...], [...], ..., [...]], # containing another menu layer
149: "Sub-Sub-Menu", # title for this container
150: undef
151: ]
152: ], # end of array/nested menu
153: "Sub-Menu", # title for the container item
154: undef
155: ] # end of 2nd item of the 1st layer menu
156: ]
157:
158: =item innerregister()
159:
160: This gets called in order to register a URL in the body of the document
161:
162: =item clear()
163:
164: =item switch()
165:
166: Switch a button or create a link
167: Switch acts on the javascript that is executed when a button is clicked.
168: The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
169:
170: =item secondlevel()
171:
172: =item openmenu()
173:
174: =item inlinemenu()
175:
176: =item rawconfig()
177:
178: =item utilityfunctions()
179:
180: Output from this routine is a number of javascript functions called by
181: items in the inline menu, and in some cases items in the Main Menu page.
182:
183: =item serverform()
184:
185: =item constspaceform()
186:
187: =item get_nav_status()
188:
189: =item hidden_button_check()
190:
191: =item roles_selector()
192:
193: =item jump_to_role()
194:
195: =back
196:
197: =cut
198:
199: package Apache::lonmenu;
200:
201: use strict;
202: use Apache::lonnet;
203: use Apache::lonhtmlcommon();
204: use Apache::loncommon();
205: use Apache::lonenc();
206: use Apache::lonlocal;
207: use Apache::lonmsg();
208: use LONCAPA qw(:DEFAULT :match);
209: use HTML::Entities();
210: use Apache::lonwishlist();
211:
212: use vars qw(@desklines %category_names %category_members %category_positions
213: $readdesk @primary_menu %primary_submenu @secondary_menu);
214:
215: my @inlineremote;
216:
217: sub prep_menuitem {
218: my ($menuitem) = @_;
219: return '' unless(ref($menuitem) eq 'ARRAY');
220: my $link;
221: if ($$menuitem[1]) { # graphical Link
222: $link = "<img class=\"LC_noBorder\""
223: . " src=\"" . &Apache::loncommon::lonhttpdurl($$menuitem[1]) . "\""
224: . " alt=\"" . &mt($$menuitem[2]) . "\" />";
225: } else { # textual Link
226: $link = &mt($$menuitem[3]);
227: }
228: return '<li><a'
229: # highlighting for new messages
230: . ( $$menuitem[4] eq 'newmsg' ? ' class="LC_new_message"' : '')
231: . qq| href="$$menuitem[0]" target="_top">$link</a></li>|;
232: }
233:
234: # primary_menu() evaluates @primary_menu and returns a two item array,
235: # with the array elements containing XHTML for the left and right sides of
236: # the menu that contains the following links:
237: # Personal, About, Message, Roles, Help, Logout
238: # @primary_menu is filled within the BEGIN block of this module with
239: # entries from mydesk.tab
240: sub primary_menu {
241: my (%menu);
242: # each element of @primary contains following array:
243: # (link url, icon path, alt text, link text, condition, position)
244: my $public;
245: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
246: || (($env{'user.name'} eq '') && ($env{'user.domain'} eq ''))) {
247: $public = 1;
248: }
249: foreach my $menuitem (@primary_menu) {
250: # evaluate conditions
251: next if ref($menuitem) ne 'ARRAY'; #
252: next if $$menuitem[4] eq 'nonewmsg' # show links depending on
253: && &Apache::lonmsg::mynewmail(); # whether a new msg
254: next if $$menuitem[4] eq 'newmsg' # arrived or not
255: && !&Apache::lonmsg::mynewmail(); #
256: next if $$menuitem[4] !~ /public/ ##we've a public user,
257: && $public; ##who should not see all
258: ##links
259: next if $$menuitem[4] eq 'onlypublic'# hide links which are
260: && !$public; # only visible to public
261: # users
262: next if $$menuitem[4] eq 'roles' ##show links depending on
263: && &Apache::loncommon::show_course(); ##term 'Courses' or
264: next if $$menuitem[4] eq 'courses' ##'Roles' wanted
265: && !&Apache::loncommon::show_course(); ##
266:
267: my $title = $menuitem->[3];
268: my $position = $menuitem->[5];
269: if ($position eq '') {
270: $position = 'right';
271: }
272: if (defined($primary_submenu{$title})) {
273: my ($link,$target);
274: if ($menuitem->[0] ne '') {
275: $link = $menuitem->[0];
276: $target = '_top';
277: } else {
278: $link = '#';
279: }
280: my @primsub;
281: if (ref($primary_submenu{$title}) eq 'ARRAY') {
282: foreach my $item (@{$primary_submenu{$title}}) {
283: next if (($item->[2] eq 'wishlist') && (!$env{'user.adv'}));
284: next if ((($item->[2] eq 'portfolio') ||
285: ($item->[2] eq 'blog')) &&
286: (!&Apache::lonnet::usertools_access('','',$item->[2],
287: undef,'tools')));
288: push(@primsub,$item);
289: }
290: if (@primsub > 0) {
291: if ($title eq 'Personal' && $env{'user.name'} && $env{'user.domain'} ) {
292: $title = &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'});
293: } else {
294: $title = &mt($title);
295: }
296: $menu{$position} .= &create_submenu($link,$target,$title,\@primsub,1);
297: } elsif ($link) {
298: $menu{$position} .= '<li><a href="'.$link.'" target="'.$target.'">'.&mt($title).'</a></li>';
299: }
300: }
301: } elsif ($$menuitem[3] eq 'Help') { # special treatment for helplink
302: if ($public) {
303: my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
304: my $defdom = &Apache::lonnet::default_login_domain();
305: my $to = &Apache::loncommon::build_recipient_list(undef,
306: 'helpdeskmail',
307: $defdom,$origmail);
308: if ($to ne '') {
309: $menu{$position} .= &prep_menuitem($menuitem);
310: }
311: } else {
312: $menu{$position} .= '<li>'.&Apache::loncommon::top_nav_help('Help').'</li>';
313: }
314: } else {
315: $menu{$position} .= prep_menuitem($menuitem);
316: }
317: }
318: my @output = ('','');
319: if ($menu{'left'} ne '') {
320: $output[0] = "<ol class=\"LC_primary_menu LC_floatleft\">$menu{'left'}</ol>";
321: }
322: if ($menu{'right'} ne '') {
323: $output[1] = "<ol class=\"LC_primary_menu LC_floatright LC_right\">$menu{'right'}</ol>";
324: }
325: return @output;
326: }
327:
328: #returns hashref {user=>'',dom=>''} containing:
329: # own name, domain if user is au
330: # name, domain of parent author if user is ca or aa
331: #empty return if user is not an author or not on homeserver
332: #
333: #TODO this should probably be moved somewhere more central
334: #since it can be used by different parts of the system
335: sub getauthor{
336: return unless $env{'request.role'}=~/^(ca|aa|au)/; #nothing to do if user isn't some kind of author
337:
338: #co- or assistent author?
339: my ($dom, $user) = ($env{'request.role'} =~ /^(?:ca|aa)\.\/($match_domain)\/($match_username)$/)
340: ? ($1, $2) #domain, username of the parent author
341: : @env{ ('request.role.domain', 'user.name') }; #own domain, username
342:
343: # current server == home server?
344: my $home = &Apache::lonnet::homeserver($user,$dom);
345: foreach (&Apache::lonnet::current_machine_ids()){
346: return {user => $user, dom => $dom} if $_ eq $home;
347: }
348:
349: # if wrong server
350: return;
351: }
352:
353: sub secondary_menu {
354: my ($httphost) = @_;
355: my $menu;
356:
357: my $crstype = &Apache::loncommon::course_type();
358: my $crs_sec = $env{'request.course.id'} . ($env{'request.course.sec'}
359: ? "/$env{'request.course.sec'}"
360: : '');
361: my $canedit = &Apache::lonnet::allowed('mdc', $env{'request.course.id'});
362: my $canviewroster = $env{'course.'.$env{'request.course.id'}.'.student_classlist_view'};
363: if ($canviewroster eq 'disabled') {
364: undef($canviewroster);
365: }
366: my $canviewgrps = &Apache::lonnet::allowed('vcg', $crs_sec);
367: my $canmodifyuser = &Apache::lonnet::allowed('cst', $crs_sec);
368: my $canviewwnew = &Apache::lonnet::allowed('whn', $crs_sec);
369: my $canmodpara = &Apache::lonnet::allowed('opa', $crs_sec);
370: my $canvgr = &Apache::lonnet::allowed('vgr', $crs_sec);
371: my $canmgr = &Apache::lonnet::allowed('mgr', $crs_sec);
372: my $author = &getauthor();
373:
374: my ($cdom,$cnum,$showsyllabus,$showfeeds,$showresv);
375: if ($env{'request.course.id'}) {
376: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
377: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
378: if ($canedit) {
379: $showsyllabus = 1;
380: $showfeeds = 1;
381: } else {
382: unless (&Apache::lonnet::is_on_map("public/$cdom/$cnum/syllabus")) {
383: if (($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'}) ||
384: ($env{'course.'.$env{'request.course.id'}.'.uploadedsyllabus'}) ||
385: ($env{'course.'.$env{'request.course.id'}.'.updatedsyllabus'}) ||
386: ($env{'request.course.syllabustime'})) {
387: $showsyllabus = 1;
388: }
389: }
390: if ($env{'request.course.feeds'}) {
391: $showfeeds = 1;
392: }
393: }
394: unless ($canmgr) {
395: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
396: if (keys(%slots) > 0) {
397: $showresv = 1;
398: }
399: }
400: }
401:
402: my ($canmodifycoauthor);
403: if ($env{'request.role'} eq "au./$env{'user.domain'}/") {
404: my $extent = "$env{'user.domain'}/$env{'user.name'}";
405: if ((&Apache::lonnet::allowed('cca',$extent)) ||
406: (&Apache::lonnet::allowed('caa',$extent))) {
407: $canmodifycoauthor = 1;
408: }
409: }
410:
411: my %groups = &Apache::lonnet::get_active_groups(
412: $env{'user.domain'}, $env{'user.name'},
413: $env{'course.' . $env{'request.course.id'} . '.domain'},
414: $env{'course.' . $env{'request.course.id'} . '.num'});
415:
416: my ($roleswitcher_js,$roleswitcher_form);
417:
418: foreach my $menuitem (@secondary_menu) {
419: # evaluate conditions
420: next if ref($menuitem) ne 'ARRAY';
421: next if $$menuitem[4] ne 'always'
422: && ($$menuitem[4] ne 'author' && $$menuitem[4] ne 'cca')
423: && !$env{'request.course.id'};
424: next if $$menuitem[4] =~ /^mdc/
425: && !$canedit;
426: next if $$menuitem[4] eq 'nvgr'
427: && $canvgr;
428: next if $$menuitem[4] eq 'vgr'
429: && !$canvgr;
430: next if $$menuitem[4] eq 'cst'
431: && !$canmodifyuser;
432: next if $$menuitem[4] eq 'ncst'
433: && ($canmodifyuser || !$canviewroster);
434: next if $$menuitem[4] eq 'mgr'
435: && !$canmgr;
436: next if $$menuitem[4] eq 'showresv'
437: && !$showresv;
438: next if $$menuitem[4] eq 'whn'
439: && !$canviewwnew;
440: next if $$menuitem[4] eq 'opa'
441: && !$canmodpara;
442: next if $$menuitem[4] =~ /showgroups$/
443: && !$canviewgrps
444: && !%groups;
445: next if $$menuitem[4] eq 'showsyllabus'
446: && !$showsyllabus;
447: next if $$menuitem[4] eq 'showfeeds'
448: && !$showfeeds;
449: next if $$menuitem[4] eq 'author'
450: && !$author;
451: next if $$menuitem[4] eq 'cca'
452: && !$canmodifycoauthor;
453:
454: if ($$menuitem[3] eq 'Roles' && $env{'request.course.id'}) {
455: # special treatment for role selector
456: ($roleswitcher_js,$roleswitcher_form,my $switcher) =
457: &roles_selector(
458: $env{'course.' . $env{'request.course.id'} . '.domain'},
459: $env{'course.' . $env{'request.course.id'} . '.num'},
460: $httphost
461: );
462: $menu .= $switcher;
463: } else {
464: if ($$menuitem[3] eq 'Syllabus' && $env{'request.course.id'}) {
465: my $url = $$menuitem[0];
466: $url =~ s{\[cdom\]/\[cnum\]}{$cdom/$cnum};
467: if (&Apache::lonnet::is_on_map($url)) {
468: unless ($$menuitem[0] =~ /\?register=1/) {
469: $$menuitem[0] .= '?register=1';
470: }
471: } else {
472: $$menuitem[0] =~ s{\?register=1}{};
473: }
474: }
475: $menu .= &prep_menuitem(\@$menuitem);
476: }
477: }
478: if ($menu =~ /\[url\].*\[symb\]/) {
479: my $escurl = &escape( &Apache::lonenc::check_encrypt(
480: $env{'request.noversionuri'}));
481:
482: my $escsymb = &escape( &Apache::lonenc::check_encrypt(
483: $env{'request.symb'}));
484:
485: if ( $env{'request.state'} eq 'construct'
486: and ( $env{'request.noversionuri'} eq ''
487: || !defined($env{'request.noversionuri'})))
488: {
489: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
490: ($escurl = $env{'request.filename'}) =~ s{^\Q$londocroot\E}{};
491: $escurl = &escape($escurl);
492: }
493: $menu =~ s/\[url\]/$escurl/g;
494: $menu =~ s/\[symb\]/$escsymb/g;
495: }
496: $menu =~ s/\[uname\]/$$author{user}/g;
497: $menu =~ s/\[udom\]/$$author{dom}/g;
498: if ($showsyllabus || $showfeeds) {
499: $menu =~ s/\[cnum\]/$cnum/g;
500: $menu =~ s/\[cdom\]/$cdom/g;
501: }
502: if ($menu) {
503: $menu = "<ul id=\"LC_secondary_menu\">$menu</ul>";
504: }
505: if ($roleswitcher_form) {
506: $menu .= "\n$roleswitcher_js\n$roleswitcher_form";
507: }
508: return $menu;
509: }
510:
511: sub create_submenu {
512: my ($link,$target,$title,$submenu,$translate) = @_;
513: return unless (ref($submenu) eq 'ARRAY');
514: my $disptarget;
515: if ($target ne '') {
516: $disptarget = ' target="'.$target.'"';
517: }
518: my $menu = '<li class="LC_hoverable">'.
519: '<a href="'.$link.'"'.$disptarget.'>'.
520: '<span class="LC_nobreak">'.$title.
521: '<span class="LC_fontsize_small" style="font-weight:normal;">'.
522: ' ▼</span></span></a>'.
523: '<ul>';
524:
525: # $link and $title are only used in the initial string written in $menu
526: # as seen above, not needed for nested submenus
527: $menu .= &build_submenu($target, $submenu, $translate, '1');
528: $menu .= '</ul></li>';
529:
530: return $menu;
531: }
532:
533: # helper routine for create_submenu
534: # build the dropdown (and nested submenus) recursively
535: # see perldoc create_submenu documentation for further information
536: sub build_submenu {
537: my ($target, $submenu, $translate, $first_level) = @_;
538: if (!defined(@{$submenu})) {
539: return '';
540: }
541:
542: my $menu = '';
543: my $count = 0;
544: my $numsub = scalar(@{$submenu});
545: foreach my $item (@{$submenu}) {
546: $count ++;
547: if (ref($item) eq 'ARRAY') {
548: my $href = $item->[0];
549: my $bordertop;
550: my $borderbot;
551: my $title;
552:
553: if ($translate) {
554: $title = &mt($item->[1]);
555: } else {
556: $title = $item->[1];
557: }
558:
559: if ($count == 1 && !$first_level) {
560: $bordertop = 'border-top: 1px solid black;';
561: }
562: if ($count == $numsub) {
563: $borderbot = 'border-bottom: 1px solid black;';
564: }
565:
566: # href is a reference to another submenu
567: if (ref($href) eq 'ARRAY') {
568: $menu .= '<li style="margin:0;padding:0;'.$bordertop . $borderbot . '">';
569: $menu .= '<p><span class="LC_primary_menu_innertitle">'
570: . $title . '</span><span class="LC_primary_menu_innerarrow">▶</span></p>';
571: $menu .= '<ul>';
572: $menu .= &build_submenu($target, $href, $translate);
573: $menu .= '</ul>';
574: $menu .= '</li>';
575: } else { # href is the actual hyperlink and does not represent another submenu
576: # for the current menu title
577: if ($href =~ /(aboutme|rss\.html)$/) {
578: next unless (($env{'user.name'} ne '') && ($env{'user.domain'} ne ''));
579: $href =~ s/\[domain\]/$env{'user.domain'}/g;
580: $href =~ s/\[user\]/$env{'user.name'}/g;
581: }
582: unless (($href eq '') || ($href =~ /^\#/)) {
583: $target = ' target="_top"';
584: }
585:
586: $menu .= '<li style="margin:0;padding:0;'. $bordertop . $borderbot .'">';
587: $menu .= '<a href="'.$href.'"'.$target.'>' . $title . '</a>';
588: $menu .= '</li>';
589: }
590: }
591: }
592: return $menu;
593: }
594:
595: sub innerregister {
596: my ($forcereg,$bread_crumbs,$group) = @_;
597: my $const_space = ($env{'request.state'} eq 'construct');
598: my $is_const_dir = 0;
599:
600: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
601:
602: $env{'request.registered'} = 1;
603:
604: undef(@inlineremote);
605:
606: my ($mapurl,$resurl);
607:
608: if ($env{'request.course.id'}) {
609: if ($env{'request.symb'}) {
610: ($mapurl, my $rid, $resurl) = &Apache::lonnet::decode_symb(&Apache::lonnet::symbread());
611: my $coursetitle = $env{'course.'.$env{'request.course.id'}.'.description'};
612:
613: my $maptitle = &Apache::lonnet::gettitle($mapurl);
614: my $restitle = &Apache::lonnet::gettitle(&Apache::lonnet::symbread());
615:
616: #SD
617: #course_type only Course and Community?
618: #
619: my @crumbs;
620: unless (($forcereg) &&
621: ($env{'request.noversionuri'} eq '/adm/navmaps') &&
622: ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'})) {
623: @crumbs = ({text => Apache::loncommon::course_type()
624: . ' Contents',
625: href => "Javascript:gopost('/adm/navmaps','')"});
626: }
627: if ($mapurl ne $env{'course.'.$env{'request.course.id'}.'.url'}) {
628: push(@crumbs, {text => '...',
629: no_mt => 1});
630: }
631:
632: push @crumbs, {text => $maptitle, no_mt => 1} if ($maptitle
633: && $maptitle ne 'default.sequence'
634: && $maptitle ne $coursetitle);
635:
636: push @crumbs, {text => $restitle, no_mt => 1} if $restitle;
637: &Apache::lonhtmlcommon::clear_breadcrumbs();
638: &Apache::lonhtmlcommon::add_breadcrumb(@crumbs);
639: } else {
640: $resurl = $env{'request.noversionuri'};
641: my $courseurl = &Apache::lonnet::courseid_to_courseurl($env{'request.course.id'});
642: my $crstype = &Apache::loncommon::course_type();
643: my $title = &mt('View Resource');
644: if ($resurl =~ m{^\Q/uploaded$courseurl/supplemental/\E(default|\d+)/}) {
645: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['folderpath','title']);
646: &Apache::lonhtmlcommon::clear_breadcrumbs();
647: if ($env{'form.title'}) {
648: $title = $env{'form.title'};
649: }
650: my $trail;
651: if ($env{'form.folderpath'}) {
652: &prepare_functions($resurl,$forcereg,$group,undef,undef,1);
653: ($trail) =
654: &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
655: } else {
656: &Apache::lonhtmlcommon::add_breadcrumb(
657: {text => "Supplemental $crstype Content",
658: href => "javascript:gopost('/adm/supplemental','')"});
659: $title = &mt('View Resource');
660: ($trail) =
661: &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
662: }
663: return $trail;
664: } elsif ($resurl =~ m{^\Q/uploaded$courseurl/portfolio/syllabus/}) {
665: &Apache::lonhtmlcommon::clear_breadcrumbs();
666: &prepare_functions('/public'.$courseurl."/syllabus",
667: $forcereg,$group,undef,undef,1);
668: $title = &mt('Syllabus File');
669: my ($trail) =
670: &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$title,1);
671: return $trail;
672: }
673: unless ($env{'request.state'} eq 'construct') {
674: &Apache::lonhtmlcommon::clear_breadcrumbs();
675: &Apache::lonhtmlcommon::add_breadcrumb({text => 'View Resource'});
676: }
677: }
678: } elsif (! $const_space){
679: #a situation when we're looking at a resource outside of context of a
680: #course or construction space (e.g. with cumulative rights)
681: &Apache::lonhtmlcommon::clear_breadcrumbs();
682: unless ($env{'request.noversionuri'} =~ m{^/adm/$match_domain/$match_username/aboutme$}) {
683: &Apache::lonhtmlcommon::add_breadcrumb({text => 'View Resource'});
684: }
685: }
686: # =============================================================================
687: # ============================ This is for URLs that actually can be registered
688: return '' unless ( ($env{'request.noversionuri'}!~m{^/(res/)*adm/})
689: || $forcereg );
690: my ($cdom,$cnum,%perms,$cfile,$switchserver,$home,$forceedit,
691: $forceview,$editbutton);
692: if (($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) ||
693: ($env{'request.role'} !~/^(aa|ca|au)/)) {
694: $editbutton = &prepare_functions($resurl,$forcereg,$group);
695: }
696: if ($editbutton eq '') {
697: $editbutton = &clear(6,1);
698: }
699:
700: #
701: # This applies in course context
702: #
703: if ($env{'request.course.id'}) {
704: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
705: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
706: $perms{'mdc'} = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
707: my @privs;
708: if ($env{'request.symb'} ne '') {
709: if ($env{'request.filename'}=~/$LONCAPA::assess_re/) {
710: push(@privs,('mgr','vgr'));
711: }
712: push(@privs,'opa');
713: }
714: foreach my $priv (@privs) {
715: $perms{$priv} = &Apache::lonnet::allowed($priv,$env{'request.course.id'});
716: if (!$perms{$priv} && $env{'request.course.sec'} ne '') {
717: $perms{$priv} =
718: &Apache::lonnet::allowed($priv,"$env{'request.course.id'}/$env{'request.course.sec'}");
719: }
720: }
721: #
722: # Determine whether or not to show Grades and Submissions buttons
723: #
724: if ($env{'request.symb'} ne '' &&
725: $env{'request.filename'}=~/$LONCAPA::assess_re/) {
726: if ($perms{'mgr'}) {
727: &switch('','',7,2,'pgrd.png','Content Grades','grades[_4]',
728: "gocmd('/adm/grades','gradingmenu')",
729: 'Content Grades');
730: } elsif ($perms{'vgr'}) {
731: &switch('','',7,2,'subm.png','Content Submissions','missions[_1]',
732: "gocmd('/adm/grades','submission')",
733: 'Content Submissions');
734: }
735: }
736: if (($env{'request.symb'} ne '') && ($perms{'opa'})) {
737: &switch('','',7,3,'pparm.png','Content Settings','parms[_2]',
738: "gocmd('/adm/parmset','set')",
739: 'Content Settings');
740: }
741: # End grades/submissions check
742:
743: #
744: # This applies to items inside a folder/page modifiable in the course.
745: #
746: if (($env{'request.symb'}=~/^uploaded/) && ($perms{'mdc'})) {
747: my $text = 'Edit Folder';
748: if (($mapurl =~ /\.page$/) ||
749: ($env{'request.symb'}=~
750: m{uploaded/$cdom/$cnum/default_\d+\.page$})) {
751: $text = 'Edit Page';
752: }
753: &switch('','',7,4,'docs-22x22.png',$text,'parms[_2]',
754: "gocmd('/adm/coursedocs','direct')",
755: 'Folder/Page Content');
756: }
757: # End modifiable folder/page container check
758: }
759: # End course context
760:
761: # Prepare the rest of the buttons
762: my ($menuitems,$got_prt,$got_wishlist);
763: if ($const_space) {
764: #
765: # We are in construction space
766: #
767:
768: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
769: my ($udom,$uname,$thisdisfn) =
770: ($env{'request.filename'}=~m{^\Q$londocroot/priv/\E([^/]+)/([^/]+)/(.*)$});
771: my $currdir = '/priv/'.$udom.'/'.$uname.'/'.$thisdisfn;
772: if ($currdir =~ m-/$-) {
773: $is_const_dir = 1;
774: } else {
775: $currdir =~ s|[^/]+$||;
776: my $cleandisfn = &Apache::loncommon::escape_single($thisdisfn);
777: my $esc_currdir = &Apache::loncommon::escape_single($currdir);
778: #
779: # Probably should be in mydesk.tab
780: #
781: $menuitems=(<<ENDMENUITEMS);
782: s&6&1&list.png&Directory&dir[_1]&golist('$esc_currdir')&List current directory
783: s&6&2&rtrv.png&Retrieve&version[_1]&gocstr('/adm/retrieve','/priv/$udom/$uname/$cleandisfn')&Retrieve old version
784: s&6&3&pub.png&Publish&resource[_3]&gocstr('/adm/publish','/priv/$udom/$uname/$cleandisfn')&Publish this resource
785: s&7&1&del.png&Delete&resource[_2]&gocstr('/adm/cfile?action=delete','/priv/$udom/$uname/$cleandisfn')&Delete this resource
786: s&7&2&prt.png&Print&printout[_1]&gocstr('/adm/printout','/priv/$udom/$uname/$cleandisfn')&Prepare a printable document
787: ENDMENUITEMS
788: }
789: if (ref($bread_crumbs) eq 'ARRAY') {
790: &Apache::lonhtmlcommon::clear_breadcrumbs();
791: foreach my $crumb (@{$bread_crumbs}){
792: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
793: }
794: }
795: } elsif ( defined($env{'request.course.id'}) &&
796: $env{'request.symb'} ne '' ) {
797: #
798: # We are in a course and looking at a registered URL
799: # Should probably be in mydesk.tab
800: #
801: $menuitems=(<<ENDMENUITEMS);
802: c&3&1
803: s&2&1&back.png&&&gopost('/adm/flip','back:'+currentURL)&Previous content resource&&1
804: s&2&3&forw.png&&&gopost('/adm/flip','forward:'+currentURL)&Next content resource&&3
805: c&6&3
806: c&8&1
807: c&8&2
808: s&8&3&prt.png&Print&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
809: ENDMENUITEMS
810: $got_prt = 1;
811: if (($env{'user.adv'}) && ($env{'request.uri'} =~ /^\/res/)
812: && (!$env{'request.enc'})) {
813: # wishlist is only available for users with access to resource-pool
814: # and links can only be set for resources within the resource-pool
815: $menuitems .= (<<ENDMENUITEMS);
816: s&9&1&wishlist-link.png&Stored Links&wishlistlink[_2]&set_wishlistlink()&Save a link for this resource in my personal Stored Links repository&&1
817: ENDMENUITEMS
818: $got_wishlist = 1;
819: }
820:
821: my $currentURL = &Apache::loncommon::get_symb();
822: my ($symb_old,$symb_old_enc) = &Apache::loncommon::clean_symb($currentURL);
823: my $annotation = &Apache::loncommon::get_annotation($symb_old,$symb_old_enc);
824: $menuitems.="s&9&3&";
825: if(length($annotation) > 0){
826: $menuitems.="anot2.png";
827: }else{
828: $menuitems.="anot.png";
829: }
830: $menuitems.="&Notes&&annotate()&";
831: $menuitems.="Make notes and annotations about this resource&&1\n";
832: my $is_mobile;
833: if ($env{'browser.mobile'}) {
834: $is_mobile = 1;
835: }
836:
837: unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme|viewclasslist|portfolio)(\?|$)/) {
838: if ((!$env{'request.enc'}) && ($env{'request.noversionuri'} !~ m{^/adm/wrapper/ext/}) && ($env{'request.noversionuri'} !~ m{^/uploaded/$match_domain/$match_courseid/docs/})) {
839: $menuitems.=(<<ENDREALRES);
840: s&6&3&catalog.png&Info&info[_1]&catalog_info('$is_mobile')&Show Metadata
841: ENDREALRES
842: }
843: unless (($env{'request.noversionuri'} =~ m{^/uploaded/$match_domain/$match_courseid/docs/}) ||
844: ($env{'request.noversionuri'} =~ m{^\Q/adm/wrapper/\E(ext|uploaded)/})) {
845: $menuitems.=(<<ENDREALRES);
846: s&8&1&eval.png&Evaluate&this[_1]&gopost('/adm/evaluate',currentURL,1)&Provide my evaluation of this resource
847: ENDREALRES
848: }
849: unless ($env{'request.noversionuri'} =~ m{^\Q/adm/wrapper/\E(ext|uploaded)/}) {
850: $menuitems.=(<<ENDREALRES);
851: s&8&2&fdbk.png&Communicate&discuss[_1]&gopost('/adm/feedback',currentURL,1)&Provide feedback messages or contribute to the course discussion about this resource
852: ENDREALRES
853: }
854: }
855: }
856: if ($env{'request.uri'} =~ /^\/res/) {
857: unless ($got_prt) {
858: $menuitems .= (<<ENDMENUITEMS);
859: s&8&3&prt.png&Print&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
860: ENDMENUITEMS
861: $got_prt = 1;
862: }
863: unless ($got_wishlist) {
864: if (($env{'user.adv'}) && (!$env{'request.enc'})) {
865: # wishlist is only available for users with access to resource-pool
866: $menuitems .= (<<ENDMENUITEMS);
867: s&9&1&wishlist-link.png&Stored Links&wishlistlink[_2]&set_wishlistlink()&Save a link for this resource in your personal Stored Links repository&&1
868: ENDMENUITEMS
869: $got_wishlist = 1;
870: }
871: }
872: }
873: my $buttons='';
874: foreach (split(/\n/,$menuitems)) {
875: my ($command,@rest)=split(/\&/,$_);
876: my $idx=10*$rest[0]+$rest[1];
877: if (&hidden_button_check() eq 'yes') {
878: if ($idx == 21 ||$idx == 23) {
879: $buttons.=&switch('','',@rest);
880: } else {
881: $buttons.=&clear(@rest);
882: }
883: } else {
884: if ($command eq 's') {
885: $buttons.=&switch('','',@rest);
886: } else {
887: $buttons.=&clear(@rest);
888: }
889: }
890: }
891:
892: my $addremote=0;
893: foreach (@inlineremote) { if ($_ ne '') { $addremote=1; last;} }
894: if ($addremote) {
895:
896: &Apache::lonhtmlcommon::clear_breadcrumb_tools();
897:
898: &Apache::lonhtmlcommon::add_breadcrumb_tool(
899: 'navigation', @inlineremote[21,23]);
900:
901: my $countdown = &countdown_timer();
902: if (&hidden_button_check() eq 'yes') {
903: if ($countdown) {
904: &Apache::lonhtmlcommon::add_breadcrumb_tool('tools',$countdown);
905: }
906: } else {
907: my @tools = @inlineremote[93,91,81,82,83];
908: if ($countdown) {
909: unshift(@tools,$countdown);
910: }
911: &Apache::lonhtmlcommon::add_breadcrumb_tool(
912: 'tools',@tools);
913:
914: #publish button in construction space
915: if ($env{'request.state'} eq 'construct'){
916: &Apache::lonhtmlcommon::add_breadcrumb_tool(
917: 'advtools', $inlineremote[63]);
918: } else {
919: &Apache::lonhtmlcommon::add_breadcrumb_tool(
920: 'tools', $inlineremote[63]);
921: }
922: &advtools_crumbs(@inlineremote);
923: }
924: }
925:
926: return &Apache::lonhtmlcommon::scripttag('', 'start')
927: . &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0)
928: . &Apache::lonhtmlcommon::scripttag('', 'end');
929: }
930:
931: sub get_editbutton {
932: my ($cfile,$home,$switchserver,$forceedit,$forceview,$forcereg) = @_;
933: my $jscall;
934: if (($forceview) && ($env{'form.todocs'})) {
935: my ($folderpath,$command);
936: if ($env{'request.symb'}) {
937: $folderpath = &Apache::loncommon::symb_to_docspath($env{'request.symb'});
938: } elsif ($env{'form.folderpath'} =~ /^supplemental/) {
939: $folderpath = $env{'form.folderpath'};
940: $command = '&forcesupplement=1';
941: }
942: $folderpath = &escape(&HTML::Entities::encode(&escape($folderpath),'<>&"'));
943: $jscall = "go('/adm/coursedocs?folderpath=$folderpath$command')";
944: } else {
945: $jscall = &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,$switchserver,
946: $forceedit,$forcereg,$env{'request.symb'},
947: &escape($env{'form.folderpath'}),
948: &escape($env{'form.title'}),$env{'form.idx'},
949: &escape($env{'form.suppurl'},$env{'form.todocs'}));
950: }
951: if ($jscall) {
952: my $icon = 'pcstr.png';
953: my $label = 'Edit';
954: if ($forceview) {
955: $icon = 'tolastloc.png';
956: $label = 'Exit Editing';
957: }
958: &switch('','',6,1,$icon,$label,'resource[_2]',
959: $jscall,"Edit this resource");
960: return 1;
961: }
962: return;
963: }
964:
965: sub prepare_functions {
966: my ($resurl,$forcereg,$group,$bread_crumbs,$advtools,$docscrumbs) = @_;
967: unless ($env{'request.registered'}) {
968: undef(@inlineremote);
969: }
970: my ($cdom,$cnum,%perms,$cfile,$switchserver,$home,$forceedit,
971: $forceview);
972:
973: if ($env{'request.course.id'}) {
974: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
975: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
976: $perms{'mdc'} = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
977: }
978:
979: my $editbutton = '';
980: #
981: # Determine whether or not to display 'Edit' icon/button
982: #
983: if ($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) {
984: my $file=&Apache::lonnet::declutter($env{'request.filename'});
985: ($cfile,$home,$switchserver,$forceedit,$forceview) =
986: &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
987: &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
988: if (($cfile) && ($home ne '') && ($home ne 'no_host')) {
989: $editbutton = &get_editbutton($cfile,$home,$switchserver,
990: $forceedit,$forceview,$forcereg);
991: }
992: } elsif ((!$env{'request.course.id'}) &&
993: ($env{'user.author'}) && ($env{'request.filename'}) &&
994: ($env{'request.role'} !~/^(aa|ca|au)/)) {
995: #
996: # Currently do not have the role of author or co-author.
997: # Do we have authoring privileges for the resource?
998: #
999: my $file=&Apache::lonnet::declutter($env{'request.filename'});
1000: ($cfile,$home,$switchserver,$forceedit,$forceview) =
1001: &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
1002: &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
1003: if (($cfile) && ($home ne '') && ($home ne 'no_host')) {
1004: $editbutton = &get_editbutton($cfile,$home,$switchserver,
1005: $forceedit,$forceview,$forcereg);
1006: }
1007: } elsif ($env{'request.course.id'}) {
1008: #
1009: # This applies in course context
1010: #
1011: if (($perms{'mdc'}) &&
1012: (($resurl eq "/public/$cdom/$cnum/syllabus") ||
1013: ($resurl =~ m{^/uploaded/$cdom/$cnum/portfolio/syllabus/}))) {
1014: $cfile = $resurl;
1015: $home = &Apache::lonnet::homeserver($cnum,$cdom);
1016: if ($env{'form.forceedit'}) {
1017: $forceview = 1;
1018: } else {
1019: $forceedit = 1;
1020: }
1021: $editbutton = &get_editbutton($cfile,$home,$switchserver,
1022: $forceedit,$forceview,$forcereg);
1023: } elsif (($resurl eq '/adm/extresedit') &&
1024: (($env{'form.symb'}) || ($env{'form.folderpath'}))) {
1025: ($cfile,$home,$switchserver,$forceedit,$forceview) =
1026: &Apache::lonnet::can_edit_resource($resurl,$cnum,$cdom,$resurl,
1027: $env{'form.symb'});
1028: if ($cfile ne '') {
1029: $editbutton = &get_editbutton($cfile,$home,$switchserver,
1030: $forceedit,$forceview,$forcereg,
1031: $env{'form.title'},$env{'form.suppurl'});
1032: }
1033: } elsif (($resurl =~ m{^/?adm/viewclasslist$}) &&
1034: (&Apache::lonnet::allowed('opa',$env{'request.course.id'}))) {
1035: ($cfile,$home,$switchserver,$forceedit,$forceview) =
1036: &Apache::lonnet::can_edit_resource($resurl,$cnum,$cdom,$resurl,
1037: $env{'form.symb'});
1038: $editbutton = &get_editbutton($cfile,$home,$switchserver,
1039: $forceedit,$forceview,$forcereg);
1040: } elsif (($resurl !~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) &&
1041: ($resurl ne '/cgi-bin/printout.pl')) {
1042: if ($env{'request.filename'}) {
1043: my $file=&Apache::lonnet::declutter($env{'request.filename'});
1044: ($cfile,$home,$switchserver,$forceedit,$forceview) =
1045: &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
1046: &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
1047: if ($cfile ne '') {
1048: $editbutton = &get_editbutton($cfile,$home,$switchserver,
1049: $forceedit,$forceview,$forcereg);
1050: }
1051: }
1052: }
1053: }
1054: # End determination of 'Edit' icon/button display
1055:
1056: if ($env{'request.course.id'}) {
1057: # This applies to about me page for users in a course
1058: if ($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) {
1059: my ($sdom,$sname) = ($1,$2);
1060: unless (&Apache::lonnet::is_course($sdom,$sname)) {
1061: &switch('','',6,4,'mail-message-new-22x22.png','Message to user',
1062: '',
1063: "go('/adm/email?compose=individual&recname=$sname&recdom=$sdom')",
1064: 'Send message to specific user');
1065: }
1066: my $hideprivileged = 1;
1067: if (&Apache::lonnet::in_course($sdom,$sname,$cdom,$cnum,undef,
1068: $hideprivileged)) {
1069: foreach my $priv ('vsa','vgr','srm') {
1070: $perms{$priv} = &Apache::lonnet::allowed($priv,$env{'request.course.id'});
1071: if (!$perms{$priv} && $env{'request.course.sec'} ne '') {
1072: $perms{$priv} =
1073: &Apache::lonnet::allowed($priv,"$env{'request.course.id'}/$env{'request.course.sec'}");
1074: }
1075: }
1076: if ($perms{'vsa'}) {
1077: &switch('','',6,5,'trck-22x22.png','Activity',
1078: '',
1079: "go('/adm/trackstudent?selected_student=$sname:$sdom')",
1080: 'View recent activity by this person');
1081: }
1082: if ($perms{'vgr'}) {
1083: &switch('','',6,6,'rsrv-22x22.png','Reservations',
1084: '',
1085: "go('/adm/slotrequest?command=showresv&origin=aboutme&uname=$sname&udom=$sdom')",
1086: 'Slot reservation history');
1087: }
1088: if ($perms{'srm'}) {
1089: &switch('','',6,7,'contact-new-22x22.png','Records',
1090: '',
1091: "go('/adm/email?recordftf=retrieve&recname=$sname&recdom=$sdom')",
1092: 'Add records');
1093: }
1094: }
1095: }
1096: if (($env{'form.folderpath'} =~ /^supplemental/) &&
1097: (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) &&
1098: (($resurl =~ m{^/adm/wrapper/ext/}) ||
1099: ($resurl =~ m{^/uploaded/$cdom/$cnum/supplemental/}) ||
1100: ($resurl eq '/adm/supplemental') ||
1101: ($resurl =~ m{^/public/$cdom/$cnum/syllabus$}) ||
1102: ($resurl =~ m{^/adm/$match_domain/$match_username/aboutme$}))) {
1103: my @folders=split('&',$env{'form.folderpath'});
1104: if ((@folders > 2) || ($resurl ne '/adm/supplemental')) {
1105: my $esc_path=&escape(&HTML::Entities::encode(&escape($env{'form.folderpath'}),'<>&"'));
1106: &switch('','',7,4,'docs-22x22.png','Edit Folder','parms[_2]',
1107: "location.href='/adm/coursedocs?command=direct&forcesupplement=1&supppath=$esc_path'",
1108: 'Folder/Page Content');
1109: }
1110: }
1111: }
1112:
1113: # End checking for items for about me page for users in a course
1114: if ($docscrumbs) {
1115: &Apache::lonhtmlcommon::clear_breadcrumb_tools();
1116: &advtools_crumbs(@inlineremote);
1117: return $editbutton;
1118: } elsif ($env{'request.registered'}) {
1119: return $editbutton;
1120: } else {
1121: if (ref($bread_crumbs) eq 'ARRAY') {
1122: if (@inlineremote > 0) {
1123: if (ref($advtools) eq 'ARRAY') {
1124: @{$advtools} = @inlineremote;
1125: }
1126: }
1127: return;
1128: } elsif (@inlineremote > 0) {
1129: &Apache::lonhtmlcommon::clear_breadcrumb_tools();
1130: &advtools_crumbs(@inlineremote);
1131: return &Apache::lonhtmlcommon::scripttag('', 'start')
1132: . &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0)
1133: . &Apache::lonhtmlcommon::scripttag('', 'end');
1134: }
1135: }
1136: }
1137:
1138: sub advtools_crumbs {
1139: my @funcs = @_;
1140: if ($env{'request.noversionuri'} =~ m{^/adm/$match_domain/$match_username/aboutme$}) {
1141: &Apache::lonhtmlcommon::add_breadcrumb_tool(
1142: 'advtools', @funcs[61,64,65,66,67,74]);
1143: } elsif ($env{'request.noversionuri'} !~ m{^/adm/(navmaps|viewclasslist)(\?|$)}) {
1144: &Apache::lonhtmlcommon::add_breadcrumb_tool(
1145: 'advtools', @funcs[61,71,72,73,74,92]);
1146: } elsif ($env{'request.noversionuri'} eq '/adm/viewclasslist') {
1147: &Apache::lonhtmlcommon::add_breadcrumb_tool(
1148: 'advtools', $funcs[61]);
1149: }
1150: return;
1151: }
1152:
1153: # ================================================================== Raw Config
1154:
1155: sub clear {
1156: my ($row,$col)=@_;
1157: $inlineremote[10*$row+$col]='';
1158: return '';
1159: }
1160:
1161: # ============================================ Switch a button or create a link
1162: # Switch acts on the javascript that is executed when a button is clicked.
1163: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
1164:
1165: sub switch {
1166: my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat,$nobreak)=@_;
1167: $act=~s/\$uname/$uname/g;
1168: $act=~s/\$udom/$udom/g;
1169: $top=&mt($top);
1170: $bot=&mt($bot);
1171: $desc=&mt($desc);
1172: my $idx=10*$row+$col;
1173: $category_members{$cat}.=':'.$idx;
1174:
1175: # Inline Menu
1176: if ($nobreak==2) { return ''; }
1177: my $text=$top.' '.$bot;
1178: $text=~s/\s*\-\s*//gs;
1179:
1180: my $pic=
1181: '<img alt="'.$text.'" src="'.
1182: &Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$img).
1183: '" align="'.($nobreak==3?'right':'left').'" class="LC_icon" />';
1184: if ($env{'browser.interface'} eq 'faketextual') {
1185: # Main Menu
1186: if ($nobreak==3) {
1187: $inlineremote[$idx]="\n".
1188: '<td class="LC_menubuttons_text" align="right">'.$text.
1189: '</td><td align="left">'.
1190: '<a href="javascript:'.$act.';">'.$pic.'</a></td></tr>';
1191: } elsif ($nobreak) {
1192: $inlineremote[$idx]="\n<tr>".
1193: '<td align="left">'.
1194: '<a href="javascript:'.$act.';">'.$pic.'</a></td>
1195: <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>';
1196: } else {
1197: $inlineremote[$idx]="\n<tr>".
1198: '<td align="left">'.
1199: '<a href="javascript:'.$act.';">'.$pic.
1200: '</a></td><td class="LC_menubuttons_text" colspan="3">'.
1201: '<a class="LC_menubuttons_link" href="javascript:'.$act.';"><span class="LC_menubuttons_inline_text">'.$desc.'</span></a></td></tr>';
1202: }
1203: } else {
1204: # Inline Menu
1205: my @tools = (93,91,81,82,83);
1206: unless ($env{'request.state'} eq 'construct') {
1207: push(@tools,63);
1208: }
1209: if (($env{'environment.icons'} eq 'iconsonly') &&
1210: (grep(/^$idx$/,@tools))) {
1211: $inlineremote[$idx] =
1212: '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.'</a>';
1213: } else {
1214: $inlineremote[$idx] =
1215: '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.
1216: '<span class="LC_menubuttons_inline_text">'.$top.' </span></a>';
1217: }
1218: }
1219: return '';
1220: }
1221:
1222: sub secondlevel {
1223: my $output='';
1224: my
1225: ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat)=@_;
1226: if ($prt eq 'any') {
1227: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1228: } elsif ($prt=~/^r(\w+)/) {
1229: if ($rol eq $1) {
1230: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1231: }
1232: }
1233: return $output;
1234: }
1235:
1236: sub inlinemenu {
1237: undef(@inlineremote);
1238: undef(%category_members);
1239: # calling rawconfig with "1" will evaluate mydesk.tab, even if there is no active remote control
1240: &rawconfig(1);
1241: my $output='<table><tr>';
1242: for (my $col=1; $col<=2; $col++) {
1243: $output.='<td class="LC_mainmenu_col_fieldset">';
1244: for (my $row=1; $row<=8; $row++) {
1245: foreach my $cat (keys(%category_members)) {
1246: if ($category_positions{$cat} ne "$col,$row") { next; }
1247: #$output.='<table><tr><td colspan="4" class="LC_menubuttons_category">'.&mt($category_names{$cat}).'</td></tr>';
1248: $output.='<div class="LC_Box LC_400Box">';
1249: $output.='<h3 class="LC_hcell">'.&mt($category_names{$cat}).'</h3>';
1250: $output.='<table>';
1251: my %active=();
1252: foreach my $menu_item (split(/\:/,$category_members{$cat})) {
1253: if ($inlineremote[$menu_item]) {
1254: $active{$menu_item}=1;
1255: }
1256: }
1257: foreach my $item (sort(keys(%active))) {
1258: $output.=$inlineremote[$item];
1259: }
1260: $output.='</table>';
1261: $output.='</div>';
1262: }
1263: }
1264: $output.="</td>";
1265: }
1266: $output.="</tr></table>";
1267: return $output;
1268: }
1269:
1270: sub rawconfig {
1271: #
1272: # This evaluates mydesk.tab
1273: # Need to add more positions and more privileges to deal with all
1274: # menu items.
1275: #
1276: my $textualoverride=shift;
1277: my $output='';
1278: return '' unless $textualoverride;
1279: my $uname=$env{'user.name'};
1280: my $udom=$env{'user.domain'};
1281: my $adv=$env{'user.adv'};
1282: my $show_course=&Apache::loncommon::show_course();
1283: my $author=$env{'user.author'};
1284: my $crs='';
1285: my $crstype='';
1286: if ($env{'request.course.id'}) {
1287: $crs='/'.$env{'request.course.id'};
1288: if ($env{'request.course.sec'}) {
1289: $crs.='_'.$env{'request.course.sec'};
1290: }
1291: $crs=~s/\_/\//g;
1292: $crstype = &Apache::loncommon::course_type();
1293: }
1294: my $pub=($env{'request.state'} eq 'published');
1295: my $con=($env{'request.state'} eq 'construct');
1296: my $rol=$env{'request.role'};
1297: my $requested_domain;
1298: if ($rol) {
1299: $requested_domain = $env{'request.role.domain'};
1300: }
1301: foreach my $line (@desklines) {
1302: my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc,$cat)=split(/\:/,$line);
1303: $prt=~s/\$uname/$uname/g;
1304: $prt=~s/\$udom/$udom/g;
1305: if ($prt =~ /\$crs/) {
1306: next unless ($env{'request.course.id'});
1307: next if ($crstype eq 'Community');
1308: $prt=~s/\$crs/$crs/g;
1309: } elsif ($prt =~ /\$cmty/) {
1310: next unless ($env{'request.course.id'});
1311: next if ($crstype ne 'Community');
1312: $prt=~s/\$cmty/$crs/g;
1313: }
1314: if ($prt =~ m/\$requested_domain/) {
1315: if ((!$requested_domain) && ($pro eq 'pbre') && ($env{'user.adv'})) {
1316: $prt=~s/\$requested_domain/$env{'user.domain'}/g;
1317: } else {
1318: $prt=~s/\$requested_domain/$requested_domain/g;
1319: }
1320: }
1321: if ($category_names{$cat}!~/\w/) { $cat='oth'; }
1322: if ($pro eq 'clear') {
1323: $output.=&clear($row,$col);
1324: } elsif ($pro eq 'any') {
1325: $output.=&secondlevel(
1326: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1327: } elsif ($pro eq 'smp') {
1328: unless ($adv) {
1329: $output.=&secondlevel(
1330: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1331: }
1332: } elsif ($pro eq 'adv') {
1333: if ($adv) {
1334: $output.=&secondlevel(
1335: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1336: }
1337: } elsif ($pro eq 'shc') {
1338: if ($show_course) {
1339: $output.=&secondlevel(
1340: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1341: }
1342: } elsif ($pro eq 'nsc') {
1343: if (!$show_course) {
1344: $output.=&secondlevel(
1345: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1346: }
1347: } elsif (($pro=~/^p(\w+)/) && ($prt)) {
1348: my $priv = $1;
1349: if ($priv =~ /^mdc(Course|Community)/) {
1350: if ($crstype eq $1) {
1351: $priv = 'mdc';
1352: } else {
1353: next;
1354: }
1355: }
1356: if ((($priv eq 'bre') && (&Apache::lonnet::allowed($priv,$prt) eq 'F')) ||
1357: (($priv ne 'bre') && (&Apache::lonnet::allowed($priv,$prt)))) {
1358: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1359: }
1360: } elsif ($pro eq 'course') {
1361: if (($env{'request.course.fn'}) && ($crstype ne 'Community')) {
1362: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1363: }
1364: } elsif ($pro eq 'community') {
1365: if (($env{'request.course.fn'}) && ($crstype eq 'Community')) {
1366: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1367: }
1368: } elsif ($pro =~ /^courseenv_(.*)$/) {
1369: my $key = $1;
1370: if ($crstype ne 'Community') {
1371: my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
1372: if ($key eq 'canuse_pdfforms') {
1373: if ($env{'request.course.id'} && $coursepref eq '') {
1374: my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
1375: $coursepref = $domdefs{'canuse_pdfforms'};
1376: }
1377: }
1378: if ($coursepref) {
1379: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1380: }
1381: }
1382: } elsif ($pro =~ /^communityenv_(.*)$/) {
1383: my $key = $1;
1384: if ($crstype eq 'Community') {
1385: my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
1386: if ($key eq 'canuse_pdfforms') {
1387: if ($env{'request.course.id'} && $coursepref eq '') {
1388: my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
1389: $coursepref = $domdefs{'canuse_pdfforms'};
1390: }
1391: }
1392: if ($coursepref) {
1393: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1394: }
1395: }
1396: } elsif ($pro =~ /^course_(.*)$/) {
1397: # Check for permissions inside of a course
1398: if (($env{'request.course.id'}) && ($crstype ne 'Community') &&
1399: (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
1400: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
1401: )) {
1402: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1403: }
1404: } elsif ($pro =~ /^community_(.*)$/) {
1405: # Check for permissions inside of a community
1406: if (($env{'request.course.id'}) && ($crstype eq 'Community') &&
1407: (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
1408: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
1409: )) {
1410: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1411: }
1412: } elsif ($pro eq 'author') {
1413: if ($author) {
1414: if ((($prt eq 'rca') && ($env{'request.role'}=~/^ca/)) ||
1415: (($prt eq 'raa') && ($env{'request.role'}=~/^aa/)) ||
1416: (($prt eq 'rau') && ($env{'request.role'}=~/^au/))) {
1417: # Check that we are on the correct machine
1418: my $cadom=$requested_domain;
1419: my $caname=$env{'user.name'};
1420: if (($prt eq 'rca') || ($prt eq 'raa')) {
1421: ($cadom,$caname)=
1422: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1423: }
1424: $act =~ s/\$caname/$caname/g;
1425: $act =~ s/\$cadom/$cadom/g;
1426: my $home = &Apache::lonnet::homeserver($caname,$cadom);
1427: my $allowed=0;
1428: my @ids=&Apache::lonnet::current_machine_ids();
1429: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
1430: if ($allowed) {
1431: $output.=&switch($caname,$cadom,
1432: $row,$col,$img,$top,$bot,$act,$desc,$cat);
1433: }
1434: }
1435: }
1436: } elsif ($pro eq 'tools') {
1437: my @tools = ('aboutme','blog','portfolio');
1438: if (grep(/^\Q$prt\E$/,@tools)) {
1439: if (!&Apache::lonnet::usertools_access($env{'user.name'},
1440: $env{'user.domain'},
1441: $prt,undef,'tools')) {
1442: $output.=&clear($row,$col);
1443: next;
1444: }
1445: } elsif (($prt eq 'reqcrsnsc') || ($prt eq 'reqcrsshc')) {
1446: if (($prt eq 'reqcrsnsc') && ($show_course)) {
1447: next;
1448: }
1449: if (($prt eq 'reqcrsshc') && (!$show_course)) {
1450: next;
1451: }
1452: my $showreqcrs = &check_for_rcrs();
1453: if (!$showreqcrs) {
1454: $output.=&clear($row,$col);
1455: next;
1456: }
1457: }
1458: $prt='any';
1459: $output.=&secondlevel(
1460: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1461: }
1462: }
1463: return $output;
1464: }
1465:
1466: sub check_for_rcrs {
1467: my $showreqcrs = 0;
1468: my @reqtypes = ('official','unofficial','community','textbook');
1469: foreach my $type (@reqtypes) {
1470: if (&Apache::lonnet::usertools_access($env{'user.name'},
1471: $env{'user.domain'},
1472: $type,undef,'requestcourses')) {
1473: $showreqcrs = 1;
1474: last;
1475: }
1476: }
1477: if (!$showreqcrs) {
1478: foreach my $type (@reqtypes) {
1479: if ($env{'environment.reqcrsotherdom.'.$type} ne '') {
1480: $showreqcrs = 1;
1481: last;
1482: }
1483: }
1484: }
1485: return $showreqcrs;
1486: }
1487:
1488: sub dc_popup_js {
1489: my %lt = &Apache::lonlocal::texthash(
1490: more => '(More ...)',
1491: less => '(Less ...)',
1492: );
1493: return <<"END";
1494:
1495: function showCourseID() {
1496: document.getElementById('dccid').style.display='block';
1497: document.getElementById('dccid').style.textAlign='left';
1498: document.getElementById('dccid').style.textFace='normal';
1499: document.getElementById('dccidtext').innerHTML ='<a href="javascript:hideCourseID();" class="LC_menubuttons_link">$lt{'less'}</a>';
1500: return;
1501: }
1502:
1503: function hideCourseID() {
1504: document.getElementById('dccid').style.display='none';
1505: document.getElementById('dccidtext').innerHTML ='<a href="javascript:showCourseID()" class="LC_menubuttons_link">$lt{'more'}</a>';
1506: return;
1507: }
1508:
1509: END
1510:
1511: }
1512:
1513: sub countdown_toggle_js {
1514: return <<"END";
1515:
1516: function toggleCountdown() {
1517: var countdownid = document.getElementById('duedatecountdown');
1518: var currstyle = countdownid.style.display;
1519: if (currstyle == 'inline') {
1520: countdownid.style.display = 'none';
1521: document.getElementById('ddcountcollapse').innerHTML='';
1522: document.getElementById('ddcountexpand').innerHTML='◄ ';
1523: } else {
1524: countdownid.style.display = 'inline';
1525: document.getElementById('ddcountcollapse').innerHTML='► ';
1526: document.getElementById('ddcountexpand').innerHTML='';
1527: }
1528: return;
1529: }
1530:
1531: END
1532: }
1533:
1534: sub utilityfunctions {
1535: my ($httphost) = @_;
1536: my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
1537: if ($currenturl =~ m{^/adm/wrapper/ext/}
1538: && $env{'request.external.querystring'} ) {
1539: $currenturl .= ($currenturl=~/\?/)?'&':'?'.$env{'request.external.querystring'};
1540: }
1541: $currenturl=&Apache::lonenc::check_encrypt(&unescape($currenturl));
1542:
1543: my $currentsymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
1544:
1545: my $dc_popup_cid;
1546: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
1547: $env{'course.'.$env{'request.course.id'}.
1548: '.domain'}.'/'})) {
1549: $dc_popup_cid = &dc_popup_js();
1550: }
1551:
1552: my $start_page_annotate =
1553: &Apache::loncommon::start_page('Annotator',undef,
1554: {'only_body' => 1,
1555: 'js_ready' => 1,
1556: 'bgcolor' => '#BBBBBB',
1557: 'add_entries' => {
1558: 'onload' => 'javascript:document.goannotate.submit();'}});
1559:
1560: my $end_page_annotate =
1561: &Apache::loncommon::end_page({'js_ready' => 1});
1562:
1563: my $jumptores = &Apache::lonhtmlcommon::javascript_jumpto_resource();
1564:
1565: my $esc_url=&escape($currenturl);
1566: my $esc_symb=&escape($currentsymb);
1567:
1568: my $countdown = &countdown_toggle_js();
1569:
1570: my $hostvar = '
1571: function setLCHost() {
1572: var lcHostname="";
1573: ';
1574: if ($httphost =~ m{^https?\://}) {
1575: $hostvar .= ' var lcServer="'.$httphost.'";'."\n".
1576: ' var hostReg = /^https?:\/\/([^\/]+)$/i;'."\n".
1577: ' var match = hostReg.exec(lcServer);'."\n".
1578: ' if (match.length) {'."\n".
1579: ' if (match[1] == location.hostname) {'."\n".
1580: ' lcHostname=lcServer;'."\n".
1581: ' }'."\n".
1582: ' }'."\n";
1583: }
1584:
1585: $hostvar .= ' return lcHostname;'."\n".
1586: '}'."\n";
1587:
1588: return (<<ENDUTILITY)
1589: $hostvar
1590: var currentURL=unescape("$esc_url");
1591: var reloadURL=unescape("$esc_url");
1592: var currentSymb=unescape("$esc_symb");
1593:
1594: $dc_popup_cid
1595:
1596: $jumptores
1597:
1598: function gopost(url,postdata) {
1599: if (url!='') {
1600: var lcHostname = setLCHost();
1601: this.document.server.action=lcHostname+url;
1602: this.document.server.postdata.value=postdata;
1603: this.document.server.command.value='';
1604: this.document.server.url.value='';
1605: this.document.server.symb.value='';
1606: this.document.server.submit();
1607: }
1608: }
1609:
1610: function gocmd(url,cmd) {
1611: if (url!='') {
1612: var lcHostname = setLCHost();
1613: this.document.server.action=lcHostname+url;
1614: this.document.server.postdata.value='';
1615: this.document.server.command.value=cmd;
1616: this.document.server.url.value=currentURL;
1617: this.document.server.symb.value=currentSymb;
1618: this.document.server.submit();
1619: }
1620: }
1621:
1622: function gocstr(url,filename) {
1623: if (url == '/adm/cfile?action=delete') {
1624: this.document.cstrdelete.filename.value = filename
1625: this.document.cstrdelete.submit();
1626: return;
1627: }
1628: if (url == '/adm/printout') {
1629: this.document.cstrprint.postdata.value = filename
1630: this.document.cstrprint.curseed.value = 0;
1631: this.document.cstrprint.problemtype.value = 0;
1632: if (this.document.lonhomework) {
1633: if ((this.document.lonhomework.rndseed) && (this.document.lonhomework.rndseed.value != null) && (this.document.lonhomework.rndseed.value != '')) {
1634: this.document.cstrprint.curseed.value = this.document.lonhomework.rndseed.value
1635: }
1636: if (this.document.lonhomework.problemtype) {
1637: if (this.document.lonhomework.problemtype.value) {
1638: this.document.cstrprint.problemtype.value =
1639: this.document.lonhomework.problemtype.value;
1640: } else if (this.document.lonhomework.problemtype.options) {
1641: for (var i=0; i<this.document.lonhomework.problemtype.options.length; i++) {
1642: if (this.document.lonhomework.problemtype.options[i].selected) {
1643: if (this.document.lonhomework.problemtype.options[i].value != null && this.document.lonhomework.problemtype.options[i].value != '') {
1644: this.document.cstrprint.problemtype.value = this.document.lonhomework.problemtype.options[i].value
1645: }
1646: }
1647: }
1648: }
1649: }
1650: }
1651: this.document.cstrprint.submit();
1652: return;
1653: }
1654: if (url !='') {
1655: this.document.constspace.filename.value = filename;
1656: this.document.constspace.action = url;
1657: this.document.constspace.submit();
1658: }
1659: }
1660:
1661: function golist(url) {
1662: if (url!='' && url!= null) {
1663: currentURL = null;
1664: currentSymb= null;
1665: var lcHostname = setLCHost();
1666: top.location.href=lcHostname+url;
1667: }
1668: }
1669:
1670:
1671:
1672: function catalog_info(isMobile) {
1673: if (isMobile == 1) {
1674: openMyModal(window.location.pathname+'.meta?modal=1',500,400,'yes');
1675: } else {
1676: loncatinfo=window.open(window.location.pathname+'.meta',"LONcatInfo",'height=500,width=400,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no');
1677: }
1678: }
1679:
1680: function chat_win() {
1681: var lcHostname = setLCHost();
1682: lonchat=window.open(lcHostname+'/res/adm/pages/chatroom.html',"LONchat",'height=320,width=480,resizable=yes,location=no,menubar=no,toolbar=no');
1683: }
1684:
1685: function group_chat(group) {
1686: var lcHostname = setLCHost();
1687: var url = lcHostname+'/adm/groupchat?group='+group;
1688: var winName = 'LONchat_'+group;
1689: grpchat=window.open(url,winName,'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
1690: }
1691:
1692: function annotate() {
1693: w_Annotator_flag=1;
1694: annotator=window.open('','Annotator','width=365,height=265,scrollbars=0');
1695: annotator.document.write(
1696: '$start_page_annotate'
1697: +"<form name='goannotate' target='Annotator' method='post' "
1698: +"action='/adm/annotations'>"
1699: +"<input type='hidden' name='symbnew' value='"+currentSymb+"' />"
1700: +"<\\/form>"
1701: +'$end_page_annotate');
1702: annotator.document.close();
1703: }
1704:
1705: function open_StoredLinks_Import(rat) {
1706: var newWin;
1707: var lcHostname = setLCHost();
1708: if (rat) {
1709: newWin = window.open(lcHostname+'/adm/wishlist?inhibitmenu=yes&mode=import&rat='+rat,
1710: 'wishlistImport','scrollbars=1,resizable=1,menubar=0');
1711: }
1712: else {
1713: newWin = window.open(lcHostname+'/adm/wishlist?inhibitmenu=yes&mode=import',
1714: 'wishlistImport','scrollbars=1,resizable=1,menubar=0');
1715: }
1716: newWin.focus();
1717: }
1718:
1719: (function (\$) {
1720: \$(document).ready(function () {
1721: \$.single=function(a){return function(b){a[0]=b;return a}}(\$([1]));
1722: /*\@cc_on
1723: if (!window.XMLHttpRequest) {
1724: \$('.LC_hoverable').each(function () {
1725: this.attachEvent('onmouseenter', function (evt) { \$.single(evt.srcElement).addClass('hover'); });
1726: this.attachEvent('onmouseleave', function (evt) { \$.single(evt.srcElement).removeClass('hover'); });
1727: });
1728: }
1729: \@*/
1730: });
1731: }(jQuery));
1732:
1733: $countdown
1734:
1735: ENDUTILITY
1736: }
1737:
1738: sub serverform {
1739: return(<<ENDSERVERFORM);
1740: <form name="server" action="/adm/logout" method="post" target="_top">
1741: <input type="hidden" name="postdata" value="none" />
1742: <input type="hidden" name="command" value="none" />
1743: <input type="hidden" name="url" value="none" />
1744: <input type="hidden" name="symb" value="none" />
1745: </form>
1746: ENDSERVERFORM
1747: }
1748:
1749: sub constspaceform {
1750: return(<<ENDCONSTSPACEFORM);
1751: <form name="constspace" action="/adm/logout" method="post" target="_top">
1752: <input type="hidden" name="filename" value="" />
1753: </form>
1754: <form name="cstrdelete" action="/adm/cfile" method="post" target="_top">
1755: <input type="hidden" name="action" value="delete" />
1756: <input type="hidden" name="filename" value="" />
1757: </form>
1758: <form name="cstrprint" action="/adm/printout" target="_parent" method="post">
1759: <input type="hidden" name="postdata" value="" />
1760: <input type="hidden" name="curseed" value="" />
1761: <input type="hidden" name="problemtype" value="" />
1762: </form>
1763:
1764: ENDCONSTSPACEFORM
1765: }
1766:
1767: sub hidden_button_check {
1768: if ( $env{'request.course.id'} eq ''
1769: || $env{'request.role.adv'} ) {
1770:
1771: return;
1772: }
1773: my $buttonshide = &Apache::lonnet::EXT('resource.0.buttonshide');
1774: return $buttonshide;
1775: }
1776:
1777: sub roles_selector {
1778: my ($cdom,$cnum,$httphost) = @_;
1779: my $crstype = &Apache::loncommon::course_type();
1780: my $now = time;
1781: my (%courseroles,%seccount,%courseprivs);
1782: my $is_cc;
1783: my ($js,$form,$switcher);
1784: my $ccrole;
1785: if ($crstype eq 'Community') {
1786: $ccrole = 'co';
1787: } else {
1788: $ccrole = 'cc';
1789: }
1790: my ($priv,$gotsymb,$destsymb);
1791: my $destinationurl = $ENV{'REQUEST_URI'};
1792: if ($destinationurl =~ /\?symb=/) {
1793: $gotsymb = 1;
1794: } elsif ($destinationurl =~ m{^/enc/}) {
1795: my $plainurl = &Apache::lonenc::unencrypted($destinationurl);
1796: if ($plainurl =~ /\?symb=/) {
1797: $gotsymb = 1;
1798: }
1799: }
1800: unless ($gotsymb) {
1801: $destsymb = &Apache::lonnet::symbread();
1802: if ($destsymb ne '') {
1803: $destsymb = &Apache::lonenc::check_encrypt($destsymb);
1804: }
1805: }
1806: my $reqprivs = &required_privs();
1807: if (ref($reqprivs) eq 'HASH') {
1808: my $destination = $destinationurl;
1809: $destination =~ s/(\?.*)$//;
1810: if (exists($reqprivs->{$destination})) {
1811: $priv = $reqprivs->{$destination};
1812: }
1813: }
1814: if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) {
1815: my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum});
1816:
1817: if ((($start) && ($start<0)) ||
1818: (($end) && ($end<$now)) ||
1819: (($start) && ($now<$start))) {
1820: $is_cc = 0;
1821: } else {
1822: $is_cc = 1;
1823: }
1824: }
1825: if ($is_cc) {
1826: &get_all_courseroles($cdom,$cnum,\%courseroles,\%seccount,\%courseprivs,$priv);
1827: } else {
1828: my %gotnosection;
1829: foreach my $item (keys(%env)) {
1830: if ($item =~ m-^user\.role\.([^.]+)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
1831: my $role = $1;
1832: my $sec = $2;
1833: next if ($role eq 'gr');
1834: my ($start,$end) = split(/\./,$env{$item});
1835: next if (($start && $start > $now) || ($end && $end < $now));
1836: if ($sec eq '') {
1837: if (!$gotnosection{$role}) {
1838: $seccount{$role} ++;
1839: $gotnosection{$role} = 1;
1840: }
1841: }
1842: if ($priv ne '') {
1843: my $cnumsec = $cnum;
1844: if ($sec ne '') {
1845: $cnumsec .= "/$sec";
1846: }
1847: $courseprivs{"$role./$cdom/$cnumsec./"} =
1848: $env{"user.priv.$role./$cdom/$cnumsec./"};
1849: $courseprivs{"$role./$cdom/$cnumsec./$cdom/"} =
1850: $env{"user.priv.$role./$cdom/$cnumsec./$cdom/"};
1851: $courseprivs{"$role./$cdom/$cnumsec./$cdom/$cnumsec"} =
1852: $env{"user.priv.$role./$cdom/$cnumsec./$cdom/$cnumsec"};
1853: }
1854: if (ref($courseroles{$role}) eq 'ARRAY') {
1855: if ($sec ne '') {
1856: if (!grep(/^\Q$sec\E$/,@{$courseroles{$role}})) {
1857: push(@{$courseroles{$role}},$sec);
1858: $seccount{$role} ++;
1859: }
1860: }
1861: } else {
1862: @{$courseroles{$role}} = ();
1863: if ($sec ne '') {
1864: $seccount{$role} ++;
1865: push(@{$courseroles{$role}},$sec);
1866: }
1867: }
1868: }
1869: }
1870: }
1871: my @roles_order = ($ccrole,'in','ta','ep','ad','st');
1872: my $numdiffsec;
1873: if (keys(%seccount) == 1) {
1874: foreach my $key (keys(%seccount)) {
1875: $numdiffsec = $seccount{$key};
1876: }
1877: }
1878: if ((keys(%seccount) > 1) || ($numdiffsec > 1)) {
1879: my @submenu;
1880: $js = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles,\%courseprivs,$priv);
1881: $form =
1882: '<form name="rolechooser" method="post" action="'.$httphost.'/adm/roles">'."\n".
1883: ' <input type="hidden" name="destinationurl" value="'.
1884: &HTML::Entities::encode($destinationurl).'" />'."\n".
1885: ' <input type="hidden" name="gotorole" value="1" />'."\n".
1886: ' <input type="hidden" name="selectrole" value="" />'."\n".
1887: ' <input type="hidden" name="switchrole" value="" />'."\n";
1888: if ($destsymb ne '') {
1889: $form .= ' <input type="hidden" name="destsymb" value="'.
1890: &HTML::Entities::encode($destsymb).'" />'."\n";
1891: }
1892: $form .= '</form>'."\n";
1893: foreach my $role (@roles_order) {
1894: my $include;
1895: if (defined($courseroles{$role})) {
1896: if ($env{'request.role'} =~ m{^\Q$role\E}) {
1897: if ($seccount{$role} > 1) {
1898: $include = 1;
1899: }
1900: } else {
1901: $include = 1;
1902: }
1903: }
1904: if ($include) {
1905: push(@submenu,['javascript:adhocRole('."'$role'".')',
1906: &Apache::lonnet::plaintext($role,$crstype)]);
1907: }
1908: }
1909: foreach my $role (sort(keys(%courseroles))) {
1910: if ($role =~ /^cr/) {
1911: my $include;
1912: if ($env{'request.role'} =~ m{^\Q$role\E}) {
1913: if ($seccount{$role} > 1) {
1914: $include = 1;
1915: }
1916: } else {
1917: $include = 1;
1918: }
1919: if ($include) {
1920: push(@submenu,['javascript:adhocRole('."'$role'".')',
1921: &Apache::lonnet::plaintext($role)]);
1922: }
1923: }
1924: }
1925: if (@submenu > 0) {
1926: $switcher = &create_submenu('','',&mt('Switch role'),\@submenu);
1927: }
1928: }
1929: return ($js,$form,$switcher);
1930: }
1931:
1932: sub get_all_courseroles {
1933: my ($cdom,$cnum,$courseroles,$seccount,$courseprivs) = @_;
1934: unless ((ref($courseroles) eq 'HASH') && (ref($seccount) eq 'HASH') &&
1935: (ref($courseprivs) eq 'HASH')) {
1936: return;
1937: }
1938: my ($result,$cached) =
1939: &Apache::lonnet::is_cached_new('getcourseroles',$cdom.'_'.$cnum);
1940: if (defined($cached)) {
1941: if (ref($result) eq 'HASH') {
1942: if ((ref($result->{'roles'}) eq 'HASH') &&
1943: (ref($result->{'seccount'}) eq 'HASH') &&
1944: (ref($result->{'privs'}) eq 'HASH')) {
1945: %{$courseroles} = %{$result->{'roles'}};
1946: %{$seccount} = %{$result->{'seccount'}};
1947: %{$courseprivs} = %{$result->{'privs'}};
1948: return;
1949: }
1950: }
1951: }
1952: my %gotnosection;
1953: my %adv_roles =
1954: &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
1955: foreach my $role (keys(%adv_roles)) {
1956: my ($urole,$usec) = split(/:/,$role);
1957: if (!$gotnosection{$urole}) {
1958: $seccount->{$urole} ++;
1959: $gotnosection{$urole} = 1;
1960: }
1961: if (ref($courseroles->{$urole}) eq 'ARRAY') {
1962: if ($usec ne '') {
1963: if (!grep(/^Q$usec\E$/,@{$courseroles->{$urole}})) {
1964: push(@{$courseroles->{$urole}},$usec);
1965: $seccount->{$urole} ++;
1966: }
1967: }
1968: } else {
1969: @{$courseroles->{$urole}} = ();
1970: if ($usec ne '') {
1971: $seccount->{$urole} ++;
1972: push(@{$courseroles->{$urole}},$usec);
1973: }
1974: }
1975: my $area = '/'.$cdom.'/'.$cnum;
1976: if ($usec ne '') {
1977: $area .= '/'.$usec;
1978: }
1979: if ($role =~ /^cr\//) {
1980: &Apache::lonnet::custom_roleprivs($courseprivs,$urole,$cdom,$cnum,$urole.'.'.$area,$area);
1981: } else {
1982: &Apache::lonnet::standard_roleprivs($courseprivs,$urole,$cdom,$urole.'.'.$area,$cnum,$area);
1983: }
1984: }
1985: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum,['st']);
1986: @{$courseroles->{'st'}} = ();
1987: &Apache::lonnet::standard_roleprivs($courseprivs,'st',$cdom,"st./$cdom/$cnum",$cnum,"/$cdom/$cnum");
1988: if (keys(%sections_count) > 0) {
1989: push(@{$courseroles->{'st'}},keys(%sections_count));
1990: $seccount->{'st'} = scalar(keys(%sections_count));
1991: }
1992: $seccount->{'st'} ++; # Increment for a section-less student role.
1993: my $rolehash = {
1994: 'roles' => $courseroles,
1995: 'seccount' => $seccount,
1996: 'privs' => $courseprivs,
1997: };
1998: &Apache::lonnet::do_cache_new('getcourseroles',$cdom.'_'.$cnum,$rolehash);
1999: return;
2000: }
2001:
2002: sub jump_to_role {
2003: my ($cdom,$cnum,$seccount,$courseroles,$courseprivs,$priv) = @_;
2004: my %lt = &Apache::lonlocal::texthash(
2005: this => 'This role has section(s) associated with it.',
2006: ente => 'Enter a specific section.',
2007: orlb => 'Enter a specific section, or leave blank for no section.',
2008: avai => 'Available sections are:',
2009: youe => 'You entered an invalid section choice:',
2010: plst => 'Please try again.',
2011: role => 'The role you selected is not permitted to view the current page.',
2012: swit => 'Switch role, but display Main Menu page instead?',
2013: );
2014: my $js;
2015: if (ref($courseroles) eq 'HASH') {
2016: $js = ' var secpick = new Array("'.$lt{'ente'}.'","'.$lt{'orlb'}.'");'."\n".
2017: ' var numsec = new Array();'."\n".
2018: ' var rolesections = new Array();'."\n".
2019: ' var rolenames = new Array();'."\n".
2020: ' var roleseclist = new Array();'."\n";
2021: my @items = keys(%{$courseroles});
2022: for (my $i=0; $i<@items; $i++) {
2023: $js .= ' rolenames['.$i.'] = "'.$items[$i].'";'."\n";
2024: my ($secs,$secstr);
2025: if (ref($courseroles->{$items[$i]}) eq 'ARRAY') {
2026: my @sections = sort { $a <=> $b } @{$courseroles->{$items[$i]}};
2027: $secs = join('","',@sections);
2028: $secstr = join(', ',@sections);
2029: }
2030: $js .= ' rolesections['.$i.'] = new Array("'.$secs.'");'."\n".
2031: ' roleseclist['.$i.'] = "'.$secstr.'";'."\n".
2032: ' numsec['.$i.'] = "'.$seccount->{$items[$i]}.'";'."\n";
2033: }
2034: }
2035: my $checkroles = 0;
2036: if ($priv && ref($courseprivs) eq 'HASH') {
2037: my (%disallowed,%allowed,@disallow);
2038: foreach my $role (sort(keys(%{$courseprivs}))) {
2039: my $trole;
2040: if ($role =~ m{^(.+?)\Q./$cdom/$cnum\E}) {
2041: $trole = $1;
2042: }
2043: if (($trole ne '') && ($trole ne 'cm')) {
2044: if ($courseprivs->{$role} =~ /\Q:$priv\E($|:|\&\w+)/) {
2045: $allowed{$trole} = 1;
2046: } else {
2047: $disallowed{$trole} = 1;
2048: }
2049: }
2050: }
2051: foreach my $trole (keys(%disallowed)) {
2052: unless ($allowed{$trole}) {
2053: push(@disallow,$trole);
2054: }
2055: }
2056: if (@disallow > 0) {
2057: $checkroles = 1;
2058: $js .= " var disallow = new Array('".join("','",@disallow)."');\n".
2059: " var rolecheck = 1;\n";
2060: }
2061: }
2062: if (!$checkroles) {
2063: $js .= " var disallow = new Array();\n".
2064: " rolecheck = 0;\n";
2065: }
2066: return <<"END";
2067: <script type="text/javascript">
2068: //<![CDATA[
2069: function adhocRole(newrole) {
2070: $js
2071: if (newrole == '') {
2072: return;
2073: }
2074: var fullrole = newrole+'./$cdom/$cnum';
2075: var selidx = '';
2076: for (var i=0; i<rolenames.length; i++) {
2077: if (rolenames[i] == newrole) {
2078: selidx = i;
2079: }
2080: }
2081: if (rolecheck > 0) {
2082: for (var i=0; i<disallow.length; i++) {
2083: if (disallow[i] == newrole) {
2084: if (confirm("$lt{'role'}\\n$lt{'swit'}")) {
2085: document.rolechooser.destinationurl.value = '/adm/menu';
2086: } else {
2087: return;
2088: }
2089: }
2090: }
2091: }
2092: var secok = 1;
2093: var secchoice = '';
2094: if (selidx >= 0) {
2095: if (numsec[selidx] > 1) {
2096: secok = 0;
2097: var numrolesec = rolesections[selidx].length;
2098: var msgidx = numsec[selidx] - numrolesec;
2099: secchoice = prompt("$lt{'this'} "+secpick[msgidx]+"\\n$lt{'avai'} "+roleseclist[selidx],"");
2100: if (secchoice == '') {
2101: if (msgidx > 0) {
2102: secok = 1;
2103: }
2104: } else {
2105: for (var j=0; j<rolesections[selidx].length; j++) {
2106: if (rolesections[selidx][j] == secchoice) {
2107: secok = 1;
2108: }
2109: }
2110: }
2111: } else {
2112: if (rolesections[selidx].length == 1) {
2113: secchoice = rolesections[selidx][0];
2114: }
2115: }
2116: }
2117: if (secok == 1) {
2118: if (secchoice != '') {
2119: fullrole += '/'+secchoice;
2120: }
2121: } else {
2122: if (secchoice != null) {
2123: alert("$lt{'youe'} \\""+secchoice+"\\".\\n $lt{'plst'}");
2124: }
2125: return;
2126: }
2127: if (fullrole == "$env{'request.role'}") {
2128: return;
2129: }
2130: itemid = retrieveIndex('gotorole');
2131: if (itemid != -1) {
2132: document.rolechooser.elements[itemid].name = fullrole;
2133: }
2134: document.rolechooser.switchrole.value = fullrole;
2135: document.rolechooser.selectrole.value = '1';
2136: document.rolechooser.submit();
2137: return;
2138: }
2139:
2140: function retrieveIndex(item) {
2141: for (var i=0;i<document.rolechooser.elements.length;i++) {
2142: if (document.rolechooser.elements[i].name == item) {
2143: return i;
2144: }
2145: }
2146: return -1;
2147: }
2148: // ]]>
2149: </script>
2150: END
2151: }
2152:
2153: sub required_privs {
2154: my $privs = {
2155: '/adm/parmset' => 'opa',
2156: '/adm/courseprefs' => 'opa',
2157: '/adm/whatsnew' => 'whn',
2158: '/adm/populate' => 'cst',
2159: '/adm/trackstudent' => 'vsa',
2160: '/adm/statistics' => 'vgr',
2161: '/adm/setblock' => 'dcm',
2162: '/adm/coursedocs' => 'mdc',
2163: };
2164: unless ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'spreadsheet') {
2165: $privs->{'/adm/classcalc'} = 'vgr',
2166: $privs->{'/adm/assesscalc'} = 'vgr',
2167: $privs->{'/adm/studentcalc'} = 'vgr';
2168: }
2169: return $privs;
2170: }
2171:
2172: sub countdown_timer {
2173: if (($env{'request.course.id'}) && ($env{'request.symb'} ne '') &&
2174: ($env{'request.filename'}=~/$LONCAPA::assess_re/)) {
2175: my ($type,$hastimeleft,$slothastime);
2176: my $now = time;
2177: if ($env{'request.filename'} =~ /\.task$/) {
2178: $type = 'Task';
2179: } else {
2180: $type = 'problem';
2181: }
2182: my ($status,$accessmsg,$slot_name,$slot) =
2183: &Apache::lonhomework::check_slot_access('0',$type);
2184: if ($slot_name ne '') {
2185: if (ref($slot) eq 'HASH') {
2186: if (($slot->{'starttime'} < $now) &&
2187: ($slot->{'endtime'} > $now)) {
2188: $slothastime = 1;
2189: }
2190: }
2191: }
2192: if ($status ne 'CAN_ANSWER') {
2193: return;
2194: }
2195: my $duedate = &Apache::lonnet::EXT("resource.0.duedate");
2196: my @interval=&Apache::lonnet::EXT("resource.0.interval");
2197: if (@interval > 1) {
2198: my $first_access=&Apache::lonnet::get_first_access($interval[1]);
2199: if ($first_access > 0) {
2200: if ($first_access+$interval[0] > time) {
2201: $hastimeleft = 1;
2202: }
2203: }
2204: }
2205: if (($duedate && $duedate > time) ||
2206: (!$duedate && $hastimeleft) ||
2207: ($slot_name ne '' && $slothastime)) {
2208: my ($collapse,$expand,$alttxt,$title,$currdisp);
2209: if ((@interval > 1 && $hastimeleft) ||
2210: ($type eq 'Task' && $slothastime)) {
2211: $currdisp = 'inline';
2212: $collapse = '► ';
2213: } else {
2214: $currdisp = 'none';
2215: $expand = '◄ ';
2216: }
2217: unless ($env{'environment.icons'} eq 'iconsonly') {
2218: $alttxt = &mt('Timer');
2219: $title = $alttxt.' ';
2220: }
2221: my $desc = &mt('Countdown to due date/time');
2222: return <<END;
2223:
2224: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
2225: <span id="ddcountcollapse" class="LC_menubuttons_inline_text">
2226: $collapse
2227: </span></a>
2228: <span id="duedatecountdown" class="LC_menubuttons_inline_text" style="display: $currdisp;"></span>
2229: <a href="javascript:toggleCountdown();" class="LC_menubuttons_link">
2230: <span id="ddcountexpand" class="LC_menubuttons_inline_text" >$expand</span>
2231: <img src="/res/adm/pages/timer.png" title="$desc" class="LC_icon" alt="$alttxt" /><span class="LC_menubuttons_inline_text">$title</span></a>
2232: END
2233: }
2234: }
2235: return;
2236: }
2237:
2238: # ================================================================ Main Program
2239:
2240: BEGIN {
2241: if (! defined($readdesk)) {
2242: {
2243: my $tabfile = $Apache::lonnet::perlvar{'lonTabDir'}.'/mydesk.tab';
2244: if ( CORE::open( my $config,"<$tabfile") ) {
2245: while (my $configline=<$config>) {
2246: $configline=(split(/\#/,$configline))[0];
2247: $configline=~s/^\s+//;
2248: chomp($configline);
2249: if ($configline=~/^cat\:/) {
2250: my @entries=split(/\:/,$configline);
2251: $category_positions{$entries[2]}=$entries[1];
2252: $category_names{$entries[2]}=$entries[3];
2253: } elsif ($configline=~/^prim\:/) {
2254: my @entries = (split(/\:/, $configline))[1..6];
2255: push(@primary_menu,\@entries);
2256: } elsif ($configline=~/^primsub\:/) {
2257: my ($parent,@entries) = (split(/\:/, $configline))[1..4];
2258: push(@{$primary_submenu{$parent}},\@entries);
2259: } elsif ($configline=~/^scnd\:/) {
2260: my @entries = (split(/\:/, $configline))[1..5];
2261: push(@secondary_menu,\@entries);
2262: } elsif ($configline) {
2263: push(@desklines,$configline);
2264: }
2265: }
2266: CORE::close($config);
2267: }
2268: }
2269: $readdesk='done';
2270: }
2271: }
2272:
2273: 1;
2274: __END__
2275:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>