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