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