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