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