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