Annotation of loncom/interface/lonmenu.pm, revision 1.372
1.1 www 1: # The LearningOnline Network with CAPA
2: # Routines to control the menu
3: #
1.372 ! raeburn 4: # $Id: lonmenu.pm,v 1.371 2012/05/18 14:27:11 raeburn Exp $
1.11 albertel 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: #
1.1 www 28: #
29:
1.244 jms 30: =head1 NAME
31:
32: Apache::lonmenu
33:
34: =head1 SYNOPSIS
35:
1.371 raeburn 36: Loads contents of /home/httpd/lonTabs/mydesk.tab,
37: used to generate inline menu, and Main Menu page.
1.244 jms 38:
39: This is part of the LearningOnline Network with CAPA project
40: described at http://www.lon-capa.org.
41:
1.314 droeschl 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
1.371 raeburn 76: of those lines of mydesk.tab that start with prim:.
1.314 droeschl 77: It is used by primary_menu() to generate the corresponding menu.
78: It gets filled in the BEGIN block of this module.
79:
1.371 raeburn 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:
1.314 droeschl 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:
1.244 jms 98: =head1 SUBROUTINES
99:
100: =over
101:
1.314 droeschl 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:
1.244 jms 118: =item innerregister()
119:
1.320 droeschl 120: This gets called in order to register a URL in the body of the document
1.244 jms 121:
122: =item clear()
123:
124: =item switch()
125:
126: Switch a button or create a link
127: Switch acts on the javascript that is executed when a button is clicked.
128: The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
129:
130: =item secondlevel()
131:
132: =item openmenu()
133:
134: =item inlinemenu()
135:
136: =item rawconfig()
137:
138: =item utilityfunctions()
139:
1.371 raeburn 140: Output from this routine is a number of javascript functions called by
141: items in the inline menu, and in some cases items in the Main Menu page.
142:
1.244 jms 143: =item serverform()
144:
145: =item constspaceform()
146:
147: =item get_nav_status()
148:
149: =item hidden_button_check()
150:
151: =item roles_selector()
152:
153: =item jump_to_role()
154:
155: =back
156:
157: =cut
158:
1.1 www 159: package Apache::lonmenu;
160:
161: use strict;
1.152 albertel 162: use Apache::lonnet;
1.47 matthew 163: use Apache::lonhtmlcommon();
1.115 albertel 164: use Apache::loncommon();
1.127 albertel 165: use Apache::lonenc();
1.88 www 166: use Apache::lonlocal;
1.361 raeburn 167: use Apache::lonmsg();
1.207 foxr 168: use LONCAPA qw(:DEFAULT :match);
1.282 amueller 169: use HTML::Entities();
1.346 wenzelju 170: use Apache::lonwishlist();
1.88 www 171:
1.283 droeschl 172: use vars qw(@desklines %category_names %category_members %category_positions
1.371 raeburn 173: $readdesk @primary_menu %primary_submenu @secondary_menu);
1.88 www 174:
1.56 www 175: my @inlineremote;
1.38 www 176:
1.283 droeschl 177: sub prep_menuitem {
1.291 raeburn 178: my ($menuitem) = @_;
179: return '' unless(ref($menuitem) eq 'ARRAY');
1.283 droeschl 180: my $link;
181: if ($$menuitem[1]) { # graphical Link
182: $link = "<img class=\"LC_noBorder\""
1.291 raeburn 183: . " src=\"" . &Apache::loncommon::lonhttpdurl($$menuitem[1]) . "\""
184: . " alt=\"" . &mt($$menuitem[2]) . "\" />";
1.283 droeschl 185: } else { # textual Link
1.291 raeburn 186: $link = &mt($$menuitem[3]);
187: }
1.316 droeschl 188: return '<li><a'
189: # highlighting for new messages
190: . ( $$menuitem[4] eq 'newmsg' ? ' class="LC_new_message"' : '')
1.325 droeschl 191: . qq| href="$$menuitem[0]" target="_top">$link</a></li>|;
1.283 droeschl 192: }
193:
194: # primary_menu() evaluates @primary_menu and returns XHTML for the menu
195: # that contains following links:
1.371 raeburn 196: # About, Message, Personal, Roles, Help, Logout
1.283 droeschl 197: # @primary_menu is filled within the BEGIN block of this module with
198: # entries from mydesk.tab
199: sub primary_menu {
200: my $menu;
201: # each element of @primary contains following array:
202: # (link url, icon path, alt text, link text, condition)
1.319 raeburn 203: my $public;
204: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
205: || (($env{'user.name'} eq '') && ($env{'user.domain'} eq ''))) {
206: $public = 1;
207: }
1.283 droeschl 208: foreach my $menuitem (@primary_menu) {
209: # evaluate conditions
1.296 droeschl 210: next if ref($menuitem) ne 'ARRAY'; #
1.283 droeschl 211: next if $$menuitem[4] eq 'nonewmsg' # show links depending on
1.291 raeburn 212: && &Apache::lonmsg::mynewmail(); # whether a new msg
1.283 droeschl 213: next if $$menuitem[4] eq 'newmsg' # arrived or not
1.291 raeburn 214: && !&Apache::lonmsg::mynewmail(); #
1.319 raeburn 215: next if $$menuitem[4] !~ /public/ ##we've a public user,
216: && $public; ##who should not see all
217: ##links
1.283 droeschl 218: next if $$menuitem[4] eq 'onlypublic'# hide links which are
1.319 raeburn 219: && !$public; # only visible to public
220: # users
1.283 droeschl 221: next if $$menuitem[4] eq 'roles' ##show links depending on
1.291 raeburn 222: && &Apache::loncommon::show_course(); ##term 'Courses' or
1.283 droeschl 223: next if $$menuitem[4] eq 'courses' ##'Roles' wanted
1.291 raeburn 224: && !&Apache::loncommon::show_course(); ##
225:
1.371 raeburn 226: my $title = $menuitem->[3];
227: if (defined($primary_submenu{$title})) {
228: my ($link,$target,$numsub);
229: if ($menuitem->[0] ne '') {
230: $link = $menuitem->[0];
231: $target = '_top';
232: } else {
233: $link = '#';
234: }
235: if (ref($primary_submenu{$title}) eq 'ARRAY') {
236: $numsub = @{$primary_submenu{$title}};
237: if ($numsub) {
238: $title =
239: '<span class="LC_nobreak">'.$title.
240: '<span class="LC_fontsize_small">'.
241: '▼</span></span>';
242: }
243: }
1.372 ! raeburn 244: $menu .= '<li class="LC_hoverable">'.
! 245: '<a href="'.$link.'" target="'.$target.'">'.$title.'</a>';
1.371 raeburn 246: if ($numsub) {
247: $menu .= '<ul>';
248: foreach my $item (@{$primary_submenu{$menuitem->[3]}}) {
249: if (ref($item) eq 'ARRAY') {
250: if ($item->[2] eq 'wishlist') {
251: next unless ((&Apache::lonnet::allowed('bre',"/res/$env{'user.domain'}/")) ||
252: (&Apache::lonnet::allowed('bro',"/res/$env{'user.domain'}/")));
253: } elsif ($item->[2] eq 'reqcrs') {
254: next unless(&check_for_rcrs());
255: } elsif (($item->[2] eq 'portfolio') ||
256: ($item->[2] eq 'blog')) {
257: if (!&Apache::lonnet::usertools_access(
258: $env{'user.name'},
259: $env{'user.domain'},
260: $item->[2],undef,'tools')) {
261: next;
262: }
263: }
264: $menu .= '<li style="margin:0;padding:0">'.
265: '<a href="'.$item->[0].
266: '" style="padding:0 0 0 10px">'.
267: $item->[1].'</a></li>';
268: }
269: }
270: $menu .= '</ul>';
271: }
272: $menu .= '</li>';
273: } elsif ($$menuitem[3] eq 'Help') { # special treatment for helplink
1.340 raeburn 274: if ($public) {
275: my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
276: my $defdom = &Apache::lonnet::default_login_domain();
277: my $to = &Apache::loncommon::build_recipient_list(undef,
278: 'helpdeskmail',
279: $defdom,$origmail);
280: if ($to ne '') {
281: $menu .= &prep_menuitem($menuitem);
282: }
283: } else {
284: $menu .= '<li>'.&Apache::loncommon::top_nav_help('Help').'</li>';
285: }
1.283 droeschl 286: } else {
1.325 droeschl 287: $menu .= prep_menuitem($menuitem);
1.283 droeschl 288: }
1.291 raeburn 289: }
1.325 droeschl 290: $menu =~ s/\[domain\]/$env{'user.domain'}/g;
291: $menu =~ s/\[user\]/$env{'user.name'}/g;
1.283 droeschl 292:
1.291 raeburn 293: return "<ol class=\"LC_primary_menu LC_right\">$menu</ol>";
1.283 droeschl 294: }
295:
1.329 droeschl 296: #returns hashref {user=>'',dom=>''} containing:
297: # own name, domain if user is au
298: # name, domain of parent author if user is ca or aa
299: #empty return if user is not an author or not on homeserver
300: #
301: #TODO this should probably be moved somewhere more central
302: #since it can be used by different parts of the system
303: sub getauthor{
304: return unless $env{'request.role'}=~/^(ca|aa|au)/; #nothing to do if user isn't some kind of author
305:
306: #co- or assistent author?
307: my ($dom, $user) = ($env{'request.role'} =~ /^(?:ca|aa)\.\/($match_domain)\/($match_username)$/)
308: ? ($1, $2) #domain, username of the parent author
309: : @env{ ('request.role.domain', 'user.name') }; #own domain, username
310:
311: # current server == home server?
312: my $home = &Apache::lonnet::homeserver($user,$dom);
313: foreach (&Apache::lonnet::current_machine_ids()){
314: return {user => $user, dom => $dom} if $_ eq $home;
315: }
316:
317: # if wrong server
318: return;
319: }
1.283 droeschl 320:
321: sub secondary_menu {
322: my $menu;
323:
1.286 raeburn 324: my $crstype = &Apache::loncommon::course_type();
1.327 droeschl 325: my $crs_sec = $env{'request.course.id'} . ($env{'request.course.sec'}
326: ? "/$env{'request.course.sec'}"
327: : '');
328: my $canedit = &Apache::lonnet::allowed('mdc', $env{'request.course.id'});
329: my $canviewgrps = &Apache::lonnet::allowed('vcg', $crs_sec);
330: my $canmodifyuser = &Apache::lonnet::allowed('cst', $crs_sec);
331: my $canviewwnew = &Apache::lonnet::allowed('whn', $crs_sec);
1.341 www 332: my $canmodpara = &Apache::lonnet::allowed('opa', $crs_sec);
1.343 www 333: my $canvgr = &Apache::lonnet::allowed('vgr', $crs_sec);
334: my $canmgr = &Apache::lonnet::allowed('mgr', $crs_sec);
335: my $author = &getauthor();
1.327 droeschl 336:
1.286 raeburn 337: my %groups = &Apache::lonnet::get_active_groups(
338: $env{'user.domain'}, $env{'user.name'},
339: $env{'course.' . $env{'request.course.id'} . '.domain'},
340: $env{'course.' . $env{'request.course.id'} . '.num'});
1.327 droeschl 341:
1.283 droeschl 342: foreach my $menuitem (@secondary_menu) {
343: # evaluate conditions
1.296 droeschl 344: next if ref($menuitem) ne 'ARRAY';
1.283 droeschl 345: next if $$menuitem[4] ne 'always'
1.329 droeschl 346: && $$menuitem[4] ne 'author'
1.283 droeschl 347: && !$env{'request.course.id'};
348: next if $$menuitem[4] =~ /^mdc/
1.286 raeburn 349: && !$canedit;
1.341 www 350: next if $$menuitem[4] eq 'nvgr'
351: && $canvgr;
352: next if $$menuitem[4] eq 'vgr'
353: && !$canvgr;
1.327 droeschl 354: next if $$menuitem[4] eq 'cst'
355: && !$canmodifyuser;
1.343 www 356: next if $$menuitem[4] eq 'ncst'
357: && $canmodifyuser;
358: next if $$menuitem[4] eq 'mgr'
359: && !$canmgr;
360: next if $$menuitem[4] eq 'nmgr'
361: && $canmgr;
1.327 droeschl 362: next if $$menuitem[4] eq 'whn'
363: && !$canviewwnew;
364: next if $$menuitem[4] eq 'opa'
365: && !$canmodpara;
1.283 droeschl 366: next if $$menuitem[4] =~ /showgroups$/
1.300 raeburn 367: && !$canviewgrps
1.286 raeburn 368: && !%groups;
1.329 droeschl 369: next if $$menuitem[4] eq 'author'
370: && !$author;
1.283 droeschl 371:
1.286 raeburn 372: if ($$menuitem[3] eq 'Roles' && $env{'request.course.id'}) {
1.283 droeschl 373: # special treatment for role selector
1.298 raeburn 374: my $roles_selector = &roles_selector(
1.283 droeschl 375: $env{'course.' . $env{'request.course.id'} . '.domain'},
376: $env{'course.' . $env{'request.course.id'} . '.num'} );
377:
378: $menu .= $roles_selector ? "<li>$roles_selector</li>"
379: : '';
1.296 droeschl 380: } else {
381: $menu .= &prep_menuitem(\@$menuitem);
1.283 droeschl 382: }
383: }
384: if ($menu =~ /\[url\].*\[symb\]/) {
1.291 raeburn 385: my $escurl = &escape( &Apache::lonenc::check_encrypt(
386: $env{'request.noversionuri'}));
1.283 droeschl 387:
1.291 raeburn 388: my $escsymb = &escape( &Apache::lonenc::check_encrypt(
389: $env{'request.symb'}));
1.283 droeschl 390:
391: if ( $env{'request.state'} eq 'construct'
392: and ( $env{'request.noversionuri'} eq ''
393: || !defined($env{'request.noversionuri'})))
394: {
1.359 raeburn 395: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
396: ($escurl = $env{'request.filename'}) =~ s{^\Q$londocroot\E}{};
1.291 raeburn 397: $escurl = &escape($escurl);
1.283 droeschl 398: }
399: $menu =~ s/\[url\]/$escurl/g;
400: $menu =~ s/\[symb\]/$escsymb/g;
401: }
1.329 droeschl 402: $menu =~ s/\[uname\]/$$author{user}/g;
403: $menu =~ s/\[udom\]/$$author{dom}/g;
1.283 droeschl 404:
1.285 wenzelju 405: return "<ul id=\"LC_secondary_menu\">$menu</ul>";
1.283 droeschl 406: }
407:
1.40 www 408: sub innerregister {
1.321 droeschl 409: my ($forcereg,$bread_crumbs) = @_;
1.152 albertel 410: my $const_space = ($env{'request.state'} eq 'construct');
1.131 raeburn 411: my $is_const_dir = 0;
1.120 raeburn 412:
1.175 albertel 413: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
1.40 www 414:
1.174 albertel 415: $env{'request.registered'} = 1;
1.40 www 416:
1.177 albertel 417: undef(@inlineremote);
1.56 www 418:
1.348 raeburn 419: my $resurl;
1.316 droeschl 420: if ( $env{'request.symb'} && $env{'request.course.id'} ) {
1.267 droeschl 421:
1.348 raeburn 422: (my $mapurl, my $rid, $resurl) = &Apache::lonnet::decode_symb(&Apache::lonnet::symbread());
1.267 droeschl 423: my $coursetitle = $env{'course.'.$env{'request.course.id'}.'.description'};
424:
425: my $maptitle = &Apache::lonnet::gettitle($mapurl);
426: my $restitle = &Apache::lonnet::gettitle(&Apache::lonnet::symbread());
1.318 droeschl 427:
428: #SD
429: #course_type only Course and Community?
430: #
1.324 raeburn 431: my @crumbs;
432: unless (($forcereg) && ($env{'request.noversionuri'} eq '/adm/navmaps')
433: && ($mapurl eq $env{'course.'.$env{'request.course.id'}.'.url'})) {
434: @crumbs = ({text => Apache::loncommon::course_type()
1.318 droeschl 435: . ' Contents',
1.324 raeburn 436: href => "Javascript:gopost('/adm/navmaps','')"});
437: }
1.289 raeburn 438: if ($mapurl ne $env{'course.'.$env{'request.course.id'}.'.url'}) {
439: push(@crumbs, {text => '...',
440: no_mt => 1});
441: }
1.268 droeschl 442:
443: push @crumbs, {text => $maptitle, no_mt => 1} if ($maptitle
444: && $maptitle ne 'default.sequence'
445: && $maptitle ne $coursetitle);
446:
447: push @crumbs, {text => $restitle, no_mt => 1} if $restitle;
448:
1.291 raeburn 449: &Apache::lonhtmlcommon::clear_breadcrumbs();
450: &Apache::lonhtmlcommon::add_breadcrumb(@crumbs);
1.328 droeschl 451: }elsif (! $const_space){
452: #a situation when we're looking at a resource outside of context of a
453: #course or construction space (e.g. with cumulative rights)
454: &Apache::lonhtmlcommon::clear_breadcrumbs();
455: &Apache::lonhtmlcommon::add_breadcrumb({text => 'View Resource'});
1.65 www 456: }
1.41 www 457: # =============================================================================
458: # ============================ This is for URLs that actually can be registered
1.316 droeschl 459: return '' unless ( ($env{'request.noversionuri'}!~m{^/(res/)*adm/})
460: || $forcereg );
1.317 droeschl 461:
1.40 www 462: # -- This applies to homework problems for users with grading privileges
1.152 albertel 463: my $crs='/'.$env{'request.course.id'};
464: if ($env{'request.course.sec'}) {
465: $crs.='_'.$env{'request.course.sec'};
1.107 albertel 466: }
467: $crs=~s/\_/\//g;
468:
1.38 www 469: my $hwkadd='';
1.152 albertel 470: if ($env{'request.symb'} ne '' &&
1.360 www 471: $env{'request.filename'}=~/$LONCAPA::assess_re/) {
1.79 www 472: if (&Apache::lonnet::allowed('mgr',$crs)) {
1.344 www 473: $hwkadd.=&switch('','',7,2,'pgrd.png','Content Grades','grades[_4]',
1.40 www 474: "gocmd('/adm/grades','gradingmenu')",
1.344 www 475: 'Content Grades');
1.154 www 476: } elsif (&Apache::lonnet::allowed('vgr',$crs)) {
1.344 www 477: $hwkadd.=&switch('','',7,2,'subm.png','Content Submissions','missions[_1]',
1.154 www 478: "gocmd('/adm/grades','submission')",
1.344 www 479: 'Content Submissions');
1.38 www 480: }
1.107 albertel 481: }
1.152 albertel 482: if ($env{'request.symb'} ne '' &&
1.145 albertel 483: &Apache::lonnet::allowed('opa',$crs)) {
1.344 www 484: $hwkadd.=&switch('','',7,3,'pparm.png','Content Settings','parms[_2]',
1.107 albertel 485: "gocmd('/adm/parmset','set')",
1.344 www 486: 'Content Settings');
1.38 www 487: }
1.363 www 488: if ($env{'request.symb'}=~/^uploaded/ &&
1.362 www 489: &Apache::lonnet::allowed('mdc',$crs)) {
490: $hwkadd.=&switch('','',7,4,'docs.png','Folder/Page Content','parms[_2]',
491: "gocmd('/adm/coursedocs','direct')",
492: 'Folder/Page Content');
493: }
1.40 www 494: # -- End Homework
1.38 www 495: ###
496: ### Determine whether or not to display the 'cstr' button for this
497: ### resource
498: ###
499: my $editbutton = '';
1.258 raeburn 500: my $noeditbutton = 1;
501: my ($cnum,$cdom);
502: if ($env{'request.course.id'}) {
503: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
504: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
505: }
1.152 albertel 506: if ($env{'user.author'}) {
1.234 raeburn 507: if ($env{'request.role'}=~/^(aa|ca|au)/) {
1.274 www 508: #
509: # We have the role of an author
510: #
1.38 www 511: # Set defaults for authors
512: my ($top,$bottom) = ('con-','struct');
1.353 www 513: my $action = "go('/priv/".$env{'user.domain'}.'/'.$env{'user.name'}."');";
1.152 albertel 514: my $cadom = $env{'request.role.domain'};
515: my $caname = $env{'user.name'};
1.236 bisitz 516: my $desc = "Enter my construction space";
1.38 www 517: # Set defaults for co-authors
1.152 albertel 518: if ($env{'request.role'} =~ /^ca/) {
1.206 albertel 519: ($cadom,$caname)=($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.38 www 520: ($top,$bottom) = ('co con-','struct');
1.353 www 521: $action = "go('/priv/".$cadom.'/'.$caname."');";
1.38 www 522: $desc = "Enter construction space as co-author";
1.234 raeburn 523: } elsif ($env{'request.role'} =~ /^aa/) {
524: ($cadom,$caname)=($env{'request.role'}=~/($match_domain)\/($match_username)$/);
525: ($top,$bottom) = ('co con-','struct');
1.353 www 526: $action = "go('/priv/".$cadom.'/'.$caname."');";
1.234 raeburn 527: $desc = "Enter construction space as assistant co-author";
1.38 www 528: }
529: # Check that we are on the correct machine
530: my $home = &Apache::lonnet::homeserver($caname,$cadom);
1.109 albertel 531: my $allowed=0;
532: my @ids=&Apache::lonnet::current_machine_ids();
533: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
534: if (!$allowed) {
535: $editbutton=&switch('','',6,1,$top,,$bottom,$action,$desc);
1.258 raeburn 536: $noeditbutton = 0;
1.38 www 537: }
538: }
1.274 www 539: #
540: # We are an author for some stuff, but currently do not have the role of author.
541: # Figure out if we have authoring privileges for the resource we are looking at.
542: # This should maybe become a privilege check in lonnet
543: #
1.38 www 544: ##
545: ## Determine if user can edit url.
546: ##
547: my $cfile='';
548: my $cfuname='';
549: my $cfudom='';
1.258 raeburn 550: my $uploaded;
1.330 raeburn 551: my $switchserver='';
552: my $home;
1.152 albertel 553: if ($env{'request.filename'}) {
554: my $file=&Apache::lonnet::declutter($env{'request.filename'});
1.258 raeburn 555: if (defined($cnum) && defined($cdom)) {
556: $uploaded = &is_course_upload($file,$cnum,$cdom);
557: }
558: if (!$uploaded) {
1.357 raeburn 559:
560: $file=~s{^(priv/$match_domain/$match_username)}{/$1};
1.358 raeburn 561: $file=~s{^($match_domain/$match_username)}{/priv/$1};
1.356 raeburn 562:
1.258 raeburn 563: # Check that the user has permission to edit this resource
1.356 raeburn 564: my $setpriv = 1;
565: ($cfuname,$cfudom)=&Apache::loncacc::constructaccess($file,$setpriv);
1.258 raeburn 566: if (defined($cfudom)) {
1.330 raeburn 567: $home=&Apache::lonnet::homeserver($cfuname,$cfudom);
1.258 raeburn 568: my $allowed=0;
569: my @ids=&Apache::lonnet::current_machine_ids();
570: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
571: if ($allowed) {
572: $cfile=$file;
1.330 raeburn 573: } else {
574: $switchserver=$file;
1.258 raeburn 575: }
1.38 www 576: }
577: }
1.258 raeburn 578: }
1.38 www 579: # Finally, turn the button on or off
1.330 raeburn 580: if (($cfile || $switchserver) && !$const_space) {
1.302 raeburn 581: my $nocrsedit;
582: # Suppress display where CC has switched to student role.
583: if ($env{'request.course.id'}) {
584: unless(&Apache::lonnet::allowed('mdc',
585: $env{'request.course.id'})) {
586: $nocrsedit = 1;
587: }
588: }
589: if ($nocrsedit) {
590: $editbutton=&clear(6,1);
591: } else {
1.336 raeburn 592: my $bot = "go('$cfile')";
1.330 raeburn 593: if ($switchserver) {
594: if ( $env{'request.symb'} && $env{'request.course.id'} ) {
1.336 raeburn 595: $cfile = '/adm/switchserver?otherserver='.$home.'&role='.
596: &HTML::Entities::encode($env{'request.role'},'"<>&').'&symb='.
597: &HTML::Entities::encode($env{'request.symb'},'"<>&');
598: $bot = "need_switchserver('$cfile');";
1.330 raeburn 599: }
600: }
1.302 raeburn 601: $editbutton=&switch
1.345 www 602: ('','',6,1,'pcstr.png','Edit','resource[_2]',
1.336 raeburn 603: $bot,"Edit this resource");
1.302 raeburn 604: $noeditbutton = 0;
605: }
1.38 www 606: } elsif ($editbutton eq '') {
1.191 www 607: $editbutton=&clear(6,1);
1.38 www 608: }
609: }
1.258 raeburn 610: if (($noeditbutton) && ($env{'request.filename'})) {
611: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
612: my $file=&Apache::lonnet::declutter($env{'request.filename'});
613: if (defined($cnum) && defined($cdom)) {
614: if (&is_course_upload($file,$cnum,$cdom)) {
615: my $cfile = &edit_course_upload($file,$cnum,$cdom);
616: if ($cfile) {
617: $editbutton=&switch
1.345 www 618: ('','',6,1,'pcstr.png','Edit',
1.258 raeburn 619: 'resource[_2]',"go('".$cfile."');",
620: 'Edit this resource');
621: }
622: }
623: }
624: }
625: }
1.348 raeburn 626: if ($env{'request.course.id'}) {
627: if ($resurl eq "public/$cdom/$cnum/syllabus") {
628: if ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ /\w/) {
629: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
630: $editbutton=&switch('','',6,1,'pcstr.png','Edit',
631: 'resource[_2]',
632: "go('/adm/courseprefs?phase=display&actions=courseinfo')",
633: 'Edit this resource');
634: }
635: }
636: }
637: }
1.38 www 638: ###
639: ###
1.41 www 640: # Prepare the rest of the buttons
1.120 raeburn 641: my $menuitems;
642: if ($const_space) {
1.274 www 643: #
644: # We are in construction space
645: #
1.353 www 646:
1.355 raeburn 647: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.353 www 648: my ($udom,$uname,$thisdisfn) =
1.355 raeburn 649: ($env{'request.filename'}=~m{^\Q$londocroot/priv/\E([^/]+)/([^/]+)/(.*)$});
1.353 www 650: my $currdir = '/priv/'.$udom.'/'.$uname.'/'.$thisdisfn;
1.131 raeburn 651: if ($currdir =~ m-/$-) {
652: $is_const_dir = 1;
653: } else {
1.267 droeschl 654: $currdir =~ s|[^/]+$||;
1.200 foxr 655: my $cleandisfn = &Apache::loncommon::escape_single($thisdisfn);
1.208 albertel 656: my $esc_currdir = &Apache::loncommon::escape_single($currdir);
1.274 www 657: #
658: # Probably should be in mydesk.tab
659: #
1.131 raeburn 660: $menuitems=(<<ENDMENUITEMS);
1.344 www 661: s&6&1&list.png&Directory&dir[_1]&golist('$esc_currdir')&List current directory
1.353 www 662: s&6&2&rtrv.png&Retrieve&version[_1]&gocstr('/adm/retrieve','/priv/$udom/$uname/$cleandisfn')&Retrieve old version
663: s&6&3&pub.png&Publish&resource[_3]&gocstr('/adm/publish','/priv/$udom/$uname/$cleandisfn')&Publish this resource
664: s&7&1&del.png&Delete&resource[_2]&gocstr('/adm/cfile?action=delete','/priv/$udom/$uname/$cleandisfn')&Delete this resource
665: s&7&2&prt.png&Print&printout[_1]&gocstr('/adm/printout','/priv/$udom/$uname/$cleandisfn')&Prepare a printable document
1.120 raeburn 666: ENDMENUITEMS
1.131 raeburn 667: }
1.308 raeburn 668: if (ref($bread_crumbs) eq 'ARRAY') {
669: &Apache::lonhtmlcommon::clear_breadcrumbs();
670: foreach my $crumb (@{$bread_crumbs}){
671: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
672: }
673: }
1.203 foxr 674: } elsif ( defined($env{'request.course.id'}) &&
675: $env{'request.symb'} ne '' ) {
1.274 www 676: #
677: # We are in a course and looking at a registred URL
678: # Should probably be in mydesk.tab
679: #
1.120 raeburn 680: $menuitems=(<<ENDMENUITEMS);
1.41 www 681: c&3&1
1.344 www 682: s&2&1&back.png&&&gopost('/adm/flip','back:'+currentURL)&Previous content resource&&1
683: s&2&3&forw.png&&&gopost('/adm/flip','forward:'+currentURL)&Next content resource&&3
1.77 www 684: c&6&3
685: c&8&1
686: c&8&2
1.344 www 687: s&8&3&prt.png&Print&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
1.41 www 688: ENDMENUITEMS
1.332 wenzelju 689: if (&Apache::lonnet::allowed('bre', $env{'request.course.id'}) eq 'F' && $env{'request.uri'} =~ /^\/res/) {
690: # wishlist is only available for users with access to resource-pool
691: # and links can only be set for resources within the resource-pool
692: $menuitems .= (<<ENDMENUITEMS);
1.370 raeburn 693: 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
1.332 wenzelju 694: ENDMENUITEMS
695: }
1.216 albertel 696:
1.243 tempelho 697: my $currentURL = &Apache::loncommon::get_symb();
698: my ($symb_old,$symb_old_enc) = &Apache::loncommon::clean_symb($currentURL);
699: my $annotation = &Apache::loncommon::get_annotation($symb_old,$symb_old_enc);
700: $menuitems.="s&9&3&";
701: if(length($annotation) > 0){
1.317 droeschl 702: $menuitems.="anot2.png";
1.243 tempelho 703: }else{
1.317 droeschl 704: $menuitems.="anot.png";
1.243 tempelho 705: }
1.344 www 706: $menuitems.="&Notes&&annotate()&";
1.243 tempelho 707: $menuitems.="Make notes and annotations about this resource&&1\n";
708:
1.323 raeburn 709: unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme|viewclasslist|portfolio)(\?|$)/) {
1.294 raeburn 710: if ((!$env{'request.enc'}) && ($env{'request.noversionuri'} !~ m{^/adm/wrapper/ext/})) {
1.216 albertel 711: $menuitems.=(<<ENDREALRES);
1.344 www 712: s&6&3&catalog.png&Info&info[_1]&catalog_info()&Show Metadata
1.216 albertel 713: ENDREALRES
714: }
1.120 raeburn 715: $menuitems.=(<<ENDREALRES);
1.344 www 716: s&8&1&eval.png&Evaluate&this[_1]&gopost('/adm/evaluate',currentURL,1)&Provide my evaluation of this resource
717: 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
1.77 www 718: ENDREALRES
1.120 raeburn 719: }
720: }
1.203 foxr 721: if ($env{'request.uri'} =~ /^\/res/) {
722: $menuitems .= (<<ENDMENUITEMS);
1.344 www 723: s&8&3&prt.png&Print&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document
1.203 foxr 724: ENDMENUITEMS
1.332 wenzelju 725: if (&Apache::lonnet::allowed('bre', $env{'request.course.id'}) eq 'F') {
726: # wishlist is only available for users with access to resource-pool
727: $menuitems .= (<<ENDMENUITEMS);
1.370 raeburn 728: s&9&1&wishlist-link.png&Stored Links&wishlistlink[_2]&set_wishlistlink()&Save a link for this resource in in your personal Stored Links repository&&1
1.332 wenzelju 729: ENDMENUITEMS
730: }
1.203 foxr 731: }
1.41 www 732: my $buttons='';
733: foreach (split(/\n/,$menuitems)) {
734: my ($command,@rest)=split(/\&/,$_);
1.220 raeburn 735: my $idx=10*$rest[0]+$rest[1];
736: if (&hidden_button_check() eq 'yes') {
737: if ($idx == 21 ||$idx == 23) {
738: $buttons.=&switch('','',@rest);
739: } else {
740: $buttons.=&clear(@rest);
741: }
742: } else {
743: if ($command eq 's') {
744: $buttons.=&switch('','',@rest);
745: } else {
746: $buttons.=&clear(@rest);
747: }
1.41 www 748: }
749: }
1.148 albertel 750:
751: my $addremote=0;
1.267 droeschl 752: foreach (@inlineremote) { if ($_ ne '') { $addremote=1; last;} }
1.301 droeschl 753: if ($addremote) {
754:
1.342 www 755: &Apache::lonhtmlcommon::clear_breadcrumb_tools();
1.301 droeschl 756:
1.342 www 757: &Apache::lonhtmlcommon::add_breadcrumb_tool(
1.312 droeschl 758: 'navigation', @inlineremote[21,23]);
759:
760: if(hidden_button_check() ne 'yes') {
1.342 www 761: &Apache::lonhtmlcommon::add_breadcrumb_tool(
1.313 droeschl 762: 'tools', @inlineremote[93,91,81,82,83]);
763:
764: #publish button in construction space
765: if ($env{'request.state'} eq 'construct'){
1.342 www 766: &Apache::lonhtmlcommon::add_breadcrumb_tool(
1.349 raeburn 767: 'advtools', $inlineremote[63]);
1.342 www 768: } else {
769: &Apache::lonhtmlcommon::add_breadcrumb_tool(
1.349 raeburn 770: 'tools', $inlineremote[63]);
1.313 droeschl 771: }
772:
1.322 raeburn 773: unless ($env{'request.noversionuri'}=~ m{^/adm/(navmaps|viewclasslist)(\?|$)}) {
1.342 www 774: &Apache::lonhtmlcommon::add_breadcrumb_tool(
1.362 www 775: 'advtools', @inlineremote[61,71,72,73,74,92]);
1.322 raeburn 776: }
1.301 droeschl 777: }
1.38 www 778: }
779:
1.342 www 780: return &Apache::lonhtmlcommon::scripttag('', 'start')
781: . &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0)
782: . &Apache::lonhtmlcommon::scripttag('', 'end');
1.38 www 783: }
784:
1.258 raeburn 785: sub is_course_upload {
786: my ($file,$cnum,$cdom) = @_;
787: my $uploadpath = &LONCAPA::propath($cdom,$cnum);
788: $uploadpath =~ s{^\/}{};
789: if (($file =~ m{^\Q$uploadpath\E/userfiles/docs/}) ||
790: ($file =~ m{^userfiles/\Q$cdom\E/\Q$cnum\E/docs/})) {
791: return 1;
792: }
793: return;
794: }
795:
796: sub edit_course_upload {
797: my ($file,$cnum,$cdom) = @_;
798: my $cfile;
799: if ($file =~/\.(htm|html|css|js|txt)$/) {
800: my $ext = $1;
801: my $url = &Apache::lonnet::hreflocation('',$file);
802: my $home = &Apache::lonnet::homeserver($cnum,$cdom);
803: my @ids=&Apache::lonnet::current_machine_ids();
804: my $dest;
805: if ($home && grep(/^\Q$home\E$/,@ids)) {
806: $dest = $url.'?forceedit=1';
807: } else {
808: unless (&Apache::lonnet::get_locks()) {
809: $dest = '/adm/switchserver?otherserver='.
810: $home.'&role='.$env{'request.role'}.
811: '&url='.$url.'&forceedit=1';
812: }
813: }
814: if ($dest) {
815: $cfile = &HTML::Entities::encode($dest,'"<>&');
816: }
817: }
818: return $cfile;
819: }
820:
1.2 www 821: # ================================================================== Raw Config
822:
1.3 www 823: sub clear {
824: my ($row,$col)=@_;
1.316 droeschl 825: $inlineremote[10*$row+$col]='';
826: return '';
1.3 www 827: }
828:
1.40 www 829: # ============================================ Switch a button or create a link
1.25 matthew 830: # Switch acts on the javascript that is executed when a button is clicked.
831: # The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
1.40 www 832:
1.2 www 833: sub switch {
1.209 www 834: my ($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat,$nobreak)=@_;
1.2 www 835: $act=~s/\$uname/$uname/g;
836: $act=~s/\$udom/$udom/g;
1.88 www 837: $top=&mt($top);
838: $bot=&mt($bot);
839: $desc=&mt($desc);
1.209 www 840: my $idx=10*$row+$col;
841: $category_members{$cat}.=':'.$idx;
842:
1.320 droeschl 843: # Inline Menu
1.317 droeschl 844: if ($nobreak==2) { return ''; }
845: my $text=$top.' '.$bot;
846: $text=~s/\s*\-\s*//gs;
1.105 www 847:
1.317 droeschl 848: my $pic=
1.225 albertel 849: '<img alt="'.$text.'" src="'.
850: &Apache::loncommon::lonhttpdurl('/res/adm/pages/'.$img).
1.303 droeschl 851: '" align="'.($nobreak==3?'right':'left').'" class="LC_icon" />';
1.317 droeschl 852: if ($env{'browser.interface'} eq 'faketextual') {
1.274 www 853: # Main Menu
1.103 www 854: if ($nobreak==3) {
1.209 www 855: $inlineremote[$idx]="\n".
1.177 albertel 856: '<td class="LC_menubuttons_text" align="right">'.$text.
1.247 harmsja 857: '</td><td align="left">'.
1.103 www 858: '<a href="javascript:'.$act.';">'.$pic.'</a></td></tr>';
859: } elsif ($nobreak) {
1.209 www 860: $inlineremote[$idx]="\n<tr>".
1.247 harmsja 861: '<td align="left">'.
1.177 albertel 862: '<a href="javascript:'.$act.';">'.$pic.'</a></td>
1.215 www 863: <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>';
1.103 www 864: } else {
1.209 www 865: $inlineremote[$idx]="\n<tr>".
1.247 harmsja 866: '<td align="left">'.
1.103 www 867: '<a href="javascript:'.$act.';">'.$pic.
1.177 albertel 868: '</a></td><td class="LC_menubuttons_text" colspan="3">'.
1.215 www 869: '<a class="LC_menubuttons_link" href="javascript:'.$act.';"><span class="LC_menubuttons_inline_text">'.$desc.'</span></a></td></tr>';
1.103 www 870: }
1.317 droeschl 871: } else {
1.103 www 872: # Inline Menu
1.317 droeschl 873: $inlineremote[$idx]=
874: '<a title="'.$desc.'" class="LC_menubuttons_link" href="javascript:'.$act.';">'.$pic.
1.344 www 875: '<span class="LC_menubuttons_inline_text">'.$top.' </span></a>';
1.317 droeschl 876: }
1.56 www 877: return '';
1.2 www 878: }
879:
880: sub secondlevel {
881: my $output='';
882: my
1.209 www 883: ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat)=@_;
1.2 www 884: if ($prt eq 'any') {
1.209 www 885: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.2 www 886: } elsif ($prt=~/^r(\w+)/) {
887: if ($rol eq $1) {
1.209 www 888: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.2 www 889: }
890: }
891: return $output;
892: }
893:
1.56 www 894: sub inlinemenu {
1.210 albertel 895: undef(@inlineremote);
896: undef(%category_members);
1.275 www 897: # calling rawconfig with "1" will evaluate mydesk.tab, even if there is no active remote control
1.56 www 898: &rawconfig(1);
1.309 bisitz 899: my $output='<table><tr>';
1.209 www 900: for (my $col=1; $col<=2; $col++) {
1.241 riegler 901: $output.='<td class="LC_mainmenu_col_fieldset">';
1.209 www 902: for (my $row=1; $row<=8; $row++) {
903: foreach my $cat (keys(%category_members)) {
904: if ($category_positions{$cat} ne "$col,$row") { next; }
1.247 harmsja 905: #$output.='<table><tr><td colspan="4" class="LC_menubuttons_category">'.&mt($category_names{$cat}).'</td></tr>';
1.309 bisitz 906: $output.='<div class="LC_Box LC_400Box">';
907: $output.='<h3 class="LC_hcell">'.&mt($category_names{$cat}).'</h3>';
1.247 harmsja 908: $output.='<table>';
1.240 riegler 909: my %active=();
910: foreach my $menu_item (split(/\:/,$category_members{$cat})) {
911: if ($inlineremote[$menu_item]) {
912: $active{$menu_item}=1;
913: }
914: }
915: foreach my $item (sort(keys(%active))) {
916: $output.=$inlineremote[$item];
917: }
918: $output.='</table>';
1.245 harmsja 919: $output.='</div>';
1.240 riegler 920: }
921: }
922: $output.="</td>";
923: }
924: $output.="</tr></table>";
925: return $output;
926: }
927:
1.2 www 928: sub rawconfig {
1.274 www 929: #
930: # This evaluates mydesk.tab
931: # Need to add more positions and more privileges to deal with all
932: # menu items.
933: #
1.34 www 934: my $textualoverride=shift;
935: my $output='';
1.316 droeschl 936: return '' unless $textualoverride;
1.152 albertel 937: my $uname=$env{'user.name'};
938: my $udom=$env{'user.domain'};
939: my $adv=$env{'user.adv'};
1.266 raeburn 940: my $show_course=&Apache::loncommon::show_course();
1.152 albertel 941: my $author=$env{'user.author'};
1.5 www 942: my $crs='';
1.295 raeburn 943: my $crstype='';
1.152 albertel 944: if ($env{'request.course.id'}) {
945: $crs='/'.$env{'request.course.id'};
946: if ($env{'request.course.sec'}) {
947: $crs.='_'.$env{'request.course.sec'};
1.7 www 948: }
1.8 www 949: $crs=~s/\_/\//g;
1.295 raeburn 950: $crstype = &Apache::loncommon::course_type();
1.5 www 951: }
1.152 albertel 952: my $pub=($env{'request.state'} eq 'published');
953: my $con=($env{'request.state'} eq 'construct');
954: my $rol=$env{'request.role'};
955: my $requested_domain = $env{'request.role.domain'};
1.184 raeburn 956: foreach my $line (@desklines) {
1.209 www 957: my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc,$cat)=split(/\:/,$line);
1.3 www 958: $prt=~s/\$uname/$uname/g;
959: $prt=~s/\$udom/$udom/g;
1.295 raeburn 960: if ($prt =~ /\$crs/) {
961: next unless ($env{'request.course.id'});
962: next if ($crstype eq 'Community');
963: $prt=~s/\$crs/$crs/g;
964: } elsif ($prt =~ /\$cmty/) {
965: next unless ($env{'request.course.id'});
966: next if ($crstype ne 'Community');
967: $prt=~s/\$cmty/$crs/g;
968: }
1.25 matthew 969: $prt=~s/\$requested_domain/$requested_domain/g;
1.211 www 970: if ($category_names{$cat}!~/\w/) { $cat='oth'; }
1.3 www 971: if ($pro eq 'clear') {
1.4 www 972: $output.=&clear($row,$col);
1.3 www 973: } elsif ($pro eq 'any') {
1.2 www 974: $output.=&secondlevel(
1.209 www 975: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2 www 976: } elsif ($pro eq 'smp') {
977: unless ($adv) {
978: $output.=&secondlevel(
1.209 www 979: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2 www 980: }
981: } elsif ($pro eq 'adv') {
982: if ($adv) {
983: $output.=&secondlevel(
1.209 www 984: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2 www 985: }
1.231 albertel 986: } elsif ($pro eq 'shc') {
987: if ($show_course) {
988: $output.=&secondlevel(
989: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
990: }
991: } elsif ($pro eq 'nsc') {
992: if (!$show_course) {
993: $output.=&secondlevel(
994: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
995: }
1.81 matthew 996: } elsif (($pro=~/^p(\w+)/) && ($prt)) {
1.295 raeburn 997: my $priv = $1;
998: if ($priv =~ /^mdc(Course|Community)/) {
999: if ($crstype eq $1) {
1000: $priv = 'mdc';
1001: } else {
1002: next;
1003: }
1004: }
1005: if (&Apache::lonnet::allowed($priv,$prt)) {
1.209 www 1006: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.4 www 1007: }
1.295 raeburn 1008: } elsif ($pro eq 'course') {
1009: if (($env{'request.course.fn'}) && ($crstype ne 'Community')) {
1.209 www 1010: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.81 matthew 1011: }
1.295 raeburn 1012: } elsif ($pro eq 'community') {
1013: if (($env{'request.course.fn'}) && ($crstype eq 'Community')) {
1014: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1015: }
1.124 matthew 1016: } elsif ($pro =~ /^courseenv_(.*)$/) {
1017: my $key = $1;
1.307 raeburn 1018: if ($crstype ne 'Community') {
1019: my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
1020: if ($key eq 'canuse_pdfforms') {
1021: if ($env{'request.course.id'} && $coursepref eq '') {
1022: my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
1023: $coursepref = $domdefs{'canuse_pdfforms'};
1024: }
1025: }
1026: if ($coursepref) {
1027: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1028: }
1.295 raeburn 1029: }
1030: } elsif ($pro =~ /^communityenv_(.*)$/) {
1031: my $key = $1;
1.307 raeburn 1032: if ($crstype eq 'Community') {
1033: my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
1034: if ($key eq 'canuse_pdfforms') {
1035: if ($env{'request.course.id'} && $coursepref eq '') {
1036: my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
1037: $coursepref = $domdefs{'canuse_pdfforms'};
1038: }
1039: }
1040: if ($coursepref) {
1041: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1042: }
1.124 matthew 1043: }
1.81 matthew 1044: } elsif ($pro =~ /^course_(.*)$/) {
1045: # Check for permissions inside of a course
1.295 raeburn 1046: if (($env{'request.course.id'}) && ($crstype ne 'Community') &&
1.152 albertel 1047: (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
1048: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
1.81 matthew 1049: )) {
1.209 www 1050: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1.26 www 1051: }
1.295 raeburn 1052: } elsif ($pro =~ /^community_(.*)$/) {
1053: # Check for permissions inside of a community
1054: if (($env{'request.course.id'}) && ($crstype eq 'Community') &&
1055: (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
1056: ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
1057: )) {
1058: $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
1059: }
1.4 www 1060: } elsif ($pro eq 'author') {
1061: if ($author) {
1.152 albertel 1062: if ((($prt eq 'rca') && ($env{'request.role'}=~/^ca/)) ||
1.234 raeburn 1063: (($prt eq 'raa') && ($env{'request.role'}=~/^aa/)) ||
1.152 albertel 1064: (($prt eq 'rau') && ($env{'request.role'}=~/^au/))) {
1.19 matthew 1065: # Check that we are on the correct machine
1.29 matthew 1066: my $cadom=$requested_domain;
1.152 albertel 1067: my $caname=$env{'user.name'};
1.234 raeburn 1068: if (($prt eq 'rca') || ($prt eq 'raa')) {
1.29 matthew 1069: ($cadom,$caname)=
1.206 albertel 1070: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.29 matthew 1071: }
1072: $act =~ s/\$caname/$caname/g;
1.353 www 1073: $act =~ s/\$cadom/$cadom/g;
1.19 matthew 1074: my $home = &Apache::lonnet::homeserver($caname,$cadom);
1.109 albertel 1075: my $allowed=0;
1076: my @ids=&Apache::lonnet::current_machine_ids();
1077: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
1078: if ($allowed) {
1.209 www 1079: $output.=&switch($caname,$cadom,
1080: $row,$col,$img,$top,$bot,$act,$desc,$cat);
1.19 matthew 1081: }
1.6 www 1082: }
1.2 www 1083: }
1.248 raeburn 1084: } elsif ($pro eq 'tools') {
1085: my @tools = ('aboutme','blog','portfolio');
1086: if (grep(/^\Q$prt\E$/,@tools)) {
1.249 raeburn 1087: if (!&Apache::lonnet::usertools_access($env{'user.name'},
1.251 raeburn 1088: $env{'user.domain'},
1089: $prt,undef,'tools')) {
1090: $output.=&clear($row,$col);
1091: next;
1092: }
1.278 raeburn 1093: } elsif (($prt eq 'reqcrsnsc') || ($prt eq 'reqcrsshc')) {
1094: if (($prt eq 'reqcrsnsc') && ($show_course)) {
1095: next;
1096: }
1097: if (($prt eq 'reqcrsshc') && (!$show_course)) {
1098: next;
1099: }
1.279 raeburn 1100: my $showreqcrs = &check_for_rcrs();
1.251 raeburn 1101: if (!$showreqcrs) {
1.248 raeburn 1102: $output.=&clear($row,$col);
1103: next;
1104: }
1105: }
1106: $prt='any';
1107: $output.=&secondlevel(
1108: $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
1.2 www 1109: }
1.13 harris41 1110: }
1.2 www 1111: return $output;
1112: }
1113:
1.279 raeburn 1114: sub check_for_rcrs {
1115: my $showreqcrs = 0;
1.280 raeburn 1116: my @reqtypes = ('official','unofficial','community');
1117: foreach my $type (@reqtypes) {
1.279 raeburn 1118: if (&Apache::lonnet::usertools_access($env{'user.name'},
1119: $env{'user.domain'},
1120: $type,undef,'requestcourses')) {
1121: $showreqcrs = 1;
1122: last;
1123: }
1124: }
1.280 raeburn 1125: if (!$showreqcrs) {
1126: foreach my $type (@reqtypes) {
1127: if ($env{'environment.reqcrsotherdom.'.$type} ne '') {
1128: $showreqcrs = 1;
1129: last;
1130: }
1131: }
1132: }
1.279 raeburn 1133: return $showreqcrs;
1134: }
1135:
1.306 raeburn 1136: sub dc_popup_js {
1137: my %lt = &Apache::lonlocal::texthash(
1138: more => '(More ...)',
1139: less => '(Less ...)',
1140: );
1141: return <<"END";
1142:
1143: function showCourseID() {
1144: document.getElementById('dccid').style.display='block';
1145: document.getElementById('dccid').style.textAlign='left';
1.307 raeburn 1146: document.getElementById('dccid').style.textFace='normal';
1.369 raeburn 1147: document.getElementById('dccidtext').innerHTML ='<a href="javascript:hideCourseID();" class="LC_menubuttons_link">$lt{'less'}</a>';
1.306 raeburn 1148: return;
1149: }
1150:
1151: function hideCourseID() {
1152: document.getElementById('dccid').style.display='none';
1.369 raeburn 1153: document.getElementById('dccidtext').innerHTML ='<a href="javascript:showCourseID()" class="LC_menubuttons_link">$lt{'more'}</a>';
1.306 raeburn 1154: return;
1155: }
1156:
1157: END
1158:
1159: }
1160:
1.42 www 1161: sub utilityfunctions {
1.152 albertel 1162: my $currenturl=&Apache::lonnet::clutter(&Apache::lonnet::fixversion((split(/\?/,$env{'request.noversionuri'}))[0]));
1.316 droeschl 1163: if ($currenturl =~ m{^/adm/wrapper/ext/}
1164: && $env{'request.external.querystring'} ) {
1.293 raeburn 1165: $currenturl .= ($currenturl=~/\?/)?'&':'?'.$env{'request.external.querystring'};
1166: }
1.183 www 1167: $currenturl=&Apache::lonenc::check_encrypt(&unescape($currenturl));
1.125 albertel 1168:
1.152 albertel 1169: my $currentsymb=&Apache::lonenc::check_encrypt($env{'request.symb'});
1.175 albertel 1170:
1.306 raeburn 1171: my $dc_popup_cid;
1172: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
1173: $env{'course.'.$env{'request.course.id'}.
1174: '.domain'}.'/'})) {
1175: $dc_popup_cid = &dc_popup_js();
1176: }
1177:
1.175 albertel 1178: my $start_page_annotate =
1179: &Apache::loncommon::start_page('Annotator',undef,
1180: {'only_body' => 1,
1181: 'js_ready' => 1,
1182: 'bgcolor' => '#BBBBBB',
1183: 'add_entries' => {
1184: 'onload' => 'javascript:document.goannotate.submit();'}});
1185:
1.205 albertel 1186: my $end_page_annotate =
1187: &Apache::loncommon::end_page({'js_ready' => 1});
1188:
1.336 raeburn 1189: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
1190: &mt('Switch server?');
1191:
1.368 www 1192: my $esc_url=&escape($currenturl);
1193: my $esc_symb=&escape($currentsymb);
1.332 wenzelju 1194:
1.42 www 1195: return (<<ENDUTILITY)
1196:
1.368 www 1197: var currentURL=unescape("$esc_url");
1198: var reloadURL=unescape("$esc_url");
1199: var currentSymb=unescape("$esc_symb");
1.42 www 1200:
1.306 raeburn 1201: $dc_popup_cid
1.114 albertel 1202:
1.42 www 1203: function go(url) {
1204: if (url!='' && url!= null) {
1205: currentURL = null;
1206: currentSymb= null;
1207: window.location.href=url;
1208: }
1209: }
1210:
1.336 raeburn 1211: function need_switchserver(url) {
1212: if (url!='' && url!= null) {
1213: if (confirm("$confirm_switch")) {
1214: go(url);
1215: }
1216: }
1217: return;
1218: }
1219:
1.42 www 1220: function gopost(url,postdata) {
1221: if (url!='') {
1222: this.document.server.action=url;
1223: this.document.server.postdata.value=postdata;
1224: this.document.server.command.value='';
1225: this.document.server.url.value='';
1226: this.document.server.symb.value='';
1227: this.document.server.submit();
1228: }
1229: }
1230:
1231: function gocmd(url,cmd) {
1232: if (url!='') {
1233: this.document.server.action=url;
1234: this.document.server.postdata.value='';
1235: this.document.server.command.value=cmd;
1236: this.document.server.url.value=currentURL;
1237: this.document.server.symb.value=currentSymb;
1238: this.document.server.submit();
1239: }
1.57 www 1240: }
1241:
1.121 raeburn 1242: function gocstr(url,filename) {
1243: if (url == '/adm/cfile?action=delete') {
1244: this.document.cstrdelete.filename.value = filename
1245: this.document.cstrdelete.submit();
1246: return;
1247: }
1.137 raeburn 1248: if (url == '/adm/printout') {
1249: this.document.cstrprint.postdata.value = filename
1250: this.document.cstrprint.curseed.value = 0;
1251: this.document.cstrprint.problemtype.value = 0;
1.138 raeburn 1252: if (this.document.lonhomework) {
1253: if ((this.document.lonhomework.rndseed) && (this.document.lonhomework.rndseed.value != null) && (this.document.lonhomework.rndseed.value != '')) {
1254: this.document.cstrprint.curseed.value = this.document.lonhomework.rndseed.value
1255: }
1256: if (this.document.lonhomework.problemtype) {
1.164 albertel 1257: if (this.document.lonhomework.problemtype.value) {
1258: this.document.cstrprint.problemtype.value =
1259: this.document.lonhomework.problemtype.value;
1260: } else if (this.document.lonhomework.problemtype.options) {
1261: for (var i=0; i<this.document.lonhomework.problemtype.options.length; i++) {
1262: if (this.document.lonhomework.problemtype.options[i].selected) {
1263: if (this.document.lonhomework.problemtype.options[i].value != null && this.document.lonhomework.problemtype.options[i].value != '') {
1264: this.document.cstrprint.problemtype.value = this.document.lonhomework.problemtype.options[i].value
1265: }
1266: }
1267: }
1268: }
1269: }
1270: }
1.137 raeburn 1271: this.document.cstrprint.submit();
1272: return;
1273: }
1.121 raeburn 1274: if (url !='') {
1275: this.document.constspace.filename.value = filename;
1276: this.document.constspace.action = url;
1277: this.document.constspace.submit();
1278: }
1279: }
1280:
1.131 raeburn 1281: function golist(url) {
1282: if (url!='' && url!= null) {
1283: currentURL = null;
1284: currentSymb= null;
1285: top.location.href=url;
1286: }
1287: }
1288:
1289:
1.121 raeburn 1290:
1.57 www 1291: function catalog_info() {
1.365 www 1292: openMyModal(window.location.pathname+'.meta',500,400,'yes');
1.57 www 1293: }
1294:
1295: function chat_win() {
1.290 raeburn 1296: lonchat=window.open('/res/adm/pages/chatroom.html',"LONchat",'height=320,width=480,resizable=yes,location=no,menubar=no,toolbar=no');
1.42 www 1297: }
1.169 raeburn 1298:
1299: function group_chat(group) {
1300: var url = '/adm/groupchat?group='+group;
1301: var winName = 'LONchat_'+group;
1302: grpchat=window.open(url,winName,'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
1303: }
1.175 albertel 1304:
1305: function annotate() {
1306: w_Annotator_flag=1;
1307: annotator=window.open('','Annotator','width=365,height=265,scrollbars=0');
1308: annotator.document.write(
1309: '$start_page_annotate'
1310: +"<form name='goannotate' target='Annotator' method='post' "
1311: +"action='/adm/annotations'>"
1.217 albertel 1312: +"<input type='hidden' name='symbnew' value='"+currentSymb+"' />"
1.181 albertel 1313: +"<\\/form>"
1.205 albertel 1314: +'$end_page_annotate');
1.175 albertel 1315: annotator.document.close();
1316: }
1317:
1.370 raeburn 1318: function open_StoredLinks_Import(rat) {
1.335 wenzelju 1319: var newWin;
1320: if (rat) {
1321: newWin = window.open('/adm/wishlist?inhibitmenu=yes&mode=import&rat='+rat,
1.334 wenzelju 1322: 'wishlistImport','scrollbars=1,resizable=1,menubar=0');
1.335 wenzelju 1323: }
1324: else {
1325: newWin = window.open('/adm/wishlist?inhibitmenu=yes&mode=import',
1326: 'wishlistImport','scrollbars=1,resizable=1,menubar=0');
1327: }
1.334 wenzelju 1328: newWin.focus();
1329: }
1330:
1.372 ! raeburn 1331: (function (\$) {
! 1332: \$(document).ready(function () {
! 1333: \$.single=function(a){return function(b){a[0]=b;return a}}(\$([1]));
! 1334: /*\@cc_on
! 1335: if (!window.XMLHttpRequest) {
! 1336: \$('.LC_hoverable').each(function () {
! 1337: this.attachEvent('onmouseenter', function (evt) { \$.single(evt.srcElement).addClass('hover'); });
! 1338: this.attachEvent('onmouseleave', function (evt) { \$.single(evt.srcElement).removeClass('hover'); });
! 1339: });
! 1340: }
! 1341: \@*/
! 1342: });
! 1343: }(jQuery));
! 1344:
1.42 www 1345: ENDUTILITY
1346: }
1347:
1348: sub serverform {
1349: return(<<ENDSERVERFORM);
1.181 albertel 1350: <form name="server" action="/adm/logout" method="post" target="_top">
1.42 www 1351: <input type="hidden" name="postdata" value="none" />
1352: <input type="hidden" name="command" value="none" />
1353: <input type="hidden" name="url" value="none" />
1354: <input type="hidden" name="symb" value="none" />
1355: </form>
1356: ENDSERVERFORM
1357: }
1.113 albertel 1358:
1.121 raeburn 1359: sub constspaceform {
1360: return(<<ENDCONSTSPACEFORM);
1.181 albertel 1361: <form name="constspace" action="/adm/logout" method="post" target="_top">
1.121 raeburn 1362: <input type="hidden" name="filename" value="" />
1363: </form>
1.181 albertel 1364: <form name="cstrdelete" action="/adm/cfile" method="post" target="_top">
1.121 raeburn 1365: <input type="hidden" name="action" value="delete" />
1366: <input type="hidden" name="filename" value="" />
1367: </form>
1.181 albertel 1368: <form name="cstrprint" action="/adm/printout" target="_parent" method="post">
1.137 raeburn 1369: <input type="hidden" name="postdata" value="" />
1370: <input type="hidden" name="curseed" value="" />
1371: <input type="hidden" name="problemtype" value="" />
1372: </form>
1373:
1.121 raeburn 1374: ENDCONSTSPACEFORM
1375: }
1376:
1.220 raeburn 1377: sub hidden_button_check {
1.317 droeschl 1378: if ( $env{'request.course.id'} eq ''
1379: || $env{'request.role.adv'} ) {
1380:
1.220 raeburn 1381: return;
1382: }
1.232 raeburn 1383: my $buttonshide = &Apache::lonnet::EXT('resource.0.buttonshide');
1384: return $buttonshide;
1.220 raeburn 1385: }
1.184 raeburn 1386:
1.235 raeburn 1387: sub roles_selector {
1388: my ($cdom,$cnum) = @_;
1.298 raeburn 1389: my $crstype = &Apache::loncommon::course_type();
1.235 raeburn 1390: my $now = time;
1.350 raeburn 1391: my (%courseroles,%seccount,%courseprivs);
1.235 raeburn 1392: my $is_cc;
1393: my $role_selector;
1.298 raeburn 1394: my $ccrole;
1395: if ($crstype eq 'Community') {
1396: $ccrole = 'co';
1397: } else {
1398: $ccrole = 'cc';
1.350 raeburn 1399: }
1400: my $priv;
1401: my $destinationurl = $ENV{'REQUEST_URI'};
1402: my $reqprivs = &required_privs();
1403: if (ref($reqprivs) eq 'HASH') {
1404: my $destination = $destinationurl;
1405: $destination =~ s/(\?.*)$//;
1406: if (exists($reqprivs->{$destination})) {
1407: $priv = $reqprivs->{$destination};
1408: }
1409: }
1.298 raeburn 1410: if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) {
1411: my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum});
1.235 raeburn 1412:
1413: if ((($start) && ($start<0)) ||
1414: (($end) && ($end<$now)) ||
1415: (($start) && ($now<$start))) {
1416: $is_cc = 0;
1417: } else {
1418: $is_cc = 1;
1419: }
1420: }
1421: if ($is_cc) {
1.350 raeburn 1422: &get_all_courseroles($cdom,$cnum,\%courseroles,\%seccount,\%courseprivs,$priv);
1.235 raeburn 1423: } else {
1.262 raeburn 1424: my %gotnosection;
1.235 raeburn 1425: foreach my $item (keys(%env)) {
1.239 raeburn 1426: if ($item =~ m-^user\.role\.([^.]+)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
1.235 raeburn 1427: my $role = $1;
1428: my $sec = $2;
1429: next if ($role eq 'gr');
1430: my ($start,$end) = split(/\./,$env{$item});
1431: next if (($start && $start > $now) || ($end && $end < $now));
1432: if ($sec eq '') {
1.239 raeburn 1433: if (!$gotnosection{$role}) {
1434: $seccount{$role} ++;
1435: $gotnosection{$role} = 1;
1436: }
1.235 raeburn 1437: }
1.350 raeburn 1438: if ($priv ne '') {
1439: my $cnumsec = $cnum;
1440: if ($sec ne '') {
1441: $cnumsec .= "/$sec";
1442: }
1443: $courseprivs{"$role./$cdom/$cnumsec./"} =
1444: $env{"user.priv.$role./$cdom/$cnumsec./"};
1445: $courseprivs{"$role./$cdom/$cnumsec./$cdom/"} =
1446: $env{"user.priv.$role./$cdom/$cnumsec./$cdom/"};
1447: $courseprivs{"$role./$cdom/$cnumsec./$cdom/$cnumsec"} =
1448: $env{"user.priv.$role./$cdom/$cnumsec./$cdom/$cnumsec"};
1449: }
1.235 raeburn 1450: if (ref($courseroles{$role}) eq 'ARRAY') {
1.239 raeburn 1451: if ($sec ne '') {
1.264 raeburn 1452: if (!grep(/^\Q$sec\E$/,@{$courseroles{$role}})) {
1.239 raeburn 1453: push(@{$courseroles{$role}},$sec);
1454: $seccount{$role} ++;
1455: }
1456: }
1457: } else {
1458: @{$courseroles{$role}} = ();
1459: if ($sec ne '') {
1460: $seccount{$role} ++;
1.235 raeburn 1461: push(@{$courseroles{$role}},$sec);
1462: }
1463: }
1464: }
1465: }
1466: }
1.286 raeburn 1467: my $switchtext;
1468: if ($crstype eq 'Community') {
1469: $switchtext = &mt('Switch community role to...')
1470: } else {
1471: $switchtext = &mt('Switch course role to...')
1472: }
1.298 raeburn 1473: my @roles_order = ($ccrole,'in','ta','ep','ad','st');
1.235 raeburn 1474: if (keys(%courseroles) > 1) {
1.350 raeburn 1475: $role_selector = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles,\%courseprivs,$priv);
1.235 raeburn 1476: $role_selector .= '<form name="rolechooser" method="post" action="/adm/roles">
1477: <select name="switchrole" onchange="javascript:adhocRole('."'switchrole'".')">';
1.286 raeburn 1478: $role_selector .= '<option value="">'.$switchtext.'</option>';
1.235 raeburn 1479: foreach my $role (@roles_order) {
1480: if (defined($courseroles{$role})) {
1.298 raeburn 1481: $role_selector .= "\n".'<option value="'.$role.'">'.&Apache::lonnet::plaintext($role,$crstype).'</option>';
1.235 raeburn 1482: }
1483: }
1484: foreach my $role (sort(keys(%courseroles))) {
1485: if ($role =~ /^cr/) {
1486: $role_selector .= "\n".'<option value="'.$role.'">'.&Apache::lonnet::plaintext($role).'</option>';
1487: }
1488: }
1489: $role_selector .= '</select>'."\n".
1490: '<input type="hidden" name="destinationurl" value="'.
1.350 raeburn 1491: &HTML::Entities::encode($destinationurl).'" />'."\n".
1.235 raeburn 1492: '<input type="hidden" name="gotorole" value="1" />'."\n".
1493: '<input type="hidden" name="selectrole" value="" />'."\n".
1494: '<input type="hidden" name="switch" value="1" />'."\n".
1495: '</form>';
1496: }
1497: return $role_selector;
1498: }
1499:
1.262 raeburn 1500: sub get_all_courseroles {
1.350 raeburn 1501: my ($cdom,$cnum,$courseroles,$seccount,$courseprivs) = @_;
1.351 raeburn 1502: unless ((ref($courseroles) eq 'HASH') && (ref($seccount) eq 'HASH') &&
1.350 raeburn 1503: (ref($courseprivs) eq 'HASH')) {
1.262 raeburn 1504: return;
1505: }
1506: my ($result,$cached) =
1507: &Apache::lonnet::is_cached_new('getcourseroles',$cdom.'_'.$cnum);
1508: if (defined($cached)) {
1509: if (ref($result) eq 'HASH') {
1510: if ((ref($result->{'roles'}) eq 'HASH') &&
1.350 raeburn 1511: (ref($result->{'seccount'}) eq 'HASH') &&
1512: (ref($result->{'privs'}) eq 'HASH')) {
1.262 raeburn 1513: %{$courseroles} = %{$result->{'roles'}};
1514: %{$seccount} = %{$result->{'seccount'}};
1.350 raeburn 1515: %{$courseprivs} = %{$result->{'privs'}};
1.262 raeburn 1516: return;
1517: }
1518: }
1519: }
1520: my %gotnosection;
1521: my %adv_roles =
1522: &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
1523: foreach my $role (keys(%adv_roles)) {
1524: my ($urole,$usec) = split(/:/,$role);
1525: if (!$gotnosection{$urole}) {
1526: $seccount->{$urole} ++;
1527: $gotnosection{$urole} = 1;
1528: }
1529: if (ref($courseroles->{$urole}) eq 'ARRAY') {
1530: if ($usec ne '') {
1531: if (!grep(/^Q$usec\E$/,@{$courseroles->{$urole}})) {
1532: push(@{$courseroles->{$urole}},$usec);
1533: $seccount->{$urole} ++;
1534: }
1535: }
1536: } else {
1537: @{$courseroles->{$urole}} = ();
1538: if ($usec ne '') {
1539: $seccount->{$urole} ++;
1540: push(@{$courseroles->{$urole}},$usec);
1541: }
1542: }
1.350 raeburn 1543: my $area = '/'.$cdom.'/'.$cnum;
1544: if ($usec ne '') {
1545: $area .= '/'.$usec;
1546: }
1547: if ($role =~ /^cr\//) {
1548: &Apache::lonnet::custom_roleprivs($courseprivs,$urole,$cdom,$cnum,$urole.'.'.$area,$area);
1549: } else {
1550: &Apache::lonnet::standard_roleprivs($courseprivs,$urole,$cdom,$urole.'.'.$area,$cnum,$area);
1551: }
1.262 raeburn 1552: }
1553: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum,['st']);
1554: @{$courseroles->{'st'}} = ();
1.350 raeburn 1555: &Apache::lonnet::standard_roleprivs($courseprivs,'st',$cdom,"st./$cdom/$cnum",$cnum,"/$cdom/$cnum");
1.262 raeburn 1556: if (keys(%sections_count) > 0) {
1557: push(@{$courseroles->{'st'}},keys(%sections_count));
1.350 raeburn 1558: $seccount->{'st'} = scalar(keys(%sections_count));
1.262 raeburn 1559: }
1560: my $rolehash = {
1561: 'roles' => $courseroles,
1562: 'seccount' => $seccount,
1.350 raeburn 1563: 'privs' => $courseprivs,
1.262 raeburn 1564: };
1565: &Apache::lonnet::do_cache_new('getcourseroles',$cdom.'_'.$cnum,$rolehash);
1566: return;
1567: }
1568:
1.235 raeburn 1569: sub jump_to_role {
1.350 raeburn 1570: my ($cdom,$cnum,$seccount,$courseroles,$courseprivs,$priv) = @_;
1.239 raeburn 1571: my %lt = &Apache::lonlocal::texthash(
1572: this => 'This role has section(s) associated with it.',
1573: ente => 'Enter a specific section.',
1574: orlb => 'Enter a specific section, or leave blank for no section.',
1575: avai => 'Available sections are:',
1576: youe => 'You entered an invalid section choice:',
1.352 raeburn 1577: plst => 'Please try again.',
1.350 raeburn 1578: role => 'The role you selected is not permitted to view the current page.',
1579: swit => 'Switch role, but display Main Menu page instead?',
1.239 raeburn 1580: );
1581: my $js;
1582: if (ref($courseroles) eq 'HASH') {
1583: $js = ' var secpick = new Array("'.$lt{'ente'}.'","'.$lt{'orlb'}.'");'."\n".
1584: ' var numsec = new Array();'."\n".
1585: ' var rolesections = new Array();'."\n".
1586: ' var rolenames = new Array();'."\n".
1587: ' var roleseclist = new Array();'."\n";
1588: my @items = keys(%{$courseroles});
1589: for (my $i=0; $i<@items; $i++) {
1590: $js .= ' rolenames['.$i.'] = "'.$items[$i].'";'."\n";
1591: my ($secs,$secstr);
1592: if (ref($courseroles->{$items[$i]}) eq 'ARRAY') {
1593: my @sections = sort { $a <=> $b } @{$courseroles->{$items[$i]}};
1594: $secs = join('","',@sections);
1595: $secstr = join(', ',@sections);
1596: }
1597: $js .= ' rolesections['.$i.'] = new Array("'.$secs.'");'."\n".
1598: ' roleseclist['.$i.'] = "'.$secstr.'";'."\n".
1599: ' numsec['.$i.'] = "'.$seccount->{$items[$i]}.'";'."\n";
1600: }
1601: }
1.350 raeburn 1602: my $checkroles = 0;
1603: if ($priv && ref($courseprivs) eq 'HASH') {
1604: my (%disallowed,%allowed,@disallow);
1605: foreach my $role (sort(keys(%{$courseprivs}))) {
1606: my $trole;
1607: if ($role =~ m{^(.+?)\Q./$cdom/$cnum\E}) {
1608: $trole = $1;
1609: }
1610: if (($trole ne '') && ($trole ne 'cm')) {
1611: if ($courseprivs->{$role} =~ /\Q:$priv\E($|:|\&\w+)/) {
1612: $allowed{$trole} = 1;
1613: } else {
1614: $disallowed{$trole} = 1;
1615: }
1616: }
1617: }
1618: foreach my $trole (keys(%disallowed)) {
1619: unless ($allowed{$trole}) {
1620: push(@disallow,$trole);
1621: }
1622: }
1623: if (@disallow > 0) {
1624: $checkroles = 1;
1625: $js .= " var disallow = new Array('".join("','",@disallow)."');\n".
1626: " var rolecheck = 1;\n";
1627: }
1628: }
1629: if (!$checkroles) {
1630: $js .= " var disallow = new Array();\n".
1631: " rolecheck = 0;\n";
1632: }
1.273 droeschl 1633: return <<"END";
1.235 raeburn 1634: <script type="text/javascript">
1.273 droeschl 1635: //<![CDATA[
1.235 raeburn 1636: function adhocRole(roleitem) {
1.239 raeburn 1637: $js
1.235 raeburn 1638: var newrole = document.rolechooser.elements[roleitem].options[document.rolechooser.elements[roleitem].selectedIndex].value;
1639: if (newrole == '') {
1.350 raeburn 1640: return;
1.235 raeburn 1641: }
1.239 raeburn 1642: var fullrole = newrole+'./$cdom/$cnum';
1643: var selidx = '';
1644: for (var i=0; i<rolenames.length; i++) {
1645: if (rolenames[i] == newrole) {
1646: selidx = i;
1647: }
1648: }
1.350 raeburn 1649: if (rolecheck > 0) {
1650: for (var i=0; i<disallow.length; i++) {
1651: if (disallow[i] == newrole) {
1652: if (confirm("$lt{'role'}\\n$lt{'swit'}")) {
1653: document.rolechooser.destinationurl.value = '/adm/menu';
1654: } else {
1655: document.rolechooser.elements[roleitem].selectedIndex = 0;
1656: return;
1657: }
1658: }
1659: }
1660: }
1.239 raeburn 1661: var secok = 1;
1662: var secchoice = '';
1663: if (selidx >= 0) {
1664: if (numsec[selidx] > 1) {
1665: secok = 0;
1666: var numrolesec = rolesections[selidx].length;
1667: var msgidx = numsec[selidx] - numrolesec;
1.339 raeburn 1668: secchoice = prompt("$lt{'this'} "+secpick[msgidx]+"\\n$lt{'avai'} "+roleseclist[selidx],"");
1.239 raeburn 1669: if (secchoice == '') {
1670: if (msgidx > 0) {
1671: secok = 1;
1672: }
1673: } else {
1674: for (var j=0; j<rolesections[selidx].length; j++) {
1675: if (rolesections[selidx][j] == secchoice) {
1676: secok = 1;
1677: }
1678: }
1679: }
1680: } else {
1681: if (rolesections[selidx].length == 1) {
1682: secchoice = rolesections[selidx][0];
1683: }
1684: }
1685: }
1686: if (secok == 1) {
1687: if (secchoice != '') {
1688: fullrole += '/'+secchoice;
1689: }
1690: } else {
1691: document.rolechooser.elements[roleitem].selectedIndex = 0;
1692: if (secchoice != null) {
1693: alert("$lt{'youe'} \\""+secchoice+"\\".\\n $lt{'plst'}");
1694: }
1695: return;
1696: }
1697: if (fullrole == "$env{'request.role'}") {
1.350 raeburn 1698: document.rolechooser.elements[roleitem].selectedIndex = 0;
1.235 raeburn 1699: return;
1700: }
1701: itemid = retrieveIndex('gotorole');
1702: if (itemid != -1) {
1.239 raeburn 1703: document.rolechooser.elements[itemid].name = fullrole;
1.235 raeburn 1704: }
1.239 raeburn 1705: document.rolechooser.elements[roleitem].options[document.rolechooser.elements[roleitem].selectedIndex].value = fullrole;
1.235 raeburn 1706: document.rolechooser.selectrole.value = '1';
1707: document.rolechooser.submit();
1708: return;
1709: }
1710:
1711: function retrieveIndex(item) {
1712: for (var i=0;i<document.rolechooser.elements.length;i++) {
1713: if (document.rolechooser.elements[i].name == item) {
1714: return i;
1715: }
1716: }
1717: return -1;
1718: }
1.273 droeschl 1719: // ]]>
1.235 raeburn 1720: </script>
1721: END
1722: }
1723:
1.350 raeburn 1724: sub required_privs {
1725: my $privs = {
1726: '/adm/parmset' => 'opa',
1727: '/adm/courseprefs' => 'opa',
1728: '/adm/whatsnew' => 'whn',
1729: '/adm/populate' => 'cst',
1730: '/adm/trackstudent' => 'vsa',
1731: '/adm/statistics' => 'vgr',
1.366 raeburn 1732: '/adm/setblock' => 'dcm',
1.367 raeburn 1733: '/adm/coursedocs' => 'mdc',
1.350 raeburn 1734: };
1735: unless ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'spreadsheet') {
1.364 raeburn 1736: $privs->{'/adm/classcalc'} = 'vgr',
1737: $privs->{'/adm/assesscalc'} = 'vgr',
1738: $privs->{'/adm/studentcalc'} = 'vgr';
1.350 raeburn 1739: }
1740: return $privs;
1741: }
1.235 raeburn 1742:
1.2 www 1743: # ================================================================ Main Program
1744:
1.16 harris41 1745: BEGIN {
1.166 albertel 1746: if (! defined($readdesk)) {
1.283 droeschl 1747: {
1748: my $tabfile = $Apache::lonnet::perlvar{'lonTabDir'}.'/mydesk.tab';
1749: if ( CORE::open( my $config,"<$tabfile") ) {
1750: while (my $configline=<$config>) {
1751: $configline=(split(/\#/,$configline))[0];
1752: $configline=~s/^\s+//;
1753: chomp($configline);
1.209 www 1754: if ($configline=~/^cat\:/) {
1.283 droeschl 1755: my @entries=split(/\:/,$configline);
1756: $category_positions{$entries[2]}=$entries[1];
1757: $category_names{$entries[2]}=$entries[3];
1758: } elsif ($configline=~/^prim\:/) {
1759: my @entries = (split(/\:/, $configline))[1..5];
1760: push @primary_menu, \@entries;
1.371 raeburn 1761: } elsif ($configline=~/^primsub\:/) {
1762: my ($parent,@entries) = (split(/\:/, $configline))[1..4];
1763: push (@{$primary_submenu{$parent}},\@entries);
1.283 droeschl 1764: } elsif ($configline=~/^scnd\:/) {
1765: my @entries = (split(/\:/, $configline))[1..5];
1766: push @secondary_menu, \@entries;
1767: } elsif ($configline) {
1768: push(@desklines,$configline);
1769: }
1770: }
1771: CORE::close($config);
1772: }
1773: }
1774: $readdesk='done';
1.2 www 1775: }
1776: }
1.30 www 1777:
1.1 www 1778: 1;
1779: __END__
1780:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>