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