Annotation of loncom/interface/loncourserespicker.pm, revision 1.17
1.1 raeburn 1: # The LearningOnline Network
2: #
1.17 ! raeburn 3: # $Id: loncourserespicker.pm,v 1.16 2024/04/16 15:35:23 raeburn Exp $
1.1 raeburn 4: #
5: # Copyright Michigan State University Board of Trustees
6: #
7: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
8: #
9: # LON-CAPA is free software; you can redistribute it and/or modify
10: # it under the terms of the GNU General Public License as published by
11: # the Free Software Foundation; either version 2 of the License, or
12: # (at your option) any later version.
13: #
14: # LON-CAPA is distributed in the hope that it will be useful,
15: # but WITHOUT ANY WARRANTY; without even the implied warranty of
16: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17: # GNU General Public License for more details.
18: #
19: # You should have received a copy of the GNU General Public License
20: # along with LON-CAPA; if not, write to the Free Software
21: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22: #
23: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27:
28: =pod
29:
30: =head1 NAME
31:
32: loncourserespicker - Utilities to choose folders and resources in a course.
33:
34: =head1 SYNOPSIS
35:
36: loncourserespicker provides an interface for selecting which folders and/or
37: resources are to be either:
38:
39: (a) exported to an IMS Content Package
1.17 ! raeburn 40: (b) subject to access blocking for the duration of an exam/quiz.
1.7 raeburn 41: (c) dumped to an Authoring Space
1.15 raeburn 42: (d) receive shortened URLs to be used when deep-linking into a course
1.1 raeburn 43:
44: =head1 DESCRIPTION
45:
46: This module provides routines to generate a hierarchical display of folders
47: and resources in a course which can be selected for specific actions.
48:
49: The choice of items is copied back to the main window from which the pop-up
50: window used to display the Course Contents was opened.
51:
52: =head1 OVERVIEW
53:
54: The main subroutine: &create_picker() will display the hierarchy of folders,
1.6 raeburn 55: sub-folders, and resources in the Main Content area. Items can be selected
56: using checkboxes, and/or a "Check All" button. Selection of a folder
1.1 raeburn 57: causes the contents of the folder to also be selected automatically. The
58: propagation of check status is recursive into sub-folders. Likewise, if an
59: item deep in a nested set of folders and sub-folders is unchecked, the
60: uncheck will propagate up through the hierarchy causing any folders at
61: a higher level to become unchecked.
62:
63: There is a submit button, which will be named differently according to the
1.7 raeburn 64: context in which resource/folder selection is being made.
1.1 raeburn 65:
1.17 ! raeburn 66: The four contexts currently supported are: IMS export, selection of
1.1 raeburn 67: content to be subject to access restructions for the duration of an
1.17 ! raeburn 68: exam, selection of items for dumping to an Authoring Space, and
! 69: display or creation of shortened URLs for deep-linking,
1.1 raeburn 70:
71: =head1 INTERNAL SUBROUTINES
72:
73: =item &create_picker()
74:
75: Created HTML mark up to display contents of course with checkboxes to
76: select items. Checking a folder causes recursive checking of items
77: within the folder. Unchecking a resource causing unchecking of folders
78: containing the item back up to the top level.
79:
1.14 raeburn 80: Inputs: 11.
1.1 raeburn 81: - $navmap -- Reference to LON-CAPA navmap object
82: (encapsulates information about resources in the course).
83:
84: - $context -- Context in which course resource selection is being made.
1.15 raeburn 85: Currently imsexport, examblock, dumpdocs, and shorturls
86: are supported.
1.1 raeburn 87:
88: - $formname -- Name of the form in the window from which the pop-up
89: used to select course items was launched.
90:
91: - $crstype -- Course or Community
92:
93: - $blockedmaps -- Reference to hash of previously selected maps
94: (e.g., for a live exam block).
95:
96: - $blockedresources -- Reference to hash of resources selected
97: previously (e.g., for an exam block).
98:
99: - $block -- An internal ID (integer) used to track which exam
100: block currently being configured.
101:
1.7 raeburn 102: - $preamble -- HTML form elements used to select Authoring Space
103: if more than one available, and also set name of 'Folder
104: in Authoring Space' where content will be dumped, when
105: context is 'dumpdocs'.
106:
107: - $numhome -- number of possible Authoring Spaces where content could
108: be dumped when context is 'dumpdocs'.
109:
110: - $uploadedfiles -- Reference to hash: keys are paths to files in
111: /home/httpd/lonUsers/$cdom/$1/$2/$3/$cnum/userfiles.
1.15 raeburn 112:
113: - $tiny -- Reference to hash: keys are symbs of course items for which
114: shortened URLs have already been created.
115:
1.14 raeburn 116: - $readonly -- if true, no "check all" or "uncheck all" buttons will
117: be displayed, and checkboxes will be disabled, if this
1.15 raeburn 118: is for an exam block or for shortened URL creation.
1.7 raeburn 119:
1.1 raeburn 120:
121: Output: $output is the HTML mark-up for display/selection of content
122: items in the pop-up window.
123:
124: =item &respicker_javascript()
125:
126: Creates javascript functions for checking/unchecking all items, and
127: for recursive checking triggered by checking a folder, or recursive
128: (upeards) unchecking of an item within a folder.
129:
130: Inputs: 7.
131: - $startcount -- Starting offset of form element numbering for items
132:
133: - $numcount -- Total numer of folders and resources in course.
134:
135: - $context -- Context in which resources are being displayed
1.17 ! raeburn 136: (imsexport, examblock, dumpdocs or shorturls).
1.1 raeburn 137:
138: - $formname -- Name of form.
139:
140: - $children -- Reference to hash of items contained within a folder.
141:
142: - $hierarchy -- Reference to hierarchy of folders containing an item.
143:
144: - $checked_maps -- Reference to array of folders currently checked.
145:
1.7 raeburn 146: Output: 1. Javascript (within <script></script> tags.
1.1 raeburn 147:
148:
149: =item &get_navmap_object()
150:
151: Instantiates a navmaps object, and generates an error message if
152: no object instantiated.
153:
154: Inputs: 2.
155: - $crstype -- Container type: Course or Community
156:
1.17 ! raeburn 157: - $context -- Context: imsexport, examblock, dumpdocs, or shorturls
1.7 raeburn 158:
159:
160: =item &clean()
161:
162: Takes incoming title and replaces non-alphanumeric characters with underscore,
163: so title can be used as suggested file name (with appended extension) for file
1.11 bisitz 164: copied from course to Authoring Space.
1.7 raeburn 165:
166:
167: =item &enumerate_course_contents()
168:
169: Create hashes of maps (for folders/pages) and symbs (for resources) in
170: a course, where keys are numbers (starting with 1) and values are
171: map url, or symb, for an iteration through the course, as seen by
172: a Course Coordinator. Used to generate numerical IDs to facilitate
173: (a) storage of lists of maps or resources to be blocked during an exam,
174: (b) processing selected form element during dumping of selected course
1.11 bisitz 175: content to Authoring Space.
1.17 ! raeburn 176: (c)
1.7 raeburn 177:
178: Inputs: 7
179:
180: $navmap - navmaps object
181:
182: $map_url - reference to hash to contain URLs of maps in course
183:
184: $resource_symb - reference to hash to contain symbs for
185: resources in course
186:
187: $title_ref - reference to hash containing titles for items in
188: course
189:
1.17 ! raeburn 190: $context - examblock, dumpdocs or shorturls
1.7 raeburn 191:
192: $cdom - course's domain
193:
194: $cnum - courseID
195:
196: Outputs: None
197:
198: Side Effects: $map_url and $resource_symb hashrefs are populated.
199:
1.1 raeburn 200:
201: =over
202:
203: =back
204:
205: =cut
206:
207:
208: package Apache::loncourserespicker;
209:
210: use strict;
211: use Apache::lonnet;
212: use Apache::loncommon;
213: use Apache::lonhtmlcommon;
214: use Apache::lonnavmaps;
1.2 raeburn 215: use Apache::londocs;
1.1 raeburn 216: use Apache::lonlocal;
217: use LONCAPA qw(:DEFAULT :match);
218:
219: sub create_picker {
1.14 raeburn 220: my ($navmap,$context,$formname,$crstype,$blockedmaps,$blockedresources,$block,$preamble,
1.15 raeburn 221: $numhome,$uploadedfiles,$tiny,$readonly) = @_;
1.1 raeburn 222: return unless (ref($navmap));
1.16 raeburn 223: my ($it,$output,$numdisc,%discussiontime,%currmaps,%currresources,%files,
1.15 raeburn 224: %shorturls,$chkname);
225: $chkname = 'archive';
226: if ($context eq 'shorturls') {
227: $chkname = 'addtiny';
228: }
1.1 raeburn 229: $it = $navmap->getIterator(undef,undef,undef,1,undef,undef);
230: if (ref($blockedmaps) eq 'HASH') {
231: %currmaps = %{$blockedmaps};
232: }
233: if (ref($blockedresources) eq 'HASH') {
234: %currresources = %{$blockedresources};
1.7 raeburn 235: } elsif (ref($uploadedfiles) eq 'HASH') {
236: %files = %{$uploadedfiles};
1.15 raeburn 237: } elsif (ref($tiny) eq 'HASH') {
238: %shorturls = %{$tiny};
1.1 raeburn 239: }
240: my @checked_maps;
241: my $curRes;
242: my $numprobs = 0;
243: my $depth = 0;
244: my $count = 0;
245: my $boards = 0;
246: my $startcount = 1;
247: my %parent = ();
248: my %children = ();
249: my %hierarchy = ();
250: my $location=&Apache::loncommon::lonhttpdurl("/adm/lonIcons");
1.7 raeburn 251: my $whitespace =
1.1 raeburn 252: '<img src="'.$location.'/whitespace_21.gif" class="LC_docs_spacer" alt="" />';
253:
1.7 raeburn 254: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
255: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
256: my $crsprefix = &propath($cdom,$cnum).'/userfiles/';
257:
1.14 raeburn 258: my ($info,$display,$onsubmit,$togglebuttons,$disabled);
1.1 raeburn 259: if ($context eq 'examblock') {
260: my $maps_elem = 'docs_maps_'.$block;
261: my $res_elem = 'docs_resources_'.$block;
262: $onsubmit = ' onsubmit="return writeToOpener('."'$maps_elem','$res_elem'".');"';
1.7 raeburn 263: $info = &mt('Items in '.lc($crstype).' for which access will be blocked.');
1.14 raeburn 264: if ($readonly) {
265: $disabled = ' disabled="disabled"';
266: }
1.1 raeburn 267: }
1.7 raeburn 268: if ($context eq 'dumpdocs') {
269: $info = '<span class="LC_fontsize_medium">'.
1.11 bisitz 270: &mt('Choose the uploaded course items and templated pages/problems to be copied to Authoring Space.').
1.7 raeburn 271: '</span><br /><br />';
272: $startcount = 3 + $numhome;
1.15 raeburn 273: $onsubmit = ' onsubmit="return checkUnique(document.'.$formname.',document.'.$formname.'.'.$chkname.');"';
274: } elsif ($context eq 'shorturls') {
275: $info = '<span class="LC_fontsize_medium">'.
276: &mt('Choose the resource(s) and/or folder(s) from Main Content for which shortened URL(s) are needed.').
277: '</span><br /><br />';
1.7 raeburn 278: } elsif ($context eq 'imsexport') {
279: $info = &mt('Choose which items you wish to export from your '.$crstype.'.');
1.1 raeburn 280: $startcount = 5;
281: }
1.14 raeburn 282: if ($disabled) {
283: $togglebuttons = '<br />';
284: } else {
285: $togglebuttons = '<input type="button" value="'.&mt('check all').'" '.
1.15 raeburn 286: 'onclick="javascript:checkAll(document.'.$formname.'.'.$chkname.')" />'.
1.14 raeburn 287: ' <input type="button" value="'.&mt('uncheck all').'"'.
1.15 raeburn 288: ' onclick="javascript:uncheckAll(document.'.$formname.'.'.$chkname.')" />';
1.14 raeburn 289: }
1.7 raeburn 290: $display = '<form name="'.$formname.'" action="" method="post"'.$onsubmit.'>'."\n";
1.1 raeburn 291: if ($context eq 'imsexport') {
1.7 raeburn 292: $display .= $info.
293: '<div class="LC_columnSection">'."\n".
1.1 raeburn 294: '<fieldset>'.
1.7 raeburn 295: '<legend>'.&mt('Content items').'</legend>'."\n".
296: $togglebuttons.
297: '</fieldset>';
298: %discussiontime = &Apache::lonnet::dump('discussiontimes',$cdom,$cnum);
1.1 raeburn 299: $numdisc = keys(%discussiontime);
300: if ($numdisc > 0) {
301: $display .=
302: '<fieldset>'.
303: '<legend>'.&mt('Discussion posts').'</legend>'.
304: '<input type="button" value="'.&mt('check all').'"'.
305: ' onclick="javascript:checkAll(document.'.$formname.'.discussion)" />'.
306: ' <input type="button" value="'.&mt('uncheck all').'"'.
307: ' onclick="javascript:uncheckAll(document.'.$formname.'.discussion)" />'.
1.2 raeburn 308: '</fieldset>';
1.1 raeburn 309: }
1.7 raeburn 310: $display .= '</div>';
1.15 raeburn 311: } elsif (($context eq 'examblock') || ($context eq 'shorturls')) {
1.7 raeburn 312: $display .= $info.$togglebuttons;
313: } elsif ($context eq 'dumpdocs') {
314: $display .= $preamble.
315: '<div class="LC_left_float">'.
316: '<fieldset>'.
317: '<legend>'.&mt('Content to copy').(' 'x4).$togglebuttons.'</legend>'.
318: $info;
1.1 raeburn 319: }
320: my $lastcontainer = $startcount;
321: $display .= &Apache::loncommon::start_data_table()
322: .&Apache::loncommon::start_data_table_header_row();
323: if ($context eq 'imsexport') {
324: $display .= '<th>'.&mt('Export content item?').'</th>';
325: if ($numdisc > 0) {
326: $display .= '<th>'.&mt('Export discussion posts?').'</th>';
327: }
328: } elsif ($context eq 'examblock') {
329: $display .= '<th>'.&mt('Access blocked?').'</th>';
1.7 raeburn 330: } elsif ($context eq 'dumpdocs') {
331: $display .= '<th>'.&mt('Copy?').'</th>'.
1.15 raeburn 332: '<th>'.&mt("Title in $crstype").'</th>'.
1.7 raeburn 333: '<th>'.&mt('Internal Identifier').'</th>'.
334: '<th>'.&mt('Save as ...').'</th>';
1.15 raeburn 335: } elsif ($context eq 'shorturls') {
336: $display .= '<th colspan="2">'.&mt('Tiny URL').'</th>'.
337: '<th>'.&mt("Title in $crstype").'</th>';
1.1 raeburn 338: }
339: $display .= &Apache::loncommon::end_data_table_header_row();
340: while ($curRes = $it->next()) {
341: if ($curRes == $it->BEGIN_MAP()) {
342: $depth++;
343: $parent{$depth} = $lastcontainer;
344: }
345: if ($curRes == $it->END_MAP()) {
346: $depth--;
347: $lastcontainer = $parent{$depth};
348: }
349: if (ref($curRes)) {
350: my $symb = $curRes->symb();
351: my $ressymb = $symb;
1.7 raeburn 352: if ($context eq 'dumpdocs') {
353: next unless (($curRes->src() =~ m{^\Q/uploaded/$cdom/$cnum/\E(docs|supplemental|simplepage)}) ||
354: ($curRes->src() =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)_\d+\.(sequence|page)}) ||
355: ($curRes->src() eq '/res/lib/templates/simpleproblem.problem') ||
356: ($curRes->src() =~ m{^/adm/$match_domain/$match_username/\d+/smppg}));
357: } elsif ($ressymb =~ m|adm/($match_domain)/($match_username)/(\d+)/bulletinboard$|) {
1.1 raeburn 358: unless ($ressymb =~ m|adm/wrapper/adm|) {
359: $ressymb = 'bulletin___'.$3.'___adm/wrapper/adm/'.$1.'/'.$2.'/'.$3.'/bulletinboard';
360: }
361: }
1.7 raeburn 362: $count ++;
1.15 raeburn 363: my ($currelem,$mapurl,$is_map);
1.7 raeburn 364: if ($context eq 'imsexport') {
365: $currelem = $count+$boards+$startcount;
366: } else {
367: $currelem = $count+$startcount;
368: }
1.15 raeburn 369: $display .= &Apache::loncommon::start_data_table_row()."\n";
1.1 raeburn 370: if (($curRes->is_sequence()) || ($curRes->is_page())) {
371: $lastcontainer = $currelem;
1.15 raeburn 372: $mapurl = (&Apache::lonnet::decode_symb($symb))[2];
373: $is_map = 1;
374: }
375: if ($context eq 'shorturls') {
376: if ($shorturls{$symb}) {
377: $display .= '<td> </td><td align="right"><b>'."/tiny/$cdom/$shorturls{$symb}".'</b></td>'."\n";
378: } else {
379: $display .= '<td align="left"><label><input type="checkbox" name="'.$chkname.'" '.
380: 'value="'.$count.'"'.$disabled.' />'.&mt('Add').'</label></td>'.
381: '<td> </td>'."\n";
1.1 raeburn 382: }
383: } else {
1.15 raeburn 384: $display .= '<td><input type="checkbox" name="'.$chkname.'" value="'.$count.'" ';
385: if ($is_map) {
386: $display .= 'onclick="javascript:checkFolder(document.'.$formname.','."'$currelem'".')" ';
387: if ($currmaps{$mapurl}) {
388: $display .= 'checked="checked"';
389: push(@checked_maps,$currelem);
390: }
391: } else {
392: if ($curRes->is_problem()) {
393: $numprobs ++;
394: }
395: $display .= 'onclick="javascript:checkResource(document.'.$formname.','."'$currelem'".')" ';
396: if ($currresources{$symb}) {
397: $display .= 'checked="checked"';
398: }
1.1 raeburn 399: }
1.15 raeburn 400: $display .= $disabled.' />'."\n";
1.1 raeburn 401: }
1.7 raeburn 402: if ($context eq 'dumpdocs') {
403: $display .= '</td><td valign="top">';
1.15 raeburn 404: } elsif ($context eq 'shorturls') {
405: $display .= '<td valign="top">';
1.7 raeburn 406: }
1.1 raeburn 407: for (my $i=0; $i<$depth; $i++) {
408: $display .= "$whitespace\n";
409: }
410: my $icon = 'src="'.$location.'/unknown.gif" alt=""';
411: if ($curRes->is_sequence()) {
1.4 bisitz 412: $icon = 'src="'.$location.'/navmap.folder.open.gif" alt="'.&mt('Folder').'"';
1.1 raeburn 413: } elsif ($curRes->is_page()) {
414: $icon = 'src="'.$location.'/navmap.page.open.gif" alt="'.&mt('Composite Page').'"';
415: } elsif ($curRes->is_problem()) {
416: $icon = 'src="'.$location.'/problem.gif" alt="'.&mt('Problem').'"';
417: } elsif ($curRes->is_task()) {
418: $icon = 'src="'.$location.'/task.gif" alt="'.&mt('Task').'"';
419: } elsif ($curRes->src ne '') {
420: $icon = 'src="'.&Apache::loncommon::icon($curRes->src).'" alt=""';
421: }
422: $display .= '<img '.$icon.' /> '."\n";
423: $children{$parent{$depth}} .= $currelem.':';
424: if ($context eq 'examblock') {
425: if ($parent{$depth} > 1) {
426: if ($hierarchy{$parent{$depth}}) {
427: $hierarchy{$currelem} = $hierarchy{$parent{$depth}}.",'$parent{$depth}'";
428: } else {
429: $hierarchy{$currelem} = "'$parent{$depth}'";
430: }
431: }
432: }
1.7 raeburn 433: $display .= ' '.$curRes->title().$whitespace.'</td>'."\n";
1.1 raeburn 434:
435: if ($context eq 'imsexport') {
436: # Existing discussion posts?
437: if ($discussiontime{$ressymb} > 0) {
438: $boards ++;
439: $display .= '<td align="right">'
440: .'<input type="checkbox" name="discussion" value="'.$count.'" />'
441: .'</td>'."\n";
442: } elsif ($numdisc > 0) {
443: $display .= '<td> </td>'."\n";
444: }
1.7 raeburn 445: } elsif ($context eq 'dumpdocs') {
446: my $src = $curRes->src();
447: my ($filepath,$title);
448: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E}) {
449: $filepath = &Apache::lonnet::filelocation('',$src);
450: $filepath =~ s/\Q$crsprefix\E//;
451: if ($curRes->is_map()) {
452: $title = $files{$filepath};
453: } else {
454: $filepath =~ s{docs/}{};
455: $title = $filepath;
456: $title =~ s{^(default|\d+)/\d*/?}{};
457: }
458: } else {
459: $title = $curRes->title();
460: $title =~ s{/}{_}g;
461: $title = &clean($title);
462: if ($src eq '/res/lib/templates/simpleproblem.problem') {
463: my ($map,$id,$res) = &Apache::lonnet::decode_symb($symb);
464: $map =~ s{^uploaded/$cdom/$cnum/}{};
465: $filepath = $map.'_'.$id;
466: $title .= '.problem';
467: } elsif ($src =~ m{^/adm/$match_domain/$match_username/(\d+)/smppg}) {
468: $filepath = 'smppage_'.$1.'.db';
469: $title .= '.html';
470: }
471: }
472: $display .= '<td>'.$filepath.'</td>'.
473: '<td><input type="text" size="40" name="namefor_'.$count.'" id="namefor_'.$count.'" value="'.$title.'" /></td>'."\n";
1.1 raeburn 474: }
475: $display .= &Apache::loncommon::end_data_table_row();
476: }
477: }
478: $display .= &Apache::loncommon::end_data_table();
479: if ($context eq 'imsexport') {
480: if ($numprobs > 0) {
481: $display .= '<p><span class="LC_nobreak">'.
482: &mt('Export format for LON-CAPA problems:').
483: '<label><input type="radio" name="format" value="xml" checked="checked" />'.
484: ' '.&mt('XML').'</label>'.(' ' x3).
485: '<label><input type="radio" name="format" value="html" />'.
486: ' '.&mt('HTML').'</label>'.(' ' x3).
487: '<label><input type="radio" name="format" value="plaintext" />'.
488: ' '.&mt('Text').'</label></span></p>';
489: }
490: }
1.7 raeburn 491: my $numcount;
1.1 raeburn 492: if ($context eq 'imsexport') {
493: $display .=
1.7 raeburn 494: '<p>'.
1.1 raeburn 495: '<input type="hidden" name="finishexport" value="1" />'.
496: '<input type="submit" name="exportcourse" value="'.
1.7 raeburn 497: &mt('Export').'" /></p>';
498: $numcount = $count + $boards + $startcount;
1.1 raeburn 499: } elsif ($context eq 'examblock') {
1.14 raeburn 500: unless ($readonly) {
501: $display .=
502: '<p>'.
503: '<input type="submit" name="resourceblocks" value="'.
504: &mt('Copy Choices to Main Window').'" /></p>';
505: }
1.7 raeburn 506: $numcount = $count + $startcount;
507: } elsif ($context eq 'dumpdocs') {
508: $display .= '</fieldset>'.
509: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
510: '<div>'.
1.8 raeburn 511: '<input type="submit" name="dumpcourse" value="'.&mt("Copy $crstype Content").'" />'.
1.7 raeburn 512: '</div>';
513: $numcount = $count + $startcount;
1.15 raeburn 514: } elsif ($context eq 'shorturls') {
515: unless ($readonly) {
516: $display .=
517: '<p>'.
518: '<input type="submit" name="shorturls" value="'.
519: &mt('Create Tiny URL(s)').'" /></p>';
520: }
1.1 raeburn 521: }
1.7 raeburn 522: $display .= '</form>';
1.17 ! raeburn 523: my $scripttag =
1.1 raeburn 524: &respicker_javascript($startcount,$numcount,$context,$formname,\%children,
1.15 raeburn 525: \%hierarchy,\@checked_maps,$numhome,$chkname);
526: if (($context eq 'dumpdocs') || ($context eq 'shorturls')) {
1.7 raeburn 527: return $scripttag.$display;
528: }
1.1 raeburn 529: my ($title,$crumbs,$args);
1.7 raeburn 530: if ($context eq 'imsexport') {
1.1 raeburn 531: $title = 'Export '.$crstype.' to IMS Package';
532: } elsif ($context eq 'examblock') {
533: $title = 'Resources with Access blocked';
534: $args = {'only_body' => 1,
535: 'add_entries' => { onload => 'javascript:recurseFolders();' },
536: };
537: }
1.3 raeburn 538: $output = &Apache::loncommon::start_page($title,$scripttag,$args);
1.1 raeburn 539: if ($context eq 'imsexport') {
1.2 raeburn 540: $output .= &Apache::lonhtmlcommon::breadcrumbs('IMS Export').
541: &Apache::londocs::startContentScreen('tools');
1.7 raeburn 542: } elsif ($context eq 'dumpdocs') {
1.15 raeburn 543: $output .= &Apache::lonhtmlcommon::breadcrumbs('Copying to Authoring Space').
544: &Apache::londocs::startContentScreen('tools');
1.1 raeburn 545: }
546: $output .= $display;
547: if ($context eq 'examblock') {
548: $output .= &Apache::loncommon::end_page();
1.2 raeburn 549: } elsif ($context eq 'imsexport') {
550: $output .= &Apache::londocs::endContentScreen();
1.1 raeburn 551: }
552: return $output;
553: }
554:
555: sub respicker_javascript {
556: my ($startcount,$numitems,$context,$formname,$children,$hierarchy,
1.15 raeburn 557: $checked_maps,$numhome,$chkname) = @_;
558: my $check_uncheck = <<"FIRST";
1.1 raeburn 559: function checkAll(field) {
560: if (field.length > 0) {
561: for (i = 0; i < field.length; i++) {
562: field[i].checked = true ;
563: }
564: } else {
565: field.checked = true
566: }
567: }
568:
569: function uncheckAll(field) {
570: if (field.length > 0) {
571: for (i = 0; i < field.length; i++) {
572: field[i].checked = false;
573: }
574: } else {
575: field.checked = false;
576: }
577: }
1.15 raeburn 578: FIRST
579: if ($context eq 'shorturls') {
580: return <<"END";
581: <script type="text/javascript">
582: // <![CDATA[
583: $check_uncheck
584: // ]]>
585: </script>
586: END
587: }
588: return unless ((ref($children) eq 'HASH') && (ref($hierarchy) eq 'HASH')
589: && (ref($checked_maps) eq 'ARRAY'));
590: my ($elem,$nested,$nameforelem);
591: if ($context eq 'dumpdocs') {
592: $elem='((parseInt(item)-'.$startcount.')*2)+'.$startcount;
593: $nested='((parseInt(nesting[item][i])-'.$startcount.')*2)+'.$startcount;
594: $nameforelem=$elem+1;
595: } else {
596: $elem='parseInt(item)';
597: $nested='parseInt(nesting[item][i])';
598: }
599: my $scripttag = <<"START";
600: <script type="text/javascript">
601: // <![CDATA[
602: $check_uncheck
1.1 raeburn 603:
604: function checkFolder(form,item) {
1.7 raeburn 605: var elem = $elem;
606: if (form.elements[elem].checked == true) {
1.1 raeburn 607: containerCheck(form,item);
608: } else {
609: containerUncheck(form,item);
610: }
611: }
612:
613: function checkResource(form,item) {
1.7 raeburn 614: var elem = $elem;
615: if (form.elements[elem].checked == false) {
1.1 raeburn 616: containerUncheck(form,item);
617: }
618: }
619:
620: numitems = $numitems;
621: var parents = new Array(numitems);
622: var nesting = new Array(numitems);
623: var initial = new Array();
624: for (var i=$startcount; i<numitems; i++) {
625: parents[i] = new Array();
626: nesting[i] = new Array();
627: }
628:
629: START
630:
631: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
632: my @contents = split(/:/,$children->{$container});
633: for (my $i=0; $i<@contents; $i ++) {
634: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
635: }
636: }
637:
638: if ($context eq 'examblock') {
639: foreach my $item (sort { $a <=> $b } (keys(%{$hierarchy}))) {
640: $scripttag .= "nesting[$item] = new Array($hierarchy->{$item});\n";
641: }
642:
643: my @sorted_maps = sort { $a <=> $b } (@{$checked_maps});
644: for (my $i=0; $i<@sorted_maps; $i++) {
645: $scripttag .= "initial[$i] = '$sorted_maps[$i]'\n";
646: }
647: $scripttag .= <<"EXTRA";
648:
649: function recurseFolders() {
650: if (initial.length > 0) {
651: for (var i=0; i<initial.length; i++) {
652: containerCheck(document.$formname,initial[i]);
653: }
654: }
655: return;
656: }
657:
658: EXTRA
1.7 raeburn 659: } elsif ($context eq 'dumpdocs') {
660: my $blankmsg = &mt('An item selected has no filename set in the "Save as ..." column.');
661: my $dupmsg = &mt('Items selected for copying need unique filenames in the "Save as ..." column.');
1.11 bisitz 662: my $homemsg = &mt('An Authoring Space needs to be selected.');
1.13 damieng 663: &js_escape(\$blankmsg);
664: &js_escape(\$dupmsg);
665: &js_escape(\$homemsg);
1.7 raeburn 666: $scripttag .= <<"EXTRA";
667:
668: function checkUnique(form,field) {
669: var duplicate = 0;
670: var blank = 0;
1.9 raeburn 671: var numhome = '$numhome';
1.7 raeburn 672: if (field.length > 0) {
673: for (i=0; i<field.length; i++) {
674: if (field[i].checked) {
675: var item = field[i].value;
676: var namefor = document.getElementById('namefor_'+item);
677: if (namefor) {
678: var possval = namefor.value;
679: if (!possval) {
680: blank = item;
681: break;
682: }
683: for (j=i+1; j<field.length; j++) {
684: if (field[j].checked) {
685: var curritem = field[j].value;
686: var currnamefor = document.getElementById('namefor_'+curritem);
687: if (currnamefor) {
688: var currval = currnamefor.value;
689: if (currval == possval) {
690: duplicate = curritem;
691: break;
692: }
693: }
694: }
695: }
696: if (duplicate) {
697: break;
698: }
699: }
700: }
701: }
702: }
703: if (blank) {
704: alert('$blankmsg');
705: return false;
706: }
707: if (duplicate) {
708: alert('$dupmsg');
709: return false;
710: }
1.9 raeburn 711: if (numhome > 1) {
712: if (!form.authorspace.options[form.authorspace.selectedIndex].value) {
713: alert('$homemsg');
714: return false;
715: }
716: }
1.7 raeburn 717: return true;
718: }
719:
720: EXTRA
721:
1.1 raeburn 722: }
723:
724: $scripttag .= <<"END";
725:
726: function containerCheck(form,item) {
1.7 raeburn 727: var elem = $elem;
728: form.elements[elem].checked = true;
1.1 raeburn 729: if(Object.prototype.toString.call(parents[item]) === '[object Array]') {
730: if (parents[item].length > 0) {
731: for (var j=0; j<parents[item].length; j++) {
732: containerCheck(form,parents[item][j]);
733: }
734: }
735: }
736: }
737:
738: function containerUncheck(form,item) {
739: if(Object.prototype.toString.call(nesting[item]) === '[object Array]') {
740: if (nesting[item].length > 0) {
741: for (var i=0; i<nesting[item].length; i++) {
1.7 raeburn 742: var nested = $nested;
1.1 raeburn 743: }
744: }
745: }
746: return;
747: }
748:
749: END
750:
751: if ($context eq 'examblock') {
752: $scripttag .= <<ENDEX;
753: function writeToOpener(maps,resources) {
754: var checkedmaps = '';
755: var checkedresources = '';
1.15 raeburn 756: for (var i=0; i<document.$formname.${chkname}.length; i++) {
757: if (document.$formname.${chkname}[i].checked) {
1.1 raeburn 758: var isResource = 1;
759: var include = 1;
760: var elemnum = i+1+$startcount;
761: if (Object.prototype.toString.call(parents[elemnum]) === '[object Array]') {
762: if (parents[elemnum].length > 0) {
763: isResource = 0;
764: }
765: }
766: if (isResource == 1) {
1.12 raeburn 767: if (nesting[elemnum] != null) {
768: if (nesting[elemnum].length > 0) {
769: var lastelem = nesting[elemnum].length-1;
770: if (document.$formname.elements[nesting[elemnum][lastelem]].checked) {
771: include = 0;
772: }
1.1 raeburn 773: }
774: }
775: }
776: if (include == 1) {
777: if (isResource == 1) {
1.15 raeburn 778: checkedresources += document.$formname.${chkname}[i].value+',';
1.1 raeburn 779: } else {
1.15 raeburn 780: checkedmaps += document.$formname.${chkname}[i].value+',';
1.1 raeburn 781: }
782: }
783: }
784: }
785: opener.document.getElementById(maps).value = checkedmaps;
786: opener.document.getElementById(resources).value = checkedresources;
787: window.close();
788: return false;
789: }
790:
791: ENDEX
792: }
793:
794: $scripttag .= '
795: // ]]>
796: </script>
797: ';
798: return $scripttag;
799: }
800:
801: sub get_navmap_object {
802: my ($crstype,$context) = @_;
803: my $navmap = Apache::lonnavmaps::navmap->new();
804: my $outcome;
805: if (!defined($navmap)) {
806: if ($context eq 'imsexport') {
807: $outcome = &Apache::loncommon::start_page('Export '.$crstype.' to IMS Package').
808: '<h2>'.&mt('IMS Export Failed').'</h2>';
809: } elsif ($context eq 'examblock') {
810: $outcome = &Apache::loncommon::start_page('Selection of Resources for Blocking',
811: undef,{'only_body' => 1,}).
812: '<h2>'.&mt('Resource Display Failed').'</h2>';
1.7 raeburn 813: } elsif ($context eq 'dumpdocs') {
1.15 raeburn 814: $outcome = '<h2>'.&mt('Copying to Authoring Space unavailable').'</h2>';
815: } elsif ($context eq 'shorturls') {
816: $outcome = '<h2>'.&mt('Display/Setting of shortened URLs unavailable').'</h2>';
1.7 raeburn 817: }
1.1 raeburn 818: $outcome .= '<div class="LC_error">';
819: if ($crstype eq 'Community') {
820: $outcome .= &mt('Unable to retrieve information about community contents');
821: } else {
822: $outcome .= &mt('Unable to retrieve information about course contents');
823: }
824: $outcome .= '</div>';
1.15 raeburn 825: if (($context eq 'imsexport') || ($context eq 'dumpdocs') || ($context eq 'shorturls') ) {
1.1 raeburn 826: $outcome .= '<a href="/adm/coursedocs">';
827: if ($crstype eq 'Community') {
828: $outcome .= &mt('Return to Community Editor');
829: } else {
830: $outcome .= &mt('Return to Course Editor');
831: }
832: $outcome .= '</a>';
1.7 raeburn 833: if ($context eq 'imsexport') {
834: &Apache::lonnet::logthis('IMS export failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.17 ! raeburn 835: } elsif ($context eq 'dumpdocs') {
1.8 raeburn 836: &Apache::lonnet::logthis('Copying to Authoring Space failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.17 ! raeburn 837: } elsif ($context eq 'shorturls') {
! 838: &Apache::lonnet::logthis('Displaying and/or saving URL shortcuts failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.7 raeburn 839: }
1.1 raeburn 840: } elsif ($context eq 'examblock') {
841: $outcome .= '<href="javascript:window.close();">'.&mt('Close window').'</a>';
842: }
843: return (undef,$outcome);
844: } else {
845: return ($navmap);
846: }
847: }
848:
1.7 raeburn 849: sub clean {
850: my ($title)=@_;
851: $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
852: return $title;
853: }
854:
855: sub enumerate_course_contents {
856: my ($navmap,$map_url,$resource_symb,$titleref,$context,$cdom,$cnum) = @_;
857: if ((ref($navmap)) && (ref($map_url) eq 'HASH') &&
858: (ref($resource_symb) eq 'HASH') && (ref($titleref) eq 'HASH')) {
859: my $it = $navmap->getIterator(undef,undef,undef,1,undef,undef);
860: my $count = 0;
861: while (my $curRes = $it->next()) {
862: if (ref($curRes)) {
863: my $symb = $curRes->symb();
864: my $ressymb = $symb;
865: if ($context eq 'dumpdocs') {
866: next unless (($curRes->src() =~ m{^\Q/uploaded/$cdom/$cnum/\E(docs|supplemental|simplepage)/}) ||
867: ($curRes->src() =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)_\d+\.(sequence|page)}) ||
868: ($curRes->src() eq '/res/lib/templates/simpleproblem.problem') ||
869: ($curRes->src() =~ m{^/adm/$match_domain/$match_username/\d+/smppg}));
870: } elsif ($ressymb =~ m{adm/($match_domain)/($match_username)/(\d+)/bulletinboard$}) {
871: unless ($ressymb =~ m{adm/wrapper/adm}) {
872: $ressymb = 'bulletin___'.$3.'___adm/wrapper/adm/'.$1.'/'.$2.'/'.$3.
873: '/bulletinboard';
874: }
875: }
876: $count ++;
1.15 raeburn 877: if ($context eq 'shorturls') {
878: $resource_symb->{$count} = $ressymb;
1.7 raeburn 879: } else {
1.15 raeburn 880: if (($curRes->is_sequence()) || ($curRes->is_page())) {
881: $map_url->{$count} = (&Apache::lonnet::decode_symb($symb))[2];
882: } else {
883: $resource_symb->{$count} = $ressymb;
884: }
1.7 raeburn 885: }
886: $titleref->{$count} = $curRes->title();
887: }
888: }
889: }
890: return;
891: }
892:
1.1 raeburn 893: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>