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