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