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