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