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