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