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