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