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