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