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