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