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