File:
[LON-CAPA] /
loncom /
interface /
londocs.pm
Revision
1.683:
download - view:
text,
annotated -
select for diffs
Wed Oct 19 02:10:20 2022 UTC (22 months ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
- Bug 6975.
- suppcount:domain:courseid item in memcached to record number of files
in course's supplemental content area replaced by showsupp:domain:courseid
item (=1, if at least one unhidden file present in supplemental content).
1: # The LearningOnline Network
2: # Documents
3: #
4: # $Id: londocs.pm,v 1.683 2022/10/19 02:10:20 raeburn Exp $
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: #
28:
29: package Apache::londocs;
30:
31: use strict;
32: use Apache::Constants qw(:common :http);
33: use Apache::imsexport;
34: use Apache::lonnet;
35: use Apache::loncommon;
36: use Apache::lonhtmlcommon;
37: use LONCAPA::map();
38: use Apache::lonratedt();
39: use Apache::lonxml;
40: use Apache::lonclonecourse;
41: use Apache::lonnavmaps;
42: use Apache::lonnavdisplay();
43: use Apache::lonextresedit();
44: use Apache::lontemplate();
45: use Apache::lonsimplepage();
46: use Apache::lonhomework();
47: use Apache::lonpublisher();
48: use Apache::lonparmset();
49: use Apache::loncourserespicker();
50: use HTML::Entities;
51: use HTML::TokeParser;
52: use GDBM_File;
53: use File::MMagic;
54: use File::Copy;
55: use Apache::lonlocal;
56: use Cwd;
57: use UUID::Tiny ':std';
58: use LONCAPA qw(:DEFAULT :match);
59:
60: my $iconpath;
61:
62: my %hash;
63:
64: my $hashtied;
65: my %alreadyseen=();
66:
67: my $hadchanges;
68: my $suppchanges;
69:
70:
71: my %help=();
72:
73:
74: sub mapread {
75: my ($coursenum,$coursedom,$map)=@_;
76: return
77: &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
78: $map);
79: }
80:
81: sub storemap {
82: my ($coursenum,$coursedom,$map,$contentchg)=@_;
83: my $report;
84: if (($contentchg) && ($map =~ /^default/)) {
85: $report = 1;
86: }
87: my ($outtext,$errtext)=
88: &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
89: $map,1,$report);
90: if ($errtext) { return ($errtext,2); }
91:
92: if ($map =~ /^default/) {
93: $hadchanges=1;
94: } elsif ($contentchg) {
95: $suppchanges=1;
96: }
97: return ($errtext,0);
98: }
99:
100:
101:
102: sub authorhosts {
103: my %outhash=();
104: my $home=0;
105: my $other=0;
106: foreach my $key (keys(%env)) {
107: if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
108: my $role=$1;
109: my $realm=$2;
110: my ($start,$end)=split(/\./,$env{$key});
111: if (($start) && ($start>time)) { next; }
112: if (($end) && (time>$end)) { next; }
113: my ($ca,$cd);
114: if ($1 eq 'au') {
115: $ca=$env{'user.name'};
116: $cd=$env{'user.domain'};
117: } else {
118: ($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
119: }
120: my $allowed=0;
121: my $myhome=&Apache::lonnet::homeserver($ca,$cd);
122: my @ids=&Apache::lonnet::current_machine_ids();
123: foreach my $id (@ids) {
124: if ($id eq $myhome) {
125: $allowed=1;
126: last;
127: }
128: }
129: if ($allowed) {
130: $home++;
131: $outhash{'home_'.$ca.':'.$cd}=1;
132: } else {
133: $outhash{'otherhome_'.$ca.':'.$cd}=$myhome;
134: $other++;
135: }
136: }
137: }
138: return ($home,$other,%outhash);
139: }
140:
141:
142: sub clean {
143: my ($title)=@_;
144: $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
145: return $title;
146: }
147:
148: sub default_folderpath {
149: my ($coursenum,$coursedom,$navmapref) = @_;
150: return unless ($coursenum && $coursedom && ref($navmapref));
151: # Check if entire course is hidden and/or encrypted
152: my ($hiddenmap,$encryptmap,$folderpath,$hiddentop);
153: my $toplevel = "uploaded/$coursedom/$coursenum/default.sequence";
154: unless (ref($$navmapref)) {
155: $$navmapref = Apache::lonnavmaps::navmap->new();
156: }
157: if (ref($$navmapref)) {
158: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.hiddenresource")) eq 'yes') {
159: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
160: my @resources = $$navmapref->retrieveResources($toplevel,$filterFunc,1,1);
161: unless (@resources) {
162: $hiddenmap = 1;
163: unless ($env{'request.role.adv'}) {
164: $hiddentop = 1;
165: if ($env{'form.folder'}) {
166: undef($env{'form.folder'});
167: }
168: }
169: }
170: }
171: if (lc($$navmapref->get_mapparam(undef,$toplevel,"0.encrypturl")) eq 'yes') {
172: $encryptmap = 1;
173: }
174: }
175: unless ($hiddentop) {
176: $folderpath='default&'.&escape(&mt('Main Content')).
177: '::'.$hiddenmap.':'.$encryptmap.'::';
178: }
179: if (wantarray) {
180: return ($folderpath,$hiddentop);
181: } else {
182: return $folderpath;
183: }
184: }
185:
186: sub validate_folderpath {
187: my ($supplementalflag) = @_;
188: if ($env{'form.folderpath'} ne '') {
189: my @items = split(/\&/,$env{'form.folderpath'});
190: my $badpath;
191: for (my $i=0; $i<@items; $i++) {
192: my $odd = $i%2;
193: if (($odd) && (!$supplementalflag) && ($items[$i] !~ /^[^:]*:(|\d+):(|1):(|1):(|1):(|1)$/)) {
194: $badpath = 1;
195: } elsif ((!$odd) && ($items[$i] !~ /^(default|supplemental)(|_\d+)$/)) {
196: $badpath = 1;
197: }
198: last if ($badpath);
199: }
200: if ($badpath) {
201: delete($env{'form.folderpath'});
202: }
203: }
204: return;
205: }
206:
207: sub validate_suppath {
208: if ($env{'form.supppath'} ne '') {
209: my @items = split(/\&/,$env{'form.supppath'});
210: my $badpath;
211: for (my $i=0; $i<@items; $i++) {
212: my $odd = $i%2;
213: if ((!$odd) && ($items[$i] !~ /^supplemental(|_\d+)$/)) {
214: $badpath = 1;
215: }
216: last if ($badpath);
217: }
218: if ($badpath) {
219: delete($env{'form.supppath'});
220: }
221: }
222: return;
223: }
224:
225: sub dumpcourse {
226: my ($r) = @_;
227: my $crstype = &Apache::loncommon::course_type();
228: my ($starthash,$js);
229: unless (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
230: $js = <<"ENDJS";
231: <script type="text/javascript">
232: // <![CDATA[
233:
234: function hide_searching() {
235: if (document.getElementById('searching')) {
236: document.getElementById('searching').style.display = 'none';
237: }
238: return;
239: }
240:
241: // ]]>
242: </script>
243: ENDJS
244: $starthash = {
245: add_entries => {'onload' => "hide_searching();"},
246: };
247: }
248: $r->print(&Apache::loncommon::start_page('Copy '.$crstype.' Content to Authoring Space',$js,$starthash)."\n".
249: &Apache::lonhtmlcommon::breadcrumbs('Copy '.$crstype.' Content to Authoring Space')."\n");
250: $r->print(&startContentScreen('tools'));
251: my ($home,$other,%outhash)=&authorhosts();
252: unless ($home) {
253: $r->print(&endContentScreen());
254: return '';
255: }
256: my $origcrsid=$env{'request.course.id'};
257: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
258: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
259: # Do the dumping
260: unless ($outhash{'home_'.$env{'form.authorspace'}}) {
261: $r->print(&endContentScreen());
262: return '';
263: }
264: my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
265: $r->print('<h3>'.&mt('Copying Files').'</h3>');
266: my $title=$env{'form.authorfolder'};
267: $title=&clean($title);
268: my ($navmap,$errormsg) =
269: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
270: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
271: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
272: my (%maps,%resources,%titles);
273: if (!ref($navmap)) {
274: $r->print($errormsg.
275: &endContentScreen());
276: return '';
277: } else {
278: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
279: 'dumpdocs',$cdom,$cnum);
280: }
281: my @todump = &Apache::loncommon::get_env_multiple('form.archive');
282: my (%tocopy,%replacehash,%lookup,%deps,%display,%result,%depresult,%simpleproblems,%simplepages,
283: %newcontent,%has_simpleprobs);
284: foreach my $item (sort {$a <=> $b} (@todump)) {
285: my $name = $env{'form.namefor_'.$item};
286: if ($resources{$item}) {
287: my ($map,$id,$res) = &Apache::lonnet::decode_symb($resources{$item});
288: if ($res =~ m{^uploaded/$cdom/$cnum/\E((?:docs|supplemental)/.+)$}) {
289: $tocopy{$1} = $name;
290: $display{$item} = $1;
291: $lookup{$1} = $item;
292: } elsif ($res eq 'lib/templates/simpleproblem.problem') {
293: $simpleproblems{$item} = {
294: symb => $resources{$item},
295: name => $name,
296: };
297: $display{$item} = 'simpleproblem_'.$name;
298: if ($map =~ m{^\Quploaded/$cdom/$cnum/\E(.+)$}) {
299: $has_simpleprobs{$1}{$id} = $item;
300: }
301: } elsif ($res =~ m{^adm/$match_domain/$match_username/(\d+)/smppg}) {
302: my $marker = $1;
303: my $db_name = &Apache::lonsimplepage::get_db_name($res,$marker,$cdom,$cnum);
304: $simplepages{$item} = {
305: res => $res,
306: title => $titles{$item},
307: db => $db_name,
308: marker => $marker,
309: symb => $resources{$item},
310: name => $name,
311: };
312: $display{$item} = '/'.$res;
313: }
314: } elsif ($maps{$item}) {
315: if ($maps{$item} =~ m{^\Quploaded/$cdom/$cnum/\E((?:default|supplemental)_\d+\.(?:sequence|page))$}) {
316: $tocopy{$1} = $name;
317: $display{$item} = $1;
318: $lookup{$1} = $item;
319: }
320: } else {
321: next;
322: }
323: }
324: my $crs='/uploaded/'.$env{'request.course.id'}.'/';
325: $crs=~s/\_/\//g;
326: my $mm = new File::MMagic;
327: my $prefix = "/uploaded/$cdom/$cnum/";
328: %replacehash = %tocopy;
329: foreach my $item (sort(keys(%simpleproblems))) {
330: my $content = &Apache::imsexport::simpleproblem($simpleproblems{$item}{'symb'});
331: $newcontent{$display{$item}} = $content;
332: }
333: my $gateway = Apache::lonhtmlgateway->new('web');
334: foreach my $item (sort(keys(%simplepages))) {
335: if (ref($simplepages{$item}) eq 'HASH') {
336: my $pagetitle = $simplepages{$item}{'title'};
337: my %fields = &Apache::lonnet::dump($simplepages{$item}{'db'},$cdom,$cnum);
338: my %contents;
339: foreach my $field (keys(%fields)) {
340: if ($field =~ /^(?:aaa|bbb|ccc)_(\w+)$/) {
341: my $name = $1;
342: my $msg = $fields{$field};
343: if ($name eq 'webreferences') {
344: if ($msg =~ m{^https?://}) {
345: $contents{$name} = '<a href="'.$msg.'"><tt>'.$msg.'</tt></a>';
346: }
347: } else {
348: $msg = &Encode::decode('utf8',$msg);
349: $msg = $gateway->process_outgoing_html($msg,1);
350: $contents{$name} = $msg;
351: }
352: } elsif ($field eq 'uploaded.photourl') {
353: my $marker = $simplepages{$item}{marker};
354: if ($fields{$field} =~ m{^\Q$prefix\E(simplepage/$marker/.+)$}) {
355: my $filepath = $1;
356: my ($relpath,$fname) = ($filepath =~ m{^(.+/)([^/]+)$});
357: if ($fname ne '') {
358: $fname=~s/\.(\w+)$//;
359: my $ext=$1;
360: $fname = &clean($fname);
361: $fname.='.'.$ext;
362: $contents{image} = '<img src="'.$relpath.$fname.'" alt="Image" />';
363: $replacehash{$filepath} = $relpath.$fname;
364: $deps{$item}{$filepath} = 1;
365: }
366: }
367: }
368: }
369: $replacehash{'/'.$simplepages{$item}{'res'}} = $simplepages{$item}{'name'};
370: $lookup{'/'.$simplepages{$item}{'res'}} = $item;
371: my $content = '
372: <html>
373: <head>
374: <title>'.$pagetitle.'</title>
375: </head>
376: <body bgcolor="#ffffff">';
377: if ($contents{title}) {
378: $content .= "\n".'<h2>'.$contents{title}.'</h2>';
379: }
380: if ($contents{image}) {
381: $content .= "\n".$contents{image};
382: }
383: if ($contents{content}) {
384: $content .= '
385: <div class="LC_Box">
386: <h4 class="LC_hcell">'.&mt('Content').'</h4>'.
387: $contents{content}.'
388: </div>';
389: }
390: if ($contents{webreferences}) {
391: $content .= '
392: <div class="LC_Box">
393: <h4 class="LC_hcell">'.&mt('Web References').'</h4>'.
394: $contents{webreferences}.'
395: </div>';
396: }
397: $content .= '
398: </body>
399: </html>
400: ';
401: $newcontent{'/'.$simplepages{$item}{res}} = $content;
402: }
403: }
404: foreach my $item (keys(%tocopy)) {
405: unless ($item=~/\.(sequence|page)$/) {
406: my $currurlpath = $prefix.$item;
407: my $currdirpath = &Apache::lonnet::filelocation('',$currurlpath);
408: &recurse_html($mm,$prefix,$currdirpath,$currurlpath,$item,$lookup{$item},\%replacehash,\%deps);
409: }
410: }
411: foreach my $num (sort {$a <=> $b} (@todump)) {
412: my $src = $display{$num};
413: next if ($src eq '');
414: my @needcopy = ();
415: if ($replacehash{$src}) {
416: push(@needcopy,$src);
417: if (ref($deps{$num}) eq 'HASH') {
418: foreach my $dep (sort(keys(%{$deps{$num}}))) {
419: if ($replacehash{$dep}) {
420: push(@needcopy,$dep);
421: }
422: }
423: }
424: } elsif ($src =~ /^simpleproblem_/) {
425: push(@needcopy,$src);
426: }
427: next if (@needcopy == 0);
428: my ($result,$depresult);
429: for (my $i=0; $i<@needcopy; $i++) {
430: my $item = $needcopy[$i];
431: my $newfilename;
432: if ($simpleproblems{$num}) {
433: $newfilename=$title.'/'.$simpleproblems{$num}{'name'};
434: } else {
435: $newfilename=$title.'/'.$replacehash{$item};
436: }
437: $newfilename=~s/\.(\w+)$//;
438: my $ext=$1;
439: $newfilename=&clean($newfilename);
440: $newfilename.='.'.$ext;
441: my ($newrelpath) = ($newfilename =~ m{^\Q$title/\E(.+)$});
442: if ($newrelpath ne $replacehash{$item}) {
443: $replacehash{$item} = $newrelpath;
444: }
445: my @dirs=split(/\//,$newfilename);
446: my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
447: my $makepath=$path;
448: my $fail;
449: my $origin;
450: for (my $i=0;$i<$#dirs;$i++) {
451: $makepath.='/'.$dirs[$i];
452: unless (-e $makepath) {
453: unless(mkdir($makepath,0755)) {
454: $fail = &mt('Directory creation failed.');
455: }
456: }
457: }
458: if ($i == 0) {
459: $result = '<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ';
460: } else {
461: $depresult .= '<li><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt> '.
462: '<span class="LC_fontsize_small" style="font-weight: bold;">'.
463: &mt('(dependency)').'</span>: ';
464: }
465: if (-e $path.'/'.$newfilename) {
466: $fail = &mt('Destination already exists -- not overwriting.');
467: } else {
468: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
469: if (($item =~ m{^/adm/$match_domain/$match_username/\d+/smppg}) ||
470: ($item =~ /^simpleproblem_/)) {
471: print $fh $newcontent{$item};
472: } else {
473: my $fileloc = &Apache::lonnet::filelocation('',$prefix.$item);
474: if (-e $fileloc) {
475: if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
476: if ((($1 eq 'sequence') || ($1 eq 'page')) &&
477: (ref($has_simpleprobs{$item}) eq 'HASH')) {
478: my %changes = %{$has_simpleprobs{$item}};
479: my $content = &Apache::lonclonecourse::rewritefile(
480: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
481: (%replacehash,$crs => '')
482: );
483: my $updatedcontent = '';
484: my $parser = HTML::TokeParser->new(\$content);
485: $parser->attr_encoded(1);
486: while (my $token = $parser->get_token) {
487: if ($token->[0] eq 'S') {
488: if (($token->[1] eq 'resource') &&
489: ($token->[2]->{'src'} eq '/res/lib/templates/simpleproblem.problem') &&
490: ($changes{$token->[2]->{'id'}})) {
491: my $id = $token->[2]->{'id'};
492: $updatedcontent .= '<'.$token->[1];
493: foreach my $attrib (@{$token->[3]}) {
494: next unless ($attrib =~ /^(src|type|title|id)$/);
495: if ($attrib eq 'src') {
496: my ($file) = ($display{$changes{$id}} =~ /^\Qsimpleproblem_\E(.+)$/);
497: if ($file) {
498: $updatedcontent .= ' '.$attrib.'="'.$file.'"';
499: } else {
500: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
501: }
502: } else {
503: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
504: }
505: }
506: $updatedcontent .= ' />'."\n";
507: } else {
508: $updatedcontent .= $token->[4]."\n";
509: }
510: } else {
511: $updatedcontent .= $token->[2];
512: }
513: }
514: print $fh $updatedcontent;
515: } else {
516: print $fh &Apache::lonclonecourse::rewritefile(
517: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
518: (%replacehash,$crs => '')
519: );
520: }
521: } else {
522: print $fh
523: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
524: }
525: } else {
526: $fail = &mt('Source does not exist.');
527: }
528: }
529: $fh->close();
530: } else {
531: $fail = &mt('Could not write to destination.');
532: }
533: }
534: my $text;
535: if ($fail) {
536: $text = '<span class="LC_error">'.&mt('fail').(' 'x3).$fail.'</span>';
537: } else {
538: $text = '<span class="LC_success">'.&mt('ok').'</span>';
539: }
540: if ($i == 0) {
541: $result .= $text;
542: } else {
543: $depresult .= $text.'</li>';
544: }
545: }
546: $r->print($result);
547: if ($depresult) {
548: $r->print('<ul>'.$depresult.'</ul>');
549: }
550: }
551: } else {
552: my ($navmap,$errormsg) =
553: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
554: if (!ref($navmap)) {
555: $r->print($errormsg);
556: } else {
557: $r->print('<div id="searching">'.&mt('Searching ...').'</div>');
558: $r->rflush();
559: my ($preamble,$formname);
560: $formname = 'dumpdoc';
561: unless ($home==1) {
562: $preamble = '<div class="LC_left_float">'.
563: '<fieldset><legend>'.
564: &mt('Select the Authoring Space').
565: '</legend><select name="authorspace">';
566: }
567: my @orderspaces = ();
568: foreach my $key (sort(keys(%outhash))) {
569: if ($key=~/^home_(.+)$/) {
570: if ($1 eq $env{'user.name'}.':'.$env{'user.domain'}) {
571: unshift(@orderspaces,$1);
572: } else {
573: push(@orderspaces,$1);
574: }
575: }
576: }
577: if ($home>1) {
578: $preamble .= '<option value="" selected="selected">'.&mt('Select').'</option>';
579: }
580: foreach my $user (@orderspaces) {
581: if ($home==1) {
582: $preamble .= '<input type="hidden" name="authorspace" value="'.$user.'" />';
583: } else {
584: $preamble .= '<option value="'.$user.'">'.$user.' - '.
585: &Apache::loncommon::plainname(split(/\:/,$user)).'</option>';
586: }
587: }
588: unless ($home==1) {
589: $preamble .= '</select></fieldset></div>'."\n";
590: }
591: my $title=$origcrsdata{'description'};
592: $title=~s/[\/\s]+/\_/gs;
593: $title=&clean($title);
594: $preamble .= '<div class="LC_left_float">'.
595: '<fieldset><legend>'.&mt('Folder in Authoring Space').'</legend>'.
596: '<input type="text" size="50" name="authorfolder" value="'.
597: $title.'" />'.
598: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>'."\n";
599: my %uploadedfiles;
600: &tiehash();
601: foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
602: my ($ext)=($file=~/\.(\w+)$/);
603: # FIXME Check supplemental here
604: my $title=$hash{'title_'.$hash{
605: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
606: if (!$title) {
607: $title=$file;
608: } else {
609: $title=~s|/|_|g;
610: }
611: $title=~s/\.(\w+)$//;
612: $title=&clean($title);
613: $title.='.'.$ext;
614: # $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
615: $uploadedfiles{$file} = $title;
616: }
617: &untiehash();
618: $r->print(&Apache::loncourserespicker::create_picker($navmap,'dumpdocs',$formname,$crstype,undef,
619: undef,undef,$preamble,$home,\%uploadedfiles));
620: }
621: }
622: $r->print(&endContentScreen());
623: }
624:
625: sub recurse_html {
626: my ($mm,$prefix,$currdirpath,$currurlpath,$container,$item,$replacehash,$deps) = @_;
627: return unless ((ref($replacehash) eq 'HASH') && (ref($deps) eq 'HASH'));
628: my (%allfiles,%codebase);
629: if (&Apache::lonnet::extract_embedded_items($currdirpath,\%allfiles,\%codebase) eq 'ok') {
630: if (keys(%allfiles)) {
631: foreach my $dependency (keys(%allfiles)) {
632: next if (($dependency =~ m{^/(res|adm)/}) || ($dependency =~ m{^https?://}));
633: my ($depurl,$relfile,$newcontainer);
634: if ($dependency =~ m{^/}) {
635: if ($dependency =~ m{^\Q$currurlpath/\E(.+)$}) {
636: $relfile = $1;
637: if ($dependency =~ m{^\Q$prefix\E(.+)$}) {
638: $newcontainer = $1;
639: next if ($replacehash->{$newcontainer});
640: }
641: $depurl = $dependency;
642: } else {
643: next;
644: }
645: } else {
646: $relfile = $dependency;
647: $depurl = $currurlpath;
648: $depurl =~ s{[^/]+$}{};
649: $depurl .= $dependency;
650: ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$});
651: }
652: next if ($relfile eq '');
653: my $newname = $replacehash->{$container};
654: $newname =~ s{[^/]+$}{};
655: $replacehash->{$newcontainer} = $newname.$relfile;
656: $deps->{$item}{$newcontainer} = 1;
657: my ($newurlpath) = ($depurl =~ m{^(.*)/[^/]+$});
658: my $depfile = &Apache::lonnet::filelocation('',$depurl);
659: my $type = $mm->checktype_filename($depfile);
660: if ($type eq 'text/html') {
661: &recurse_html($mm,$prefix,$depfile,$newurlpath,$newcontainer,$item,$replacehash,$deps);
662: }
663: }
664: }
665: }
666: return;
667: }
668:
669: sub group_import {
670: my ($coursenum, $coursedom, $folder, $container, $caller, $ltitoolsref, @files) = @_;
671: my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
672: %removeparam,$importuploaded,$fixuperrors);
673: $allmaps = {};
674: while (@files) {
675: my ($name, $url, $residx) = @{ shift(@files) };
676: if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
677: && ($caller eq 'londocs')
678: && (!&Apache::lonnet::stat_file($url))) {
679:
680: my $errtext = '';
681: my $fatal = 0;
682: my $newmapstr = '<map>'."\n".
683: '<resource id="1" src="" type="start"></resource>'."\n".
684: '<link from="1" to="2" index="1"></link>'."\n".
685: '<resource id="2" src="" type="finish"></resource>'."\n".
686: '</map>';
687: $env{'form.output'}=$newmapstr;
688: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
689: 'output',$1.$2);
690: if ($result !~ m{^/uploaded/}) {
691: $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
692: $fatal = 2;
693: }
694: if ($fatal) {
695: return ($errtext,$fatal);
696: }
697: }
698: if ($url) {
699: if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/ext\.tool)\:?(.*)$}) {
700: $url = $1;
701: my $marker = $2;
702: my $info = $3;
703: my ($toolid,%toolhash,%toolsettings);
704: my @extras = ('linktext','explanation','crslabel','crstitle','crsappend');
705: my @toolinfo = split(/:/,$info);
706: if ($residx) {
707: %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
708: $toolid = $toolsettings{'id'};
709: } else {
710: $toolid = shift(@toolinfo);
711: }
712: $toolid =~ s/\D//g;
713: ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'},
714: $toolhash{'linktext'},$toolhash{'explanation'},$toolhash{'crslabel'},
715: $toolhash{'crstitle'},$toolhash{'crsappend'},$toolhash{'gradable'}) = @toolinfo;
716: foreach my $item (@extras) {
717: $toolhash{$item} = &unescape($toolhash{$item});
718: }
719: if ($folder =~ /^supplemental/) {
720: delete($toolhash{'gradable'});
721: } else {
722: $toolhash{'gradable'} =~ s/\D+//g;
723: }
724: if (ref($ltitoolsref) eq 'HASH') {
725: if (ref($ltitoolsref->{$toolid}) eq 'HASH') {
726: my @deleted;
727: $toolhash{'id'} = $toolid;
728: if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'tab') ||
729: ($toolhash{'target'} eq 'window')) {
730: if ($toolhash{'target'} eq 'window') {
731: foreach my $item ('width','height') {
732: $toolhash{$item} =~ s/^\s+//;
733: $toolhash{$item} =~ s/\s+$//;
734: if ($toolhash{$item} =~ /\D/) {
735: delete($toolhash{$item});
736: if ($residx) {
737: if ($toolsettings{$item}) {
738: push(@deleted,$item);
739: }
740: }
741: }
742: }
743: }
744: } elsif ($residx) {
745: $toolhash{'target'} = $toolsettings{'target'};
746: if ($toolhash{'target'} eq 'window') {
747: foreach my $item ('width','height') {
748: $toolhash{$item} = $toolsettings{$item};
749: }
750: }
751: } elsif (ref($ltitoolsref->{$toolid}->{'display'}) eq 'HASH') {
752: $toolhash{'target'} = $ltitoolsref->{$toolid}->{'display'}->{'target'};
753: if ($toolhash{'target'} eq 'window') {
754: $toolhash{'width'} = $ltitoolsref->{$toolid}->{'display'}->{'width'};
755: $toolhash{'height'} = $ltitoolsref->{$toolid}->{'display'}->{'height'};
756: }
757: }
758: if ($toolhash{'target'} eq 'iframe') {
759: foreach my $item ('width','height','linktext','explanation') {
760: delete($toolhash{$item});
761: if ($residx) {
762: if ($toolsettings{$item}) {
763: push(@deleted,$item);
764: }
765: }
766: }
767: } elsif ($toolhash{'target'} eq 'tab') {
768: foreach my $item ('width','height') {
769: delete($toolhash{$item});
770: if ($residx) {
771: if ($toolsettings{$item}) {
772: push(@deleted,$item);
773: }
774: }
775: }
776: }
777: if (ref($ltitoolsref->{$toolid}->{'crsconf'}) eq 'HASH') {
778: foreach my $item ('label','title','linktext','explanation') {
779: my $crsitem;
780: if (($item eq 'label') || ($item eq 'title')) {
781: $crsitem = 'crs'.$item;
782: } else {
783: $crsitem = $item;
784: }
785: if ($ltitoolsref->{$toolid}->{'crsconf'}->{$item}) {
786: $toolhash{$crsitem} =~ s/^\s+//;
787: $toolhash{$crsitem} =~ s/\s+$//;
788: if ($toolhash{$crsitem} eq '') {
789: delete($toolhash{$crsitem});
790: }
791: } else {
792: delete($toolhash{$crsitem});
793: }
794: if (($residx) && (exists($toolsettings{$crsitem}))) {
795: unless (exists($toolhash{$crsitem})) {
796: push(@deleted,$crsitem);
797: }
798: }
799: }
800: }
801: if ($toolhash{'passback'}) {
802: my $gradesecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
803: $toolhash{'gradesecret'} = $gradesecret;
804: $toolhash{'gradesecretdate'} = time;
805: }
806: if ($toolhash{'roster'}) {
807: my $rostersecret = UUID::Tiny::create_uuid_as_string(UUID_V4);
808: $toolhash{'rostersecret'} = $rostersecret;
809: $toolhash{'rostersecretdate'} = time;
810: }
811: my $changegradable;
812: if (($residx) && ($folder =~ /^default/)) {
813: if ($toolsettings{'gradable'}) {
814: unless (($toolhash{'gradable'}) || (defined($LONCAPA::map::zombies[$residx]))) {
815: push(@deleted,'gradable');
816: $changegradable = 1;
817: }
818: } elsif ($toolhash{'gradable'}) {
819: $changegradable = 1;
820: }
821: if (($caller eq 'londocs') && (defined($LONCAPA::map::zombies[$residx]))) {
822: $changegradable = 1;
823: if ($toolsettings{'gradable'}) {
824: $toolhash{'gradable'} = 1;
825: }
826: }
827: }
828: my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum);
829: if ($putres eq 'ok') {
830: if (@deleted) {
831: &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum);
832: }
833: if (($changegradable) && ($folder =~ /^default/)) {
834: my $val;
835: if ($toolhash{'gradable'}) {
836: $val = 'yes';
837: } else {
838: $val = 'no';
839: }
840: &LONCAPA::map::storeparameter($residx,'parameter_0_gradable',$val,
841: 'string_yesno');
842: &remember_parms($residx,'gradable','set',$val);
843: }
844: } else {
845: return (&mt('Failed to save update to external tool.'),1);
846: }
847: }
848: }
849: }
850: if (($caller eq 'londocs') &&
851: ($folder =~ /^default/)) {
852: if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
853: my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
854: my $cid = $coursedom.'_'.$coursenum;
855: $allmaps =
856: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
857: $chome,$cid);
858: $donechk = 1;
859: }
860: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
861: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
862: \%removeparam,\%addedmaps,\%hierarchy,\%titles,$allmaps);
863: $importuploaded = 1;
864: } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
865: next if ($allmaps->{$url});
866: }
867: }
868: if (!$residx
869: || defined($LONCAPA::map::zombies[$residx])) {
870: $residx = &LONCAPA::map::getresidx($url,$residx);
871: push(@LONCAPA::map::order, $residx);
872: }
873: my $ext = 'false';
874: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
875: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
876: my $filepath = $1;
877: my $fname;
878: if ($name eq '') {
879: $name = &mt('Web Page');
880: $fname = 'web';
881: } else {
882: $fname = $name;
883: $fname=&Apache::lonnet::clean_filename($fname);
884: if ($fname eq '') {
885: $fname = 'web';
886: } elsif (length($fname) > 15) {
887: $fname = substr($fname,0,14);
888: }
889: }
890: my $title = &Apache::loncommon::cleanup_html($name);
891: my $initialtext = &mt('Replace with your own content.');
892: my $newhtml = <<END;
893: <html>
894: <head>
895: <title>$title</title>
896: </head>
897: <body bgcolor="#ffffff">
898: $initialtext
899: </body>
900: </html>
901: END
902: $env{'form.output'}=$newhtml;
903: my $result =
904: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
905: 'output',
906: "$filepath/$residx/$fname.html");
907: if ($result =~ m{^/uploaded/}) {
908: $url = $result;
909: if ($filepath =~ /^supplemental/) {
910: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
911: $env{'user.domain'}.'___&&&___'.$name;
912: }
913: } else {
914: return (&mt('Failed to save new web page.'),1);
915: }
916: }
917: $name = &LONCAPA::map::qtunescape($name);
918: $url = &LONCAPA::map::qtunescape($url);
919: $LONCAPA::map::resources[$residx] =
920: join(':', ($name, $url, $ext, 'normal', 'res'));
921: }
922: }
923: if ($importuploaded) {
924: my %import_errors;
925: my %updated = (
926: removefrommap => \%removefrommap,
927: removeparam => \%removeparam,
928: );
929: my ($result,$msgsarray,$lockerror) =
930: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
931: if (keys(%import_errors) > 0) {
932: $fixuperrors =
933: '<p span class="LC_warning">'."\n".
934: &mt('The following files are either dependencies of a web page or references within a folder and/or composite page for which errors occurred during import:')."\n".
935: '<ul>'."\n";
936: foreach my $key (sort(keys(%import_errors))) {
937: $fixuperrors .= '<li>'.$key.'</li>'."\n";
938: }
939: $fixuperrors .= '</ul></p>'."\n";
940: }
941: if (ref($msgsarray) eq 'ARRAY') {
942: if (@{$msgsarray} > 0) {
943: $fixuperrors .= '<p class="LC_info">'.
944: join('<br />',@{$msgsarray}).
945: '</p>';
946: }
947: }
948: if ($lockerror) {
949: $fixuperrors .= '<p class="LC_error">'.
950: $lockerror.
951: '</p>';
952: }
953: }
954: my ($errtext,$fatal) =
955: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
956: unless ($fatal) {
957: if ($folder =~ /^supplemental/) {
958: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
959: $folder.'.'.$container);
960: }
961: }
962: return ($errtext,$fatal,$fixuperrors);
963: }
964:
965: sub log_docs {
966: return &Apache::lonnet::write_log('course','docslog',@_);
967: }
968:
969: {
970: my @oldresources=();
971: my @oldorder=();
972: my $parmidx;
973: my %parmaction=();
974: my %parmvalue=();
975: my $changedflag;
976:
977: sub snapshotbefore {
978: @oldresources=@LONCAPA::map::resources;
979: @oldorder=@LONCAPA::map::order;
980: $parmidx=undef;
981: %parmaction=();
982: %parmvalue=();
983: $changedflag=0;
984: }
985:
986: sub remember_parms {
987: my ($idx,$parameter,$action,$value)=@_;
988: $parmidx=$idx;
989: $parmaction{$parameter}=$action;
990: $parmvalue{$parameter}=$value;
991: $changedflag=1;
992: }
993:
994: sub log_differences {
995: my ($plain)=@_;
996: my %storehash=('folder' => $plain,
997: 'currentfolder' => $env{'form.folder'});
998: if ($parmidx) {
999: $storehash{'parameter_res'}=$oldresources[$parmidx];
1000: foreach my $parm (keys(%parmaction)) {
1001: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
1002: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
1003: }
1004: }
1005: my $maxidx=$#oldresources;
1006: if ($#LONCAPA::map::resources>$#oldresources) {
1007: $maxidx=$#LONCAPA::map::resources;
1008: }
1009: for (my $idx=0; $idx<=$maxidx; $idx++) {
1010: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
1011: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
1012: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
1013: $changedflag=1;
1014: }
1015: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
1016: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
1017: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
1018: $changedflag=1;
1019: }
1020: }
1021: $storehash{'maxidx'}=$maxidx;
1022: if ($changedflag) { &log_docs(\%storehash); }
1023: }
1024: }
1025:
1026: sub docs_change_log {
1027: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_;
1028: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1029: my $navmap;
1030: my $js = '<script type="text/javascript">'."\n".
1031: '// <![CDATA['."\n".
1032: &Apache::loncommon::display_filter_js('docslog')."\n".
1033: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag,
1034: $coursedom,$coursenum,'','',$canedit,'',\$navmap)."\n".
1035: &history_tab_js()."\n".
1036: &Apache::lonratedt::editscript('simple')."\n".
1037: '// ]]>'."\n".
1038: '</script>'."\n";
1039: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
1040: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1041: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1042: my %orderhash;
1043: my $container='sequence';
1044: my $pathitem;
1045: if ($env{'form.folderpath'} =~ /\:1$/) {
1046: $container='page';
1047: }
1048: my $folderpath=$env{'form.folderpath'};
1049: if ($folderpath eq '') {
1050: $folderpath = &default_folderpath($coursenum,$coursedom,\$navmap);
1051: }
1052: undef($navmap);
1053: $pathitem = '<input type="hidden" name="folderpath" value="'.
1054: &HTML::Entities::encode($folderpath,'<>&"').'" />';
1055: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1056: my $jumpto = $readfile;
1057: $jumpto =~ s{^/}{};
1058: my $tid = 1;
1059: if ($supplementalflag) {
1060: $tid = 2;
1061: }
1062: my ($breadcrumbtrail) =
1063: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1064: $r->print($breadcrumbtrail.
1065: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
1066: $readfile));
1067: my %docslog=&Apache::lonnet::dump('nohist_docslog',
1068: $env{'course.'.$env{'request.course.id'}.'.domain'},
1069: $env{'course.'.$env{'request.course.id'}.'.num'});
1070:
1071: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
1072:
1073: my %saveable_parameters = ('show' => 'scalar',);
1074: &Apache::loncommon::store_course_settings('docs_log',
1075: \%saveable_parameters);
1076: &Apache::loncommon::restore_course_settings('docs_log',
1077: \%saveable_parameters);
1078: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1079: # FIXME: internationalization seems wrong here
1080: my %lt=('hiddenresource' => 'Resources hidden',
1081: 'encrypturl' => 'URL hidden',
1082: 'randompick' => 'Randomly pick',
1083: 'randomorder' => 'Randomly ordered',
1084: 'gradable' => 'Grade can be assigned to External Tool',
1085: 'set' => 'set to',
1086: 'del' => 'deleted');
1087: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
1088: $pathitem."\n".
1089: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
1090: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
1091: $r->print('<div class="LC_left_float">'.
1092: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
1093: &makedocslogform($filter,1).
1094: '</fieldset></div><br clear="all" />');
1095: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
1096: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
1097: &mt('After').'</th>'.
1098: &Apache::loncommon::end_data_table_header_row());
1099: my $shown=0;
1100: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
1101: if ($env{'form.displayfilter'} eq 'currentfolder') {
1102: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
1103: }
1104: my @changes=keys(%{$docslog{$id}{'logentry'}});
1105: if ($env{'form.displayfilter'} eq 'containing') {
1106: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
1107: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
1108: foreach my $key (@changes) {
1109: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
1110: }
1111: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1112: }
1113: my $count = 0;
1114: my $time =
1115: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
1116: my $plainname =
1117: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
1118: $docslog{$id}{'exe_udom'});
1119: my $about_me_link =
1120: &Apache::loncommon::aboutmewrapper($plainname,
1121: $docslog{$id}{'exe_uname'},
1122: $docslog{$id}{'exe_udom'});
1123: my $send_msg_link='';
1124: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
1125: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
1126: $send_msg_link ='<br />'.
1127: &Apache::loncommon::messagewrapper(&mt('Send message'),
1128: $docslog{$id}{'exe_uname'},
1129: $docslog{$id}{'exe_udom'});
1130: }
1131: $r->print(&Apache::loncommon::start_data_table_row());
1132: $r->print('<td>'.$time.'</td>
1133: <td>'.$about_me_link.
1134: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
1135: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
1136: $send_msg_link.'</td><td>'.
1137: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1138: my $is_supp = 0;
1139: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
1140: $is_supp = 1;
1141: }
1142: # Before
1143: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1144: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1145: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1146: if ($oldname ne $newname) {
1147: my $shown = &LONCAPA::map::qtescape($oldname);
1148: if ($is_supp) {
1149: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1150: }
1151: $r->print($shown);
1152: }
1153: }
1154: $r->print('<ul>');
1155: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1156: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1157: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
1158: if ($is_supp) {
1159: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1160: }
1161: $r->print('<li>'.$shown.'</li>');
1162: }
1163: }
1164: $r->print('</ul>');
1165: # After
1166: $r->print('</td><td>');
1167:
1168: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1169: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1170: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1171: if ($oldname ne '' && $oldname ne $newname) {
1172: my $shown = &LONCAPA::map::qtescape($newname);
1173: if ($is_supp) {
1174: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
1175: }
1176: $r->print($shown);
1177: }
1178: }
1179: $r->print('<ul>');
1180: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1181: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1182: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
1183: if ($is_supp) {
1184: $shown = &Apache::loncommon::parse_supplemental_title($shown);
1185: }
1186: $r->print('<li>'.$shown.'</li>');
1187: }
1188: }
1189: $r->print('</ul>');
1190: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1191: $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');
1192: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder','gradable') {
1193: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1194: # FIXME: internationalization seems wrong here
1195: $r->print('<li>'.
1196: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
1197: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1198: .'</li>');
1199: }
1200: }
1201: $r->print('</ul>');
1202: }
1203: # End
1204: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1205: $shown++;
1206: if (!($env{'form.show'} eq &mt('all')
1207: || $shown<=$env{'form.show'})) { last; }
1208: }
1209: $r->print(&Apache::loncommon::end_data_table()."\n".
1210: &makesimpleeditform($pathitem)."\n".
1211: '</div></div>');
1212: $r->print(&endContentScreen());
1213: }
1214:
1215: sub update_paste_buffer {
1216: my ($coursenum,$coursedom,$folder) = @_;
1217: my (@possibles,%removals,%cuts,$output);
1218: if ($env{'form.multiremove'}) {
1219: $env{'form.multiremove'} =~ s/,$//;
1220: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
1221: }
1222: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
1223: if ($env{'form.multicut'}) {
1224: $env{'form.multicut'} =~ s/,$//;
1225: foreach my $item (split(/,/,$env{'form.multicut'})) {
1226: unless ($removals{$item}) {
1227: $cuts{$item} = 1;
1228: push(@possibles,$item.':cut');
1229: }
1230: }
1231: }
1232: if ($env{'form.multicopy'}) {
1233: $env{'form.multicopy'} =~ s/,$//;
1234: foreach my $item (split(/,/,$env{'form.multicopy'})) {
1235: unless ($removals{$item} || $cuts{$item}) {
1236: push(@possibles,$item.':copy');
1237: }
1238: }
1239: }
1240: } elsif ($env{'form.markcopy'}) {
1241: @possibles = split(/,/,$env{'form.markcopy'});
1242: }
1243:
1244: return if (@possibles == 0);
1245: return if (!defined($env{'form.copyfolder'}));
1246:
1247: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1248: $env{'form.copyfolder'});
1249: return if ($fatal);
1250:
1251: my %curr_groups = &Apache::longroup::coursegroups();
1252:
1253: # Retrieve current paste buffer suffixes.
1254: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1255: my (%pasteurls,@newpaste);
1256:
1257: # Construct identifiers for current contents of user's paste buffer
1258: if (@currpaste) {
1259: foreach my $suffix (@currpaste) {
1260: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1261: my $url = $env{'docs.markedcopy_url_'.$suffix};
1262: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1263: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
1264: ($url ne '')) {
1265: if ($url eq '/res/lib/templates/simpleproblem.problem') {
1266: $pasteurls{$cid.'_'.$mapidx} = 1;
1267: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
1268: $pasteurls{$url} = 1;
1269: } else {
1270: $pasteurls{$cid.'_'.$url} = 1;
1271: }
1272: }
1273: }
1274: }
1275:
1276: # Mark items for copying (skip any items already in user's paste buffer)
1277: my %addtoenv;
1278:
1279: my @pathitems = split(/\&/,$env{'form.folderpath'});
1280: my @folderconf = split(/\:/,$pathitems[-1]);
1281: my $ispage = $folderconf[5];
1282:
1283: foreach my $item (@possibles) {
1284: my ($orderidx,$cmd) = split(/:/,$item);
1285: next if ($orderidx =~ /\D/);
1286: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1287: my $mapidx = $folder.':'.$orderidx.':'.$ispage;
1288: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
1289: my %denied = &action_restrictions($coursenum,$coursedom,
1290: &LONCAPA::map::qtescape($url),
1291: $env{'form.folderpath'},\%curr_groups);
1292: next if ($denied{'copy'});
1293: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1294: if ($url eq '/res/lib/templates/simpleproblem.problem') {
1295: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$mapidx}));
1296: } elsif ($url =~ m{^/res/$match_domain/$match_username/}) {
1297: next if (exists($pasteurls{$url}));
1298: } else {
1299: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$url}));
1300: }
1301: my ($suffix,$errortxt,$locknotfreed) =
1302: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1303: if ($suffix ne '') {
1304: push(@newpaste,$suffix);
1305: } else {
1306: if ($locknotfreed) {
1307: return $locknotfreed;
1308: }
1309: }
1310: if (&is_supplemental_title($title)) {
1311: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
1312: ($title) = &Apache::loncommon::parse_supplemental_title($title);
1313: }
1314:
1315: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
1316: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
1317: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
1318: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1319: $addtoenv{'docs.markedcopy_map_'.$suffix} = $mapidx;
1320: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
1321: my $prefix = $1;
1322: my $subdir =$2;
1323: if ($subdir eq '') {
1324: $subdir = $prefix;
1325: }
1326: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1327: &contained_map_check($url,$folder,$coursenum,$coursedom,\%removefrommap,
1328: \%removeparam,\%addedmaps,\%hierarchy,\%titles,\%allmaps);
1329: if (ref($hierarchy{$url}) eq 'HASH') {
1330: my ($nested,$nestednames);
1331: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
1332: $nested =~ s/\&$//;
1333: $nestednames =~ s/\Q___&&&___\E$//;
1334: if ($nested ne '') {
1335: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
1336: }
1337: if ($nestednames ne '') {
1338: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
1339: }
1340: }
1341: }
1342: if ($locknotfreed) {
1343: $output = $locknotfreed;
1344: last;
1345: }
1346: }
1347: if (@newpaste) {
1348: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
1349: }
1350: &Apache::lonnet::appenv(\%addtoenv);
1351: delete($env{'form.markcopy'});
1352: return $output;
1353: }
1354:
1355: sub recurse_uploaded_maps {
1356: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
1357: if (ref($hierarchy->{$url}) eq 'HASH') {
1358: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
1359: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
1360: my (@uploaded,@names,%shorter);
1361: for (my $i=0; $i<@maps; $i++) {
1362: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
1363: if ($inner ne '') {
1364: push(@uploaded,$inner);
1365: push(@names,&escape($titles[$i]));
1366: $shorter{$maps[$i]} = $inner;
1367: }
1368: }
1369: $$nestref .= "$dir:".join(',',@uploaded).'&';
1370: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
1371: foreach my $map (@maps) {
1372: if ($shorter{$map} ne '') {
1373: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
1374: }
1375: }
1376: }
1377: return;
1378: }
1379:
1380: sub print_paste_buffer {
1381: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1382: return if (!defined($env{'docs.markedcopies'}));
1383:
1384: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
1385: return if ($env{'docs.markedcopies'} eq '');
1386: }
1387:
1388: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1389: my ($pasteitems,@pasteable);
1390: my $clipboardcount = 0;
1391:
1392: # Construct identifiers for current contents of user's paste buffer
1393: foreach my $suffix (@currpaste) {
1394: next if ($suffix =~ /\D/);
1395: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1396: my $url = $env{'docs.markedcopy_url_'.$suffix};
1397: my $mapidx = $env{'docs.markedcopy_map_'.$suffix};
1398: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
1399: ($url ne '')) {
1400: $clipboardcount ++;
1401: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1402: $canpaste,$nopaste,$othercrs,$areachange,$is_exttool);
1403: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
1404: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1405: $is_external = 1;
1406: } elsif ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$}) {
1407: $is_exttool = 1;
1408: }
1409: if ($folder =~ /^supplemental/) {
1410: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
1411: unless ($canpaste) {
1412: $nopaste = &mt('Paste into Supplemental Content unavailable.');
1413: }
1414: } else {
1415: $canpaste = 1;
1416: }
1417: if ($canpaste) {
1418: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1419: my $srcdom = $1;
1420: my $srcnum = $2;
1421: my $rem = $3;
1422: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
1423: $othercourse = 1;
1424: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1425: $othercrs = '<br />'.&mt('(from another course)');
1426: } else {
1427: $canpaste = 0;
1428: $nopaste = &mt('Paste from another course unavailable.');
1429: }
1430: }
1431: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
1432: my $prefix = $1;
1433: $parent = $2;
1434: if ($folder !~ /^\Q$prefix\E/) {
1435: $areachange = 1;
1436: }
1437: $is_uploaded_map = 1;
1438: }
1439: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1440: ($url =~ m{^/adm/($match_domain)/($match_username)/\d+/(bulletinboard|smppg|ext\.tool)$})) {
1441: if ($cid ne $env{'request.course.id'}) {
1442: my ($srcdom,$srcnum) = split(/_/,$cid);
1443: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1444: if (($is_exttool) && ($srcdom ne $coursedom)) {
1445: $canpaste = 0;
1446: $nopaste = &mt('Paste from another domain unavailable.');
1447: } else {
1448: $othercrs = '<br />'.&mt('(from another course)');
1449: }
1450: } else {
1451: $canpaste = 0;
1452: $nopaste = &mt('Paste from another course unavailable.');
1453: }
1454: }
1455: }
1456: if ($canpaste) {
1457: push(@pasteable,$suffix);
1458: }
1459: }
1460: my $buffer;
1461: if ($is_external) {
1462: $buffer = &mt('External Resource').': '.
1463: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
1464: &LONCAPA::map::qtescape($url).')';
1465: } elsif ($is_exttool) {
1466: $buffer = &mt('External Tool').': '.
1467: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1468: } else {
1469: my $icon = &Apache::loncommon::icon($extension);
1470: if ($extension eq 'sequence' &&
1471: $url =~ m{/default_\d+\.sequence$}x) {
1472: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1473: $icon .= '/navmap.folder.closed.gif';
1474: }
1475: my $title = $env{'docs.markedcopy_title_'.$suffix};
1476: if ($title eq '') {
1477: ($title) = ($url =~ m{/([^/]+)$});
1478: }
1479: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
1480: ': '.
1481: &Apache::loncommon::parse_supplemental_title(
1482: &LONCAPA::map::qtescape($title));
1483: }
1484: $pasteitems .= '<div class="LC_left_float">';
1485: my ($options,$onclick);
1486: if (($canpaste) && (!$areachange) && (!$othercourse) &&
1487: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
1488: if (($is_uploaded_map) ||
1489: ($url =~ /(bulletinboard|smppg)$/) ||
1490: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
1491: $options = &paste_options($suffix,$is_uploaded_map,$parent);
1492: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
1493: }
1494: }
1495: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
1496: if ($nopaste) {
1497: $pasteitems .= ' <span class="LC_cusr_emph">'.$nopaste.'</span>';
1498: } else {
1499: if ($othercrs) {
1500: $pasteitems .= $othercrs;
1501: }
1502: if ($options) {
1503: $pasteitems .= $options;
1504: }
1505: }
1506: $pasteitems .= '</div>';
1507: }
1508: }
1509: if ($pasteitems eq '') {
1510: &Apache::lonnet::delenv('docs.markedcopies');
1511: }
1512: my ($pasteform,$form_start,$buttons,$form_end);
1513: if ($pasteitems) {
1514: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1515: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1516: if (@pasteable) {
1517: my $value = &mt('Paste to current folder');
1518: if ($container eq 'page') {
1519: $value = &mt('Paste to current page');
1520: }
1521: $buttons = '<input type="submit" name="pastemarked" value="'.$value.'" />'.(' 'x2);
1522: }
1523: $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Remove from clipboard').'" />'.(' 'x2);
1524: if ($clipboardcount > 1) {
1525: $buttons .=
1526: '<span style="text-decoration:line-through">'.(' 'x20).'</span>'.(' 'x2).
1527: '<input type="button" name="checkallclip" value="'.&mt('Check all').'" style="height:20px;" onclick="checkClipboard();" />'.
1528: (' 'x2).
1529: '<input type="button" name="uncheckallclip" value="'.&mt('Uncheck all').'" style="height:20px;" onclick="uncheckClipboard();" />'.
1530: (' 'x2);
1531: }
1532: $form_end = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />'.
1533: '</form>';
1534: } else {
1535: $pasteitems = &mt('Clipboard is empty');
1536: }
1537: $r->print($form_start
1538: .'<fieldset>'
1539: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
1540: .$pasteitems
1541: .'</fieldset>'
1542: .$form_end);
1543: }
1544:
1545: sub paste_options {
1546: my ($suffix,$is_uploaded_map,$parent) = @_;
1547: my ($copytext,$movetext);
1548: if ($is_uploaded_map) {
1549: $copytext = &mt('Copy to new folder');
1550: $movetext = &mt('Move old');
1551: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
1552: $copytext = &mt('Copy to new board');
1553: $movetext = &mt('Move (not posts)');
1554: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
1555: $copytext = &mt('Copy to new page');
1556: $movetext = &mt('Move');
1557: } else {
1558: $copytext = &mt('Copy to new file');
1559: $movetext = &mt('Move');
1560: }
1561: my $output = '<br />'.
1562: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
1563: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
1564: '<label>'.
1565: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
1566: $copytext.'</label></span>'.(' 'x2).' '.
1567: '<span class="LC_nobreak"><label>'.
1568: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
1569: $movetext.'</label></span>';
1570: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
1571: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
1572: '</legend><table border="0">';
1573: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1574: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
1575: my $lastdir = $parent;
1576: my %depths = (
1577: $lastdir => 0,
1578: );
1579: my (%display,%deps);
1580: for (my $i=0; $i<@pastemaps; $i++) {
1581: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
1582: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
1583: my @subfolders = split(/,/,$subfolderstr);
1584: $deps{$lastdir} = \@subfolders;
1585: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
1586: my $depth = $depths{$lastdir} + 1;
1587: my $offset = int($depth * 4);
1588: my $indent = (' ' x $offset);
1589: for (my $j=0; $j<@subfolders; $j++) {
1590: $depths{$subfolders[$j]} = $depth;
1591: $display{$subfolders[$j]} =
1592: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
1593: '<td><label>'.
1594: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
1595: '<label>'.
1596: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
1597: &mt('Move old').'</label>'.
1598: '</td></tr>';
1599: }
1600: }
1601: &recurse_print(\$output,$parent,\%deps,\%display);
1602: $output .= '</table></fieldset>';
1603: }
1604: $output .= '</div>';
1605: return $output;
1606: }
1607:
1608: sub recurse_print {
1609: my ($outputref,$dir,$deps,$display) = @_;
1610: $$outputref .= $display->{$dir}."\n";
1611: if (ref($deps->{$dir}) eq 'ARRAY') {
1612: foreach my $subdir (@{$deps->{$dir}}) {
1613: &recurse_print($outputref,$subdir,$deps,$display);
1614: }
1615: }
1616: }
1617:
1618: sub supp_pasteable {
1619: my ($url) = @_;
1620: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
1621: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
1622: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
1623: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1624: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1625: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1626: return 1;
1627: }
1628: return;
1629: }
1630:
1631: sub paste_popup_js {
1632: my %html_js_lt = &Apache::lonlocal::texthash(
1633: show => 'Show Options',
1634: hide => 'Hide Options',
1635: );
1636: my %js_lt = &Apache::lonlocal::texthash(
1637: none => 'No items selected from clipboard.',
1638: );
1639: &html_escape(\%html_js_lt);
1640: &js_escape(\%html_js_lt);
1641: &js_escape(\%js_lt);
1642: return <<"END";
1643:
1644: function showPasteOptions(suffix) {
1645: document.getElementById('pasteoptions_'+suffix).style.display='block';
1646: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$html_js_lt{'hide'}</a>';
1647: return;
1648: }
1649:
1650: function hidePasteOptions(suffix) {
1651: document.getElementById('pasteoptions_'+suffix).style.display='none';
1652: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1653: return;
1654: }
1655:
1656: function showOptions(caller,suffix) {
1657: if (document.getElementById('pasteoptionstext_'+suffix)) {
1658: if (caller.checked) {
1659: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$html_js_lt{'show'}</a>';
1660: } else {
1661: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
1662: }
1663: if (document.getElementById('pasteoptions_'+suffix)) {
1664: document.getElementById('pasteoptions_'+suffix).style.display='none';
1665: }
1666: }
1667: return;
1668: }
1669:
1670: function validateClipboard() {
1671: var numchk = 0;
1672: if (document.pasteform.pasting.length > 1) {
1673: for (var i=0; i<document.pasteform.pasting.length; i++) {
1674: if (document.pasteform.pasting[i].checked) {
1675: numchk ++;
1676: }
1677: }
1678: } else {
1679: if (document.pasteform.pasting.type == 'checkbox') {
1680: if (document.pasteform.pasting.checked) {
1681: numchk ++;
1682: }
1683: }
1684: }
1685: if (numchk > 0) {
1686: return true;
1687: } else {
1688: alert("$js_lt{'none'}");
1689: return false;
1690: }
1691: }
1692:
1693: function checkClipboard() {
1694: if (document.pasteform.pasting.length > 1) {
1695: for (var i=0; i<document.pasteform.pasting.length; i++) {
1696: document.pasteform.pasting[i].checked = true;
1697: }
1698: }
1699: return;
1700: }
1701:
1702: function uncheckClipboard() {
1703: if (document.pasteform.pasting.length >1) {
1704: for (var i=0; i<document.pasteform.pasting.length; i++) {
1705: document.pasteform.pasting[i].checked = false;
1706: }
1707: }
1708: return;
1709: }
1710:
1711: END
1712:
1713: }
1714:
1715: sub do_paste_from_buffer {
1716: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1717:
1718: # Array of items in paste buffer
1719: my (@currpaste,%pastebuffer,%allerrors);
1720: @currpaste = split(/,/,$env{'docs.markedcopies'});
1721:
1722: # Early out if paste buffer is empty
1723: if (@currpaste == 0) {
1724: return ();
1725: }
1726: map { $pastebuffer{$_} = 1; } @currpaste;
1727:
1728: # Array of items selected items to paste
1729: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
1730:
1731: # Early out if nothing selected to paste
1732: if (@reqpaste == 0) {
1733: return();
1734: }
1735: my @topaste;
1736: foreach my $suffix (@reqpaste) {
1737: next if ($suffix =~ /\D/);
1738: next unless (exists($pastebuffer{$suffix}));
1739: push(@topaste,$suffix);
1740: }
1741:
1742: # Early out if nothing available to paste
1743: if (@topaste == 0) {
1744: return();
1745: }
1746:
1747: my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%notindom,%duplicate,
1748: %prefixchg,%srcdom,%srcnum,%srcmapidx,%marktomove,$save_err,$lockerrors,$allresult);
1749:
1750: foreach my $suffix (@topaste) {
1751: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1752: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1753: my $mapidx=&LONCAPA::map::qtescape($env{'docs.markedcopy_map_'.$suffix});
1754: # Supplemental content may only include certain types of content
1755: # Early out if pasted content is not supported in Supplemental area
1756: if ($folder =~ /^supplemental/) {
1757: unless (&supp_pasteable($url)) {
1758: $notinsupp{$suffix} = 1;
1759: next;
1760: }
1761: }
1762: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
1763: my $srcd = $1;
1764: my $srcn = $2;
1765: # When paste buffer was populated using an active role in a different course
1766: # check for mdc privilege in the course from which the resource was pasted
1767: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1768: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1769: $notincrs{$suffix} = 1;
1770: next;
1771: }
1772: }
1773: $srcdom{$suffix} = $srcd;
1774: $srcnum{$suffix} = $srcn;
1775: } elsif (($url =~ m{^/res/lib/templates/\w+\.problem$}) ||
1776: ($url =~ m{^/adm/$match_domain/$match_username/\d+/(bulletinboard|smppg)$}) ||
1777: ($url =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$})) {
1778: my ($srcd,$srcn) = split(/_/,$cid);
1779: # When paste buffer was populated using an active role in a different course
1780: # check for mdc privilege in the course from which the resource was pasted
1781: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1782: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1783: $notincrs{$suffix} = 1;
1784: next;
1785: }
1786: }
1787: # When buffer was populated using an active role in a different course
1788: # disallow pasting of External Tool if course is in a different domain.
1789: if (($url =~ m{/ext\.tool$}) && ($srcd ne $coursedom)) {
1790: $notindom{$suffix} = 1;
1791: next;
1792: }
1793: $srcdom{$suffix} = $srcd;
1794: $srcnum{$suffix} = $srcn;
1795: }
1796: $srcmapidx{$suffix} = $mapidx;
1797: push(@dopaste,$suffix);
1798: if ($url=~/\.(page|sequence)$/) {
1799: $is_map{$suffix} = 1;
1800: }
1801: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
1802: my $oldprefix = $1;
1803: # When pasting content from Main Content to Supplemental Content and vice versa
1804: # URLs will contain different paths (which depend on whether pasted item is
1805: # a folder/page or a document).
1806: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
1807: $prefixchg{$suffix} = 'docstosupp';
1808: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
1809: $prefixchg{$suffix} = 'supptodocs';
1810: }
1811:
1812: # If pasting an uploaded map, get list of contained uploaded maps.
1813: if ($env{'docs.markedcopy_nested_'.$suffix}) {
1814: my @nested;
1815: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
1816: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1817: my @deps = map { /\d+:([\d,]+$)/ } @items;
1818: foreach my $dep (@deps) {
1819: if ($dep =~ /,/) {
1820: push(@nested,split(/,/,$dep));
1821: } else {
1822: push(@nested,$dep);
1823: }
1824: }
1825: foreach my $item (@nested) {
1826: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
1827: push(@{$marktomove{$suffix}},$type.'_'.$item);
1828: }
1829: }
1830: }
1831: }
1832: }
1833:
1834: # Early out if nothing available to paste
1835: if (@dopaste == 0) {
1836: return ();
1837: }
1838:
1839: # Populate message hash and hashes used for main content <=> supplemental content
1840: # changes
1841:
1842: %msgs = &Apache::lonlocal::texthash (
1843: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
1844: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1845: notindom => 'Paste failed: Item is an external tool from a course in a different domain.',
1846: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
1847: );
1848:
1849: %before = (
1850: docstosupp => {
1851: map => 'default',
1852: doc => 'docs',
1853: },
1854: supptodocs => {
1855: map => 'supplemental',
1856: doc => 'supplemental',
1857: },
1858: );
1859:
1860: %after = (
1861: docstosupp => {
1862: map => 'supplemental',
1863: doc => 'supplemental'
1864: },
1865: supptodocs => {
1866: map => 'default',
1867: doc => 'docs',
1868: },
1869: );
1870:
1871: # Retrieve information about all course maps in main content area
1872:
1873: my $allmaps = {};
1874: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results,$donechk);
1875:
1876: # Loop over the items to paste
1877: foreach my $suffix (@dopaste) {
1878: # Maps need to be copied first
1879: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
1880: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1881: %newurls,%tomove,%resdatacopy);
1882: if (ref($marktomove{$suffix}) eq 'ARRAY') {
1883: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
1884: }
1885: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1886: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1887: my $cid=&LONCAPA::map::qtescape($env{'docs.markedcopy_crs_'.$suffix});
1888: my $oldurl = $url;
1889: if ($is_map{$suffix}) {
1890: # If pasting a map, check if map contains other maps
1891: my (%hierarchy,%titles);
1892: if (($folder =~ /^default/) && (!$donechk)) {
1893: $allmaps =
1894: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1895: $env{"course.$env{'request.course.id'}.home"},
1896: $env{'request.course.id'});
1897: $donechk = 1;
1898: }
1899: &contained_map_check($url,$folder,$coursenum,$coursedom,
1900: \%removefrommap,\%removeparam,\%addedmaps,
1901: \%hierarchy,\%titles,$allmaps);
1902: if ($url=~ m{^/uploaded/}) {
1903: my $newurl;
1904: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1905: ($newurl,my $error) =
1906: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
1907: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1908: \$title,$allmaps,\%newurls);
1909: if ($error) {
1910: $allerrors{$suffix} = $error;
1911: next;
1912: }
1913: if ($newurl ne '') {
1914: if ($newurl ne $url) {
1915: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
1916: $newsubdir{$url} = $1;
1917: }
1918: $mapchanges{$url} = 1;
1919: }
1920: }
1921: }
1922: if (($srcdom{$suffix} ne $coursedom) ||
1923: ($srcnum{$suffix} ne $coursenum) ||
1924: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
1925: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
1926: $coursedom,$coursenum,$srcdom{$suffix},
1927: $srcnum{$suffix},$allmaps,\%rewrites,
1928: \%retitles,\%copies,\%dbcopies,
1929: \%zombies,\%params,\%mapmoves,
1930: \%mapchanges,\%tomove,\%newsubdir,
1931: \%newurls,\%resdatacopy)) {
1932: $mapmoves{$url} = 1;
1933: }
1934: $url = $newurl;
1935: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
1936: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
1937: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1938: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
1939: \%zombies,\%params,\%mapmoves,\%mapchanges,
1940: \%tomove,\%newsubdir,\%newurls,\%resdatacopy);
1941: }
1942: } elsif ($url=~m {^/res/}) {
1943: # published map can only exist once, so remove from paste buffer when done
1944: push(@toclear,$suffix);
1945: # if pasting published map (main content area only) check map not already in course
1946: if ($folder =~ /^default/) {
1947: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
1948: $duplicate{$suffix} = 1;
1949: next;
1950: }
1951: }
1952: }
1953: }
1954: if ($url=~ m{/(bulletinboard|smppg|ext\.tool)$}) {
1955: my $prefix = $1;
1956: my $fromothercrs;
1957: #need to copy the db contents to a new one, unless this is a move.
1958: my %info = (
1959: src => $url,
1960: cdom => $coursedom,
1961: cnum => $coursenum,
1962: );
1963: if ($prefix eq 'ext.tool') {
1964: if ($prefixchg{$suffix} eq 'docstosupp') {
1965: $info{'delgradable'} = 1;
1966: }
1967: }
1968: if (($srcdom{$suffix} =~ /^$match_domain$/) && ($srcnum{$suffix} =~ /^$match_courseid$/)) {
1969: unless (($srcdom{$suffix} eq $coursedom) && ($srcnum{$suffix} eq $coursenum)) {
1970: $fromothercrs = 1;
1971: $info{'cdom'} = $srcdom{$suffix};
1972: $info{'cnum'} = $srcnum{$suffix};
1973: }
1974: }
1975: unless (($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') && (!$fromothercrs)) {
1976: my (%lockerr,$msg);
1977: my ($newurl,$result,$errtext) =
1978: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
1979: if ($result eq 'ok') {
1980: $url = $newurl;
1981: $title=&mt('Copy of').' '.$title;
1982: } else {
1983: if ($prefix eq 'smppg') {
1984: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
1985: } elsif ($prefix eq 'bulletinboard') {
1986: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1987: } elsif ($prefix eq 'ext.tool') {
1988: $msg = &mt('Paste failed: An error occurred when copying the external tool.').' '.$errtext;
1989: }
1990: $results{$suffix} = $result;
1991: $msgerrs{$suffix} = $msg;
1992: $lockerrs{$suffix} = $lockerr{$prefix};
1993: next;
1994: }
1995: if ($lockerr{$prefix}) {
1996: $lockerrs{$suffix} = $lockerr{$prefix};
1997: }
1998: }
1999: }
2000: $title = &LONCAPA::map::qtunescape($title);
2001: my $ext='false';
2002: if ($url=~m{^http(|s)://}) { $ext='true'; }
2003: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
2004: if ($folder !~ /^supplemental/) {
2005: (undef,undef,$title) =
2006: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
2007: }
2008: } else {
2009: if ($folder=~/^supplemental/) {
2010: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
2011: $env{'user.domain'}.'___&&&___'.$title;
2012: }
2013: }
2014:
2015: # For uploaded files (excluding pages/sequences) path in copied file is changed
2016: # if paste is from Main to Supplemental (or vice versa), or if pasting between
2017: # courses.
2018:
2019: unless ($is_map{$suffix}) {
2020: my $newidx;
2021: # Now insert the URL at the bottom
2022: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
2023: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
2024: my $relpath = $1;
2025: if ($relpath ne '') {
2026: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
2027: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
2028: my $newprefix = $newloc;
2029: if ($newloc eq 'default') {
2030: $newprefix = 'docs';
2031: }
2032: if ($newdocsdir eq '') {
2033: $newdocsdir = 'default';
2034: }
2035: if (($prefixchg{$suffix}) ||
2036: ($srcdom{$suffix} ne $coursedom) ||
2037: ($srcnum{$suffix} ne $coursenum) ||
2038: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
2039: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
2040: $url =
2041: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
2042: &Apache::lonnet::getfile($oldurl));
2043: if ($url eq '/adm/notfound.html') {
2044: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
2045: next;
2046: } else {
2047: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
2048: $newsubpath =~ s{/+$}{/};
2049: $docmoves{$oldurl} = $newsubpath;
2050: }
2051: }
2052: }
2053: } elsif ($url =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2054: my $template = $1;
2055: if ($newidx) {
2056: ©_templated_files($url,$srcdom{$suffix},$srcnum{$suffix},$srcmapidx{$suffix},
2057: $coursedom,$coursenum,$template,$newidx,"$folder.$container");
2058: }
2059: } elsif ($url =~ /ext\.tool$/) {
2060: if (($newidx) && ($folder=~/^default/)) {
2061: my $marker = (split(m{/},$url))[4];
2062: my %toolsettings = &Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum);
2063: my $val = 'no';
2064: if ($toolsettings{'gradable'}) {
2065: $val = 'yes';
2066: }
2067: &LONCAPA::map::storeparameter($newidx,'parameter_0_gradable',$val,
2068: 'string_yesno');
2069: &remember_parms($newidx,'gradable','set',$val);
2070: }
2071: }
2072: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2073: ':'.$ext.':normal:res';
2074: push(@LONCAPA::map::order,$newidx);
2075: # Store the result
2076: my ($errtext,$fatal) =
2077: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2078: if ($fatal) {
2079: $save_err .= $errtext;
2080: $allresult = 'fail';
2081: }
2082: }
2083:
2084: # Apply any changes to maps, or copy dependencies for uploaded HTML pages, or update
2085: # resourcedata for simpleproblems copied from another course
2086: unless ($allresult eq 'fail') {
2087: my %updated = (
2088: rewrites => \%rewrites,
2089: zombies => \%zombies,
2090: removefrommap => \%removefrommap,
2091: removeparam => \%removeparam,
2092: dbcopies => \%dbcopies,
2093: resdatacopy => \%resdatacopy,
2094: retitles => \%retitles,
2095: );
2096: my %info = (
2097: newsubdir => \%newsubdir,
2098: params => \%params,
2099: );
2100: if ($prefixchg{$suffix}) {
2101: $info{'before'} = $before{$prefixchg{$suffix}};
2102: $info{'after'} = $after{$prefixchg{$suffix}};
2103: }
2104: my %moves = (
2105: copies => \%copies,
2106: docmoves => \%docmoves,
2107: mapmoves => \%mapmoves,
2108: );
2109: (my $result,$msgs{$suffix},my $lockerror) =
2110: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
2111: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
2112: $url,'paste');
2113: $lockerrors .= $lockerror;
2114: if ($result eq 'ok') {
2115: if ($is_map{$suffix}) {
2116: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
2117: $folder.'.'.$container);
2118: if ($fatal) {
2119: $allresult = 'failread';
2120: } else {
2121: if ($#LONCAPA::map::order<1) {
2122: my $idx=&LONCAPA::map::getresidx();
2123: if ($idx<=0) { $idx=1; }
2124: $LONCAPA::map::order[0]=$idx;
2125: $LONCAPA::map::resources[$idx]='';
2126: }
2127: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
2128: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
2129: ':'.$ext.':normal:res';
2130: push(@LONCAPA::map::order,$newidx);
2131:
2132: # Store the result
2133: my ($errtext,$fatal) =
2134: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2135: if ($fatal) {
2136: $save_err .= $errtext;
2137: $allresult = 'failstore';
2138: }
2139: }
2140: }
2141: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
2142: push(@toclear,$suffix);
2143: }
2144: }
2145: }
2146: }
2147: &clear_from_buffer(\@toclear,\@currpaste);
2148: my $msgsarray;
2149: foreach my $suffix (keys(%msgs)) {
2150: if (ref($msgs{$suffix}) eq 'ARRAY') {
2151: $msgsarray .= join(',',@{$msgs{$suffix}});
2152: }
2153: }
2154: return ($allresult,$save_err,$msgsarray,$lockerrors);
2155: }
2156:
2157: sub do_buffer_empty {
2158: my @currpaste = split(/,/,$env{'docs.markedcopies'});
2159: if (@currpaste == 0) {
2160: return &mt('Clipboard is already empty');
2161: }
2162: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
2163: if (@toclear == 0) {
2164: return &mt('Nothing selected to clear from clipboard');
2165: }
2166: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
2167: if ($numdel) {
2168: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
2169: } else {
2170: return &mt('Clipboard unchanged');
2171: }
2172: return;
2173: }
2174:
2175: sub clear_from_buffer {
2176: my ($toclear,$currpaste) = @_;
2177: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
2178: my %pastebuffer;
2179: map { $pastebuffer{$_} = 1; } @{$currpaste};
2180: my $numdel = 0;
2181: foreach my $suffix (@{$toclear}) {
2182: next if ($suffix =~ /\D/);
2183: next unless (exists($pastebuffer{$suffix}));
2184: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
2185: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
2186: delete($pastebuffer{$suffix});
2187: $numdel ++;
2188: }
2189: }
2190: my $newbuffer = join(',',sort(keys(%pastebuffer)));
2191: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
2192: return $numdel;
2193: }
2194:
2195: sub get_newmap_url {
2196: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
2197: $titleref,$allmaps,$newurls) = @_;
2198: my $newurl;
2199: if ($url=~ m{^/uploaded/}) {
2200: $$titleref=&mt('Copy of').' '.$$titleref;
2201: }
2202: my $now = time;
2203: my $suffix=$$.int(rand(100)).$now;
2204: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
2205: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
2206: my $path = $1;
2207: my $prefix = $2;
2208: my $ancestor = $3;
2209: if (length($ancestor) > 10) {
2210: $ancestor = substr($ancestor,-10,10);
2211: }
2212: my $newid;
2213: if ($prefixchg) {
2214: if ($folder =~ /^supplemental/) {
2215: $prefix =~ s/^default/supplemental/;
2216: } else {
2217: $prefix =~ s/^supplemental/default/;
2218: }
2219: }
2220: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2221: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2222: } else {
2223: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
2224: }
2225: my $counter = 0;
2226: my $is_unique = &uniqueness_check($newurl);
2227: if ($folder =~ /^default/) {
2228: if ($allmaps->{$newurl}) {
2229: $is_unique = 0;
2230: }
2231: }
2232: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
2233: $counter ++;
2234: $suffix ++;
2235: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
2236: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
2237: } else {
2238: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
2239: }
2240: $is_unique = &uniqueness_check($newurl);
2241: }
2242: if ($is_unique) {
2243: $newurls->{$newurl} = 1;
2244: } else {
2245: if ($url=~/\.page$/) {
2246: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
2247: } else {
2248: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
2249: }
2250: }
2251: }
2252: return ($newurl);
2253: }
2254:
2255: sub dbcopy {
2256: my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
2257: my ($url,$result,$errtext);
2258: if (ref($dbref) eq 'HASH') {
2259: $url = $dbref->{'src'};
2260: if ($url =~ m{/(smppg|bulletinboard|ext\.tool)$}) {
2261: my $prefix = $1;
2262: if ($prefix eq 'ext.tool') {
2263: $prefix = 'exttool';
2264: }
2265: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2266: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2267: my $db_name;
2268: my $marker = (split(m{/},$url))[4];
2269: $marker=~s/\D//g;
2270: if ($dbref->{'src'} =~ m{/smppg$}) {
2271: $db_name =
2272: &Apache::lonsimplepage::get_db_name($url,$marker,
2273: $dbref->{'cdom'},
2274: $dbref->{'cnum'});
2275: } elsif ($dbref->{'src'} =~ m{/ext\.tool$}) {
2276: $db_name = 'exttool_'.$marker;
2277: } else {
2278: $db_name = 'bulletinpage_'.$marker;
2279: }
2280: my ($suffix,$freedlock,$error) =
2281: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
2282: $coursedom,$coursenum,
2283: 'concat');
2284: if (!$suffix) {
2285: if ($prefix eq 'smppg') {
2286: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
2287: } elsif ($prefix eq 'exttool') {
2288: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying an external tool [_1].',$url);
2289: } else {
2290: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
2291: }
2292: if ($error) {
2293: $errtext .= '<br />'.$error;
2294: }
2295: } else {
2296: #need to copy the db contents to a new one.
2297: my %contents=&Apache::lonnet::dump($db_name,
2298: $dbref->{'cdom'},
2299: $dbref->{'cnum'});
2300: if (exists($contents{'uploaded.photourl'})) {
2301: my $photo = $contents{'uploaded.photourl'};
2302: my ($subdir,$fname) =
2303: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
2304: my $newphoto;
2305: if ($fname ne '') {
2306: my $content = &Apache::lonnet::getfile($photo);
2307: unless ($content eq '-1') {
2308: $env{'form.'.$suffix.'.photourl'} = $content;
2309: $newphoto =
2310: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
2311: delete($env{'form.'.$suffix.'.photourl'});
2312: }
2313: }
2314: if ($newphoto =~ m{^/uploaded/}) {
2315: $contents{'uploaded.photourl'} = $newphoto;
2316: }
2317: }
2318: $db_name =~ s{_\d*$ }{_$suffix}x;
2319: if (($prefix eq 'exttool') && ($dbref->{'delgradable'}) && ($contents{'gradable'})) {
2320: delete($contents{'gradable'});
2321: }
2322: $result=&Apache::lonnet::put($db_name,\%contents,
2323: $coursedom,$coursenum);
2324: if ($result eq 'ok') {
2325: $url =~ s{/(\d*)/(smppg|bulletinboard|ext\.tool)$}{/$suffix/$2}x;
2326: }
2327: }
2328: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
2329: $lockerrorsref->{$prefix} =
2330: '<div class="LC_error">'.
2331: &mt('There was a problem removing a lockfile.');
2332: if ($prefix eq 'smppg') {
2333: $lockerrorsref->{$prefix} .=
2334: ' '.&mt('This will prevent creation of additional simple pages in this course.');
2335: } elsif ($prefix eq 'exttool') {
2336: $lockerrorsref->{$prefix} .=
2337: ' '.&mt('This will prevent addition of more external tools to this course.');
2338: } else {
2339: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
2340: }
2341: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
2342: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
2343: '</div>';
2344: }
2345: }
2346: } elsif ($url =~ m{/syllabus$}) {
2347: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
2348: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
2349: if (($dbref->{'cdom'} ne $coursedom) ||
2350: ($dbref->{'cnum'} ne $coursenum)) {
2351: my %contents=&Apache::lonnet::dump('syllabus',
2352: $dbref->{'cdom'},
2353: $dbref->{'cnum'});
2354: $result=&Apache::lonnet::put('syllabus',\%contents,
2355: $coursedom,$coursenum);
2356: }
2357: }
2358: }
2359: }
2360: return ($url,$result,$errtext);
2361: }
2362:
2363: sub copy_templated_files {
2364: my ($srcurl,$srcdom,$srcnum,$srcmapinfo,$coursedom,$coursenum,$template,$newidx,$newmapname) = @_;
2365: my ($srcfolder,$srcid,$srcwaspage) = split(/:/,$srcmapinfo);
2366: my $srccontainer = 'sequence';
2367: if ($srcwaspage) {
2368: $srccontainer = 'page';
2369: }
2370: my $srcsymb = "uploaded/$srcdom/$srcnum/$srcfolder.$srccontainer".
2371: '___'.$srcid.'___'.&Apache::lonnet::declutter($srcurl);
2372: my $srcprefix = $srcdom.'_'.$srcnum.'.'.$srcsymb;
2373: my %srcparms=&Apache::lonnet::dump('resourcedata',$srcdom,$srcnum,$srcprefix);
2374: my $newsymb = "uploaded/$coursedom/$coursenum/$newmapname".'___'.$newidx.'___lib/templates/'.
2375: $template.'.problem';
2376: my $newprefix = $coursedom.'_'.$coursenum.'.'.$newsymb;
2377: if ($template eq 'simpleproblem') {
2378: $srcprefix .= '.0.';
2379: my $weightprefix = $newprefix;
2380: $newprefix .= '.0.';
2381: my @simpleprobqtypes = qw(radio option string essay numerical);
2382: my $qtype=$srcparms{$srcprefix.'questiontype'};
2383: if (grep(/^\Q$qtype\E$/,@simpleprobqtypes)) {
2384: my %newdata = (
2385: $newprefix.'questiontype' => $qtype,
2386: );
2387: foreach my $type (@simpleprobqtypes) {
2388: if ($type eq $qtype) {
2389: $newdata{"$weightprefix.$type.weight"}=1;
2390: } else {
2391: $newdata{"$weightprefix.$type.weight"}=0;
2392: }
2393: }
2394: $newdata{$newprefix.'hiddenparts'} = '!'.$qtype;
2395: $newdata{$newprefix.'questiontext'} = $srcparms{$srcprefix.'questiontext'};
2396: $newdata{$newprefix.'hinttext'} = $srcparms{$srcprefix.'hinttext'};
2397: if ($qtype eq 'numerical') {
2398: $newdata{$newprefix.'numericalscript'} = $srcparms{$srcprefix.'numericalscript'};
2399: $newdata{$newprefix.'numericalanswer'} = $srcparms{$srcprefix.'numericalanswer'};
2400: $newdata{$newprefix.'numericaltolerance'} = $srcparms{$srcprefix.'numericaltolerance'};
2401: $newdata{$newprefix.'numericalsigfigs'} = $srcparms{$srcprefix.'numericalsigfigs'};
2402: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2403: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2404: unless (defined($maxfoils)) { $maxfoils=10; }
2405: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2406: if ($maxfoils<=0) { $maxfoils=10; }
2407: my $randomize=$srcparms{$srcprefix.'randomize'};
2408: unless (defined($randomize)) { $randomize='yes'; }
2409: unless ($randomize eq 'no') { $randomize='yes'; }
2410: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2411: $newdata{$newprefix.'randomize'} = $randomize;
2412: if ($qtype eq 'option') {
2413: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2414: }
2415: for (my $i=1; $i<=10; $i++) {
2416: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2417: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2418: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2419: }
2420:
2421: } elsif (($qtype eq 'option') || ($qtype eq 'radio')) {
2422: my $maxfoils=$srcparms{$srcprefix.'maxfoils'};
2423: unless (defined($maxfoils)) { $maxfoils=10; }
2424: unless ($maxfoils=~/^\d+$/) { $maxfoils=10; }
2425: if ($maxfoils<=0) { $maxfoils=10; }
2426: my $randomize=$srcparms{$srcprefix.'randomize'};
2427: unless (defined($randomize)) { $randomize='yes'; }
2428: unless ($randomize eq 'no') { $randomize='yes'; }
2429: $newdata{$newprefix.'maxfoils'} = $maxfoils;
2430: $newdata{$newprefix.'randomize'} = $randomize;
2431: if ($qtype eq 'option') {
2432: $newdata{$newprefix.'options'} = $srcparms{$srcprefix.'options'};
2433: }
2434: for (my $i=1; $i<=10; $i++) {
2435: $newdata{$newprefix.'value'.$i} = $srcparms{$srcprefix.'value'.$i};
2436: $newdata{$newprefix.'position'.$i} = $srcparms{$srcprefix.'position'.$i};
2437: $newdata{$newprefix.'text'.$i} = $srcparms{$srcprefix.'text'.$i};
2438: }
2439: } elsif ($qtype eq 'string') {
2440: $newdata{$newprefix.'stringanswer'} = $srcparms{$srcprefix.'stringanswer'};
2441: $newdata{$newprefix.'stringtype'} = $srcparms{$srcprefix.'stringtype'};
2442: }
2443: if (keys(%newdata)) {
2444: my $putres = &Apache::lonnet::cput('resourcedata',\%newdata,$coursedom,
2445: $coursenum);
2446: if ($putres eq 'ok') {
2447: &Apache::lonnet::devalidatecourseresdata($coursenum,$coursedom);
2448: }
2449: }
2450: }
2451: }
2452: }
2453:
2454: sub uniqueness_check {
2455: my ($newurl) = @_;
2456: my $unique = 1;
2457: foreach my $res (@LONCAPA::map::order) {
2458: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2459: $url=&LONCAPA::map::qtescape($url);
2460: if ($newurl eq $url) {
2461: $unique = 0;
2462: last;
2463: }
2464: }
2465: return $unique;
2466: }
2467:
2468: sub contained_map_check {
2469: my ($url,$folder,$coursenum,$coursedom,$removefrommap,$removeparam,$addedmaps,
2470: $hierarchy,$titles,$allmaps) = @_;
2471: my $content = &Apache::lonnet::getfile($url);
2472: unless ($content eq '-1') {
2473: my $parser = HTML::TokeParser->new(\$content);
2474: $parser->attr_encoded(1);
2475: while (my $token = $parser->get_token) {
2476: next if ($token->[0] ne 'S');
2477: if ($token->[1] eq 'resource') {
2478: next if ($token->[2]->{'type'} eq 'zombie');
2479: my $ressrc = $token->[2]->{'src'};
2480: if ($ressrc =~ m{^/adm/($match_domain)/$match_courseid/\d+/ext\.tool$}) {
2481: my $srcdom = $1;
2482: unless ($srcdom eq $coursedom) {
2483: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2484: next;
2485: }
2486: } elsif ($folder =~ /^supplemental/) {
2487: unless (&supp_pasteable($ressrc)) {
2488: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2489: next;
2490: }
2491: }
2492: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
2493: if ($1 eq 'uploaded') {
2494: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
2495: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
2496: } else {
2497: if ($allmaps->{$ressrc}) {
2498: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2499: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
2500: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2501: } else {
2502: $addedmaps->{$ressrc} = [$url];
2503: }
2504: }
2505: &contained_map_check($ressrc,$folder,$coursenum,$coursedom,$removefrommap,
2506: $removeparam,$addedmaps,$hierarchy,$titles,$allmaps);
2507: }
2508: } elsif ($token->[1] eq 'param') {
2509: if ($folder =~ /^supplemental/) {
2510: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
2511: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
2512: } else {
2513: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
2514: }
2515: }
2516: }
2517: }
2518: }
2519: return;
2520: }
2521:
2522: sub url_paste_fixups {
2523: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
2524: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
2525: $mapchanges,$tomove,$newsubdir,$newurls,$resdatacopy) = @_;
2526: my $checktitle;
2527: if (($prefixchg) &&
2528: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
2529: $checktitle = 1;
2530: }
2531: my $skip;
2532: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
2533: my $mapid = $1.$2;
2534: if ($tomove->{$mapid}) {
2535: $skip = 1;
2536: }
2537: }
2538: my $file = &Apache::lonnet::getfile($oldurl);
2539: return if ($file eq '-1');
2540: my $parser = HTML::TokeParser->new(\$file);
2541: $parser->attr_encoded(1);
2542: my $changed = 0;
2543: while (my $token = $parser->get_token) {
2544: next if ($token->[0] ne 'S');
2545: if ($token->[1] eq 'resource') {
2546: my $ressrc = $token->[2]->{'src'};
2547: next if ($ressrc eq '');
2548: my $id = $token->[2]->{'id'};
2549: my $title = $token->[2]->{'title'};
2550: if ($checktitle) {
2551: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2552: $retitles->{$oldurl}{$id} = $ressrc;
2553: }
2554: }
2555: next if ($token->[2]->{'type'} eq 'external');
2556: if ($token->[2]->{'type'} eq 'zombie') {
2557: next if ($skip);
2558: $zombies->{$oldurl}{$id} = $ressrc;
2559: $changed = 1;
2560: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
2561: my $srcdom = $1;
2562: my $srcnum = $2;
2563: my $rem = $3;
2564: my $newurl;
2565: my $mapname;
2566: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2567: my $prefix = $1;
2568: $mapname = $prefix.$2;
2569: if ($tomove->{$mapname}) {
2570: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
2571: $srcdom,$srcnum,$allmaps,$rewrites,
2572: $retitles,$copies,$dbcopies,$zombies,
2573: $params,$mapmoves,$mapchanges,$tomove,
2574: $newsubdir,$newurls,$resdatacopy);
2575: next;
2576: } else {
2577: ($newurl,my $error) =
2578: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
2579: $srcdom,$srcnum,\$title,$allmaps,$newurls);
2580: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
2581: $newsubdir->{$ressrc} = $1;
2582: }
2583: if ($error) {
2584: next;
2585: }
2586: }
2587: }
2588: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
2589: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
2590:
2591: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2592: $rewrites->{$oldurl}{$id} = $ressrc;
2593: $mapchanges->{$ressrc} = 1;
2594: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
2595: $cnum,$srcdom,$srcnum,$allmaps,
2596: $rewrites,$retitles,$copies,$dbcopies,
2597: $zombies,$params,$mapmoves,$mapchanges,
2598: $tomove,$newsubdir,$newurls,$resdatacopy)) {
2599: $mapmoves->{$ressrc} = 1;
2600: }
2601: $changed = 1;
2602: } else {
2603: $rewrites->{$oldurl}{$id} = $ressrc;
2604: $copies->{$oldurl}{$ressrc} = $id;
2605: $changed = 1;
2606: }
2607: }
2608: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/(.+)$}) {
2609: next if ($skip);
2610: my $srcdom = $1;
2611: my $srcnum = $2;
2612: my $rem = $3;
2613: my ($is_exttool,$exttoolchg);
2614: if ($rem =~ m{\d+/ext\.tool$}) {
2615: $is_exttool = 1;
2616: }
2617: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
2618: $rewrites->{$oldurl}{$id} = $ressrc;
2619: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2620: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2621: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2622: $changed = 1;
2623: if ($is_exttool) {
2624: $exttoolchg = 1;
2625: }
2626: } elsif (($rem =~ m{\d+/ext\.tool$}) &&
2627: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2628: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2629: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2630: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2631: $changed = 1;
2632: $exttoolchg = 1;
2633: }
2634: if (($is_exttool) && ($prefixchg)) {
2635: if ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/default}) {
2636: if ($exttoolchg) {
2637: $dbcopies->{$oldurl}{$id}{'delgradable'} = 1;
2638: }
2639: }
2640: }
2641: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
2642: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
2643: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2644: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2645: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
2646: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
2647: $changed = 1;
2648: }
2649: } elsif ($ressrc eq '/res/lib/templates/simpleproblem.problem') {
2650: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum)) {
2651: $resdatacopy->{$oldurl}{$id}{'src'} = $ressrc;
2652: $resdatacopy->{$oldurl}{$id}{'cdom'} = $fromcdom;
2653: $resdatacopy->{$oldurl}{$id}{'cnum'} = $fromcnum;
2654: }
2655: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
2656: next if ($skip);
2657: my $srcdom = $1;
2658: my $srcnum = $2;
2659: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
2660: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2661: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2662: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2663: $changed = 1;
2664: }
2665: }
2666: } elsif ($token->[1] eq 'param') {
2667: next if ($skip);
2668: my $to = $token->[2]->{'to'};
2669: if ($to ne '') {
2670: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
2671: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
2672: } else {
2673: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
2674: }
2675: }
2676: }
2677: }
2678: return $changed;
2679: }
2680:
2681: sub apply_fixups {
2682: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
2683: $oldurl,$url,$caller) = @_;
2684: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
2685: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
2686: %resdatacopy,%lockerrors,$lockmsg);
2687: if (ref($updated) eq 'HASH') {
2688: if (ref($updated->{'rewrites'}) eq 'HASH') {
2689: %rewrites = %{$updated->{'rewrites'}};
2690: }
2691: if (ref($updated->{'zombies'}) eq 'HASH') {
2692: %zombies = %{$updated->{'zombies'}};
2693: }
2694: if (ref($updated->{'removefrommap'}) eq 'HASH') {
2695: %removefrommap = %{$updated->{'removefrommap'}};
2696: }
2697: if (ref($updated->{'removeparam'}) eq 'HASH') {
2698: %removeparam = %{$updated->{'removeparam'}};
2699: }
2700: if (ref($updated->{'dbcopies'}) eq 'HASH') {
2701: %dbcopies = %{$updated->{'dbcopies'}};
2702: }
2703: if (ref($updated->{'retitles'}) eq 'HASH') {
2704: %retitles = %{$updated->{'retitles'}};
2705: }
2706: if (ref($updated->{'resdatacopy'}) eq 'HASH') {
2707: %resdatacopy = %{$updated->{'resdatacopy'}};
2708: }
2709: }
2710: if (ref($info) eq 'HASH') {
2711: if (ref($info->{'newsubdir'}) eq 'HASH') {
2712: %newsubdir = %{$info->{'newsubdir'}};
2713: }
2714: if (ref($info->{'params'}) eq 'HASH') {
2715: %params = %{$info->{'params'}};
2716: }
2717: if (ref($info->{'before'}) eq 'HASH') {
2718: %before = %{$info->{'before'}};
2719: }
2720: if (ref($info->{'after'}) eq 'HASH') {
2721: %after = %{$info->{'after'}};
2722: }
2723: }
2724: if (ref($moves) eq 'HASH') {
2725: if (ref($moves->{'copies'}) eq 'HASH') {
2726: %copies = %{$moves->{'copies'}};
2727: }
2728: if (ref($moves->{'docmoves'}) eq 'HASH') {
2729: %docmoves = %{$moves->{'docmoves'}};
2730: }
2731: if (ref($moves->{'mapmoves'}) eq 'HASH') {
2732: %mapmoves = %{$moves->{'mapmoves'}};
2733: }
2734: }
2735: foreach my $key (keys(%copies),keys(%docmoves)) {
2736: my @allcopies;
2737: if (exists($copies{$key})) {
2738: if (ref($copies{$key}) eq 'HASH') {
2739: my %added;
2740: foreach my $innerkey (keys(%{$copies{$key}})) {
2741: if (($innerkey ne '') && (!$added{$innerkey})) {
2742: push(@allcopies,$innerkey);
2743: $added{$innerkey} = 1;
2744: }
2745: }
2746: undef(%added);
2747: }
2748: }
2749: if ($key eq $oldurl) {
2750: if ((exists($docmoves{$key}))) {
2751: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
2752: push(@allcopies,$oldurl);
2753: }
2754: }
2755: }
2756: if (@allcopies > 0) {
2757: foreach my $item (@allcopies) {
2758: my ($relpath,$oldsubdir,$fname) =
2759: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
2760: if ($fname ne '') {
2761: my $content = &Apache::lonnet::getfile($item);
2762: unless ($content eq '-1') {
2763: my $storefn;
2764: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
2765: $storefn = $docmoves{$key};
2766: } else {
2767: $storefn = $relpath;
2768: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
2769: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
2770: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
2771: }
2772: if ($newsubdir{$key}) {
2773: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
2774: }
2775: }
2776: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
2777: my $copyurl =
2778: &Apache::lonclonecourse::writefile($env{'request.course.id'},
2779: $storefn.$fname,$content);
2780: if ($copyurl eq '/adm/notfound.html') {
2781: if (exists($docmoves{$oldurl})) {
2782: return &mt('Paste failed: an error occurred copying the file.');
2783: } elsif (ref($errors) eq 'HASH') {
2784: $errors->{$item} = 1;
2785: }
2786: }
2787: }
2788: }
2789: }
2790: }
2791: }
2792: foreach my $key (keys(%mapmoves)) {
2793: my $storefn=$key;
2794: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2795: if ($prefixchg && $before{'map'} && $after{'map'}) {
2796: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
2797: }
2798: if ($newsubdir{$key}) {
2799: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2800: }
2801: my $mapcontent = &Apache::lonnet::getfile($key);
2802: if (($mapcontent eq '-1') && ($before{'map'} eq 'supplemental') &&
2803: ($after{'map'} eq 'default') &&
2804: ($key =~ m{^/uploaded/$match_domain/$match_courseid/supplemental_\d+\.sequence$})) {
2805: $mapcontent = '<map>'."\n".
2806: '<resource id="1" src="" type="start" />'."\n".
2807: '<link from="1" to="2" index="1" />'."\n".
2808: '<resource id="2" src="" type="finish" />'."\n".
2809: '</map>';
2810: }
2811: if ($mapcontent eq '-1') {
2812: if (ref($errors) eq 'HASH') {
2813: $errors->{$key} = 1;
2814: }
2815: } else {
2816: my $newmap =
2817: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
2818: $mapcontent);
2819: if ($newmap eq '/adm/notfound.html') {
2820: if (ref($errors) eq 'HASH') {
2821: $errors->{$key} = 1;
2822: }
2823: }
2824: }
2825: }
2826: my %updates;
2827: if ($is_map) {
2828: if (ref($updated) eq 'HASH') {
2829: foreach my $type (keys(%{$updated})) {
2830: if (ref($updated->{$type}) eq 'HASH') {
2831: foreach my $key (keys(%{$updated->{$type}})) {
2832: $updates{$key} = 1;
2833: }
2834: }
2835: }
2836: }
2837: foreach my $key (keys(%updates)) {
2838: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
2839: if (ref($rewrites{$key}) eq 'HASH') {
2840: %torewrite = %{$rewrites{$key}};
2841: }
2842: if (ref($retitles{$key}) eq 'HASH') {
2843: %toretitle = %{$retitles{$key}};
2844: }
2845: if (ref($removefrommap{$key}) eq 'HASH') {
2846: %toremove = %{$removefrommap{$key}};
2847: }
2848: if (ref($removeparam{$key}) eq 'HASH') {
2849: %remparam = %{$removeparam{$key}};
2850: }
2851: if (ref($zombies{$key}) eq 'HASH') {
2852: %zombie = %{$zombies{$key}};
2853: }
2854: if (ref($dbcopies{$key}) eq 'HASH') {
2855: foreach my $idx (keys(%{$dbcopies{$key}})) {
2856: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
2857: my ($newurl,$result,$errtext) =
2858: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);
2859: if ($result eq 'ok') {
2860: $newdb{$idx} = $newurl;
2861: } elsif (ref($errors) eq 'HASH') {
2862: $errors->{$key} = 1;
2863: }
2864: push(@msgs,$errtext);
2865: }
2866: }
2867: }
2868: if (ref($resdatacopy{$key}) eq 'HASH') {
2869: my ($gotnewmapname,$newmapname,$srcfolder,$srccontainer);
2870: foreach my $idx (keys(%{$resdatacopy{$key}})) {
2871: if (ref($resdatacopy{$key}{$idx}) eq 'HASH') {
2872: my $srcurl = $resdatacopy{$key}{$idx}{'src'};
2873: if ($srcurl =~ m{^/res/lib/templates/(\w+)\.problem$}) {
2874: my $template = $1;
2875: if (($resdatacopy{$key}{$idx}{'cdom'} =~ /^$match_domain$/) &&
2876: ($resdatacopy{$key}{$idx}{'cnum'} =~ /^$match_courseid$/)) {
2877: my $srcdom = $resdatacopy{$key}{$idx}{'cdom'};
2878: my $srcnum = $resdatacopy{$key}{$idx}{'cnum'};
2879: unless ($gotnewmapname) {
2880: ($newmapname) = ($key =~ m{/([^/]+)$});
2881: ($srcfolder,$srccontainer) = split(/\./,$newmapname);
2882: if ($newsubdir{$key}) {
2883: $newmapname =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2884: }
2885: $gotnewmapname = 1;
2886: }
2887: my $srcmapinfo = $srcfolder.':'.$idx;
2888: if ($srccontainer eq 'page') {
2889: $srcmapinfo .= ':1';
2890: }
2891: ©_templated_files($srcurl,$srcdom,$srcnum,$srcmapinfo,$cdom,
2892: $cnum,$template,$idx,$newmapname);
2893: }
2894: }
2895: }
2896: }
2897: }
2898: if (ref($params{$key}) eq 'HASH') {
2899: %currparam = %{$params{$key}};
2900: }
2901: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
2902: if ($fatal) {
2903: return ($errtext);
2904: }
2905: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
2906: if (defined($LONCAPA::map::zombies[$i])) {
2907: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
2908: if ($zombie{$i} eq $src) {
2909: undef($LONCAPA::map::zombies[$i]);
2910: }
2911: }
2912: }
2913: my $total = scalar(@LONCAPA::map::order) - 1;
2914: for (my $i=$total; $i>=0; $i--) {
2915: my $idx = $LONCAPA::map::order[$i];
2916: if (defined($LONCAPA::map::resources[$idx])) {
2917: my $changed;
2918: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
2919: if ((exists($toremove{$idx})) &&
2920: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
2921: splice(@LONCAPA::map::order,$i,1);
2922: if (ref($currparam{$idx}) eq 'ARRAY') {
2923: foreach my $name (@{$currparam{$idx}}) {
2924: &LONCAPA::map::delparameter($idx,$name);
2925: }
2926: }
2927: next;
2928: }
2929: my $origsrc = $src;
2930: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
2931: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2932: $changed = 1;
2933: }
2934: }
2935: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
2936: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
2937: if ($origsrc =~ m{^/uploaded/}) {
2938: if ($prefixchg && $before{'map'} && $after{'map'}) {
2939: if ($src =~ /\.(page|sequence)$/) {
2940: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
2941: } else {
2942: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
2943: }
2944: }
2945: if ($origsrc =~ /\.(page|sequence)$/) {
2946: if ($newsubdir{$origsrc}) {
2947: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
2948: }
2949: } elsif ($newsubdir{$key}) {
2950: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
2951: }
2952: }
2953: $changed = 1;
2954: } elsif ($newdb{$idx} ne '') {
2955: $src = $newdb{$idx};
2956: $changed = 1;
2957: }
2958: if ($changed) {
2959: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
2960: }
2961: }
2962: }
2963: foreach my $idx (keys(%remparam)) {
2964: if (ref($remparam{$idx}) eq 'ARRAY') {
2965: foreach my $name (@{$remparam{$idx}}) {
2966: &LONCAPA::map::delparameter($idx,$name);
2967: }
2968: }
2969: }
2970: if (values(%lockerrors) > 0) {
2971: $lockmsg = join('<br />',values(%lockerrors));
2972: }
2973: my $storefn;
2974: if ($key eq $oldurl) {
2975: $storefn = $url;
2976: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2977: } else {
2978: $storefn = $key;
2979: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2980: if ($prefixchg && $before{'map'} && $after{'map'}) {
2981: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
2982: }
2983: if ($newsubdir{$key}) {
2984: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
2985: }
2986: }
2987: my $report;
2988: if ($folder !~ /^supplemental/) {
2989: $report = 1;
2990: }
2991: (my $outtext,$errtext) =
2992: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
2993: if ($errtext) {
2994: if ($caller eq 'paste') {
2995: return (&mt('Paste failed: an error occurred saving the folder or page.'));
2996: }
2997: }
2998: }
2999: }
3000: return ('ok',\@msgs,$lockmsg);
3001: }
3002:
3003: sub copy_dependencies {
3004: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
3005: my $content;
3006: if (ref($contentref)) {
3007: $content = $$contentref;
3008: } else {
3009: $content = &Apache::lonnet::getfile($item);
3010: }
3011: unless ($content eq '-1') {
3012: my $mm = new File::MMagic;
3013: my $mimetype = $mm->checktype_contents($content);
3014: if ($mimetype eq 'text/html') {
3015: my (%allfiles,%codebase,$state);
3016: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
3017: if ($res eq 'ok') {
3018: my ($numexisting,$numpathchanges,$existing);
3019: (undef,$numexisting,$numpathchanges,$existing) =
3020: &Apache::loncommon::ask_for_embedded_content(
3021: '/adm/coursedocs',$state,\%allfiles,\%codebase,
3022: {'error_on_invalid_names' => 1,
3023: 'ignore_remote_references' => 1,
3024: 'docs_url' => $item,
3025: 'context' => 'paste'});
3026: if ($numexisting > 0) {
3027: if (ref($existing) eq 'HASH') {
3028: foreach my $dep (keys(%{$existing})) {
3029: my $depfile = $dep;
3030: unless ($depfile =~ m{^\Q$relpath\E}) {
3031: $depfile = $relpath.$dep;
3032: }
3033: my $depcontent = &Apache::lonnet::getfile($depfile);
3034: unless ($depcontent eq '-1') {
3035: my $storedep = $dep;
3036: $storedep =~ s{^\Q$relpath\E}{};
3037: my $dep_url =
3038: &Apache::lonclonecourse::writefile(
3039: $env{'request.course.id'},
3040: $storefn.$storedep,$depcontent);
3041: if ($dep_url eq '/adm/notfound.html') {
3042: if (ref($errors) eq 'HASH') {
3043: $errors->{$depfile} = 1;
3044: }
3045: } else {
3046: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
3047: }
3048: }
3049: }
3050: }
3051: }
3052: }
3053: }
3054: }
3055: return;
3056: }
3057:
3058: my %parameter_type = ( 'randompick' => 'int_pos',
3059: 'hiddenresource' => 'string_yesno',
3060: 'encrypturl' => 'string_yesno',
3061: 'randomorder' => 'string_yesno',);
3062: my $valid_parameters_re = join('|',keys(%parameter_type));
3063: # set parameters
3064: sub update_parameter {
3065: if ($env{'form.changeparms'} eq 'all') {
3066: my (@allidx,@allmapidx,%allchecked,%currchecked);
3067: %allchecked = (
3068: 'hiddenresource' => {},
3069: 'encrypturl' => {},
3070: 'randompick' => {},
3071: 'randomorder' => {},
3072: );
3073: foreach my $which (keys(%allchecked)) {
3074: $env{'form.all'.$which} =~ s/,$//;
3075: if ($which eq 'randompick') {
3076: foreach my $item (split(/,/,$env{'form.all'.$which})) {
3077: my ($res,$value) = split(/:/,$item);
3078: if ($value =~ /^\d+$/) {
3079: $allchecked{$which}{$res} = $value;
3080: }
3081: }
3082: } else {
3083: if ($env{'form.all'.$which}) {
3084: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
3085: }
3086: }
3087: }
3088: my $haschanges = 0;
3089: foreach my $res (@LONCAPA::map::order) {
3090: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3091: $name=&LONCAPA::map::qtescape($name);
3092: $url=&LONCAPA::map::qtescape($url);
3093: next unless ($name && $url);
3094: my $is_map;
3095: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3096: $is_map = 1;
3097: }
3098: foreach my $which (keys(%allchecked)) {
3099: if (($which eq 'randompick' || $which eq 'randomorder')) {
3100: next if (!$is_map);
3101: }
3102: my $oldvalue = 0;
3103: my $newvalue = 0;
3104: if ($allchecked{$which}{$res}) {
3105: $newvalue = $allchecked{$which}{$res};
3106: }
3107: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
3108: if ($which eq 'randompick') {
3109: if ($current =~ /^(\d+)$/) {
3110: $oldvalue = $1;
3111: }
3112: } else {
3113: if ($current =~ /^yes$/i) {
3114: $oldvalue = 1;
3115: }
3116: }
3117: if ($oldvalue ne $newvalue) {
3118: $haschanges = 1;
3119: if ($newvalue) {
3120: my $storeval = 'yes';
3121: if ($which eq 'randompick') {
3122: $storeval = $newvalue;
3123: }
3124: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
3125: $storeval,
3126: $parameter_type{$which});
3127: &remember_parms($res,$which,'set',$storeval);
3128: } elsif ($oldvalue) {
3129: &LONCAPA::map::delparameter($res,'parameter_'.$which);
3130: &remember_parms($res,$which,'del');
3131: }
3132: }
3133: }
3134: }
3135: return $haschanges;
3136: } else {
3137: my $haschanges = 0;
3138: return $haschanges if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
3139:
3140: my $which = $env{'form.changeparms'};
3141: my $idx = $env{'form.setparms'};
3142: my $oldvalue = 0;
3143: my $newvalue = 0;
3144: my $current = (&LONCAPA::map::getparameter($idx,'parameter_'.$which))[0];
3145: if ($which eq 'randompick') {
3146: if ($current =~ /^(\d+)$/) {
3147: $oldvalue = $1;
3148: }
3149: } elsif ($current =~ /^yes$/i) {
3150: $oldvalue = 1;
3151: }
3152: if ($env{'form.'.$which.'_'.$idx}) {
3153: $newvalue = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
3154: : 1;
3155: }
3156: if ($oldvalue ne $newvalue) {
3157: $haschanges = 1;
3158: if ($newvalue) {
3159: my $storeval = 'yes';
3160: if ($which eq 'randompick') {
3161: $storeval = $newvalue;
3162: }
3163: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $storeval,
3164: $parameter_type{$which});
3165: &remember_parms($idx,$which,'set',$storeval);
3166: } else {
3167: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
3168: &remember_parms($idx,$which,'del');
3169: }
3170: }
3171: return $haschanges;
3172: }
3173: }
3174:
3175: sub handle_edit_cmd {
3176: my ($coursenum,$coursedom) =@_;
3177: my $haschanges = 0;
3178: if ($env{'form.cmd'} eq '') {
3179: return $haschanges;
3180: }
3181: my ($cmd,$idx)=split('_',$env{'form.cmd'});
3182:
3183: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
3184: my ($title, $url, @rrest) = split(':', $ratstr);
3185:
3186: if ($cmd eq 'remove') {
3187: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3188: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3189: &Apache::lonnet::removeuploadedurl($url);
3190: } else {
3191: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3192: }
3193: splice(@LONCAPA::map::order, $idx, 1);
3194: $haschanges = 1;
3195: } elsif ($cmd eq 'cut') {
3196: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
3197: splice(@LONCAPA::map::order, $idx, 1);
3198: $haschanges = 1;
3199: } elsif ($cmd eq 'up'
3200: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
3201: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
3202: $haschanges = 1;
3203: } elsif ($cmd eq 'down'
3204: && defined($LONCAPA::map::order[$idx+1])) {
3205: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
3206: $haschanges = 1;
3207: } elsif ($cmd eq 'rename') {
3208: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
3209: if ($comment=~/\S/) {
3210: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
3211: $comment.':'.join(':', $url, @rrest);
3212: }
3213: # Devalidate title cache
3214: my $renamed_url=&LONCAPA::map::qtescape($url);
3215: &Apache::lonnet::devalidate_title_cache($renamed_url);
3216: $haschanges = 1;
3217: } elsif ($cmd eq 'setalias') {
3218: my $newvalue = $env{'form.alias'};
3219: if ($newvalue ne '') {
3220: unless (Apache::lonnet::get_symb_from_alias($newvalue)) {
3221: &LONCAPA::map::storeparameter($idx,'parameter_0_mapalias',$newvalue,
3222: 'string');
3223: &remember_parms($idx,'mapalias','set',$newvalue);
3224: $haschanges = 1;
3225: }
3226: }
3227: } elsif ($cmd eq 'delalias') {
3228: my $current = (&LONCAPA::map::getparameter($idx,'parameter_0_mapalias'))[0];
3229: if ($current ne '') {
3230: &LONCAPA::map::delparameter($idx,'parameter_0_mapalias');
3231: &remember_parms($idx,'mapalias','del');
3232: $haschanges = 1;
3233: }
3234: }
3235: return $haschanges;
3236: }
3237:
3238: sub editor {
3239: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
3240: $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
3241: $canedit,$hostname,$navmapref,$hiddentop)=@_;
3242: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
3243: if ($allowed) {
3244: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
3245: $is_random_order,$container) =
3246: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
3247: $r->print($breadcrumbtrail);
3248: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
3249: $container = 'page';
3250: } else {
3251: $container = 'sequence';
3252: }
3253:
3254: my $jumpto;
3255:
3256: unless ($supplementalflag) {
3257: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
3258: }
3259:
3260: unless ($allowed) {
3261: $randompick = -1;
3262: }
3263:
3264: my ($errtext,$fatal);
3265: if (($folder eq '') && (!$supplementalflag)) {
3266: if (@LONCAPA::map::order) {
3267: undef(@LONCAPA::map::order);
3268: undef(@LONCAPA::map::resources);
3269: undef(@LONCAPA::map::resparms);
3270: undef(@LONCAPA::map::zombies);
3271: }
3272: $folder = 'default';
3273: $container = 'sequence';
3274: } else {
3275: ($errtext,$fatal) = &mapread($coursenum,$coursedom,
3276: $folder.'.'.$container);
3277: return $errtext if ($fatal);
3278: }
3279:
3280: my (%supphidden,%suppids,$suppmapid);
3281:
3282: if ($#LONCAPA::map::order<1) {
3283: my $idx=&LONCAPA::map::getresidx();
3284: if ($idx<=0) { $idx=1; }
3285: $LONCAPA::map::order[0]=$idx;
3286: $LONCAPA::map::resources[$idx]='';
3287: } elsif ($supplementalflag && !$allowed) {
3288: my ($supplemental) = &Apache::lonnet::get_supplemental($coursenum,$coursedom);
3289: if (ref($supplemental) eq 'HASH') {
3290: if (ref($supplemental->{'hidden'}) eq 'HASH') {
3291: %supphidden = %{$supplemental->{'hidden'}};
3292: }
3293: if (ref($supplemental->{'ids'}) eq 'HASH') {
3294: %suppids = %{$supplemental->{'ids'}};
3295: }
3296: }
3297: if ($folder eq 'supplemental') {
3298: $suppmapid = 0;
3299: } elsif ($folder =~ /^supplemental_(\d+)$/) {
3300: $suppmapid = $1;
3301: }
3302: }
3303:
3304: # ------------------------------------------------------------ Process commands
3305:
3306: # ---------------- if they are for this folder and user allowed to make changes
3307: if (($allowed && $canedit) && ($env{'form.folder'} eq $folder)) {
3308: # set parameters and change order
3309: &snapshotbefore();
3310:
3311: if (&update_parameter()) {
3312: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3313: return $errtext if ($fatal);
3314: }
3315:
3316: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
3317: # change order
3318: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
3319: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
3320:
3321: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
3322: return $errtext if ($fatal);
3323: }
3324:
3325: if ($env{'form.pastemarked'}) {
3326: my %paste_errors;
3327: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
3328: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
3329: \%paste_errors);
3330: if (ref($pastemsgarray) eq 'ARRAY') {
3331: if (@{$pastemsgarray} > 0) {
3332: $r->print('<p class="LC_info">'.
3333: join('<br />',@{$pastemsgarray}).
3334: '</p>');
3335: }
3336: }
3337: if ($lockerror) {
3338: $r->print('<p class="LC_error">'.
3339: $lockerror.
3340: '</p>');
3341: }
3342: if ($save_error ne '') {
3343: return $save_error;
3344: }
3345: if ($paste_res) {
3346: my %errortext = &Apache::lonlocal::texthash (
3347: fail => 'Storage of folder contents failed',
3348: failread => 'Reading folder contents failed',
3349: failstore => 'Storage of folder contents failed',
3350: );
3351: if ($errortext{$paste_res}) {
3352: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
3353: }
3354: }
3355: if (keys(%paste_errors) > 0) {
3356: $r->print('<p class="LC_warning">'."\n".
3357: &mt('The following files are either dependencies of a web page or references within a folder and/or composite page which could not be copied during the paste operation:')."\n".
3358: '<ul>'."\n");
3359: foreach my $key (sort(keys(%paste_errors))) {
3360: $r->print('<li>'.$key.'</li>'."\n");
3361: }
3362: $r->print('</ul></p>'."\n");
3363: }
3364: } elsif ($env{'form.clearmarked'}) {
3365: my $output = &do_buffer_empty();
3366: if ($output) {
3367: $r->print('<p class="LC_info">'.$output.'</p>');
3368: }
3369: }
3370:
3371: $r->print($upload_output);
3372:
3373: # Rename, cut, copy or remove a single resource
3374: if (&handle_edit_cmd($coursenum,$coursedom)) {
3375: my $contentchg;
3376: if ($env{'form.cmd'} =~ m{^(remove|cut|setalias|delalias)_}) {
3377: $contentchg = 1;
3378: }
3379: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
3380: return $errtext if ($fatal);
3381: }
3382:
3383: # Cut, copy and/or remove multiple resources
3384: if ($env{'form.multichange'}) {
3385: my %allchecked = (
3386: cut => {},
3387: remove => {},
3388: );
3389: my $needsupdate;
3390: foreach my $which (keys(%allchecked)) {
3391: $env{'form.multi'.$which} =~ s/,$//;
3392: if ($env{'form.multi'.$which}) {
3393: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
3394: if (ref($allchecked{$which}) eq 'HASH') {
3395: $needsupdate += scalar(keys(%{$allchecked{$which}}));
3396: }
3397: }
3398: }
3399: if ($needsupdate) {
3400: my $haschanges = 0;
3401: my %curr_groups = &Apache::longroup::coursegroups();
3402: my $total = scalar(@LONCAPA::map::order) - 1;
3403: for (my $i=$total; $i>=0; $i--) {
3404: my $res = $LONCAPA::map::order[$i];
3405: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3406: $name=&LONCAPA::map::qtescape($name);
3407: $url=&LONCAPA::map::qtescape($url);
3408: next unless $url;
3409: my %denied =
3410: &action_restrictions($coursenum,$coursedom,$url,
3411: $env{'form.folderpath'},\%curr_groups);
3412: foreach my $which (keys(%allchecked)) {
3413: next if ($denied{$which});
3414: next unless ($allchecked{$which}{$res});
3415: if ($which eq 'remove') {
3416: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
3417: ($url!~/$LONCAPA::assess_page_seq_re/)) {
3418: &Apache::lonnet::removeuploadedurl($url);
3419: } else {
3420: &LONCAPA::map::makezombie($res);
3421: }
3422: splice(@LONCAPA::map::order,$i,1);
3423: $haschanges ++;
3424: } elsif ($which eq 'cut') {
3425: &LONCAPA::map::makezombie($res);
3426: splice(@LONCAPA::map::order,$i,1);
3427: $haschanges ++;
3428: }
3429: }
3430: }
3431: if ($haschanges) {
3432: ($errtext,$fatal) =
3433: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
3434: return $errtext if ($fatal);
3435: }
3436: }
3437: }
3438:
3439: # Group import/search
3440: if ($env{'form.importdetail'}) {
3441: my @imports;
3442: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
3443: if (defined($item)) {
3444: my ($name,$url,$residx)=
3445: map { &unescape($_); } split(/\=/,$item);
3446: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
3447: my ($suffix,$errortxt,$locknotfreed) =
3448: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
3449: if ($locknotfreed) {
3450: $r->print($locknotfreed);
3451: }
3452: if ($suffix) {
3453: $url =~ s/_new\./_$suffix./;
3454: } else {
3455: return $errortxt;
3456: }
3457: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
3458: my $type = $1;
3459: my ($suffix,$errortxt,$locknotfreed) =
3460: &new_timebased_suffix($coursedom,$coursenum,$type);
3461: if ($locknotfreed) {
3462: $r->print($locknotfreed);
3463: }
3464: if ($suffix) {
3465: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
3466: } else {
3467: return $errortxt;
3468: }
3469: } elsif ($url =~ m{^/adm/$coursedom/$coursenum/new/ext\.tool}) {
3470: my ($suffix,$errortxt,$locknotfreed) =
3471: &new_timebased_suffix($coursedom,$coursenum,'exttool');
3472: if ($locknotfreed) {
3473: $r->print($locknotfreed);
3474: }
3475: if ($suffix) {
3476: $url =~ s{^(/adm/$coursedom/$coursenum)/new}{$1/$suffix};
3477: } else {
3478: return $errortxt;
3479: }
3480: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
3481: if ($supplementalflag) {
3482: next unless ($1 eq 'supplemental');
3483: if ($folder eq 'supplemental') {
3484: next unless ($2 eq 'default');
3485: } else {
3486: next unless ($folder eq 'supplemental_'.$2);
3487: }
3488: } else {
3489: next unless ($1 eq 'docs');
3490: if ($folder eq 'default') {
3491: next unless ($2 eq 'default');
3492: } else {
3493: next unless ($folder eq 'default_'.$2);
3494: }
3495: }
3496: }
3497: push(@imports, [$name, $url, $residx]);
3498: }
3499: }
3500: ($errtext,$fatal,my $fixuperrors) =
3501: &group_import($coursenum, $coursedom, $folder,$container,
3502: 'londocs',$ltitoolsref,@imports);
3503: return $errtext if ($fatal);
3504: if ($fixuperrors) {
3505: $r->print($fixuperrors);
3506: }
3507: }
3508: # Loading a complete map
3509: if ($env{'form.loadmap'}) {
3510: if ($env{'form.importmap'}=~/\w/) {
3511: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
3512: my ($title,$url,$ext,$type)=split(/\:/,$res);
3513: my $idx=&LONCAPA::map::getresidx($url);
3514: $LONCAPA::map::resources[$idx]=$res;
3515: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
3516: }
3517: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
3518: $folder.'.'.$container,1);
3519: return $errtext if ($fatal);
3520: } else {
3521: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
3522:
3523: }
3524: }
3525: &log_differences($plain);
3526: }
3527: # ---------------------------------------------------------------- End commands
3528: # ---------------------------------------------------------------- Print screen
3529: my $idx=0;
3530: my $shown=0;
3531: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
3532: $r->print('<div class="LC_Box">'.
3533: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
3534: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
3535: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
3536: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
3537: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
3538: '</ol>');
3539: if ($randompick>=0) {
3540: $r->print('<p class="LC_warning">'
3541: .&mt('Caution: this folder is set to randomly pick a subset'
3542: .' of resources. Adding or removing resources from this'
3543: .' folder will change the set of resources that the'
3544: .' students see, resulting in spurious or missing credit'
3545: .' for completed problems, not limited to ones you'
3546: .' modify. Do not modify the contents of this folder if'
3547: .' it is in active student use.')
3548: .'</p>'
3549: );
3550: }
3551: if ($is_random_order) {
3552: $r->print('<p class="LC_warning">'
3553: .&mt('Caution: this folder is set to randomly order its'
3554: .' contents. Adding or removing resources from this folder'
3555: .' will change the order of resources shown.')
3556: .'</p>'
3557: );
3558: }
3559: $r->print('</div>');
3560: }
3561:
3562: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
3563: %filters = (
3564: canremove => [],
3565: cancut => [],
3566: cancopy => [],
3567: hiddenresource => [],
3568: encrypturl => [],
3569: randomorder => [],
3570: randompick => [],
3571: );
3572: %curr_groups = &Apache::longroup::coursegroups();
3573: &Apache::loncommon::start_data_table_count(); #setup a row counter
3574: foreach my $res (@LONCAPA::map::order) {
3575: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
3576: $name=&LONCAPA::map::qtescape($name);
3577: $url=&LONCAPA::map::qtescape($url);
3578: unless ($name) { $name=(split(/\//,$url))[-1]; }
3579: unless ($name) { $idx++; next; }
3580: push(@allidx,$res);
3581: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
3582: push(@allmapidx,$res);
3583: }
3584:
3585: if (($supplementalflag) && (!$allowed) && (!$env{'request.role.adv'})) {
3586: next if ($supphidden{$suppmapid.':'.$res});
3587: }
3588: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
3589: $coursenum,$coursedom,$crstype,
3590: $pathitem,$supplementalflag,$container,
3591: \%filters,\%curr_groups,$ltitoolsref,$canedit,
3592: $isencrypted,$navmapref,$hostname,
3593: \%supphidden,\%suppids,$suppmapid);
3594: $idx++;
3595: $shown++;
3596: }
3597: &Apache::loncommon::end_data_table_count();
3598:
3599: my $need_save;
3600: if ($allowed || ($supplementalflag && $folder eq 'supplemental')) {
3601: my $toolslink;
3602: if ($allowed || $canedit) {
3603: my $helpitem = 'Navigation_Screen';
3604: if (!$allowed) {
3605: $helpitem = 'Supplemental_Navigation';
3606: }
3607: $toolslink = '<table><tr><td>'
3608: .&Apache::loncommon::help_open_menu('Navigation Screen',
3609: $helpitem,undef,'RAT')
3610: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
3611: .'<td align="left"><ul id="LC_toolbar">'
3612: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
3613: .'id="LC_content_toolbar_edittoplevel" '
3614: .'class="LC_toolbarItem" '
3615: .'title="'.&mt('Supplemental Content Editor').'">'
3616: .'</a></li></ul></td></tr></table><br />';
3617: }
3618: if ($shown) {
3619: if ($allowed) {
3620: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
3621: .&Apache::loncommon::start_data_table(undef,'contentlist')
3622: .&Apache::loncommon::start_data_table_header_row()
3623: .'<th colspan="2">'.&mt('Move').'</th>'
3624: .'<th colspan="3">'.&mt('Actions').'</th>'
3625: .'<th>'.&mt('Document').'</th>'
3626: .'<th colspan="2">'.&mt('Settings').'</th>'
3627: .&Apache::loncommon::end_data_table_header_row();
3628: if ($folder !~ /^supplemental/) {
3629: $lists{'canhide'} = join(',',@allidx);
3630: $lists{'canrandomlyorder'} = join(',',@allmapidx);
3631: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
3632: 'randomorder','randompick');
3633: foreach my $item (@possfilters) {
3634: if (ref($filters{$item}) eq 'ARRAY') {
3635: if (@{$filters{$item}} > 0) {
3636: $lists{$item} = join(',',@{$filters{$item}});
3637: }
3638: }
3639: }
3640: if (@allidx > 0) {
3641: my $path;
3642: if ($env{'form.folderpath'}) {
3643: $path =
3644: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3645: }
3646: if (@allidx > 1) {
3647: $to_show .=
3648: &Apache::loncommon::continue_data_table_row().
3649: '<td colspan="2"> </td>'.
3650: '<td>'.
3651: &multiple_check_form('actions',\%lists,$canedit).
3652: '</td>'.
3653: '<td colspan="3"> </td>'.
3654: '<td colspan="2">'.
3655: &multiple_check_form('settings',\%lists,$canedit).
3656: '</td>'.
3657: &Apache::loncommon::end_data_table_row();
3658: $need_save = 1;
3659: }
3660: }
3661: }
3662: $to_show .= $output.' '
3663: .&Apache::loncommon::end_data_table()
3664: .'<br style="line-height:2px;" />'
3665: .&Apache::loncommon::end_scrollbox();
3666: } else {
3667: $to_show .= $toolslink
3668: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3669: .$output.' '
3670: .&Apache::loncommon::end_data_table();
3671: }
3672: } else {
3673: if (!$allowed) {
3674: $to_show .= $toolslink;
3675: }
3676: my $noresmsg;
3677: if ($allowed && $hiddentop && !$supplementalflag) {
3678: $noresmsg = &mt('Main Content Hidden');
3679: } else {
3680: $noresmsg = &mt('Currently empty');
3681: }
3682: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
3683: .'<div class="LC_info" id="contentlist">'
3684: .$noresmsg
3685: .'</div>'
3686: .&Apache::loncommon::end_scrollbox();
3687: }
3688: } else {
3689: if ($shown) {
3690: $to_show = '<div>'
3691: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3692: .$output
3693: .&Apache::loncommon::end_data_table()
3694: .'</div>';
3695: } else {
3696: $to_show = '<div class="LC_info" id="contentlist">'
3697: .&mt('Currently empty')
3698: .'</div>'
3699: }
3700: }
3701: my $tid = 1;
3702: if ($supplementalflag) {
3703: $tid = 2;
3704: }
3705: if ($allowed) {
3706: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
3707: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
3708: $jumpto,$readfile,$need_save,"$folder.$container",$canedit));
3709: if ($canedit) {
3710: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
3711: }
3712: } else {
3713: $r->print($to_show);
3714: }
3715: return;
3716: }
3717:
3718: sub multiple_check_form {
3719: my ($caller,$listsref,$canedit) = @_;
3720: return unless (ref($listsref) eq 'HASH');
3721: my $disabled;
3722: unless ($canedit) {
3723: $disabled = 'disabled="disabled"';
3724: }
3725: my $output =
3726: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
3727: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
3728: '<label><input type="radio" name="showmultpick" value="0" onclick="javascript:togglePick('."'$caller','0'".');" checked="checked" />'.&mt('one').'</label>'.(' 'x2).'<label><input type="radio" name="showmultpick" value="1" onclick="javascript:togglePick('."'$caller','1'".');" />'.&mt('multiple').'</label></span><span id="more'.$caller.'" class="LC_nobreak LC_docs_ext_edit"></span></form>'.
3729: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
3730: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
3731: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
3732: if ($caller eq 'settings') {
3733: $output .=
3734: '<table><tr>'.
3735: '<td class="LC_docs_entry_parameter">'.
3736: '<span class="LC_nobreak"><label>'.
3737: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')"'.$disabled.' />'.&mt('Hidden').
3738: '</label></span></td>'.
3739: '<td class="LC_docs_entry_parameter">'.
3740: '<span class="LC_nobreak"><label><input type="checkbox" name="randompickall" id="randompickall" onclick="updatePick(this.form,'."'all','check'".');propagateState(this.form,'."'randompick'".');propagateState(this.form,'."'rpicknum'".');"'.$disabled.' />'.&mt('Randomly Pick').'</label><span id="rpicktextall"></span><input type="hidden" name="rpicknumall" id="rpicknumall" value="" />'.
3741: '</span></td>'.
3742: '</tr>'."\n".
3743: '<tr>'.
3744: '<td class="LC_docs_entry_parameter">'.
3745: '<span class="LC_nobreak"><label><input type="checkbox" name="encrypturlall" id="encrypturlall" onclick="propagateState(this.form,'."'encrypturl'".')"'.$disabled.' />'.&mt('URL hidden').'</label></span></td><td class="LC_docs_entry_parameter"><span class="LC_nobreak"><label><input type="checkbox" name="randomorderall" id="randomorderall" onclick="propagateState(this.form,'."'randomorder'".')"'.$disabled.' />'.&mt('Random Order').
3746: '</label></span>'.
3747: '</td></tr></table>'."\n";
3748: } else {
3749: $output .=
3750: '<table><tr>'.
3751: '<td class="LC_docs_entry_parameter">'.
3752: '<span class="LC_nobreak LC_docs_remove">'.
3753: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')"'.$disabled.' />'.&mt('Remove').
3754: '</label></span></td>'.
3755: '<td class="LC_docs_entry_parameter">'.
3756: '<span class="LC_nobreak LC_docs_cut">'.
3757: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');"'.$disabled.' />'.&mt('Cut').
3758: '</label></span></td>'."\n".
3759: '<td class="LC_docs_entry_parameter">'.
3760: '<span class="LC_nobreak LC_docs_copy">'.
3761: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')"'. $disabled.' />'.&mt('Copy').
3762: '</label></span></td>'.
3763: '</tr></table>'."\n";
3764: }
3765: $output .=
3766: '</fieldset>'.
3767: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
3768: if ($caller eq 'settings') {
3769: $output .=
3770: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
3771: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
3772: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
3773: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
3774: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
3775: } elsif ($caller eq 'actions') {
3776: $output .=
3777: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
3778: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
3779: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
3780: }
3781: $output .=
3782: '</form>'.
3783: '</div>';
3784: return $output;
3785: }
3786:
3787: sub process_file_upload {
3788: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
3789: # upload a file, if present
3790: my $filesize = length($env{'form.uploaddoc'});
3791: if (!$filesize) {
3792: $$upload_output = '<div class="LC_error">'.
3793: &mt('Unable to upload [_1]. (size = [_2] bytes)',
3794: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
3795: $filesize).'<br />'.
3796: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
3797: '</div>';
3798: return;
3799: }
3800: my $quotatype = 'unofficial';
3801: if ($crstype eq 'Community') {
3802: $quotatype = 'community';
3803: } elsif ($crstype eq 'Placement') {
3804: $quotatype = 'placement';
3805: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
3806: $quotatype = 'official';
3807: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
3808: $quotatype = 'textbook';
3809: }
3810: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
3811: $filesize = int($filesize/1000); #expressed in kb
3812: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
3813: $env{'form.uploaddoc.filename'},$filesize,
3814: 'upload',$quotatype);
3815: return if ($$upload_output);
3816: }
3817: my ($parseaction,$showupload,$nextphase,$mimetype);
3818: if ($env{'form.parserflag'}) {
3819: $parseaction = 'parse';
3820: }
3821: my $folder=$env{'form.folder'};
3822: if ($folder eq '') {
3823: $folder='default';
3824: }
3825: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
3826: my $errtext='';
3827: my $fatal=0;
3828: my $container='sequence';
3829: if ($env{'form.folderpath'} =~ /:1$/) {
3830: $container='page';
3831: }
3832: ($errtext,$fatal)=
3833: &mapread($coursenum,$coursedom,$folder.'.'.$container);
3834: if ($#LONCAPA::map::order<1) {
3835: $LONCAPA::map::order[0]=1;
3836: $LONCAPA::map::resources[1]='';
3837: }
3838: my $destination = 'docs/';
3839: if ($folder =~ /^supplemental/) {
3840: $destination = 'supplemental/';
3841: }
3842: if (($folder eq 'default') || ($folder eq 'supplemental')) {
3843: $destination .= 'default/';
3844: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
3845: $destination .= $2.'/';
3846: }
3847: if ($fatal) {
3848: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('The uploaded file has not been stored as an error occurred reading the contents of the current folder.').'</div>';
3849: return;
3850: }
3851: # this is for a course, not a user, so set context to coursedoc.
3852: my $newidx=&LONCAPA::map::getresidx();
3853: $destination .= $newidx;
3854: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
3855: $parseaction,$allfiles,
3856: $codebase,undef,undef,undef,undef,
3857: undef,undef,\$mimetype);
3858: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
3859: my $stored = $1;
3860: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
3861: $stored.'</span>').'</p>';
3862: } else {
3863: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
3864:
3865: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
3866: return;
3867: }
3868: my $ext='false';
3869: if ($url=~m{^http://}) { $ext='true'; }
3870: $url = &LONCAPA::map::qtunescape($url);
3871: my $comment=$env{'form.comment'};
3872: $comment = &LONCAPA::map::qtunescape($comment);
3873: if ($folder=~/^supplemental/) {
3874: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
3875: $env{'user.domain'}.'___&&&___'.$comment;
3876: }
3877:
3878: $LONCAPA::map::resources[$newidx]=
3879: $comment.':'.$url.':'.$ext.':normal:res';
3880: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
3881: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
3882: $folder.'.'.$container,1);
3883: if ($fatal) {
3884: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
3885: return;
3886: } else {
3887: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
3888: $$upload_output = $showupload;
3889: my $total_embedded = scalar(keys(%{$allfiles}));
3890: if ($total_embedded > 0) {
3891: my $uploadphase = 'upload_embedded';
3892: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
3893: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
3894: my ($embedded,$num) =
3895: &Apache::loncommon::ask_for_embedded_content(
3896: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
3897: if ($embedded) {
3898: if ($num) {
3899: $$upload_output .=
3900: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
3901: $nextphase = $uploadphase;
3902: } else {
3903: $$upload_output .= $embedded;
3904: }
3905: } else {
3906: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
3907: }
3908: } else {
3909: $$upload_output .= &mt('No embedded items identified').'<br />';
3910: }
3911: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
3912: } elsif ((&Apache::loncommon::is_archive_file($mimetype)) &&
3913: ($env{'form.uploaddoc.filename'} =~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i)) {
3914: $nextphase = 'decompress_uploaded';
3915: my $position = scalar(@LONCAPA::map::order)-1;
3916: my $noextract = &return_to_editor();
3917: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
3918: my %archiveitems = (
3919: folderpath => $env{'form.folderpath'},
3920: cmd => $nextphase,
3921: newidx => $newidx,
3922: position => $position,
3923: phase => $nextphase,
3924: comment => $comment,
3925: );
3926: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
3927: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
3928: $$upload_output = $showupload.
3929: &Apache::loncommon::decompress_form($mimetype,
3930: $archiveurl,'/adm/coursedocs',$noextract,
3931: \%archiveitems,\@current);
3932: }
3933: }
3934: }
3935: return $nextphase;
3936: }
3937:
3938: sub get_dir_list {
3939: my ($url,$coursenum,$coursedom,$newidx) = @_;
3940: my ($destination,$dir_root) = &embedded_destination();
3941: my ($dirlistref,$listerror) =
3942: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
3943: my @dir_lines;
3944: my $dirptr=16384;
3945: if (ref($dirlistref) eq 'ARRAY') {
3946: foreach my $dir_line (sort
3947: {
3948: my ($afile)=split('&',$a,2);
3949: my ($bfile)=split('&',$b,2);
3950: return (lc($afile) cmp lc($bfile));
3951: } (@{$dirlistref})) {
3952: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
3953: $filename =~ s/\s+$//;
3954: next if ($filename =~ /^\.\.?$/);
3955: my $isdir = 0;
3956: if ($dirptr&$testdir) {
3957: $isdir = 1;
3958: }
3959: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
3960: }
3961: }
3962: return @dir_lines;
3963: }
3964:
3965: sub is_supplemental_title {
3966: my ($title) = @_;
3967: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
3968: }
3969:
3970: # --------------------------------------------------------------- An entry line
3971:
3972: sub entryline {
3973: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
3974: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
3975: $ltitoolsref,$canedit,$isencrypted,$navmapref,$hostname,
3976: $supphidden,$suppids,$suppmapid)=@_;
3977: my ($foldertitle,$renametitle,$oldtitle);
3978: if (&is_supplemental_title($title)) {
3979: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
3980: } else {
3981: $title=&HTML::Entities::encode($title,'"<>&\'');
3982: $renametitle=$title;
3983: $foldertitle=$title;
3984: }
3985:
3986: my ($disabled,$readonly,$js_lt);
3987: unless ($canedit) {
3988: $disabled = 'disabled="disabled"';
3989: $readonly = 1;
3990: }
3991:
3992: my $orderidx=$LONCAPA::map::order[$index];
3993:
3994: $renametitle=~s/\\/\\\\/g;
3995: $renametitle=~s/\"\;/\\\"/g;
3996: $renametitle=~s/"/%22/g;
3997: $renametitle=~s/ /%20/g;
3998: $oldtitle = $renametitle;
3999: $renametitle=~s/\'/\\\'/g;
4000: my $line=&Apache::loncommon::start_data_table_row();
4001: my ($form_start,$form_end,$form_common,$form_param);
4002: # Edit commands
4003: my ($esc_path, $path, $symb, $shownsymb, $curralias);
4004: if ($env{'form.folderpath'}) {
4005: $esc_path=&escape($env{'form.folderpath'});
4006: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
4007: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
4008: }
4009: my $isexternal;
4010: if ($residx) {
4011: my $currurl = $url;
4012: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
4013: if ($currurl =~ m{^/adm/wrapper/ext/}) {
4014: $isexternal = 1;
4015: }
4016: if (!$supplementalflag) {
4017: my $path = 'uploaded/'.
4018: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
4019: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
4020: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
4021: $residx,
4022: &Apache::lonnet::declutter($currurl));
4023: }
4024: }
4025: my ($renamelink,%lt,$ishash);
4026: if (ref($filtersref) eq 'HASH') {
4027: $ishash = 1;
4028: }
4029:
4030: if ($allowed) {
4031: $form_start = '
4032: <form action="/adm/coursedocs" method="post">
4033: ';
4034: $form_common=(<<END);
4035: <input type="hidden" name="folderpath" value="$path" />
4036: <input type="hidden" name="symb" value="$symb" />
4037: END
4038: $form_param=(<<END);
4039: <input type="hidden" name="setparms" value="$orderidx" />
4040: <input type="hidden" name="changeparms" value="0" />
4041: END
4042: $form_end = '</form>';
4043:
4044: my $incindex=$index+1;
4045: my $selectbox='';
4046: if (($#LONCAPA::map::order>0) &&
4047: ((split(/\:/,
4048: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
4049: ne '') &&
4050: ((split(/\:/,
4051: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
4052: ne '')) {
4053: $selectbox=
4054: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
4055: '<select name="newpos" onchange="this.form.submit()"'.$disabled.'>';
4056: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
4057: if ($i==$incindex) {
4058: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
4059: } else {
4060: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
4061: }
4062: }
4063: $selectbox.='</select>';
4064: }
4065: %lt=&Apache::lonlocal::texthash(
4066: 'up' => 'Move Up',
4067: 'dw' => 'Move Down',
4068: 'rm' => 'Remove',
4069: 'ct' => 'Cut',
4070: 'rn' => 'Rename',
4071: 'cp' => 'Copy',
4072: 'da' => 'Unset alias',
4073: 'sa' => 'Set alias',
4074: 'ex' => 'External Resource',
4075: 'et' => 'External Tool',
4076: 'ed' => 'Edit',
4077: 'pr' => 'Preview',
4078: 'sv' => 'Save',
4079: 'ul' => 'URL',
4080: 'ti' => 'Title',
4081: 'er' => 'Editing rights unavailable for your current role.',
4082: );
4083: my %denied = &action_restrictions($coursenum,$coursedom,$url,
4084: $env{'form.folderpath'},
4085: $currgroups);
4086: my ($copylink,$cutlink,$removelink);
4087: my $skip_confirm = 0;
4088: my $confirm_removal = 0;
4089: if ( $folder =~ /^supplemental/
4090: || ($url =~ m{( /smppg$
4091: |/syllabus$
4092: |/aboutme$
4093: |/navmaps$
4094: |/bulletinboard$
4095: |/ext\.tool$
4096: |\.html$)}x)
4097: || $isexternal) {
4098: $skip_confirm = 1;
4099: }
4100: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
4101: ($url!~/$LONCAPA::assess_page_seq_re/)) {
4102: $confirm_removal = 1;
4103: }
4104: if ($url =~ /$LONCAPA::assess_re/) {
4105: $curralias = (&LONCAPA::map::getparameter($orderidx,'parameter_0_mapalias'))[0];
4106: }
4107:
4108: if ($denied{'copy'}) {
4109: $copylink=(<<ENDCOPY)
4110: <span style="visibility: hidden;">$lt{'cp'}</span>
4111: ENDCOPY
4112: } else {
4113: my $formname = 'edit_copy_'.$orderidx;
4114: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
4115: $copylink=(<<ENDCOPY);
4116: <form name="$formname" method="post" action="/adm/coursedocs">
4117: $form_common
4118: <input type="checkbox" name="copy" id="copy_$orderidx" value="$orderidx" onclick="javascript:singleCheck(this,'$orderidx','copy');" class="LC_hidden" $disabled /><a href="$js" class="LC_docs_copy">$lt{'cp'}</a>
4119: $form_end
4120: ENDCOPY
4121: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
4122: push(@{$filtersref->{'cancopy'}},$orderidx);
4123: }
4124: }
4125: if ($denied{'cut'}) {
4126: $cutlink=(<<ENDCUT);
4127: <span style="visibility: hidden;">$lt{'ct'}</span>
4128: ENDCUT
4129: } else {
4130: my $formname = 'edit_cut_'.$orderidx;
4131: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
4132: $cutlink=(<<ENDCUT);
4133: <form name="$formname" method="post" action="/adm/coursedocs">
4134: $form_common
4135: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
4136: <input type="checkbox" name="cut" id="cut_$orderidx" value="$orderidx" onclick="javascript:singleCheck(this,'$orderidx','cut');" class="LC_hidden" $disabled /><a href="$js" class="LC_docs_cut">$lt{'ct'}</a>
4137: $form_end
4138: ENDCUT
4139: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
4140: push(@{$filtersref->{'cancut'}},$orderidx);
4141: }
4142: }
4143: if ($denied{'remove'}) {
4144: $removelink=(<<ENDREM);
4145: <span style="visibility: hidden;">$lt{'rm'}</a>
4146: ENDREM
4147: } else {
4148: my $formname = 'edit_remove_'.$orderidx;
4149: my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder',$confirm_removal);";
4150: $removelink=(<<ENDREM);
4151: <form name="$formname" method="post" action="/adm/coursedocs">
4152: $form_common
4153: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
4154: <input type="hidden" name="confirm_rem_$orderidx" id="confirm_removal_$orderidx" value="$confirm_removal" />
4155: <input type="checkbox" name="remove" id="remove_$orderidx" value="$orderidx" onclick="javascript:singleCheck(this,'$orderidx','remove');" class="LC_hidden" $disabled /><a href="$js" class="LC_docs_remove">$lt{'rm'}</a>
4156: $form_end
4157: ENDREM
4158: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
4159: push(@{$filtersref->{'canremove'}},$orderidx);
4160: }
4161: }
4162: $renamelink=(<<ENDREN);
4163: <a href='javascript:changename("$esc_path","$index","$oldtitle");' class="LC_docs_rename">$lt{'rn'}</a>
4164: ENDREN
4165: my ($uplink,$downlink);
4166: if ($canedit) {
4167: $uplink = "/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb";
4168: $downlink = "/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb";
4169: } else {
4170: $uplink = "javascript:alert('".&js_escape($lt{'er'})."');";
4171: $downlink = $uplink;
4172: }
4173: $line.=(<<END);
4174: <td>
4175: <div class="LC_docs_entry_move">
4176: <a href="$uplink">
4177: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
4178: </a>
4179: </div>
4180: <div class="LC_docs_entry_move">
4181: <a href="$downlink">
4182: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
4183: </a>
4184: </div>
4185: </td>
4186: <td>
4187: $form_start
4188: $form_param
4189: $form_common
4190: $selectbox
4191: $form_end
4192: </td>
4193: <td class="LC_docs_entry_commands LC_nobreak">
4194: $removelink
4195: $cutlink
4196: $copylink
4197: </td>
4198: END
4199: }
4200: # Figure out what kind of a resource this is
4201: my ($extension)=($url=~/\.(\w+)$/);
4202: my $uploaded=($url=~/^\/*uploaded\//);
4203: my $icon=&Apache::loncommon::icon($url);
4204: my $isfolder;
4205: my $ispage;
4206: my $containerarg;
4207: my $folderurl;
4208: if ($uploaded) {
4209: if (($extension eq 'sequence') || ($extension eq 'page')) {
4210: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
4211: $containerarg = $1;
4212: if ($extension eq 'sequence') {
4213: $icon=$iconpath.'navmap.folder.closed.gif';
4214: $isfolder=1;
4215: } else {
4216: $icon=$iconpath.'page.gif';
4217: $ispage=1;
4218: }
4219: $folderurl = &Apache::lonnet::declutter($url);
4220: if ($allowed) {
4221: $url='/adm/coursedocs?';
4222: } else {
4223: $url='/adm/supplemental?';
4224: }
4225: } else {
4226: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
4227: }
4228: }
4229:
4230: my ($editlink,$extresform,$anchor,$hiddenres,$nomodal);
4231: my $orig_url = $url;
4232: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
4233: if ($container eq 'page') {
4234: $url=~s{^http(|s)(:|:)//}{/ext/};
4235: } else {
4236: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
4237: }
4238: if (!$supplementalflag && $residx && $symb) {
4239: if ((!$isfolder) && (!$ispage)) {
4240: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
4241: if (($url =~ m{^ext/}) && ($container eq 'page')) {
4242: $url=&Apache::lonnet::clutter_with_no_wrapper($url);
4243: } else {
4244: $url=&Apache::lonnet::clutter($url);
4245: }
4246: if ($url=~/^\/*uploaded\//) {
4247: $url=~/\.(\w+)$/;
4248: my $embstyle=&Apache::loncommon::fileembstyle($1);
4249: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
4250: $url='/adm/wrapper'.$url;
4251: } elsif ($embstyle eq 'ssi') {
4252: #do nothing with these
4253: } elsif ($url!~/\.(sequence|page)$/) {
4254: $url='/adm/coursedocs/showdoc'.$url;
4255: }
4256: } elsif ($url=~m{^(|/adm/wrapper)/ext/([^#]+)}) {
4257: my $wrapped = $1;
4258: my $exturl = $2;
4259: if (($wrapped eq '') && ($container ne 'page')) {
4260: $url='/adm/wrapper'.$url;
4261: }
4262: if (($ENV{'SERVER_PORT'} == 443) && ($exturl !~ /^https:/)) {
4263: $nomodal = 1;
4264: }
4265: } elsif ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
4266: $url='/adm/wrapper'.$url;
4267: } elsif ($url eq "/public/$coursedom/$coursenum/syllabus") {
4268: if (($ENV{'SERVER_PORT'} == 443) &&
4269: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
4270: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
4271: $url .= '?usehttp=1';
4272: }
4273: $nomodal = 1;
4274: }
4275: }
4276: my ($checkencrypt,$shownurl);
4277: if (!$env{'request.role.adv'}) {
4278: if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
4279: ($isencrypted) || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
4280: $checkencrypt = 1;
4281: } elsif (ref($navmapref)) {
4282: unless (ref($$navmapref)) {
4283: $$navmapref = Apache::lonnavmaps::navmap->new();
4284: }
4285: if (ref($$navmapref)) {
4286: if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
4287: $checkencrypt = 1;
4288: }
4289: }
4290: }
4291: }
4292: if ($checkencrypt) {
4293: my $currenc = $env{'request.enc'};
4294: $env{'request.enc'} = 1;
4295: $shownsymb = &Apache::lonenc::encrypted($symb);
4296: $shownurl = &Apache::lonenc::encrypted($url);
4297: if (&Apache::lonnet::symbverify($symb,$url)) {
4298: $url = $shownurl;
4299: } else {
4300: $url = '';
4301: }
4302: $env{'request.enc'} = $currenc;
4303: } elsif (&Apache::lonnet::symbverify($symb,$url)) {
4304: $shownsymb = $symb;
4305: if ($isexternal) {
4306: $url =~ s/\#[^#]+$//;
4307: if ($container eq 'page') {
4308: $url = &Apache::lonnet::clutter($url);
4309: }
4310: }
4311: $shownurl = $url;
4312: }
4313: unless ($env{'request.role.adv'}) {
4314: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4315: $url = '';
4316: }
4317: if (&Apache::lonnet::EXT('resource.0.hiddenresource',$symb) =~ /^yes$/i) {
4318: $url = '';
4319: $hiddenres = 1;
4320: }
4321: }
4322: if ($url ne '') {
4323: $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&escape($shownsymb);
4324: }
4325: }
4326: } elsif ($supplementalflag) {
4327: if ($isexternal) {
4328: if ($url =~ /^([^#]+)#([^#]+)$/) {
4329: $url = $1;
4330: $anchor = $2;
4331: if (($url =~ m{^(|/adm/wrapper)/ext/(?!https:)}) && ($ENV{'SERVER_PORT'} == 443)) {
4332: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
4333: if ($hostname ne '') {
4334: $url = 'http://'.$hostname.$url;
4335: }
4336: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
4337: }
4338: $nomodal = 1;
4339: }
4340: }
4341: } elsif ($url =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
4342: if (($ENV{'SERVER_PORT'} == 443) &&
4343: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
4344: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
4345: if ($hostname ne '') {
4346: $url = 'http://'.$hostname.$url;
4347: }
4348: $url .= (($url =~ /\?/) ? '&':'?').'usehttp=1';
4349: }
4350: $nomodal = 1;
4351: }
4352: }
4353: }
4354: my ($rand_pick_text,$rand_order_text,$hiddenfolder);
4355: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
4356: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
4357: my $foldername=&escape($foldertitle);
4358: my $folderpath=$env{'form.folderpath'};
4359: if ($folderpath) { $folderpath.='&' };
4360: if (!$allowed && $supplementalflag) {
4361: $folderpath.=$containerarg.'&'.$foldername;
4362: $url.='folderpath='.&escape($folderpath);
4363: if (ref($supphidden) eq 'HASH') {
4364: if ($supphidden->{$suppmapid.':'.$residx}) {
4365: $hiddenfolder = 1;
4366: }
4367: }
4368: } else {
4369: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
4370: 'parameter_randompick'))[0];
4371: my $randorder = ((&LONCAPA::map::getparameter($orderidx,
4372: 'parameter_randomorder'))[0]=~/^yes$/i);
4373: my $hiddenmap = ((&LONCAPA::map::getparameter($orderidx,
4374: 'parameter_hiddenresource'))[0]=~/^yes$/i);
4375: my $encryptmap = ((&LONCAPA::map::getparameter($orderidx,
4376: 'parameter_encrypturl'))[0]=~/^yes$/i);
4377: unless ($hiddenmap) {
4378: if (ref($navmapref)) {
4379: unless (ref($$navmapref)) {
4380: $$navmapref = Apache::lonnavmaps::navmap->new();
4381: }
4382: if (ref($$navmapref)) {
4383: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
4384: my @resources = $$navmapref->retrieveResources($folderurl,$filterFunc,1,1);
4385: unless (@resources) {
4386: $hiddenmap = 1;
4387: unless ($env{'request.role.adv'}) {
4388: $url = '';
4389: $hiddenfolder = 1;
4390: }
4391: }
4392: }
4393: }
4394: }
4395: }
4396: unless ($encryptmap) {
4397: if ((ref($navmapref)) && (ref($$navmapref))) {
4398: if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.encrypturl")) eq 'yes') {
4399: $encryptmap = 1;
4400: }
4401: }
4402: }
4403:
4404: # Append randompick number, hidden, and encrypted with ":" to foldername,
4405: # so it gets transferred between levels
4406: $folderpath.=$containerarg.'&'.$foldername.
4407: ':'.$rpicknum.':'.$hiddenmap.':'.$encryptmap.':'.$randorder.':'.$ispage;
4408: unless ($url eq '') {
4409: $url.='folderpath='.&escape($folderpath);
4410: }
4411: my $rpckchk;
4412: if ($rpicknum) {
4413: $rpckchk = ' checked="checked"';
4414: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
4415: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
4416: }
4417: }
4418: my $formname = 'edit_randompick_'.$orderidx;
4419: $rand_pick_text =
4420: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
4421: $form_param."\n".
4422: $form_common."\n".
4423: '<span class="LC_nobreak"><label><input type="checkbox" name="randompick_'.$orderidx.'" id="randompick_'.$orderidx.'" onclick="'."updatePick(this.form,'$orderidx','check');".'"'.$rpckchk.$disabled.' /> '.&mt('Randomly Pick').'</label><input type="hidden" name="rpicknum_'.$orderidx.'" id="rpicknum_'.$orderidx.'" value="'.$rpicknum.'" /><span id="randompicknum_'.$orderidx.'">';
4424: if ($rpicknum ne '') {
4425: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
4426: }
4427: $rand_pick_text .= '</span></span>'.
4428: $form_end;
4429: my $ro_set;
4430: if ($randorder) {
4431: $ro_set = 'checked="checked"';
4432: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4433: push(@{$filtersref->{'randomorder'}},$orderidx);
4434: }
4435: }
4436: $formname = 'edit_rorder_'.$orderidx;
4437: $rand_order_text =
4438: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
4439: $form_param."\n".
4440: $form_common."\n".
4441: '<span class="LC_nobreak"><label><input type="checkbox" name="randomorder_'.$orderidx.'" id="randomorder_'.$orderidx.'" onclick="checkForSubmit(this.form,'."'randomorder','settings'".');" '.$ro_set.$disabled.' /> '.&mt('Random Order').' </label></span>'.
4442: $form_end;
4443: }
4444: } elsif ($supplementalflag && !$allowed) {
4445: my $isexttool;
4446: if ($url=~m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
4447: $url='/adm/wrapper'.$url;
4448: $isexttool = 1;
4449: }
4450: $url .= ($url =~ /\?/) ? '&':'?';
4451: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
4452: if ($title) {
4453: $url .= '&title='.&HTML::Entities::encode($renametitle,'<>&"');
4454: }
4455: if ((($isexternal) || ($isexttool)) && $orderidx) {
4456: $url .= '&idx='.$orderidx;
4457: }
4458: if ($anchor ne '') {
4459: $url .= '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4460: }
4461: if (ref($supphidden) eq 'HASH') {
4462: if ($supphidden->{$suppmapid.':'.$residx}) {
4463: $hiddenres = 1;
4464: }
4465: }
4466: }
4467: my ($tdalign,$tdwidth);
4468: if ($allowed) {
4469: my $fileloc =
4470: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
4471: if ($isexternal) {
4472: ($editlink,$extresform) =
4473: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4474: undef,undef,undef,undef,undef,undef,
4475: undef,$disabled);
4476: } elsif ($orig_url =~ m{^/adm/$coursedom/$coursenum/\d+/ext\.tool$}) {
4477: ($editlink,$extresform) =
4478: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem,
4479: undef,undef,undef,'tool',$coursedom,
4480: $coursenum,$ltitoolsref,$disabled);
4481: } elsif (!$isfolder && !$ispage) {
4482: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
4483: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
4484: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
4485: my $suppanchor;
4486: if ($supplementalflag) {
4487: $suppanchor = $anchor;
4488: }
4489: my $jscall =
4490: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
4491: $switchserver,
4492: $forceedit,
4493: undef,$symb,$shownsymb,
4494: &escape($env{'form.folderpath'}),
4495: $renametitle,$hostname,
4496: '','',1,$suppanchor);
4497: if ($jscall) {
4498: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
4499: $jscall.'" >'.&mt('Edit').'</a> '."\n";
4500: }
4501: }
4502: }
4503: $tdalign = ' align="right" valign="top"';
4504: $tdwidth = ' width="80%"';
4505: }
4506: my $reinit;
4507: if ($crstype eq 'Community') {
4508: $reinit = &mt('(re-initialize community to access)');
4509: } else {
4510: $reinit = &mt('(re-initialize course to access)');
4511: }
4512: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
4513: if ($orig_url =~ /$LONCAPA::assess_re/) {
4514: $line.= '<br />';
4515: if ($curralias ne '') {
4516: $line.='<span class="LC_nobreak"><a href="javascript:delalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
4517: $lt{'da'}.'</a></span>';
4518: } else {
4519: $line.='<span class="LC_nobreak"><a href="javascript:setalias('."'$esc_path','$orderidx'".');" class="LC_docs_alias">'.
4520: $lt{'sa'}.'</a></span>';
4521: }
4522: }
4523: $line.='</td><td>';
4524: my $link;
4525: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
4526: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
4527: } elsif ($url) {
4528: if ($anchor ne '') {
4529: if ($supplementalflag) {
4530: $anchor = '&anchor='.&HTML::Entities::encode($anchor,'"<>&');
4531: } else {
4532: $anchor = '#'.&HTML::Entities::encode($anchor,'"<>&');
4533: }
4534: }
4535: if ((!$supplementalflag) && ($nomodal) && ($hostname ne '')) {
4536: $link = 'http://'.$hostname.$url;
4537: } else {
4538: $link = $url;
4539: }
4540: $link = &js_escape($link.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.$anchor);
4541: if ($nomodal) {
4542: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4543: '<img src="'.$icon.'" alt="" class="LC_icon" border="0" /></a>';
4544: } else {
4545: $line.=&Apache::loncommon::modal_link($link,
4546: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
4547: }
4548: } else {
4549: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
4550: }
4551: $line.='</span></td><td'.$tdwidth.'>';
4552: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
4553: $line.='<a href="'.$url.'">'.$title.'</a>';
4554: if (!$allowed && $supplementalflag && $canedit && $isfolder) {
4555: my $editicon = &Apache::loncommon::lonhttpdurl('/res/adm/pages').'/editmap.png';
4556: my $editurl = $url;
4557: $editurl =~ s{^\Q/adm/supplemental?\E}{/adm/coursedocs?command=direct&forcesupplement=1&};
4558: $line .= ' '.'<a href="'.$editurl.'">'.
4559: '<img src="'.$editicon.'" alt="'.&mt('Edit Content').'" title="'.&mt('Edit Content').'" />'.
4560: '</a>';
4561: }
4562: if ((($hiddenfolder) || ($hiddenres)) && (!$allowed) && ($supplementalflag)) {
4563: $line.= ' <span class="LC_warning">('.&mt('hidden').')</span> ';
4564: }
4565: } elsif ($url) {
4566: if ($nomodal) {
4567: $line.='<a href="#" onclick="javascript:window.open('."'$link','syllabuspreview','height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1')".'; return false;" />'.
4568: $title.'</a>';
4569: } else {
4570: $line.=&Apache::loncommon::modal_link($link,$title,600,500);
4571: }
4572: } elsif (($hiddenfolder) || ($hiddenres)) {
4573: $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">('.&mt('Hidden').')</span>';
4574: } else {
4575: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
4576: }
4577: if (($allowed) && ($curralias ne '')) {
4578: $line .= '<br /><span class="LC_docs_alias_name">('.$curralias.')</span>';
4579: } else {
4580: $line .= $extresform;
4581: }
4582: $line .= '</td>';
4583: $rand_pick_text = ' ' if ($rand_pick_text eq '');
4584: $rand_order_text = ' ' if ($rand_order_text eq '');
4585: if ($allowed) {
4586: my %lt=&Apache::lonlocal::texthash(
4587: 'hd' => 'Hidden',
4588: 'ec' => 'URL hidden');
4589: my ($enctext,$hidtext,$formhidden,$formurlhidden);
4590: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
4591: $hidtext = ' checked="checked"';
4592: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
4593: push(@{$filtersref->{'hiddenresource'}},$orderidx);
4594: }
4595: }
4596: $formhidden = 'edit_hiddenresource_'.$orderidx;
4597: $line.=(<<ENDPARMS);
4598: <td class="LC_docs_entry_parameter">
4599: <form action="/adm/coursedocs" method="post" name="$formhidden">
4600: $form_param
4601: $form_common
4602: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext $disabled /> $lt{'hd'}</label>
4603: $form_end
4604: ENDPARMS
4605: if ($folder =~/^supplemental/) {
4606: $line.= "\n <td>";
4607: } else {
4608: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
4609: $enctext = ' checked="checked"';
4610: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
4611: push(@{$filtersref->{'encrypturl'}},$orderidx);
4612: }
4613: }
4614: $formurlhidden = 'edit_encrypturl_'.$orderidx;
4615: $line.=(<<ENDPARMS);
4616: <br />
4617: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
4618: $form_param
4619: $form_common
4620: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext $disabled /> $lt{'ec'}</label>
4621: $form_end
4622: </td>
4623: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
4624: $rand_order_text</td>
4625: ENDPARMS
4626: }
4627: }
4628: $line.=&Apache::loncommon::end_data_table_row();
4629: return $line;
4630: }
4631:
4632: sub action_restrictions {
4633: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
4634: my %denied = (
4635: cut => 0,
4636: copy => 0,
4637: remove => 0,
4638: );
4639: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
4640: # no copy for published maps
4641: $denied{'copy'} = 1;
4642: } elsif ($url=~m{^/res/lib/templates/([^/]+)\.problem$}) {
4643: unless ($1 eq 'simpleproblem') {
4644: $denied{'copy'} = 1;
4645: }
4646: $denied{'cut'} = 1;
4647: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
4648: if ($folderpath =~ /^default&[^\&]+$/) {
4649: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
4650: $denied{'remove'} = 1;
4651: }
4652: $denied{'cut'} = 1;
4653: $denied{'copy'} = 1;
4654: }
4655: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
4656: my $group = $1;
4657: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
4658: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4659: $denied{'remove'} = 1;
4660: }
4661: }
4662: $denied{'cut'} = 1;
4663: $denied{'copy'} = 1;
4664: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
4665: my $group = $1;
4666: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
4667: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4668: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4669: if (keys(%groupsettings) > 0) {
4670: $denied{'remove'} = 1;
4671: }
4672: $denied{'cut'} = 1;
4673: $denied{'copy'} = 1;
4674: }
4675: }
4676: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
4677: my $group = $1;
4678: if ($url =~ /group_boards_\Q$group\E/) {
4679: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
4680: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
4681: if (keys(%groupsettings) > 0) {
4682: if (ref($groupsettings{'functions'}) eq 'HASH') {
4683: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
4684: $denied{'remove'} = 1;
4685: }
4686: }
4687: }
4688: $denied{'cut'} = 1;
4689: $denied{'copy'} = 1;
4690: }
4691: }
4692: }
4693: return %denied;
4694: }
4695:
4696: sub new_timebased_suffix {
4697: my ($dom,$num,$type,$area,$container) = @_;
4698: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
4699: if ($type eq 'paste') {
4700: $prefix = $type;
4701: $namespace = 'courseeditor';
4702: $idtype = 'addcode';
4703: } elsif ($type eq 'map') {
4704: $prefix = 'docs';
4705: if ($area eq 'supplemental') {
4706: $prefix = 'supp';
4707: }
4708: $prefix .= $container;
4709: $namespace = 'uploadedmaps';
4710: } else {
4711: $prefix = $type;
4712: $namespace = 'templated';
4713: }
4714: my ($suffix,$freedlock,$error) =
4715: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num,$idtype);
4716: if (!$suffix) {
4717: if ($type eq 'paste') {
4718: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
4719: } elsif ($type eq 'map') {
4720: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
4721: } elsif ($type eq 'smppg') {
4722: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
4723: } elsif ($type eq 'exttool') {
4724: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new external tool.');
4725: } else {
4726: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
4727: }
4728: if ($error) {
4729: $errtext .= '<br />'.$error;
4730: }
4731: }
4732: if ($freedlock ne 'ok') {
4733: $locknotfreed =
4734: '<div class="LC_error">'.
4735: &mt('There was a problem removing a lockfile.').' ';
4736: if ($type eq 'paste') {
4737: if ($freedlock eq 'nolock') {
4738: $locknotfreed =
4739: '<div class="LC_error">'.
4740: &mt('A lockfile was not released when you added content to the clipboard earlier in this session.').' '.
4741:
4742: &mt('As a result addition of items to the clipboard will be unavailable until your next log-in.');
4743: } else {
4744: $locknotfreed .=
4745: &mt('This will prevent addition of items to the clipboard until your next log-in.');
4746: }
4747: } elsif ($type eq 'map') {
4748: $locknotfreed .=
4749: &mt('This will prevent creation of additional folders or composite pages in this course.');
4750: } elsif ($type eq 'smppg') {
4751: $locknotfreed .=
4752: &mt('This will prevent creation of additional simple pages in this course.');
4753: } elsif ($type eq 'exttool') {
4754: $locknotfreed .=
4755: &mt('This will prevent creation of additional external tools in this course.');
4756: } else {
4757: $locknotfreed .=
4758: &mt('This will prevent creation of additional discussion boards in this course.');
4759: }
4760: unless ($type eq 'paste') {
4761: $locknotfreed .=
4762: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
4763: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
4764: }
4765: $locknotfreed .= '</div>';
4766: }
4767: return ($suffix,$errtext,$locknotfreed);
4768: }
4769:
4770: =pod
4771:
4772: =item tiehash()
4773:
4774: tie the hash
4775:
4776: =cut
4777:
4778: sub tiehash {
4779: my ($mode)=@_;
4780: $hashtied=0;
4781: if ($env{'request.course.fn'}) {
4782: if ($mode eq 'write') {
4783: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4784: &GDBM_WRCREAT(),0640)) {
4785: $hashtied=2;
4786: }
4787: } else {
4788: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
4789: &GDBM_READER(),0640)) {
4790: $hashtied=1;
4791: }
4792: }
4793: }
4794: }
4795:
4796: sub untiehash {
4797: if ($hashtied) { untie %hash; }
4798: $hashtied=0;
4799: return OK;
4800: }
4801:
4802:
4803:
4804:
4805: sub checkonthis {
4806: my ($r,$url,$level,$title,$checkstale)=@_;
4807: $url=&unescape($url);
4808: $alreadyseen{$url}=1;
4809: $r->rflush();
4810: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
4811: $r->print("\n<br />");
4812: if ($level==0) {
4813: $r->print("<br />");
4814: }
4815: for (my $i=0;$i<=$level*5;$i++) {
4816: $r->print(' ');
4817: }
4818: $r->print('<a href="'.$url.'" target="cat">'.
4819: ($title?$title:$url).'</a> ');
4820: if ($url=~/^\/res\//) {
4821: my $updated;
4822: if (($checkstale) && ($url !~ m{^/res/lib/templates/}) &&
4823: ($url !~ /\.\d+\.\w+$/)) {
4824: $updated = &Apache::lonnet::remove_stale_resfile($url);
4825: }
4826: my $result=&Apache::lonnet::repcopy(
4827: &Apache::lonnet::filelocation('',$url));
4828: if ($result eq 'ok') {
4829: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4830: if ($updated) {
4831: $r->print('<br />');
4832: for (my $i=0;$i<=$level*5;$i++) {
4833: $r->print(' ');
4834: }
4835: $r->print('- '.&mt('Outdated copy removed'));
4836: }
4837: $r->rflush();
4838: &Apache::lonnet::countacc($url);
4839: $url=~/\.(\w+)$/;
4840: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
4841: $r->print('<br />');
4842: $r->rflush();
4843: for (my $i=0;$i<=$level*5;$i++) {
4844: $r->print(' ');
4845: }
4846: $r->print('- '.&mt('Rendering:').' ');
4847: my ($errorcount,$warningcount)=split(/:/,
4848: &Apache::lonnet::ssi_body($url,
4849: ('grade_target'=>'web',
4850: 'return_only_error_and_warning_counts' => 1)));
4851: if (($errorcount) ||
4852: ($warningcount)) {
4853: if ($errorcount) {
4854: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
4855: &mt('[quant,_1,error]',$errorcount).'</span>');
4856: }
4857: if ($warningcount) {
4858: $r->print('<span class="LC_warning">'.
4859: &mt('[quant,_1,warning]',$warningcount).'</span>');
4860: }
4861: } else {
4862: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
4863: }
4864: $r->rflush();
4865: }
4866: my $dependencies=
4867: &Apache::lonnet::metadata($url,'dependencies');
4868: foreach my $dep (split(/\,/,$dependencies)) {
4869: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
4870: &checkonthis($r,$dep,$level+1,'',$checkstale);
4871: }
4872: }
4873: } elsif ($result eq 'unavailable') {
4874: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
4875: } elsif ($result eq 'not_found') {
4876: unless ($url=~/\$/) {
4877: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
4878: } else {
4879: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
4880: }
4881: } else {
4882: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
4883: }
4884: if (($updated) && ($result ne 'ok')) {
4885: $r->print('<br />'.&mt('Outdated copy removed'));
4886: }
4887: }
4888: }
4889: }
4890:
4891:
4892:
4893: =pod
4894:
4895: =item list_symbs()
4896:
4897: List Content Identifiers
4898:
4899: =cut
4900:
4901: sub list_symbs {
4902: my ($r) = @_;
4903:
4904: my $crstype = &Apache::loncommon::course_type();
4905: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
4906: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
4907: $r->print(&startContentScreen('tools'));
4908: my $navmap = Apache::lonnavmaps::navmap->new();
4909: if (!defined($navmap)) {
4910: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
4911: '<div class="LC_error">'.
4912: &mt('Unable to retrieve information about course contents').
4913: '</div>');
4914: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
4915: } else {
4916: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
4917: &Apache::loncommon::start_data_table().
4918: &Apache::loncommon::start_data_table_header_row().
4919: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
4920: &Apache::loncommon::end_data_table_header_row()."\n");
4921: my $count;
4922: foreach my $res ($navmap->retrieveResources()) {
4923: $r->print(&Apache::loncommon::start_data_table_row().
4924: '<td>'.$res->compTitle().'</td>'.
4925: '<td>'.$res->symb().'</td>'.
4926: &Apache::loncommon::end_data_table_row());
4927: $count ++;
4928: }
4929: if (!$count) {
4930: $r->print(&Apache::loncommon::start_data_table_row().
4931: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
4932: &Apache::loncommon::end_data_table_row());
4933: }
4934: $r->print(&Apache::loncommon::end_data_table());
4935: }
4936: $r->print(&endContentScreen());
4937: }
4938:
4939: sub short_urls {
4940: my ($r,$canedit) = @_;
4941: my $crstype = &Apache::loncommon::course_type();
4942: my $formname = 'shortenurl';
4943: $r->print(&Apache::loncommon::start_page('Display/Set Shortened URLs'));
4944: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Shortened URLs'));
4945: $r->print(&startContentScreen('tools'));
4946: my ($navmap,$errormsg) =
4947: &Apache::loncourserespicker::get_navmap_object($crstype,'shorturls');
4948: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4949: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4950: my (%maps,%resources,%titles);
4951: if (!ref($navmap)) {
4952: $r->print($errormsg.
4953: &endContentScreen());
4954: return '';
4955: } else {
4956: $r->print('<h4 class="LC_info">'.&mt('Tiny URLs for deep-linking into course').'</h4>'."\n");
4957: $r->rflush();
4958: my $readonly;
4959: if ($canedit) {
4960: my ($numnew,$errors) = &Apache::loncommon::get_requested_shorturls($cdom,$cnum,$navmap);
4961: if ($numnew) {
4962: $r->print('<p class="LC_info">'.&mt('Created [quant,_1,URL]',$numnew).'</p>');
4963: }
4964: if ((ref($errors) eq 'ARRAY') && (@{$errors} > 0)) {
4965: $r->print(&mt('The following errors occurred when processing your request to create shortened URLs:').'<br /><ul>');
4966: foreach my $error (@{$errors}) {
4967: $r->print('<li>'.$error.'</li>');
4968: }
4969: $r->print('</ul><br />');
4970: }
4971: } else {
4972: $readonly = 1;
4973: }
4974: my %currtiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
4975: $r->print(&Apache::loncourserespicker::create_picker($navmap,'shorturls',$formname,$crstype,undef,
4976: undef,undef,undef,undef,undef,\%currtiny,$readonly));
4977: }
4978: $r->print(&endContentScreen());
4979: }
4980:
4981: sub contentverifyform {
4982: my ($r) = @_;
4983: my $crstype = &Apache::loncommon::course_type();
4984: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
4985: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
4986: $r->print(&startContentScreen('tools'));
4987: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
4988: $r->print('<form method="post" action="/adm/coursedocs"><p>'.
4989: &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?').
4990: ' <span class="LC_nobreak">'.
4991: '<label><input type="radio" name="checkstale" value="0" checked="checked" />'.
4992: &mt('No').'</label>'.(' 'x2).
4993: '<label><input type="radio" name="checkstale" value="1" />'.
4994: &mt('Yes').'</label></span></p><p>'.
4995: '<input type="submit" value="'.&mt('Verify Content').' "/>'.
4996: '<input type="hidden" value="1" name="tools" />'.
4997: '<input type="hidden" value="1" name="verify" /></p></form>');
4998: $r->print(&endContentScreen());
4999: return;
5000: }
5001:
5002: sub verifycontent {
5003: my ($r,$checkstale) = @_;
5004: my $crstype = &Apache::loncommon::course_type();
5005: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
5006: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
5007: $r->print(&startContentScreen('tools'));
5008: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
5009: $hashtied=0;
5010: undef %alreadyseen;
5011: %alreadyseen=();
5012: &tiehash();
5013:
5014: foreach my $key (keys(%hash)) {
5015: if ($hash{$key}=~/\.(page|sequence)$/) {
5016: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
5017: $r->print('<hr /><span class="LC_error">'.
5018: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
5019: &unescape($hash{$key}).'</span><br />'.
5020: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
5021: }
5022: }
5023: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
5024: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale);
5025: }
5026: }
5027: &untiehash();
5028: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
5029: $r->print(&endContentScreen());
5030: }
5031:
5032: sub devalidateversioncache {
5033: my $src=shift;
5034: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
5035: &Apache::lonnet::clutter($src));
5036: }
5037:
5038: sub checkversions {
5039: my ($r,$canedit) = @_;
5040: my $crstype = &Apache::loncommon::course_type();
5041: $r->print(&Apache::loncommon::start_page("Check $crstype Resource Versions"));
5042: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Resource Versions"));
5043: $r->print(&startContentScreen('tools'));
5044:
5045: my $header='';
5046: my $startsel='';
5047: my $monthsel='';
5048: my $weeksel='';
5049: my $daysel='';
5050: my $allsel='';
5051: my %changes=();
5052: my $starttime=0;
5053: my $haschanged=0;
5054: my %setversions=&Apache::lonnet::dump('resourceversions',
5055: $env{'course.'.$env{'request.course.id'}.'.domain'},
5056: $env{'course.'.$env{'request.course.id'}.'.num'});
5057:
5058: $hashtied=0;
5059: &tiehash();
5060: if ($canedit) {
5061: my %newsetversions=();
5062: if ($env{'form.setmostrecent'}) {
5063: $haschanged=1;
5064: foreach my $key (keys(%hash)) {
5065: if ($key=~/^ids\_(\/res\/.+)$/) {
5066: $newsetversions{$1}='mostrecent';
5067: &devalidateversioncache($1);
5068: }
5069: }
5070: } elsif ($env{'form.setcurrent'}) {
5071: $haschanged=1;
5072: foreach my $key (keys(%hash)) {
5073: if ($key=~/^ids\_(\/res\/.+)$/) {
5074: my $getvers=&Apache::lonnet::getversion($1);
5075: if ($getvers>0) {
5076: $newsetversions{$1}=$getvers;
5077: &devalidateversioncache($1);
5078: }
5079: }
5080: }
5081: } elsif ($env{'form.setversions'}) {
5082: $haschanged=1;
5083: foreach my $key (keys(%env)) {
5084: if ($key=~/^form\.set_version_(.+)$/) {
5085: my $src=$1;
5086: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
5087: $newsetversions{$src}=$env{$key};
5088: &devalidateversioncache($src);
5089: }
5090: }
5091: }
5092: }
5093: if ($haschanged) {
5094: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
5095: $env{'course.'.$env{'request.course.id'}.'.domain'},
5096: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
5097: $r->print(&Apache::loncommon::confirmwrapper(
5098: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
5099: } else {
5100: $r->print(&Apache::loncommon::confirmwrapper(
5101: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
5102: }
5103: &mark_hash_old();
5104: }
5105: &changewarning($r,'');
5106: }
5107: if ($env{'form.timerange'} eq 'all') {
5108: # show all documents
5109: $header=&mt('All content in '.$crstype);
5110: $allsel=' selected="selected"';
5111: foreach my $key (keys(%hash)) {
5112: if ($key=~/^ids\_(\/res\/.+)$/) {
5113: my $src=$1;
5114: $changes{$src}=1;
5115: }
5116: }
5117: } else {
5118: # show documents which changed
5119: %changes=&Apache::lonnet::dump
5120: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
5121: $env{'course.'.$env{'request.course.id'}.'.num'});
5122: my $firstkey=(keys(%changes))[0];
5123: unless ($firstkey=~/^error\:/) {
5124: unless ($env{'form.timerange'}) {
5125: $env{'form.timerange'}=604800;
5126: }
5127: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
5128: .&mt('seconds');
5129: if ($env{'form.timerange'}==-1) {
5130: $seltext='since start of course';
5131: $startsel=' selected="selected"';
5132: $env{'form.timerange'}=time;
5133: }
5134: $starttime=time-$env{'form.timerange'};
5135: if ($env{'form.timerange'}==2592000) {
5136: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
5137: $monthsel=' selected="selected"';
5138: } elsif ($env{'form.timerange'}==604800) {
5139: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
5140: $weeksel=' selected="selected"';
5141: } elsif ($env{'form.timerange'}==86400) {
5142: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
5143: $daysel=' selected="selected"';
5144: }
5145: $header=&mt('Content changed').' '.$seltext;
5146: } else {
5147: $header=&mt('No content modifications yet.');
5148: }
5149: }
5150: %setversions=&Apache::lonnet::dump('resourceversions',
5151: $env{'course.'.$env{'request.course.id'}.'.domain'},
5152: $env{'course.'.$env{'request.course.id'}.'.num'});
5153: my %lt=&Apache::lonlocal::texthash
5154: ('st' => 'Version changes since start of '.$crstype,
5155: 'lm' => 'Version changes since last Month',
5156: 'lw' => 'Version changes since last Week',
5157: 'sy' => 'Version changes since Yesterday',
5158: 'al' => 'All Resources (possibly large output)',
5159: 'cd' => 'Change display',
5160: 'sd' => 'Display',
5161: 'fi' => 'File',
5162: 'md' => 'Modification Date',
5163: 'mr' => 'Most recently published Version',
5164: 've' => 'Version used in '.$crstype,
5165: 'vu' => 'Set Version to be used in '.$crstype,
5166: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
5167: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
5168: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
5169: 'di' => 'Differences',
5170: 'save' => 'Save changes',
5171: 'vers' => 'Version choice(s) for specific resources',
5172: 'act' => 'Actions');
5173: my ($disabled,$readonly);
5174: unless ($canedit) {
5175: $disabled = 'disabled="disabled"';
5176: $readonly = 1;
5177: }
5178: $r->print(<<ENDHEADERS);
5179: <h4 class="LC_info">$header</h4>
5180: <form action="/adm/coursedocs" method="post">
5181: <input type="hidden" name="versions" value="1" />
5182: <div class="LC_left_float">
5183: <fieldset>
5184: <legend>$lt{'cd'}</legend>
5185: <select name="timerange">
5186: <option value='all'$allsel>$lt{'al'}</option>
5187: <option value="-1"$startsel>$lt{'st'}</option>
5188: <option value="2592000"$monthsel>$lt{'lm'}</option>
5189: <option value="604800"$weeksel>$lt{'lw'}</option>
5190: <option value="86400"$daysel>$lt{'sy'}</option>
5191: </select>
5192: <input type="submit" name="display" value="$lt{'sd'}" />
5193: </fieldset>
5194: </div>
5195: <div class="LC_left_float">
5196: <fieldset>
5197: <legend>$lt{'act'}</legend>
5198: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" $disabled /><br />
5199: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" $disabled />
5200: </fieldset>
5201: </div>
5202: <br clear="all" />
5203: <hr />
5204: <h4>$lt{'vers'}</h4>
5205: ENDHEADERS
5206: #number of columns for version history
5207: my %changedbytime;
5208: foreach my $key (keys(%changes)) {
5209: #excludes not versionable problems from resource version history:
5210: next if ($key =~ /^\/res\/lib\/templates/);
5211: my $chg;
5212: if ($env{'form.timerange'} eq 'all') {
5213: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
5214: $chg = &Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate');
5215: } else {
5216: $chg = $changes{$key};
5217: next if ($chg < $starttime);
5218: }
5219: push(@{$changedbytime{$chg}},$key);
5220: }
5221: if (keys(%changedbytime) == 0) {
5222: &untiehash();
5223: $r->print(&mt('No content changes in imported content in specified time frame').
5224: &endContentScreen());
5225: return;
5226: }
5227: $r->print(
5228: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
5229: &Apache::loncommon::start_data_table().
5230: &Apache::loncommon::start_data_table_header_row().
5231: '<th>'.&mt('Resources').'</th>'.
5232: "<th>$lt{'mr'}</th>".
5233: "<th>$lt{'ve'}</th>".
5234: "<th>$lt{'vu'}</th>".
5235: '<th>'.&mt('History').'</th>'.
5236: &Apache::loncommon::end_data_table_header_row()
5237: );
5238: foreach my $chg (sort {$b <=> $a } keys(%changedbytime)) {
5239: foreach my $key (sort(@{$changedbytime{$chg}})) {
5240: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
5241: my $currentversion=&Apache::lonnet::getversion($key);
5242: if ($currentversion<0) {
5243: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
5244: }
5245: my $linkurl=&Apache::lonnet::clutter($key);
5246: $r->print(
5247: &Apache::loncommon::start_data_table_row().
5248: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
5249: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
5250: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
5251: &Apache::lonlocal::locallocaltime($chg).')</span></td>'.
5252: '<td align="right">'
5253: );
5254: # Used in course
5255: my $usedversion=$hash{'version_'.$linkurl};
5256: if (($usedversion) && ($usedversion ne 'mostrecent')) {
5257: if ($usedversion != $currentversion) {
5258: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
5259: } else {
5260: $r->print($usedversion);
5261: }
5262: } else {
5263: $r->print($currentversion);
5264: }
5265: $r->print('</td><td title="'.$lt{'vu'}.'">');
5266: # Set version
5267: $r->print(&Apache::loncommon::select_form(
5268: $setversions{$linkurl},
5269: 'set_version_'.$linkurl,
5270: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
5271: '' => '',
5272: 'mostrecent' => &mt('most recent'),
5273: map {$_,$_} (1..$currentversion)},'',$readonly));
5274: my $lastold=1;
5275: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
5276: my $url=$root.'.'.$prevvers.'.'.$extension;
5277: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
5278: $lastold=$prevvers;
5279: }
5280: }
5281: $r->print('</td>');
5282: # List all available versions
5283: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
5284: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
5285: my $url=$root.'.'.$prevvers.'.'.$extension;
5286: $r->print(
5287: '<span class="LC_nobreak">'
5288: .'<a href="'.&Apache::lonnet::clutter($url).'">'
5289: .&mt('Version [_1]',$prevvers).'</a>'
5290: .' ('.&Apache::lonlocal::locallocaltime(
5291: &Apache::lonnet::metadata($url,'lastrevisiondate'))
5292: .')');
5293: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
5294: $r->print(
5295: ' <a href="/adm/diff?filename='.
5296: &Apache::lonnet::clutter($root.'.'.$extension).
5297: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
5298: '" target="diffs">'.&mt('Diffs').'</a>');
5299: }
5300: $r->print('</span><br />');
5301: }
5302: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
5303: }
5304: }
5305: $r->print(
5306: &Apache::loncommon::end_data_table().
5307: '<input type="submit" name="setversions" value="'.$lt{'save'}.'"'.$disabled.' />'.
5308: '</form>'
5309: );
5310:
5311: &untiehash();
5312: $r->print(&endContentScreen());
5313: return;
5314: }
5315:
5316: sub mark_hash_old {
5317: my $retie_hash=0;
5318: if ($hashtied) {
5319: $retie_hash=1;
5320: &untiehash();
5321: }
5322: &tiehash('write');
5323: $hash{'old'}=1;
5324: &untiehash();
5325: if ($retie_hash) { &tiehash(); }
5326: }
5327:
5328: sub is_hash_old {
5329: my $untie_hash=0;
5330: if (!$hashtied) {
5331: $untie_hash=1;
5332: &tiehash();
5333: }
5334: my $return=$hash{'old'};
5335: if ($untie_hash) { &untiehash(); }
5336: return $return;
5337: }
5338:
5339: sub changewarning {
5340: my ($r,$postexec,$message,$url)=@_;
5341: if (!&is_hash_old()) { return; }
5342: my $pathvar='folderpath';
5343: my $path=&escape($env{'form.folderpath'});
5344: if (!defined($url)) {
5345: $url='/adm/coursedocs?'.$pathvar.'='.$path;
5346: }
5347: my $course_type = &Apache::loncommon::course_type();
5348: if (!defined($message)) {
5349: $message='Changes will become active for your current session after [_1], or the next time you log in.';
5350: }
5351: my $windowname = 'loncapaclient';
5352: if ($env{'request.lti.login'}) {
5353: $windowname .= 'lti';
5354: }
5355: $r->print("\n\n".
5356: '<script type="text/javascript">'."\n".
5357: '// <![CDATA['."\n".
5358: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
5359: '// ]]>'."\n".
5360: '</script>'."\n".
5361: '<form name="reinitform" method="post" action="/adm/roles" target="'.$windowname.'">'.
5362: '<input type="hidden" name="orgurl" value="'.$url.
5363: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
5364: &mt($message,' <input type="hidden" name="'.
5365: $env{'request.role'}.'" value="1" /><input type="button" value="'.
5366: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
5367: $help{'Caching'}.'</p></form>'."\n\n");
5368: }
5369:
5370:
5371: sub init_breadcrumbs {
5372: my ($form,$text,$help)=@_;
5373: &Apache::lonhtmlcommon::clear_breadcrumbs();
5374: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
5375: text=>&Apache::loncommon::course_type().' Editor',
5376: faq=>273,
5377: bug=>'Instructor Interface',
5378: help => $help});
5379: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
5380: text=>$text,
5381: faq=>273,
5382: bug=>'Instructor Interface'});
5383: }
5384:
5385: # subroutine to list form elements
5386: sub create_list_elements {
5387: my @formarr = @_;
5388: my $list = '';
5389: foreach my $button (@formarr){
5390: foreach my $picture (keys(%{$button})) {
5391: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
5392: }
5393: }
5394: return $list;
5395: }
5396:
5397: # subroutine to create ul from list elements
5398: sub create_form_ul {
5399: my $list = shift;
5400: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
5401: return $ul;
5402: }
5403:
5404: #
5405: # Start tabs
5406: #
5407:
5408: sub startContentScreen {
5409: my ($mode) = @_;
5410: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
5411: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
5412: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
5413: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
5414: $output .= '<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n";
5415: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
5416: } else {
5417: $output .= '<li '.(($mode eq 'docs')?' class="active"':'').' id="tabbededitor"><a href="/adm/coursedocs?forcestandard=1"><b> '.&mt('Main Content Editor').' </b></a></li>'."\n";
5418: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
5419: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
5420: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
5421: }
5422: $output .= "\n".'</ul>'."\n";
5423: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
5424: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
5425: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
5426: return $output;
5427: }
5428:
5429: #
5430: # End tabs
5431: #
5432:
5433: sub endContentScreen {
5434: return '</div></div></div>';
5435: }
5436:
5437: sub supplemental_base {
5438: return 'supplemental&'.&escape(&mt('Supplemental Content'));
5439: }
5440:
5441: sub handler {
5442: my $r = shift;
5443: &Apache::loncommon::content_type($r,'text/html');
5444: $r->send_http_header;
5445: return OK if $r->header_only;
5446:
5447: # get course data
5448: my $crstype = &Apache::loncommon::course_type();
5449: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
5450: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5451:
5452: # get docroot
5453: my $londocroot = $r->dir_config('lonDocRoot');
5454:
5455: # graphics settings
5456: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
5457:
5458: #
5459: # --------------------------------------------- Initialize help topics for this
5460: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
5461: 'Adding_External_Resource','Adding_External_Tool',
5462: 'Navigate_Content','Adding_Folders','Docs_Overview',
5463: 'Load_Map','Supplemental','Score_Upload_Form',
5464: 'Adding_Pages','Importing_LON-CAPA_Resource',
5465: 'Importing_IMS_Course','Uploading_From_Harddrive',
5466: 'Course_Roster','Web_Page','Dropbox','Simple_Problem') {
5467: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
5468: }
5469: # Composite help files
5470: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
5471: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
5472: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
5473: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
5474: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
5475: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
5476: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
5477: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
5478: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
5479: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
5480:
5481: my ($allowed,$canedit,$canview,$noendpage,$disabled);
5482: # does this user have privileges to modify content.
5483: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
5484: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
5485: unless ($r->uri eq '/adm/supplemental') {
5486: $allowed = 1;
5487: }
5488: $canedit = 1;
5489: $canview = 1;
5490: } elsif (&Apache::lonnet::allowed('cev',$env{'request.course.id'})) {
5491: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
5492: unless ($r->uri eq '/adm/supplemental') {
5493: $allowed = 1;
5494: }
5495: $canview = 1;
5496: }
5497: unless ($canedit) {
5498: $disabled = ' disabled="disabled"';
5499: }
5500: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['inhibitmenu']);
5501: if ($env{'form.inhibitmenu'}) {
5502: unless ($env{'form.inhibitmenu'} eq 'yes') {
5503: delete($env{'form.inhibitmenu'});
5504: }
5505: }
5506:
5507: if ($allowed && $env{'form.verify'}) {
5508: &init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
5509: if (!$canedit) {
5510: &verifycontent($r);
5511: } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) {
5512: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}",
5513: text=>'Results',
5514: faq=>273,
5515: bug=>'Instructor Interface'});
5516: &verifycontent($r,$env{'form.checkstale'});
5517: } else {
5518: &contentverifyform($r);
5519: }
5520: } elsif ($allowed && $env{'form.listsymbs'}) {
5521: &init_breadcrumbs('listsymbs','List Content IDs');
5522: &list_symbs($r);
5523: } elsif ($allowed && $env{'form.shorturls'}) {
5524: &init_breadcrumbs('shorturls','Set/Display Shortened URLs','Docs_Short_URLs');
5525: &short_urls($r,$canedit);
5526: } elsif ($allowed && $env{'form.docslog'}) {
5527: &init_breadcrumbs('docslog','Show Log');
5528: my $folder = $env{'form.folder'};
5529: if ($folder eq '') {
5530: $folder='default';
5531: }
5532: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit);
5533: } elsif ($allowed && $env{'form.versions'}) {
5534: &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
5535: &checkversions($r,$canedit);
5536: } elsif ($canedit && $env{'form.dumpcourse'}) {
5537: &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
5538: &dumpcourse($r);
5539: } elsif ($canedit && $env{'form.exportcourse'}) {
5540: &init_breadcrumbs('exportcourse','IMS Export');
5541: &Apache::imsexport::exportcourse($r);
5542: } else {
5543: if ($canedit && $env{'form.authorrole'}) {
5544: $noendpage = 1;
5545: my ($redirect,$error) = &makenewproblem($r,$coursedom,$coursenum);
5546: if ($redirect) {
5547: if (($env{'form.newresourceadd'}) && ($env{'form.folderpath'})) {
5548: my $container = 'sequence';
5549: my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
5550: $is_random_order,$container) =
5551: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
5552: my (@folders)=split('&',$env{'form.folderpath'});
5553: $env{'form.foldername'}=&unescape(pop(@folders));
5554: my $folder=pop(@folders);
5555: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
5556: $folder.'.'.$container);
5557: my $warning;
5558: if ($fatal) {
5559: if ($container eq 'page') {
5560: $warning = &mt('An error occurred retrieving the contents of the current page.');
5561: } else {
5562: $warning = &mt('An error occurred retrieving the contents of the current folder.');
5563: }
5564: } else {
5565: my $url = $redirect;
5566: my $srcfile = $londocroot.$url;
5567: $url =~ s{^/priv/}{/res/};
5568: my $targetfile = $londocroot.$url;
5569: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
5570: my $output = &Apache::lonpublisher::batchpublish($r,$srcfile,$targetfile,$nokeyref,1);
5571: $env{'form.folder'} = $folder;
5572: &snapshotbefore();
5573: my $title = &LONCAPA::map::qtunescape($env{'form.newresourcetitle'});
5574: my $ext = 'false';
5575: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
5576: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
5577: ':'.$ext.':normal:res';
5578: push(@LONCAPA::map::order,$newidx);
5579: &LONCAPA::map::storeparameter($newidx,'parameter_hiddenresource','yes',
5580: 'string_yesno');
5581: &remember_parms($newidx,'hiddenresource','set','yes');
5582: ($errtext,$fatal) =
5583: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
5584: &log_differences($plain);
5585: &mark_hash_old();
5586: $r->internal_redirect($redirect);
5587: return OK;
5588: }
5589: } else {
5590: $r->internal_redirect($redirect);
5591: }
5592: }
5593: }
5594: #
5595: # Done catching special calls
5596: # The whole rest is for course and supplemental documents and utilities menu
5597: # Get the parameters that may be needed
5598: #
5599: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
5600: ['folderpath','title',
5601: 'forcesupplement','forcestandard',
5602: 'tools','symb','command','supppath']);
5603:
5604: foreach my $item ('forcesupplement','forcestandard','tools') {
5605: next if ($env{'form.'.$item} eq '');
5606: unless ($env{'form.'.$item} eq '1') {
5607: delete($env{'form.'.$item});
5608: }
5609: }
5610:
5611: if ($env{'form.command'}) {
5612: unless ($env{'form.command'} =~ /^(direct|directnav|editdocs|editsupp|contents|home)$/) {
5613: delete($env{'form.command'});
5614: }
5615: }
5616:
5617: if ($env{'form.symb'}) {
5618: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
5619: unless (($id =~ /^\d+$/) && (&Apache::lonnet::is_on_map($resurl))) {
5620: delete($env{'form.symb'});
5621: }
5622: }
5623:
5624: # standard=1: this is a "new-style" course with an uploaded map as top level
5625: # standard=2: this is a "old-style" course, and there is nothing we can do
5626:
5627: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
5628:
5629: # Decide whether this should display supplemental or main content or utilities
5630: # supplementalflag=1: show supplemental documents
5631: # supplementalflag=0: show standard documents
5632: # toolsflag=1: show utilities
5633:
5634: my $unesc_folderpath = &unescape($env{'form.folderpath'});
5635: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
5636: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
5637: $supplementalflag=0;
5638: }
5639: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
5640: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
5641: unless ($allowed) { $supplementalflag=1; }
5642: unless ($standard) { $supplementalflag=1; }
5643: my $toolsflag=0;
5644: if ($env{'form.tools'}) { $toolsflag=1; }
5645:
5646: if ($env{'form.folderpath'} ne '') {
5647: &validate_folderpath($supplementalflag);
5648: }
5649:
5650: if ($env{'form.supppath'} ne '') {
5651: &validate_suppath();
5652: }
5653:
5654: my $script='';
5655: my $showdoc=0;
5656: my $addentries = {};
5657: my $container;
5658: my $containertag;
5659: my $pathitem;
5660: my %ltitools;
5661: my $hiddentop;
5662: my $navmap;
5663: my $filterFunc = sub { my $res = shift; return (!$res->randomout() && !$res->is_map()) };
5664:
5665: # Do we directly jump somewhere?
5666: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
5667: if ($env{'form.symb'} ne '') {
5668: $env{'form.folderpath'}=
5669: &Apache::loncommon::symb_to_docspath($env{'form.symb'},\$navmap);
5670: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
5671: $env{'form.command'}.'_'.$env{'form.symb'}});
5672: } elsif ($env{'form.supppath'} ne '') {
5673: $env{'form.folderpath'}=$env{'form.supppath'};
5674: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
5675: $env{'form.command'}.'_'.$env{'form.supppath'}});
5676: }
5677: } elsif ($env{'form.command'} eq 'editdocs') {
5678: $env{'form.folderpath'} = &default_folderpath($coursenum,$coursedom,\$navmap);
5679: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
5680: } elsif ($env{'form.command'} eq 'editsupp') {
5681: $env{'form.folderpath'} = &supplemental_base();
5682: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
5683: } elsif ($env{'form.command'} eq 'contents') {
5684: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
5685: } elsif ($env{'form.command'} eq 'home') {
5686: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
5687: }
5688:
5689:
5690: # Where do we store these for when we come back?
5691: my $stored_folderpath='docs_folderpath';
5692: if ($supplementalflag) {
5693: $stored_folderpath='docs_sup_folderpath';
5694: }
5695:
5696: # No folderpath, and in edit mode, see if we have something stored
5697: if ((!$env{'form.folderpath'}) && $allowed) {
5698: &Apache::loncommon::restore_course_settings($stored_folderpath,
5699: {'folderpath' => 'scalar'});
5700:
5701: if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
5702: if ($supplementalflag) {
5703: undef($env{'form.folderpath'}) if ($1 eq 'default');
5704: } else {
5705: undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
5706: }
5707: } else {
5708: undef($env{'form.folderpath'});
5709: }
5710: if ($env{'form.folderpath'} ne '') {
5711: &validate_folderpath($supplementalflag);
5712: }
5713: }
5714:
5715: # If we are not allowed to make changes, all we can see are supplemental docs
5716: if (!$allowed) {
5717: unless ($env{'form.folderpath'} =~ /^supplemental/) {
5718: $env{'form.folderpath'} = &supplemental_base();
5719: }
5720: }
5721: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
5722: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
5723: $env{'form.folderpath'} = &supplemental_base()
5724: .'&'.
5725: $env{'form.folderpath'};
5726: }
5727: # If allowed and user's role is not advanced check folderpath is not hidden
5728: if (($allowed) && (!$env{'request.role.adv'}) &&
5729: ($env{'form.folderpath'} ne '') && (!$supplementalflag)) {
5730: my $folderurl;
5731: my @pathitems = split(/\&/,$env{'form.folderpath'});
5732: my $folder = $pathitems[-2];
5733: if ($folder eq '') {
5734: undef($env{'form.folderpath'});
5735: } else {
5736: $folderurl = "uploaded/$coursedom/$coursenum/$folder";
5737: if ((split(/\:/,$pathitems[-1]))[5]) {
5738: $folderurl .= '.page';
5739: } else {
5740: $folderurl .= '.sequence';
5741: }
5742: unless (ref($navmap)) {
5743: $navmap = Apache::lonnavmaps::navmap->new();
5744: }
5745: if (ref($navmap)) {
5746: if (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
5747: my @resources = $navmap->retrieveResources($folderurl,$filterFunc,1,1);
5748: unless (@resources) {
5749: undef($env{'form.folderpath'});
5750: }
5751: }
5752: }
5753: }
5754: }
5755:
5756:
5757: # If after all of this, we still don't have any paths, make them
5758: unless ($env{'form.folderpath'}) {
5759: if ($supplementalflag) {
5760: $env{'form.folderpath'}=&supplemental_base();
5761: } elsif ($allowed) {
5762: ($env{'form.folderpath'},$hiddentop) = &default_folderpath($coursenum,$coursedom,\$navmap);
5763: }
5764: }
5765:
5766: # Store this
5767: unless ($toolsflag) {
5768: if (($allowed) && ($env{'form.folderpath'} ne '')) {
5769: &Apache::loncommon::store_course_settings($stored_folderpath,
5770: {'folderpath' => 'scalar'});
5771: }
5772: my $folderpath;
5773: if ($env{'form.folderpath'}) {
5774: $folderpath = $env{'form.folderpath'};
5775: my (@folders)=split('&',$env{'form.folderpath'});
5776: $env{'form.foldername'}=&unescape(pop(@folders));
5777: if ($env{'form.foldername'} =~ /\:1$/) {
5778: $container = 'page';
5779: } else {
5780: $container = 'sequence';
5781: }
5782: $env{'form.folder'}=pop(@folders);
5783: } else {
5784: if ($env{'form.folder'} eq '' ||
5785: $env{'form.folder'} eq 'supplemental') {
5786: if ($env{'form.folder'} eq 'supplemental') {
5787: $folderpath=&supplemental_base();
5788: } elsif (!$hiddentop) {
5789: $folderpath='default&'.
5790: &escape(&mt('Main Content').':::::');
5791: }
5792: }
5793: }
5794: $containertag = '<input type="hidden" name="folderpath" value="" />';
5795: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
5796: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
5797: $showdoc='/'.$1;
5798: }
5799: if ($showdoc) { # got called in sequence from course
5800: $allowed=0;
5801: } else {
5802: if ($canedit) {
5803: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
5804: $script=&Apache::lonratedt::editscript('simple');
5805: }
5806: }
5807: }
5808:
5809: # get personal data
5810: my $uname=$env{'user.name'};
5811: my $udom=$env{'user.domain'};
5812: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
5813:
5814: if ($allowed) {
5815: if ($toolsflag) {
5816: $script .= &inject_data_js();
5817: my ($home,$other,%outhash)=&authorhosts();
5818: if (!$home && $other) {
5819: my @hosts;
5820: foreach my $aurole (keys(%outhash)) {
5821: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5822: push(@hosts,$outhash{$aurole});
5823: }
5824: }
5825: $script .= &dump_switchserver_js(@hosts);
5826: }
5827: } else {
5828: my $tid = 1;
5829: my @tabids;
5830: if ($supplementalflag) {
5831: @tabids = ('002','dd2','ee2','ff2');
5832: $tid = 2;
5833: } else {
5834: @tabids = ('aa1','bb1','cc1','ff1');
5835: unless ($env{'form.folderpath'} =~ /\:1$/) {
5836: unshift(@tabids,'001');
5837: push(@tabids,('dd1','ee1'));
5838: }
5839: }
5840: my $tabidstr = join("','",@tabids);
5841: %ltitools = &Apache::lonnet::get_domain_lti($coursedom,'consumer');
5842: my $posslti = keys(%ltitools);
5843: my $hostname = $r->hostname();
5844: $script .= &editing_js($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
5845: $londocroot,$canedit,$hostname,\$navmap).
5846: &history_tab_js().
5847: &inject_data_js().
5848: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr,$tid).
5849: &Apache::lonextresedit::extedit_javascript(\%ltitools);
5850: $addentries = {
5851: onload => "javascript:resize_scrollbox('contentscroll','1','1');",
5852: };
5853: }
5854: $script .= &paste_popup_js();
5855: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
5856: &mt('Switch server?');
5857:
5858:
5859: }
5860: # -------------------------------------------------------------------- Body tag
5861: $script = '<script type="text/javascript">'."\n"
5862: .'// <![CDATA['."\n"
5863: .$script."\n"
5864: .'// ]]>'."\n"
5865: .'</script>'."\n"
5866: .'<script type="text/javascript"
5867: src="/res/adm/includes/file_upload.js"></script>'."\n";
5868:
5869: # Breadcrumbs
5870: &Apache::lonhtmlcommon::clear_breadcrumbs();
5871:
5872: if ($showdoc) {
5873: my $args;
5874: if ($supplementalflag) {
5875: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype,undef,$env{'form.title'},1);
5876: $args = {'bread_crumbs' => $brcrum};
5877: } else {
5878: $args = {'force_register' => $showdoc};
5879: }
5880: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,$args));
5881: } elsif ($toolsflag) {
5882: my ($breadtext,$breadtitle);
5883: $breadtext = "$crstype Editor";
5884: if ($canedit) {
5885: $breadtitle = 'Editing '.$crstype.' Contents';
5886: } else {
5887: $breadtext .= ' (View-only mode)';
5888: $breadtitle = 'Viewing '.$crstype.' Contents';
5889: }
5890: &Apache::lonhtmlcommon::add_breadcrumb({
5891: href=>"/adm/coursedocs",text=>$breadtext});
5892: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script)
5893: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5894: .&Apache::lonhtmlcommon::breadcrumbs(
5895: $breadtitle)
5896: );
5897: } elsif ($r->uri eq '/adm/supplemental') {
5898: unless ($env{'request.role.adv'}) {
5899: unless (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom)) {
5900: $r->internal_redirect('/adm/navmaps');
5901: return OK;
5902: }
5903: }
5904: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
5905: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
5906: {'bread_crumbs' => $brcrum,}));
5907: } else {
5908: my ($breadtext,$breadtitle,$helpitem);
5909: $breadtext = "$crstype Editor";
5910: if ($canedit) {
5911: $breadtitle = 'Editing '.$crstype.' Contents';
5912: $helpitem = 'Docs_Adding_Course_Doc';
5913: } else {
5914: $breadtext .= ' (View-only mode)';
5915: $breadtitle = 'Viewing '.$crstype.' Contents';
5916: $helpitem = 'Docs_Viewing_Course_Doc';
5917: }
5918: &Apache::lonhtmlcommon::add_breadcrumb({
5919: href=>"/adm/coursedocs",text=>$breadtext});
5920: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
5921: {'add_entries' => $addentries}
5922: )
5923: .&Apache::loncommon::help_open_menu('','',273,'RAT')
5924: .&Apache::lonhtmlcommon::breadcrumbs(
5925: $breadtitle,
5926: $helpitem)
5927: );
5928: }
5929:
5930: my %allfiles = ();
5931: my %codebase = ();
5932: my ($upload_result,$upload_output,$uploadphase);
5933: if ($canedit) {
5934: if (($env{'form.uploaddoc.filename'}) &&
5935: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
5936: my $context = $1;
5937: # Process file upload - phase one - upload and parse primary file.
5938: undef($hadchanges);
5939: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
5940: \%allfiles,\%codebase,$context,$crstype);
5941: undef($navmap);
5942: if ($hadchanges) {
5943: &mark_hash_old();
5944: }
5945: $r->print($upload_output);
5946: } elsif ($env{'form.phase'} eq 'upload_embedded') {
5947: # Process file upload - phase two - upload embedded objects
5948: $uploadphase = 'check_embedded';
5949: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
5950: my $state = &embedded_form_elems($uploadphase,$primaryurl,
5951: $env{'form.newidx'});
5952: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5953: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5954: my ($destination,$dir_root) = &embedded_destination();
5955: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
5956: my $actionurl = '/adm/coursedocs';
5957: my ($result,$flag) =
5958: &Apache::loncommon::upload_embedded('coursedoc',$destination,
5959: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
5960: $actionurl);
5961: $r->print($result.&return_to_editor());
5962: } elsif ($env{'form.phase'} eq 'check_embedded') {
5963: # Process file upload - phase three - modify references in HTML file
5964: $uploadphase = 'modified_orightml';
5965: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5966: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5967: my ($destination,$dir_root) = &embedded_destination();
5968: my $result =
5969: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
5970: $docuname,$docudom,undef,
5971: $dir_root);
5972: $r->print($result.&return_to_editor());
5973: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
5974: $uploadphase = 'decompress_phase_one';
5975: $r->print(&decompression_phase_one().
5976: &return_to_editor());
5977: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
5978: $uploadphase = 'decompress_phase_two';
5979: $r->print(&decompression_phase_two().
5980: &return_to_editor());
5981: }
5982: }
5983:
5984: if ($allowed && $toolsflag) {
5985: $r->print(&startContentScreen('tools'));
5986: $r->print(&generate_admin_menu($crstype,$canedit));
5987: $r->print(&endContentScreen());
5988: } elsif ((!$showdoc) && (!$uploadphase)) {
5989: # -----------------------------------------------------------------------------
5990: my %lt=&Apache::lonlocal::texthash(
5991: 'copm' => 'All documents out of a published map into this folder',
5992: 'upfi' => 'Upload File',
5993: 'upld' => 'Upload Content',
5994: 'srch' => 'Search',
5995: 'impo' => 'Import',
5996: 'lnks' => 'Import from Stored Links',
5997: 'impm' => 'Import from Assembled Map',
5998: 'imcr' => 'Import from Course Resources',
5999: 'extr' => 'External Resource',
6000: 'extt' => 'External Tool',
6001: 'selm' => 'Select Map',
6002: 'load' => 'Load Map',
6003: 'newf' => 'New Folder',
6004: 'newp' => 'New Composite Page',
6005: 'syll' => 'Syllabus',
6006: 'navc' => 'Table of Contents',
6007: 'sipa' => 'Simple Course Page',
6008: 'sipr' => 'Simple Problem',
6009: 'webp' => 'Blank Web Page (editable)',
6010: 'stpr' => 'Standard Problem',
6011: 'news' => 'New sub-directory',
6012: 'crpr' => 'Create Problem',
6013: 'drbx' => 'Drop Box',
6014: 'scuf' => 'External Scores (handgrade, upload, clicker)',
6015: 'bull' => 'Discussion Board',
6016: 'mypi' => 'My Personal Information Page',
6017: 'grpo' => 'Group Portfolio',
6018: 'rost' => 'Course Roster',
6019: 'abou' => 'Personal Information Page for a User',
6020: 'imsf' => 'IMS Upload',
6021: 'imsl' => 'Upload IMS package',
6022: 'cms' => 'Origin of IMS package',
6023: 'se' => 'Select',
6024: 'file' => 'File',
6025: 'title' => 'Title',
6026: 'addp' => 'Add Placeholder to course?',
6027: 'uste' => 'Use Template?',
6028: 'fnam' => 'File Name:',
6029: 'loca' => 'Location:',
6030: 'dire' => 'Directory:',
6031: 'cate' => 'Category:',
6032: 'tmpl' => 'Template:',
6033: 'comment' => 'Comment',
6034: 'parse' => 'Upload embedded images/multimedia files if HTML file',
6035: 'bb5' => 'Blackboard 5',
6036: 'bb6' => 'Blackboard 6',
6037: 'angel5' => 'ANGEL 5.5',
6038: 'webctce4' => 'WebCT 4 Campus Edition',
6039: 'yes' => 'Yes',
6040: 'no' => 'No',
6041: 'er' => 'Editing rights unavailable for your current role.',
6042: );
6043: # -----------------------------------------------------------------------------
6044:
6045: # Calculate free quota space for a user or course. A javascript function checks
6046: # file size to determine if upload should be allowed.
6047: my $quotatype = 'unofficial';
6048: if ($crstype eq 'Community') {
6049: $quotatype = 'community';
6050: } elsif ($crstype eq 'Placement') {
6051: $quotatype = 'placement';
6052: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) {
6053: $quotatype = 'official';
6054: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) {
6055: $quotatype = 'textbook';
6056: }
6057: my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom,
6058: 'course',$quotatype); # expressed in MB
6059: my $current_disk_usage = 0;
6060: foreach my $subdir ('docs','supplemental') {
6061: $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum,
6062: "userfiles/$subdir",1); # expressed in kB
6063: }
6064: my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage);
6065: my $usage = $current_disk_usage/1024; # in MB
6066: my $quota = $disk_quota;
6067: my $percent;
6068: if ($disk_quota == 0) {
6069: $percent = 100.0;
6070: } else {
6071: $percent = 100*($usage/$disk_quota);
6072: }
6073: $usage = sprintf("%.2f",$usage);
6074: $quota = sprintf("%.2f",$quota);
6075: $percent = sprintf("%.0f",$percent);
6076: my $quotainfo = '<p>'.&mt('Currently using [_1] of the [_2] available.',
6077: $percent.'%',$quota.' MB').'</p>';
6078:
6079: my $fileupload=(<<FIUP);
6080: $quotainfo
6081: $lt{'file'}:<br />
6082: <input type="file" name="uploaddoc" class="LC_flUpload" size="40" $disabled />
6083: <input type="hidden" id="LC_free_space" value="$free_space" />
6084: FIUP
6085:
6086: my $checkbox=(<<CHBO);
6087: <!-- <label>$lt{'parse'}?
6088: <input type="checkbox" name="parserflag" />
6089: </label> -->
6090: <label>
6091: <input type="checkbox" name="parserflag" checked="checked" $disabled /> $lt{'parse'}
6092: </label>
6093: CHBO
6094: my $imsfolder = $env{'form.folder'};
6095: if ($imsfolder eq '') {
6096: $imsfolder = 'default';
6097: }
6098: my $imspform=(<<IMSFORM);
6099: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
6100: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
6101: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
6102: <fieldset id="uploadimsform" style="display: none;">
6103: <legend>$lt{'imsf'}</legend>
6104: $fileupload
6105: <br />
6106: <p>
6107: $lt{'cms'}:
6108: <select name="source" $disabled>
6109: <option value="-1" selected="selected">$lt{'se'}</option>
6110: <option value="bb5">$lt{'bb5'}</option>
6111: <option value="bb6">$lt{'bb6'}</option>
6112: <option value="angel5">$lt{'angel5'}</option>
6113: <option value="webctce4">$lt{'webctce4'}</option>
6114: </select>
6115: <input type="hidden" name="folder" value="$imsfolder" />
6116: </p>
6117: <input type="hidden" name="phase" value="one" />
6118: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" $disabled />
6119: </fieldset>
6120: </form>
6121: IMSFORM
6122:
6123: my $fileuploadform=(<<FUFORM);
6124: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
6125: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
6126: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
6127: <fieldset id="uploaddocform" style="display: none;">
6128: <legend>$lt{'upfi'}</legend>
6129: <input type="hidden" name="active" value="aa" />
6130: $fileupload
6131: <br />
6132: $lt{'title'}:<br />
6133: <input type="text" size="60" name="comment" $disabled />
6134: $pathitem
6135: <input type="hidden" name="cmd" value="upload_default" />
6136: <br />
6137: <span class="LC_nobreak" style="float:left">
6138: $checkbox
6139: </span>
6140: <br clear="all" />
6141: <input type="submit" value="$lt{'upld'}" $disabled />
6142: </fieldset>
6143: </form>
6144: FUFORM
6145:
6146: my $mapimportjs;
6147: if ($canedit) {
6148: $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');";
6149: } else {
6150: $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');";
6151: }
6152: my $importpubform=(<<SEDFFORM);
6153: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
6154: $lt{'impm'}</a>$help{'Load_Map'}
6155: <form action="/adm/coursedocs" method="post" name="mapimportform">
6156: <fieldset id="importmapform" style="display: none;">
6157: <legend>$lt{'impm'}</legend>
6158: <input type="hidden" name="active" value="bb" />
6159: $lt{'copm'}<br />
6160: <span class="LC_nobreak">
6161: <input type="text" name="importmap" size="40" value=""
6162: onfocus="this.blur();$mapimportjs" $disabled />
6163: <a href="$mapimportjs">$lt{'selm'}</a></span><br />
6164: <input type="submit" name="loadmap" value="$lt{'load'}" $disabled />
6165: </fieldset>
6166: </form>
6167:
6168: SEDFFORM
6169: my $importcrsresform;
6170: my ($numdirs,$pickfile) =
6171: &Apache::loncommon::import_crsauthor_form('crsresimportform','coursepath','coursefile',
6172: "resize_scrollbox('contentscroll','1','0');",
6173: undef,'res');
6174: if ($pickfile) {
6175: $importcrsresform=(<<CRSFORM);
6176: <a class="LC_menubuttons_link" href="javascript:toggleImportCrsres('res','$numdirs');">
6177: $lt{'imcr'}</a>$help{'Course_Resources'}
6178: <form action="/adm/coursedocs" method="post" name="crsresimportform" onsubmit="return validImportCrsRes();">
6179: <fieldset id="importcrsresform" style="display: none;">
6180: <legend>$lt{'imcr'}</legend>
6181: <input type="hidden" name="active" value="bb" />
6182: $pickfile
6183: <p>
6184: $lt{'title'}: <input type="textbox" name="crsrestitle" value="" $disabled />
6185: </p>
6186: <input type="hidden" name="importdetail" value="" />
6187: <input type="submit" name="crsres" value="$lt{'impo'}" $disabled />
6188: </fieldset>
6189: </form>
6190: CRSFORM
6191: }
6192:
6193: my $fromstoredjs;
6194: if ($canedit) {
6195: $fromstoredjs = 'open_StoredLinks_Import()';
6196: } else {
6197: $fromstoredjs = "alert('".&js_escape($lt{'er'})."')";
6198: }
6199:
6200: my @importpubforma = (
6201: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/src.png" alt="'.$lt{srch}.'" onclick="javascript:groupsearch()" />' => $pathitem."<a class='LC_menubuttons_link' href='javascript:groupsearch()'>$lt{'srch'}</a>" },
6202: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/res.png" alt="'.$lt{impo}.'" onclick="javascript:groupimport();"/>' => "<a class='LC_menubuttons_link' href='javascript:groupimport();'>$lt{'impo'}</a>$help{'Importing_LON-CAPA_Resource'}" },
6203: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/wishlist.png" alt="'.$lt{lnks}.'" onclick="javascript:'.$fromstoredjs.';" />' => '<a class="LC_menubuttons_link" href="javascript:'.$fromstoredjs.';">'.$lt{'lnks'}.'</a>' },
6204: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform },
6205: );
6206: if ($pickfile) {
6207: push(@importpubforma,{ '<img class="LC_noBorder LC_middle" src="/res/adm/pages/res.png" alt="'.$lt{imcr}.'" onclick="javascript:toggleImportCrsres(\'res\','."'$numdirs'".');"/>' => $importcrsresform});
6208: }
6209: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
6210: my $extresourcesform =
6211: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
6212: $help{'Adding_External_Resource'},
6213: undef,undef,undef,undef,undef,undef,$disabled);
6214: my $exttoolform =
6215: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
6216: $help{'Adding_External_Tool'},undef,
6217: undef,'tool',$coursedom,$coursenum,
6218: \%ltitools,$disabled);
6219: if ($allowed) {
6220: my $folder = $env{'form.folder'};
6221: if ($folder eq '') {
6222: $folder='default';
6223: }
6224: if ($canedit) {
6225: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
6226: if ($output) {
6227: $r->print($output);
6228: }
6229: }
6230: $r->print(<<HIDDENFORM);
6231: <form name="renameform" method="post" action="/adm/coursedocs">
6232: <input type="hidden" name="title" />
6233: <input type="hidden" name="cmd" />
6234: <input type="hidden" name="markcopy" />
6235: <input type="hidden" name="copyfolder" />
6236: $containertag
6237: </form>
6238: <form name="aliasform" method="post" action="/adm/coursedocs">
6239: <input type="hidden" name="alias" />
6240: <input type="hidden" name="cmd" />
6241: $containertag
6242: </form>
6243:
6244: HIDDENFORM
6245: $r->print(&makesimpleeditform($pathitem)."\n".
6246: &makedocslogform($pathitem."\n".
6247: '<input type="hidden" name="folder" value="'.
6248: $env{'form.folder'}.'" />'."\n"));
6249: }
6250:
6251: # Generate the tabs
6252: my ($mode,$needs_end);
6253: if (($supplementalflag) && (!$allowed)) {
6254: my @folders = split('&',$env{'form.folderpath'});
6255: unless (@folders > 2) {
6256: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
6257: $needs_end = 1;
6258: }
6259: } else {
6260: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
6261: $needs_end = 1;
6262: }
6263:
6264: #
6265: my $hostname = $r->hostname();
6266: my $savefolderpath;
6267:
6268: if ($allowed) {
6269: my $folder=$env{'form.folder'};
6270: if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
6271: $folder='default';
6272: $savefolderpath = $env{'form.folderpath'};
6273: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
6274: $pathitem = '<input type="hidden" name="folderpath" value="'.
6275: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
6276: }
6277: my $postexec='';
6278: if ($folder eq 'default') {
6279: my $windowname = 'loncapaclient';
6280: if ($env{'request.lti.login'}) {
6281: $windowname .= 'lti';
6282: }
6283: $r->print('<script type="text/javascript">'."\n"
6284: .'// <![CDATA['."\n"
6285: .'this.window.name="'.$windowname.'";'."\n"
6286: .'// ]]>'."\n"
6287: .'</script>'."\n"
6288: );
6289: } else {
6290: #$postexec='self.close();';
6291: }
6292: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
6293: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
6294: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
6295:
6296: my $newnavform=(<<NNFORM);
6297: <form action="/adm/coursedocs" method="post" name="newnav">
6298: <input type="hidden" name="active" value="ff" />
6299: $pathitem
6300: <input type="hidden" name="importdetail"
6301: value="$lt{'navc'}=/adm/navmaps" />
6302: <a class="LC_menubuttons_link" href="javascript:makenew(document.newnav);">$lt{'navc'}</a>
6303: $help{'Navigate_Content'}
6304: </form>
6305: NNFORM
6306: my $newsmppageform=(<<NSPFORM);
6307: <form action="/adm/coursedocs" method="post" name="newsmppg">
6308: <input type="hidden" name="active" value="ff" />
6309: $pathitem
6310: <input type="hidden" name="importdetail" value="" />
6311: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
6312: $help{'Simple Page'}
6313: </form>
6314: NSPFORM
6315:
6316: my $newsmpproblemform=(<<NSPROBFORM);
6317: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
6318: <input type="hidden" name="active" value="dd" />
6319: $pathitem
6320: <input type="hidden" name="importdetail" value="" />
6321: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
6322: $help{'Simple_Problem'}
6323: </form>
6324:
6325: NSPROBFORM
6326:
6327: my $newdropboxform=(<<NDBFORM);
6328: <form action="/adm/coursedocs" method="post" name="newdropbox">
6329: <input type="hidden" name="active" value="dd" />
6330: $pathitem
6331: <input type="hidden" name="importdetail" value="" />
6332: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
6333: $help{'Dropbox'}
6334: </form>
6335: NDBFORM
6336:
6337: my $newexuploadform=(<<NEXUFORM);
6338: <form action="/adm/coursedocs" method="post" name="newexamupload">
6339: <input type="hidden" name="active" value="dd" />
6340: $pathitem
6341: <input type="hidden" name="importdetail" value="" />
6342: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
6343: $help{'Score_Upload_Form'}
6344: </form>
6345: NEXUFORM
6346:
6347: my $newbulform=(<<NBFORM);
6348: <form action="/adm/coursedocs" method="post" name="newbul">
6349: <input type="hidden" name="active" value="ee" />
6350: $pathitem
6351: <input type="hidden" name="importdetail" value="" />
6352: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
6353: $help{'Bulletin Board'}
6354: </form>
6355: NBFORM
6356:
6357: my $newaboutmeform=(<<NAMFORM);
6358: <form action="/adm/coursedocs" method="post" name="newaboutme">
6359: <input type="hidden" name="active" value="ee" />
6360: $pathitem
6361: <input type="hidden" name="importdetail"
6362: value="$plainname=/adm/$udom/$uname/aboutme" />
6363: <a class="LC_menubuttons_link" href="javascript:makenew(document.newaboutme);">$lt{'mypi'}</a>
6364: $help{'My Personal Information Page'}
6365: </form>
6366: NAMFORM
6367:
6368: my $newaboutsomeoneform=(<<NASOFORM);
6369: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
6370: <input type="hidden" name="active" value="ee" />
6371: $pathitem
6372: <input type="hidden" name="importdetail" value="" />
6373: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
6374: </form>
6375: NASOFORM
6376:
6377: my $newrosterform=(<<NROSTFORM);
6378: <form action="/adm/coursedocs" method="post" name="newroster">
6379: <input type="hidden" name="active" value="ee" />
6380: $pathitem
6381: <input type="hidden" name="importdetail"
6382: value="$lt{'rost'}=/adm/viewclasslist" />
6383: <a class="LC_menubuttons_link" href="javascript:makenew(document.newroster);">$lt{'rost'}</a>
6384: $help{'Course_Roster'}
6385: </form>
6386: NROSTFORM
6387:
6388: my $newwebpage;
6389: if ($folder =~ /^default_?(\d*)$/) {
6390: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
6391: if ($1) {
6392: $newwebpage .= $1;
6393: } else {
6394: $newwebpage .= 'default';
6395: }
6396: $newwebpage .= '/new.html';
6397: }
6398: my $newwebpageform =(<<NWEBFORM);
6399: <form action="/adm/coursedocs" method="post" name="newwebpage">
6400: <input type="hidden" name="active" value="ff" />
6401: $pathitem
6402: <input type="hidden" name="importdetail" value="$newwebpage" />
6403: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
6404: $help{'Web_Page'}
6405: </form>
6406: NWEBFORM
6407:
6408: my @ids=&Apache::lonnet::current_machine_ids();
6409: my %select_menus;
6410: my $numauthor = 0;
6411: my $numcrsdirs = 0;
6412: my $toppath = "/priv/$env{'user.domain'}/$env{'user.name'}";
6413: if ($env{'user.author'}) {
6414: $numauthor ++;
6415: $select_menus{'author'}->{'text'} = &Apache::lonnet::plaintext('au');
6416: if (grep(/^\Q$env{'user.home'}\E$/,@ids)) {
6417: my $is_home = 1;
6418: my %subdirs;
6419: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
6420: $select_menus{'author'}->{'default'} = '/';
6421: $select_menus{'author'}->{'select2'}->{'/'} = '/';
6422: my @ordered = ('/');
6423: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6424: $select_menus{'author'}->{'select2'}->{$relpath} = $relpath;
6425: push(@ordered,$relpath);
6426: }
6427: $select_menus{'author'}->{'order'} = \@ordered;
6428: } else {
6429: $select_menus{'author'}->{'select2'}->{'switch'} = &mt('Switch server required');
6430: $select_menus{'author'}->{'default'} = 'switch';
6431: $select_menus{'author'}->{'order'} = ['switch'];
6432: }
6433: }
6434: my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
6435: ['active'],['ca','aa']);
6436: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
6437: my %by_roletype;
6438: if (keys(%roleshash)) {
6439: foreach my $entry (keys(%roleshash)) {
6440: my ($auname,$audom,$roletype) = split(/:/,$entry);
6441: my $key = $entry;
6442: $key =~ s/:/___/g;
6443: $by_roletype{$roletype}{$auname.'___'.$audom} = 1;
6444: $select_menus{$key}->{'text'} = &Apache::lonnet::plaintext($roletype)." ($audom/$auname)";
6445: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
6446: if (grep(/^\Q$rolehome\E$/,@ids)) {
6447: my $is_home = 1;
6448: my (%subdirs,@ordered);
6449: my $toppath="/priv/$audom/$auname";
6450: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
6451: $select_menus{$key}->{'default'} = '/';
6452: $select_menus{$key}->{'select2'}->{'/'} = '/';
6453: my @ordered = ('/');
6454: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6455: $select_menus{$key}->{'select2'}->{$relpath} = $relpath;
6456: push(@ordered,$relpath);
6457: }
6458: $select_menus{$key}->{'order'} = \@ordered;
6459: } else {
6460: $select_menus{$key}->{'select2'}->{'switch'} = &mt('Switch server required');
6461: $select_menus{$key}->{'default'} = 'switch';
6462: $select_menus{$key}->{'order'} = ['switch'];
6463: }
6464: $numauthor ++;
6465: }
6466: }
6467: my ($pickdir,$showtitle);
6468: if ($numauthor) {
6469: my @order;
6470: my $defrole;
6471: if ($env{'user.author'}) {
6472: push(@order,'author');
6473: $defrole = 'author';
6474: }
6475: if (keys(%by_roletype)) {
6476: foreach my $possrole ('ca','aa') {
6477: if (ref($by_roletype{$possrole}) eq 'HASH') {
6478: foreach my $author (sort { lc($a) cmp lc($b) } (keys(%{$by_roletype{$possrole}}))) {
6479: unless ($defrole) {
6480: $defrole = $author;
6481: }
6482: push(@order,$author.'___'.$possrole);
6483: }
6484: }
6485: }
6486: }
6487: $select_menus{'course'}->{'text'} = &mt('Course Resource');
6488: if (grep(/^\Q$crshome\E$/,@ids)) {
6489: my $is_home = 1;
6490: my %subdirs;
6491: my $toppath="/priv/$coursedom/$coursenum";
6492: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
6493: $numcrsdirs = keys(%subdirs);
6494: $select_menus{'course'}->{'default'} = '/';
6495: $select_menus{'course'}->{'select2'}->{'/'} = '/';
6496: my @ordered = ('/');
6497: foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6498: $select_menus{'course'}->{'select2'}->{$relpath} = $relpath;
6499: push(@ordered,$relpath);
6500: }
6501: $select_menus{'course'}->{'order'} = \@ordered;
6502: } else {
6503: $select_menus{'course'}->{'select2'}->{'switch'} = &mt('Switch server required');
6504: $select_menus{'course'}->{'default'} = 'switch';
6505: $select_menus{'course'}->{'order'} = ['switch'];
6506: }
6507: push(@order,'course');
6508: $pickdir = $lt{'loca'}.
6509: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'dire'},
6510: $defrole,'authorrole','authorpath',
6511: \%select_menus,\@order,'toggleCrsResTitle();',
6512: '','priv').'<br />';
6513: $showtitle = 'none';
6514: } else {
6515: my $is_home;
6516: $showtitle = 'inline';
6517: if (grep(/^\Q$crshome\E$/,@ids)) {
6518: $is_home = 1;
6519: $pickdir .= '<input type="hidden" name="authorrole" value="course" />';
6520: my $toppath="/priv/$coursedom/$coursenum'}";
6521: my %subdirs;
6522: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs);
6523: $numcrsdirs = keys(%subdirs);
6524: if ($numcrsdirs) {
6525: $pickdir .= &mt('Directory: ').'<select name="authorpath">'."\n".
6526: '<option value="/">/</option>'."\n";
6527: foreach my $key (sort { lc($a) cmp lc($b) } (keys(%subdirs))) {
6528: $pickdir .= '<option value="'.$key.'">'.$key.'</option>'."\n";
6529: }
6530: $pickdir .= '</select>';
6531: } else {
6532: $pickdir .= '<input type="hidden" name="authorpath" value="/" />'."\n";
6533: }
6534: }
6535: }
6536:
6537: my %seltemplate_menus;
6538: my @files = &Apache::lonhomework::get_template_list('problem');
6539: my @noexamplelink = ('blank.problem','blank.library','script.library');
6540: my $currentcategory = '';
6541: my @ordered = ('');
6542: my %templatehelp;
6543: my $defcategory = '';
6544: my @catorder = ($defcategory);
6545: $seltemplate_menus{$defcategory}->{'order'} = [''];
6546: $seltemplate_menus{$defcategory}->{'text'} = '';
6547: foreach my $file (@files) {
6548: if (ref($file) eq 'ARRAY') {
6549: my ($path,$title,$category,$help) = @{$file};
6550: next if ($title !~ /\S/);
6551: if (&js_escape($category) ne $currentcategory) {
6552: $currentcategory = &js_escape($category);
6553: push(@catorder,&js_escape($currentcategory));
6554: $seltemplate_menus{$currentcategory}->{'text'} = $category;
6555: $seltemplate_menus{$currentcategory}->{'default'} = '';
6556: $seltemplate_menus{$currentcategory}->{'select2'}->{''} = '';
6557: push(@{$seltemplate_menus{$currentcategory}->{'order'}},'');
6558: }
6559: if ($path) {
6560: $seltemplate_menus{$currentcategory}->{'select2'}->{&js_escape($path)} = $title;
6561: push(@{$seltemplate_menus{$currentcategory}->{'order'}},&js_escape($path));
6562: if ($help) {
6563: $templatehelp{$path} = $help;
6564: }
6565: }
6566: }
6567: }
6568:
6569: my $templates = $lt{'cate'}.' '.
6570: &Apache::loncommon::linked_select_forms('courseresform','<br />'.$lt{'tmpl'}.' ',
6571: $defcategory,'tempcategory','template',
6572: \%seltemplate_menus,\@catorder,
6573: "resize_scrollbox('contentscroll','1','0');",
6574: "toggleExampleText();",'template').'<br />';
6575: my $templatepreview = '<a href="#" target="sample" onclick="javascript:getExample(600,420,\'yes\',true); return false;">'.
6576: '<span id="newresexample">'.&mt('Example').'<span></a>';
6577: my $crsresform=(<<RESFORM);
6578: <a class="LC_menubuttons_link" href="javascript:toggleCrsRes('res','$numauthor','$numcrsdirs');">
6579: $lt{'stpr'}</a>$help{'Course_Resource'}
6580: <form action="/adm/coursedocs" method="post" name="courseresform">
6581: <fieldset id="crsresform" style="display:none;">
6582: <legend>$lt{'stpr'}</legend>
6583: <input type="hidden" name="active" value="bb" />
6584: <p>
6585: $pickdir
6586: <span class="LC_nobreak">$lt{'news'}?
6587: <label><input type="radio" name="newsubdir" value="0" onclick="toggleNewsubdir(this.form);" checked="checked" $disabled />No</label>
6588:
6589: <label><input type="radio" name="newsubdir" value="1" onclick="toggleNewsubdir(this.form);" $disabled />Yes</label>
6590: </span><span id="newsubdir"></span>
6591: <input type="hidden" name="newsubdirname" id="newsubdirname" value="" autocomplete="off" />
6592: </p>
6593: $lt{'fnam'}
6594: <input type="text" size="20" name="newresourcename" autocomplete="off" $disabled />
6595: <p>
6596: <div id="newresource" style="display:$showtitle">
6597: $lt{'addp'}
6598: <label><input type="radio" name="newresourceadd" value="0" checked="checked" onclick="toggleNewInCourse(this.form);" $disabled />
6599: $lt{'no'}</label>
6600: <label><input type="radio" name="newresourceadd" value="1" onclick="toggleNewInCourse(this.form);" $disabled />
6601: $lt{'yes'}</label>
6602: <span id="newrestitle"></span>
6603: <input type="hidden" size="20" name="newresourcetitle" id="newresourcetitle" autocomplete="off" $disabled />
6604: </div>
6605: </p>
6606: <p>
6607: $lt{'uste'}
6608: <label><input type="radio" name="newresusetemp" value="0" checked="checked" onclick="toggleWithTemplate(this.form);" $disabled />
6609: $lt{'no'}</label>
6610: <label><input type="radio" name="newresusetemp" value="1" onclick="toggleWithTemplate(this.form);" $disabled />
6611: $lt{'yes'}</label>
6612: <div id="newrestemplate" style="display:none">
6613: $templates
6614: $templatepreview
6615: </div>
6616: </p>
6617: <span class="LC_nobreak">
6618: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
6619: <input type="submit" name="newcrs" value="$lt{'crpr'}" $disabled />
6620: </span>
6621: </fieldset>
6622: </form>
6623:
6624: RESFORM
6625:
6626: my $specialdocumentsform;
6627: my @specialdocumentsforma;
6628: my $gradingform;
6629: my @gradingforma;
6630: my $communityform;
6631: my @communityforma;
6632: my $newfolderform;
6633: my $newfolderb;
6634:
6635: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6636:
6637: my $newpageform=(<<NPFORM);
6638: <form action="/adm/coursedocs" method="post" name="newpage">
6639: <input type="hidden" name="folderpath" value="$path" />
6640: <input type="hidden" name="importdetail" value="" />
6641: <input type="hidden" name="active" value="ee" />
6642: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
6643: $help{'Adding_Pages'}
6644: </form>
6645: NPFORM
6646:
6647:
6648: $newfolderform=(<<NFFORM);
6649: <form action="/adm/coursedocs" method="post" name="newfolder">
6650: $pathitem
6651: <input type="hidden" name="importdetail" value="" />
6652: <input type="hidden" name="active" value="" />
6653: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
6654: </form>
6655: NFFORM
6656:
6657: my $newsylform=(<<NSYLFORM);
6658: <form action="/adm/coursedocs" method="post" name="newsyl">
6659: <input type="hidden" name="active" value="ee" />
6660: $pathitem
6661: <input type="hidden" name="importdetail"
6662: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
6663: <a class="LC_menubuttons_link" href="javascript:makenew(document.newsyl);">$lt{'syll'}</a>
6664: $help{'Syllabus'}
6665:
6666: </form>
6667: NSYLFORM
6668:
6669: my $newgroupfileform=(<<NGFFORM);
6670: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
6671: <input type="hidden" name="active" value="ee" />
6672: $pathitem
6673: <input type="hidden" name="importdetail"
6674: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
6675: <a class="LC_menubuttons_link" href="javascript:makenew(document.newgroupfiles);">$lt{'grpo'}</a>
6676: $help{'Group Portfolio'}
6677: </form>
6678: NGFFORM
6679: if ($container eq 'page') {
6680: @specialdocumentsforma=(
6681: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
6682: );
6683: } else {
6684: @specialdocumentsforma=(
6685: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/page.png" alt="'.$lt{newp}.'" onclick="javascript:makenewpage(document.newpage,\''.$pageseq.'\');" />'=>$newpageform},
6686: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.newsyl);" />'=>$newsylform},
6687: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="javascript:makenew(document.newnav);" />'=>$newnavform},
6688: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
6689: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
6690: );
6691: }
6692: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
6693:
6694: my @external = (
6695: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleExternal(\'ext\');" />'=>$extresourcesform}
6696: );
6697: if (keys(%ltitools)) {
6698: push(@external,
6699: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="toggleExternal(\'tool\');" />'=>$exttoolform},
6700: );
6701: }
6702: my $externalform = &create_form_ul(&create_list_elements(@external));
6703:
6704: my @importdoc = ();
6705: unless ($container eq 'page') {
6706: push(@importdoc,
6707: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
6708: );
6709: }
6710: push(@importdoc,
6711: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
6712: );
6713: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
6714:
6715: @gradingforma=(
6716: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
6717: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
6718: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
6719: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{stpr}.'" onclick="javascript:toggleCrsRes(\'res\','."'$numauthor','$numcrsdirs'".');" />'=>$crsresform},
6720: );
6721: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
6722:
6723: @communityforma=(
6724: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
6725: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
6726: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
6727: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="javascript:makenew(document.newroster);" />'=>$newrosterform},
6728: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="javascript:makenew(document.newgroupfiles);" />'=>$newgroupfileform},
6729: );
6730: $communityform = &create_form_ul(&create_list_elements(@communityforma));
6731:
6732: my %orderhash = (
6733: 'aa' => ['Upload',$fileuploadform],
6734: 'bb' => ['Import',$importpubform],
6735: 'cc' => ['External',$externalform],
6736: 'dd' => ['Grading',$gradingform],
6737: 'ff' => ['Other',$specialdocumentsform],
6738: );
6739: unless ($container eq 'page') {
6740: $orderhash{'00'} = ['Newfolder',$newfolderform];
6741: $orderhash{'ee'} = ['Collaboration',$communityform];
6742: }
6743:
6744: $hadchanges=0;
6745: unless (($supplementalflag || $toolsflag)) {
6746: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
6747: $supplementalflag,\%orderhash,$iconpath,$pathitem,
6748: \%ltitools,$canedit,$hostname,\$navmap,$hiddentop);
6749: undef($navmap);
6750: if ($error) {
6751: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6752: }
6753: if ($hadchanges) {
6754: unless (&is_hash_old()) {
6755: &mark_hash_old();
6756: }
6757: }
6758:
6759: &changewarning($r,'');
6760: }
6761: }
6762:
6763: # Supplemental documents start here
6764:
6765: my $folder=$env{'form.folder'};
6766: unless ($supplementalflag) {
6767: $folder='supplemental';
6768: }
6769: if ($folder =~ /^supplemental$/ &&
6770: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
6771: $env{'form.folderpath'} = &supplemental_base();
6772: } elsif ($allowed) {
6773: $env{'form.folderpath'} = $savefolderpath;
6774: }
6775: $pathitem = '<input type="hidden" name="folderpath" value="'.
6776: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
6777: if ($allowed) {
6778: my $folderseq=
6779: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
6780:
6781: my $supupdocform=(<<SUPDOCFORM);
6782: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
6783: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
6784: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
6785: <fieldset id="uploadsuppdocform" style="display: none;">
6786: <legend>$lt{'upfi'}</legend>
6787: <input type="hidden" name="active" value="ee" />
6788: $fileupload
6789: <br />
6790: <br />
6791: <span class="LC_nobreak">
6792: $checkbox
6793: </span>
6794: <br /><br />
6795: $lt{'comment'}:<br />
6796: <textarea cols="50" rows="4" name="comment"></textarea>
6797: <br />
6798: $pathitem
6799: <input type="hidden" name="cmd" value="upload_supplemental" />
6800: <input type='submit' value="$lt{'upld'}" />
6801: </form>
6802: SUPDOCFORM
6803:
6804: my $supnewfolderform=(<<SNFFORM);
6805: <form action="/adm/coursedocs" method="post" name="supnewfolder">
6806: <input type="hidden" name="active" value="" />
6807: $pathitem
6808: <input type="hidden" name="importdetail" value="" />
6809: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
6810: $help{'Adding_Folders'}
6811: </form>
6812: SNFFORM
6813:
6814: my $supextform =
6815: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
6816: $help{'Adding_External_Resource'},
6817: undef,undef,undef,undef,undef,undef,
6818: $disabled);
6819:
6820: my $supexttoolform =
6821: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
6822: $help{'Adding_External_Tool'},
6823: undef,undef,'tool',$coursedom,
6824: $coursenum,\%ltitools,$disabled);
6825:
6826: my $supnewsylform=(<<SNSFORM);
6827: <form action="/adm/coursedocs" method="post" name="supnewsyl">
6828: <input type="hidden" name="active" value="ff" />
6829: $pathitem
6830: <input type="hidden" name="importdetail"
6831: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
6832: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewsyl);">$lt{'syll'}</a>
6833: $help{'Syllabus'}
6834: </form>
6835: SNSFORM
6836:
6837: my $supnewaboutmeform=(<<SNAMFORM);
6838: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
6839: <input type="hidden" name="active" value="ff" />
6840: $pathitem
6841: <input type="hidden" name="importdetail"
6842: value="$plainname=/adm/$udom/$uname/aboutme" />
6843: <a class="LC_menubuttons_link" href="javascript:makenew(document.supnewaboutme);">$lt{'mypi'}</a>
6844: $help{'My Personal Information Page'}
6845: </form>
6846: SNAMFORM
6847:
6848: my $supwebpage;
6849: if ($folder =~ /^supplemental_?(\d*)$/) {
6850: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
6851: if ($1) {
6852: $supwebpage .= $1;
6853: } else {
6854: $supwebpage .= 'default';
6855: }
6856: $supwebpage .= '/new.html';
6857: }
6858: my $supwebpageform =(<<SWEBFORM);
6859: <form action="/adm/coursedocs" method="post" name="supwebpage">
6860: <input type="hidden" name="active" value="cc" />
6861: $pathitem
6862: <input type="hidden" name="importdetail" value="$supwebpage" />
6863: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
6864: $help{'Web_Page'}
6865: </form>
6866: SWEBFORM
6867:
6868:
6869: my @specialdocs = (
6870: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="javascript:makenew(document.supnewsyl);" />'
6871: =>$supnewsylform},
6872: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makenew(document.supnewaboutme);" />'
6873: =>$supnewaboutmeform},
6874: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
6875:
6876: );
6877: my @supexternal = (
6878: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleExternal(\'suppext\')" />'
6879: =>$supextform});
6880: if (keys(%ltitools)) {
6881: push(@supexternal,
6882: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/exttool.png" alt="'.$lt{extt}.'" onclick="javascript:toggleExternal(\'supptool\')" />'
6883: =>$supexttoolform});
6884: }
6885: my @supimportdoc = (
6886: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
6887: =>$supupdocform},
6888: );
6889:
6890: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
6891: my %suporderhash = (
6892: '00' => ['Supnewfolder', $supnewfolderform],
6893: 'dd' => ['Upload',$supupdocform],
6894: 'ee' => ['External',&create_form_ul(&create_list_elements(@supexternal))],
6895: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
6896: );
6897: if ($supplementalflag) {
6898: $suppchanges = 0;
6899: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
6900: $supplementalflag,\%suporderhash,$iconpath,$pathitem,
6901: \%ltitools,$canedit,$hostname);
6902: if ($error) {
6903: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6904: }
6905: if ($suppchanges) {
6906: my %servers = &Apache::lonnet::internet_dom_servers($coursedom);
6907: my @ids=&Apache::lonnet::current_machine_ids();
6908: foreach my $server (keys(%servers)) {
6909: next if (grep(/^\Q$server\E$/,@ids));
6910: my $hashid=$coursenum.':'.$coursedom;
6911: my $cachekey = &escape('showsupp').':'.&escape($hashid);
6912: &Apache::lonnet::remote_devalidate_cache($server,[$cachekey]);
6913: }
6914: &Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom,1);
6915: &Apache::lonnet::count_supptools($coursenum,$coursedom,1);
6916: my $now = time;
6917: if ($env{'request.course.id'} eq $coursedom.'_'.$coursenum) {
6918: &Apache::lonnet::appenv({'request.course.suppupdated' => $now});
6919: }
6920: &Apache::lonnet::put('environment',{'internal.supplementalchange' => $now},
6921: $coursedom,$coursenum);
6922: &Apache::lonnet::appenv(
6923: {'course.'.$coursedom.'_'.$coursenum.'.internal.supplementalchange' => $now});
6924: &Apache::lonnet::do_cache_new('suppchange',$coursedom.'_'.$coursenum,$now,600);
6925: undef($suppchanges);
6926: }
6927: }
6928: } elsif ($supplementalflag) {
6929: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
6930: $supplementalflag,'',$iconpath,$pathitem,'',$canedit,
6931: $hostname);
6932: if ($error) {
6933: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
6934: }
6935: }
6936:
6937: if ($needs_end) {
6938: $r->print(&endContentScreen());
6939: }
6940:
6941: if ($allowed) {
6942: $r->print('
6943: <form method="post" name="extimport" action="/adm/coursedocs">
6944: <input type="hidden" name="title" />
6945: <input type="hidden" name="url" />
6946: <input type="hidden" name="useform" />
6947: <input type="hidden" name="residx" />
6948: </form>');
6949: }
6950: } elsif ($showdoc) {
6951: # -------------------------------------------------------- This is showdoc mode
6952: $r->print("<h1>".&mt('Uploaded Document').' - '.
6953: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
6954: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
6955: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
6956: }
6957: }
6958: unless ($noendpage) {
6959: $r->print(&Apache::loncommon::end_page());
6960: }
6961: return OK;
6962: }
6963:
6964: sub embedded_form_elems {
6965: my ($phase,$primaryurl,$newidx) = @_;
6966: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
6967: $newidx =~s /\D+//g;
6968: return <<STATE;
6969: <input type="hidden" name="folderpath" value="$folderpath" />
6970: <input type="hidden" name="cmd" value="upload_embedded" />
6971: <input type="hidden" name="newidx" value="$newidx" />
6972: <input type="hidden" name="phase" value="$phase" />
6973: <input type="hidden" name="primaryurl" value="$primaryurl" />
6974: STATE
6975: }
6976:
6977: sub embedded_destination {
6978: my $folder=$env{'form.folder'};
6979: my $destination = 'docs/';
6980: if ($folder =~ /^supplemental/) {
6981: $destination = 'supplemental/';
6982: }
6983: if (($folder eq 'default') || ($folder eq 'supplemental')) {
6984: $destination .= 'default/';
6985: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
6986: $destination .= $2.'/';
6987: }
6988: my $newidx = $env{'form.newidx'};
6989: $newidx =~s /\D+//g;
6990: if ($newidx) {
6991: $destination .= $newidx;
6992: }
6993: my $dir_root = '/userfiles';
6994: return ($destination,$dir_root);
6995: }
6996:
6997: sub return_to_editor {
6998: my $actionurl = '/adm/coursedocs';
6999: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
7000: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
7001: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
7002: '</a></p>';
7003: }
7004:
7005: sub decompression_info {
7006: my ($destination,$dir_root) = &embedded_destination();
7007: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
7008: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
7009: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
7010: my $container='sequence';
7011: my ($pathitem,$hiddenelem);
7012: my @hiddens = ('newidx','comment','position','folderpath','archiveurl');
7013: if ($env{'form.folderpath'} =~ /\:1$/) {
7014: $container='page';
7015: }
7016: unshift(@hiddens,$pathitem);
7017: foreach my $item (@hiddens) {
7018: if ($item eq 'newidx') {
7019: next if ($env{'form.'.$item} =~ /\D/);
7020: }
7021: if ($env{'form.'.$item}) {
7022: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
7023: &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n";
7024: }
7025: }
7026: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
7027: $hiddenelem);
7028: }
7029:
7030: sub decompression_phase_one {
7031: my ($dir,$file,$warning,$error,$output);
7032: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
7033: &decompression_info();
7034: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
7035: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
7036: } else {
7037: my $file = $1;
7038: $output =
7039: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
7040: $destination,$dir_root,
7041: $hiddenelem);
7042: if ($env{'form.autoextract_camtasia'}) {
7043: $output .= &remove_archive($docudom,$docuname,$container);
7044: }
7045: }
7046: if ($error) {
7047: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
7048: $error.'</p>'."\n";
7049: }
7050: if ($warning) {
7051: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
7052: }
7053: return $output;
7054: }
7055:
7056: sub decompression_phase_two {
7057: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
7058: &decompression_info();
7059: my $output;
7060: if ($env{'form.archivedelete'}) {
7061: $output = &remove_archive($docudom,$docuname,$container);
7062: }
7063: $output .=
7064: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
7065: $destination,$dir_root,$hiddenelem);
7066: return $output;
7067: }
7068:
7069: sub remove_archive {
7070: my ($docudom,$docuname,$container) = @_;
7071: my $map = $env{'form.folder'}.'.'.$container;
7072: my ($output,$delwarning,$delresult,$url);
7073: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
7074: if ($fatal) {
7075: if ($container eq 'page') {
7076: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
7077: } else {
7078: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
7079: }
7080: $delwarning .= ' '.&mt('As a result the archive file has not been removed.');
7081: } else {
7082: my $currcmd = $env{'form.cmd'};
7083: my $position = $env{'form.position'};
7084: my $archiveidx = $position;
7085: if ($position > 0) {
7086: if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) {
7087: $archiveidx = $position-1;
7088: }
7089: $env{'form.cmd'} = 'remove_'.$archiveidx;
7090: my ($title,$url,@rrest) =
7091: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]);
7092: if ($url eq $env{'form.archiveurl'}) {
7093: if (&handle_edit_cmd($docuname,$docudom)) {
7094: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
7095: if ($fatal) {
7096: if ($container eq 'page') {
7097: $delwarning = &mt('An error occurred updating the contents of the current page.');
7098: } else {
7099: $delwarning = &mt('An error occurred updating the contents of the current folder.');
7100: }
7101: } else {
7102: $delresult = &mt('Archive file removed.');
7103: }
7104: }
7105: } else {
7106: $delwarning .= &mt('Archive file had unexpected item number in folder.').
7107: ' '.&mt('As a result the archive file has not been removed.');
7108: }
7109: }
7110: $env{'form.cmd'} = $currcmd;
7111: }
7112: if ($delwarning) {
7113: $output = '<p class="LC_warning">'.
7114: $delwarning.
7115: '</p>';
7116: }
7117: if ($delresult) {
7118: $output .= '<p class="LC_info">'.
7119: $delresult.
7120: '</p>';
7121: }
7122: return $output;
7123: }
7124:
7125: sub generate_admin_menu {
7126: my ($crstype,$canedit) = @_;
7127: my $lc_crstype = lc($crstype);
7128: my ($home,$other,%outhash)=&authorhosts();
7129: my %lt= ( # do not translate here
7130: 'vc' => 'Verify Content',
7131: 'cv' => 'Check/Set Resource Versions',
7132: 'ls' => 'List Resource Identifiers',
7133: 'ct' => 'Display/Set Shortened URLs for Deep-linking',
7134: 'imse' => 'Export contents to IMS Archive',
7135: 'dcd' => "Copy $crstype Content to Authoring Space",
7136: );
7137: my ($candump,$dumpurl);
7138: if ($home + $other > 0) {
7139: $candump = 'F';
7140: if ($home) {
7141: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
7142: } else {
7143: my @hosts;
7144: foreach my $aurole (keys(%outhash)) {
7145: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
7146: push(@hosts,$outhash{$aurole});
7147: }
7148: }
7149: if (@hosts == 1) {
7150: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
7151: '&role='.
7152: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
7153: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
7154: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
7155: } else {
7156: $dumpurl = "javascript:choose_switchserver_window()";
7157: }
7158: }
7159: }
7160: my @menu=
7161: ({ categorytitle=>'Administration',
7162: items =>[
7163: { linktext => $lt{'vc'},
7164: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
7165: permission => 'F',
7166: help => 'Docs_Verify_Content',
7167: icon => 'verify.png',
7168: linktitle => 'Verify contents can be retrieved/rendered',
7169: },
7170: { linktext => $lt{'cv'},
7171: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
7172: permission => 'F',
7173: help => 'Docs_Check_Resource_Versions',
7174: icon => 'resversion.png',
7175: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
7176: },
7177: { linktext => $lt{'ls'},
7178: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
7179: permission => 'F',
7180: #help => '',
7181: icon => 'symbs.png',
7182: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
7183: },
7184: { linktext => $lt{'ct'},
7185: url => "javascript:injectData(document.courseverify,'dummy','shorturls','$lt{'ct'}')",
7186: permission => 'F',
7187: help => 'Docs_Short_URLs',
7188: icon => 'shorturls.png',
7189: linktitle => "Set shortened URLs for a resource or folder in your $lc_crstype for use in deep-linking"
7190: },
7191: ]
7192: });
7193: if ($canedit) {
7194: push(@menu,
7195: { categorytitle=>'Export',
7196: items =>[
7197: { linktext => $lt{'imse'},
7198: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
7199: permission => 'F',
7200: help => 'Docs_Export_Course_Docs',
7201: icon => 'imsexport.png',
7202: linktitle => $lt{'imse'},
7203: },
7204: { linktext => $lt{'dcd'},
7205: url => $dumpurl,
7206: permission => $candump,
7207: help => 'Docs_Dump_Course_Docs',
7208: icon => 'dump.png',
7209: linktitle => $lt{'dcd'},
7210: },
7211: ]
7212: });
7213: }
7214: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
7215: '<input type="hidden" id="dummy" />'."\n".
7216: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
7217: '</form>';
7218: }
7219:
7220: sub generate_edit_table {
7221: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
7222: $need_save,$copyfolder,$canedit) = @_;
7223: return unless(ref($orderhash_ref) eq 'HASH');
7224: my %orderhash = %{$orderhash_ref};
7225: my ($form, $activetab, $active, $disabled);
7226: if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) {
7227: $activetab = $env{'form.active'};
7228: }
7229: unless ($canedit) {
7230: $disabled = ' disabled="disabled"';
7231: }
7232: my $backicon = $iconpath.'clickhere.gif';
7233: my $backtext = &mt('Exit Editor');
7234: $form = '<div class="LC_Box" style="margin:0;">'.
7235: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
7236: '<li class="goback">'.
7237: '<a href="javascript:toContents('."'$jumpto'".');">'.
7238: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
7239: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
7240: '<li>'.
7241: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
7242: &mt('Undo Delete').'</a></li>'."\n";
7243: if ($env{'form.docslog'}) {
7244: $form .= '<li class="active">';
7245: } else {
7246: $form .= '<li>';
7247: }
7248: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
7249: &mt('History').'</a></li>'."\n";
7250: if ($env{'form.docslog'}) {
7251: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
7252: &mt('Edit').'</a></li>'."\n";
7253: }
7254: foreach my $name (reverse(sort(keys(%orderhash)))) {
7255: if($name ne '00'){
7256: if($activetab eq '' || $activetab ne $name){
7257: $active = '';
7258: }elsif($activetab eq $name){
7259: $active = 'class="active"';
7260: }
7261: $form .= '<li style="float:right" '.$active
7262: .' onclick="javascript:showPage(this, \''.$name.$tid.'\', \'navigation'.$tid.'\',\'content'.$tid.'\');"><a href="javascript:;"><b>'.&mt(${$orderhash{$name}}[0]).'</b></a></li>'."\n";
7263: } else {
7264: $form .= '<li style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
7265:
7266: }
7267: }
7268: $form .= '</ul>'."\n";
7269: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
7270:
7271: if ($to_show ne '') {
7272: my $saveform;
7273: if ($need_save) {
7274: my $button = &mt('Make changes');
7275: my $path;
7276: if ($env{'form.folderpath'}) {
7277: $path =
7278: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
7279: }
7280: $saveform = <<"END";
7281: <div id="multisave" style="display:none; clear:both;" >
7282: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
7283: <input type="hidden" name="folderpath" value="$path" />
7284: <input type="hidden" name="symb" value="$env{'form.symb'}" />
7285: <input type="hidden" name="allhiddenresource" value="" />
7286: <input type="hidden" name="allencrypturl" value="" />
7287: <input type="hidden" name="allrandompick" value="" />
7288: <input type="hidden" name="allrandomorder" value="" />
7289: <input type="hidden" name="changeparms" value="" />
7290: <input type="hidden" name="multiremove" value="" />
7291: <input type="hidden" name="multicut" value="" />
7292: <input type="hidden" name="multicopy" value="" />
7293: <input type="hidden" name="multichange" value="" />
7294: <input type="hidden" name="copyfolder" value="$copyfolder" />
7295: <input type="submit" name="savemultiples" value="$button" $disabled />
7296: </form>
7297: </div>
7298: END
7299: }
7300: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
7301: }
7302: foreach my $field (keys(%orderhash)){
7303: if($field ne '00'){
7304: if($activetab eq '' || $activetab ne $field){
7305: $active = 'style="display: none;float:left"';
7306: }elsif($activetab eq $field){
7307: $active = 'style="display:block;float:left"';
7308: }
7309: $form .= '<div id="'.$field.$tid.'"'
7310: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
7311: .'</div>'."\n";
7312: }
7313: }
7314: unless ($env{'form.docslog'}) {
7315: $form .= '</div></div>'."\n";
7316: }
7317: return $form;
7318: }
7319:
7320: sub editing_js {
7321: my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,
7322: $londocroot,$canedit,$hostname,$navmapref) = @_;
7323: my %js_lt = &Apache::lonlocal::texthash(
7324: p_mnf => 'Name of New Folder',
7325: t_mnf => 'New Folder',
7326: p_mnp => 'Name of New Page',
7327: t_mnp => 'New Page',
7328: p_mxu => 'Title for the External Score',
7329: p_msp => 'Name of Simple Course Page',
7330: p_msb => 'Title for the Problem',
7331: p_mdb => 'Title for the Drop Box',
7332: p_mbb => 'Title for the Discussion Board',
7333: p_mwp => 'Title for Web Page',
7334: p_mnr => 'Title for the Resource',
7335: p_mab => "Enter user:domain for User's Personal Information Page",
7336: p_mab2 => 'Personal Information Page of ',
7337: p_mab_alrt1 => 'Not a valid user:domain',
7338: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
7339: p_chn => 'New Title',
7340: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
7341: p_rmr2a => 'Remove',
7342: p_rmr2b => '?',
7343: p_rmr3a => 'Remove those',
7344: p_rmr3b => 'items?',
7345: p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".',
7346: p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.',
7347: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
7348: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
7349: p_ctr2a => 'Cut',
7350: p_ctr2b => '?',
7351: p_ctr3a => 'Cut those',
7352: p_ctr3b => 'items?',
7353: setal => 'Enter a (unique) alias',
7354: delal => 'Are you sure you want to eliminate the alias?',
7355: rpck => 'Enter number to pick (e.g., 3)',
7356: imsfile => 'You must choose an IMS package for import',
7357: imscms => 'You must select which Course Management System was the source of the IMS package',
7358: invurl => 'Invalid URL',
7359: titbl => 'Title is blank',
7360: more => '(More ...)',
7361: less => '(Less ...)',
7362: noor => 'No actions selected or changes to settings specified.',
7363: noch => 'No changes to settings specified.',
7364: noac => 'No actions selected.',
7365: nofi => 'No file selected',
7366: tinc => 'Title in course',
7367: sunm => 'Sub-directory name',
7368: edri => 'Editing rights unavailable for your current role.',
7369: );
7370: &js_escape(\%js_lt);
7371: my $crstype = &Apache::loncommon::course_type();
7372: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
7373: my $main_container_page;
7374: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
7375: $main_container_page = 1;
7376: }
7377: my $backtourl;
7378: my $toplevelmain = &escape(&default_folderpath($coursenum,$coursedom,$navmapref));
7379: my $toplevelsupp = &supplemental_base();
7380:
7381: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
7382: my $caller = $1;
7383: if ($caller =~ /^supplemental/) {
7384: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
7385: } else {
7386: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
7387: $res = &Apache::lonnet::clutter($res);
7388: if (&Apache::lonnet::is_on_map($res)) {
7389: my ($url,$anchor);
7390: if ($res =~ /^([^#]+)#([^#]+)$/) {
7391: $url = $1;
7392: $anchor = $2;
7393: if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) {
7394: $caller = $1.&escape('#').$anchor;
7395: }
7396: } else {
7397: $url = $res;
7398: }
7399: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"');
7400: if ($backtourl =~ m{^\Q/uploaded/$coursedom/$coursenum/\Edefault_\d+\.sequence$}) {
7401: $backtourl .= '?navmap=1';
7402: } else {
7403: $backtourl .= '?symb='.
7404: &HTML::Entities::encode($caller,'<>&"');
7405: }
7406: if ($backtourl =~ m{^\Q/public/$coursedom/$coursenum/syllabus\E}) {
7407: if (($ENV{'SERVER_PORT'} == 443) &&
7408: ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ m{^http://})) {
7409: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
7410: if ($hostname ne '') {
7411: $backtourl = 'http://'.$hostname.$backtourl;
7412: }
7413: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
7414: }
7415: }
7416: } elsif ($backtourl =~ m{^/adm/wrapper/ext/(?!https:)}) {
7417: if (($ENV{'SERVER_PORT'} == 443) && ($hostname ne '')) {
7418: unless ((&Apache::lonnet::uses_sts()) || (&Apache::lonnet::waf_allssl($hostname))) {
7419: if ($hostname ne '') {
7420: $backtourl = 'http://'.$hostname.$backtourl;
7421: }
7422: $backtourl .= (($backtourl =~ /\?/) ? '&':'?').'usehttp=1';
7423: }
7424: }
7425: }
7426: if ($anchor ne '') {
7427: $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"');
7428: }
7429: $backtourl = &Apache::loncommon::escape_single($backtourl);
7430: } else {
7431: $backtourl = '/adm/navmaps';
7432: }
7433: }
7434: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
7435: $backtourl = '/adm/menu';
7436: } elsif ($supplementalflag) {
7437: if (($env{'request.role.adv'}) ||
7438: (&Apache::lonnet::has_unhidden_suppfiles($coursenum,$coursedom))) {
7439: $backtourl = '/adm/supplemental';
7440: } else {
7441: $backtourl = '/adm/navmaps';
7442: }
7443: } else {
7444: $backtourl = '/adm/navmaps';
7445: }
7446:
7447: my $fieldsets = "'doc'";
7448: unless ($main_container_page) {
7449: $fieldsets .=",'ims'";
7450: }
7451: my $extfieldsets = "'ext'";
7452: if ($posslti) {
7453: $extfieldsets .= ",'tool'";
7454: }
7455: if ($supplementalflag) {
7456: $fieldsets = "'suppdoc'";
7457: $extfieldsets = "'suppext'";
7458: if ($posslti) {
7459: $extfieldsets .= ",'supptool'";
7460: }
7461: }
7462:
7463: my $jsmakefunctions;
7464: if ($canedit) {
7465: $jsmakefunctions = <<ENDNEWSCRIPT;
7466: function makenewfolder(targetform,folderseq) {
7467: var foldername=prompt('$js_lt{"p_mnf"}','$js_lt{"t_mnf"}');
7468: if (foldername) {
7469: targetform.importdetail.value=encodeURIComponent(foldername)+"="+folderseq;
7470: targetform.submit();
7471: }
7472: }
7473:
7474: function makenewpage(targetform,folderseq) {
7475: var pagename=prompt('$js_lt{"p_mnp"}','$js_lt{"t_mnp"}');
7476: if (pagename) {
7477: targetform.importdetail.value=encodeURIComponent(pagename)+"="+folderseq;
7478: targetform.submit();
7479: }
7480: }
7481:
7482: function makeexamupload() {
7483: var title=prompt('$js_lt{"p_mxu"}');
7484: if (title) {
7485: this.document.forms.newexamupload.importdetail.value=
7486: encodeURIComponent(title)+'=/res/lib/templates/examupload.problem';
7487: this.document.forms.newexamupload.submit();
7488: }
7489: }
7490:
7491: function makesmppage() {
7492: var title=prompt('$js_lt{"p_msp"}');
7493: if (title) {
7494: this.document.forms.newsmppg.importdetail.value=
7495: encodeURIComponent(title)+'=/adm/$udom/$uname/new/smppg';
7496: this.document.forms.newsmppg.submit();
7497: }
7498: }
7499:
7500: function makewebpage(type) {
7501: var title=prompt('$js_lt{"p_mwp"}');
7502: var formname;
7503: if (type == 'supp') {
7504: formname = this.document.forms.supwebpage;
7505: } else {
7506: formname = this.document.forms.newwebpage;
7507: }
7508: if (title) {
7509: var webpage = formname.importdetail.value;
7510: formname.importdetail.value = encodeURIComponent(title)+'='+webpage;
7511: formname.submit();
7512: }
7513: }
7514:
7515: function makesmpproblem() {
7516: var title=prompt('$js_lt{"p_msb"}');
7517: if (title) {
7518: this.document.forms.newsmpproblem.importdetail.value=
7519: encodeURIComponent(title)+'=/res/lib/templates/simpleproblem.problem';
7520: this.document.forms.newsmpproblem.submit();
7521: }
7522: }
7523:
7524: function makedropbox() {
7525: var title=prompt('$js_lt{"p_mdb"}');
7526: if (title) {
7527: this.document.forms.newdropbox.importdetail.value=
7528: encodeURIComponent(title)+'=/res/lib/templates/DropBox.problem';
7529: this.document.forms.newdropbox.submit();
7530: }
7531: }
7532:
7533: function makebulboard() {
7534: var title=prompt('$js_lt{"p_mbb"}');
7535: if (title) {
7536: this.document.forms.newbul.importdetail.value=
7537: encodeURIComponent(title)+'=/adm/$udom/$uname/new/bulletinboard';
7538: this.document.forms.newbul.submit();
7539: }
7540: }
7541:
7542: function makeabout() {
7543: var user=prompt("$js_lt{'p_mab'}");
7544: if (user) {
7545: var comp=new Array();
7546: comp=user.split(':');
7547: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
7548: if ((comp[0]) && (comp[1])) {
7549: this.document.forms.newaboutsomeone.importdetail.value=
7550: '$js_lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
7551: this.document.forms.newaboutsomeone.submit();
7552: } else {
7553: alert("$js_lt{'p_mab_alrt1'}");
7554: }
7555: } else {
7556: alert("$js_lt{'p_mab_alrt2'}");
7557: }
7558: }
7559: }
7560:
7561: function makenew(targetform) {
7562: targetform.submit();
7563: }
7564:
7565: function changename(folderpath,index,oldtitle) {
7566: var title=prompt('$js_lt{"p_chn"}',oldtitle);
7567: if (title) {
7568: this.document.forms.renameform.markcopy.value='';
7569: this.document.forms.renameform.title.value=title;
7570: this.document.forms.renameform.cmd.value='rename_'+index;
7571: this.document.forms.renameform.folderpath.value=folderpath;
7572: this.document.forms.renameform.submit();
7573: }
7574: }
7575:
7576: function setalias(folderpath,index) {
7577: var alias = prompt('$js_lt{"setal"}');
7578: if ((alias != null) && (alias != '')) {
7579: this.document.forms.aliasform.alias.value=alias;
7580: this.document.forms.aliasform.cmd.value='setalias_'+index;
7581: this.document.forms.aliasform.folderpath.value=folderpath;
7582: this.document.forms.aliasform.submit();
7583: }
7584: }
7585:
7586: function delalias(folderpath,index) {
7587: if (confirm('$js_lt{"delal"}')) {
7588: this.document.forms.aliasform.cmd.value='delalias_'+index;
7589: this.document.forms.aliasform.folderpath.value=folderpath;
7590: this.document.forms.aliasform.submit();
7591: }
7592: }
7593:
7594: ENDNEWSCRIPT
7595: } else {
7596: $jsmakefunctions = <<ENDNEWSCRIPT;
7597:
7598: function makenewfolder() {
7599: alert("$js_lt{'edri'}");
7600: }
7601:
7602: function makenewpage() {
7603: alert("$js_lt{'edri'}");
7604: }
7605:
7606: function makeexamupload() {
7607: alert("$js_lt{'edri'}");
7608: }
7609:
7610: function makesmppage() {
7611: alert("$js_lt{'edri'}");
7612: }
7613:
7614: function makewebpage(type) {
7615: alert("$js_lt{'edri'}");
7616: }
7617:
7618: function makesmpproblem() {
7619: alert("$js_lt{'edri'}");
7620: }
7621:
7622: function makedropbox() {
7623: alert("$js_lt{'edri'}");
7624: }
7625:
7626: function makebulboard() {
7627: alert("$js_lt{'edri'}");
7628: }
7629:
7630: function makeabout() {
7631: alert("$js_lt{'edri'}");
7632: }
7633:
7634: function changename() {
7635: alert("$js_lt{'edri'}");
7636: }
7637:
7638: function setalias() {
7639: alert("$js_lt{'edri'}");
7640: }
7641:
7642: function delalias() {
7643: alert("$js_lt{'edri'}");
7644: }
7645:
7646: function makenew() {
7647: alert("$js_lt{'edri'}");
7648: }
7649:
7650: function groupimport() {
7651: alert("$js_lt{'edri'}");
7652: }
7653:
7654: function groupsearch() {
7655: alert("$js_lt{'edri'}");
7656: }
7657:
7658: function groupopen(url,recover) {
7659: var options="scrollbars=1,resizable=1,menubar=0";
7660: idxflag=1;
7661: idx=open("/adm/groupsort?inhibitmenu=yes&mode=simple&recover="+recover+"&readfile="+url,"idxout",options);
7662: idx.focus();
7663: }
7664:
7665: ENDNEWSCRIPT
7666:
7667: }
7668: return <<ENDSCRIPT;
7669:
7670: $jsmakefunctions
7671:
7672: function toggleUpload(caller) {
7673: var blocks = Array($fieldsets);
7674: for (var i=0; i<blocks.length; i++) {
7675: var disp = 'none';
7676: if (caller == blocks[i]) {
7677: var curr = document.getElementById('upload'+caller+'form').style.display;
7678: if (curr == 'none') {
7679: disp='block';
7680: }
7681: }
7682: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
7683: }
7684: resize_scrollbox('contentscroll','1','1');
7685: return;
7686: }
7687:
7688: function toggleExternal(caller) {
7689: var blocks = Array($extfieldsets);
7690: for (var i=0; i<blocks.length; i++) {
7691: var disp = 'none';
7692: if (caller == blocks[i]) {
7693: var curr = document.getElementById('external'+caller+'form').style.display;
7694: if (curr == 'none') {
7695: disp='block';
7696: }
7697: }
7698: document.getElementById('external'+blocks[i]+'form').style.display=disp;
7699: if ((caller == 'tool') || (caller == 'supptool')) {
7700: if (disp == 'block') {
7701: if (document.getElementById('LC_exttoolid')) {
7702: var toolselector = document.getElementById('LC_exttoolid');
7703: var suppflag = 0;
7704: if (caller == 'supptool') {
7705: suppflag = 1;
7706: }
7707: currForm = document.getElementById('new'+caller);
7708: updateExttool(toolselector,currForm,suppflag);
7709: }
7710: }
7711: }
7712: }
7713: resize_scrollbox('contentscroll','1','1');
7714: return;
7715: }
7716:
7717: function toggleMap(caller) {
7718: var disp = 'none';
7719: if (document.getElementById('importmapform')) {
7720: if (caller == 'map') {
7721: var curr = document.getElementById('importmapform').style.display;
7722: if (curr == 'none') {
7723: disp='block';
7724: }
7725: }
7726: document.getElementById('importmapform').style.display=disp;
7727: resize_scrollbox('contentscroll','1','1');
7728: }
7729: return;
7730: }
7731:
7732: function toggleCrsRes(caller,numauthorrole,numcrsdirs) {
7733: var disp = 'none';
7734: if (document.getElementById('crsresform')) {
7735: if (caller == 'res') {
7736: var curr = document.getElementById('crsresform').style.display;
7737: if (curr == 'none') {
7738: disp='block';
7739: numauthor = parseInt(numauthorrole);
7740: if (numauthor > 0) {
7741: document.courseresform.authorrole.selectedIndex = 0;
7742: select1priv_changed();
7743: document.courseresform.authorpath.selectedIndex = 0;
7744: document.courseresform.newresourceadd.selectedIndex = 0;
7745: toggleNewInCourse(document.courseresform);
7746: if (document.getElementById('newresource')) {
7747: document.getElementById('newresource').style.display = 'none';
7748: }
7749: } else {
7750: if (numcrsdirs) {
7751: document.courseresform.authorpath.selectedIndex = 0;
7752: }
7753: }
7754: if (document.courseresform.newresusetemp.length) {
7755: document.courseresform.newresusetemp[0].checked = true;
7756: toggleWithTemplate(document.courseresform);
7757: }
7758: document.courseresform.newresourcename.value = '';
7759: }
7760: }
7761: if (document.courseresform.newsubdir.length) {
7762: for (var j=0; j<document.courseresform.newsubdir.length; j++) {
7763: if (document.courseresform.newsubdir[j].value == 0) {
7764: document.courseresform.newsubdir[j].checked = true;
7765: }
7766: break;
7767: }
7768: if (document.getElementById('newsubdirname')) {
7769: document.getElementById('newsubdirname').type = "hidden";
7770: document.getElementById('newsubdirname').value = "";
7771: }
7772: if (document.getElementById('newsubdir')) {
7773: document.getElementById('newsubdir').innerHTML = "";
7774: }
7775: }
7776: document.getElementById('crsresform').style.display=disp;
7777: resize_scrollbox('contentscroll','1','0');
7778: }
7779: return;
7780: }
7781:
7782: function toggleNewsubdir(form) {
7783: if (form.newsubdir.length) {
7784: for (var j=0; j<form.newsubdir.length; j++) {
7785: if (form.newsubdir[j].checked) {
7786: if (document.getElementById('newsubdirname')) {
7787: if (form.newsubdir[j].value == '1') {
7788: document.getElementById('newsubdirname').type = "text";
7789: if (document.getElementById('newsubdir')) {
7790: document.getElementById('newsubdir').innerHTML = '<br />$js_lt{'sunm'}';
7791: }
7792: } else {
7793: document.getElementById('newsubdirname').type = "hidden";
7794: document.getElementById('newsubdirname').value = "";
7795: document.getElementById('newsubdir').innerHTML = "";
7796: }
7797: }
7798: break;
7799: }
7800: }
7801: }
7802: }
7803:
7804: function toggleCrsResTitle() {
7805: if (document.getElementById('newresource')) {
7806: if (document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value == 'course') {
7807: document.getElementById('newresource').style.display = 'inline';
7808: document.courseresform.newresourceadd[0].checked = true;
7809: toggleNewInCourse(document.courseresform);
7810: } else {
7811: document.getElementById('newresource').style.display = 'none';
7812: }
7813: }
7814: }
7815:
7816: function toggleNewInCourse(form) {
7817: if (form.newresourceadd.length) {
7818: for (var i=0; i<form.newresourceadd.length; i++) {
7819: if (form.newresourceadd[i].checked) {
7820: if (document.getElementById('newresourcetitle')) {
7821: if (form.newresourceadd[i].value == '1') {
7822: document.getElementById('newresourcetitle').type = 'text';
7823: if (document.getElementById('newrestitle')) {
7824: document.getElementById('newrestitle').innerHTML = "<br />$js_lt{'tinc'}";
7825: }
7826: } else {
7827: document.getElementById('newresourcetitle').type = 'hidden';
7828: document.getElementById('newresourcetitle').value = '';
7829: if (document.getElementById('newrestitle')) {
7830: document.getElementById('newrestitle').innerHTML = '';
7831: }
7832: }
7833: }
7834: break;
7835: }
7836: }
7837: }
7838: }
7839:
7840: function toggleWithTemplate(form) {
7841: if (form.newresusetemp.length) {
7842: for (var i=0; i<form.newresusetemp.length; i++) {
7843: if (form.newresusetemp[i].checked) {
7844: if (document.getElementById('newrestemplate')) {
7845: if (form.newresusetemp[i].value == '1') {
7846: document.getElementById('newrestemplate').style.display = 'inline';
7847: toggleExampleText();
7848: } else {
7849: form.tempcategory.selectedIndex = 0;
7850: select1template_changed();
7851: document.getElementById('newrestemplate').style.display = 'none';
7852: }
7853: }
7854: }
7855: }
7856: }
7857: }
7858:
7859: function toggleExampleText() {
7860: if (document.getElementById('newresexample')) {
7861: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7862: if (url == '') {
7863: document.getElementById('newresexample').style.fontWeight = 'normal';
7864: } else {
7865: document.getElementById('newresexample').style.fontWeight = 'bold';
7866: }
7867: }
7868: }
7869:
7870: function getExample(width,height,scrolling,transparency) {
7871: var url;
7872: if (document.courseresform.newresusetemp.length) {
7873: for (var i=0; i<document.courseresform.newresusetemp.length; i++) {
7874: if (document.courseresform.newresusetemp[i].checked) {
7875: if (document.courseresform.newresusetemp[i].value == '1') {
7876: var url = document.courseresform.template.options[document.courseresform.template.selectedIndex].value;
7877: if (url == '') {
7878: alert('Pick a category and template');
7879: } else {
7880: url = url.replace("$londocroot","");
7881: url += '?inhibitmenu=yes';
7882: }
7883: }
7884: break;
7885: }
7886: }
7887: }
7888: if (url != '') {
7889: openMyModal(url,width,height,scrolling,transparency,'');
7890: }
7891: }
7892:
7893: function toggleImportCrsres(caller,dircount) {
7894: var disp = 'none';
7895: if (document.getElementById('importcrsresform')) {
7896: if (caller == 'res') {
7897: var numdirs = parseInt(dircount);
7898: var curr = document.getElementById('importcrsresform').style.display;
7899: if (curr == 'none') {
7900: disp='block';
7901: if (numdirs > 1) {
7902: select1res_changed();
7903: }
7904: }
7905: }
7906: document.getElementById('importcrsresform').style.display=disp;
7907: resize_scrollbox('contentscroll','1','0');
7908: }
7909: return;
7910: }
7911:
7912: function makeims(imsform) {
7913: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
7914: alert("$js_lt{'imsfile'}");
7915: return;
7916: }
7917: if (imsform.source.selectedIndex == 0) {
7918: alert("$js_lt{'imscms'}");
7919: return;
7920: }
7921: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
7922: imsform.submit();
7923: }
7924:
7925: function updatePick(targetform,index,caller) {
7926: var pickitem;
7927: var picknumitem;
7928: var picknumtext;
7929: if (index == 'all') {
7930: pickitem = document.getElementById('randompickall');
7931: picknumitem = document.getElementById('rpicknumall');
7932: picknumtext = document.getElementById('rpicktextall');
7933: } else {
7934: pickitem = document.getElementById('randompick_'+index);
7935: picknumitem = document.getElementById('rpicknum_'+index);
7936: picknumtext = document.getElementById('randompicknum_'+index);
7937: }
7938: if (pickitem.checked) {
7939: var picknum=prompt('$js_lt{"rpck"}',picknumitem.value);
7940: if (picknum == '' || picknum == null) {
7941: if (caller == 'check') {
7942: pickitem.checked=false;
7943: if (index == 'all') {
7944: picknumtext.innerHTML = '';
7945: if (caller == 'link') {
7946: propagateState(targetform,'rpicknum');
7947: }
7948: } else {
7949: checkForSubmit(targetform,'randompick','settings');
7950: }
7951: }
7952: } else {
7953: picknum.toString();
7954: var regexdigit=/^\\d+\$/;
7955: if (regexdigit.test(picknum)) {
7956: picknumitem.value = picknum;
7957: if (index == 'all') {
7958: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
7959: if (caller == 'link') {
7960: propagateState(targetform,'rpicknum');
7961: }
7962: } else {
7963: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
7964: checkForSubmit(targetform,'randompick','settings');
7965: }
7966: } else {
7967: if (caller == 'check') {
7968: if (index == 'all') {
7969: picknumtext.innerHTML = '';
7970: if (caller == 'link') {
7971: propagateState(targetform,'rpicknum');
7972: }
7973: } else {
7974: pickitem.checked=false;
7975: checkForSubmit(targetform,'randompick','settings');
7976: }
7977: }
7978: return;
7979: }
7980: }
7981: } else {
7982: picknumitem.value = '';
7983: picknumtext.innerHTML = '';
7984: if (index == 'all') {
7985: if (caller == 'link') {
7986: propagateState(targetform,'rpicknum');
7987: }
7988: } else {
7989: checkForSubmit(targetform,'randompick','settings');
7990: }
7991: }
7992: }
7993:
7994: function propagateState(form,param) {
7995: if (document.getElementById(param+'all')) {
7996: var setcheck = 0;
7997: var rpick = 0;
7998: if (param == 'rpicknum') {
7999: if (document.getElementById('randompickall')) {
8000: if (document.getElementById('randompickall').checked) {
8001: if (document.getElementById('rpicknumall')) {
8002: rpick = document.getElementById('rpicknumall').value;
8003: }
8004: }
8005: }
8006: } else {
8007: if (document.getElementById(param+'all').checked) {
8008: setcheck = 1;
8009: }
8010: }
8011: var allidxlist;
8012: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
8013: if (document.getElementById('all'+param+'idx')) {
8014: allidxlist = document.getElementById('all'+param+'idx').value;
8015: }
8016: var actions = new Array ('remove','cut','copy');
8017: for (var i=0; i<actions.length; i++) {
8018: if (actions[i] != param) {
8019: if (document.getElementById(actions[i]+'all')) {
8020: document.getElementById(actions[i]+'all').checked = false;
8021: }
8022: }
8023: }
8024: }
8025: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
8026: allidxlist = form.allidx.value;
8027: }
8028: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
8029: allidxlist = form.allmapidx.value;
8030: }
8031: if ((allidxlist != '') && (allidxlist != null)) {
8032: var allidxs = allidxlist.split(',');
8033: if (allidxs.length > 1) {
8034: for (var i=0; i<allidxs.length; i++) {
8035: if (document.getElementById(param+'_'+allidxs[i])) {
8036: if (param == 'rpicknum') {
8037: if (document.getElementById('randompick_'+allidxs[i])) {
8038: if (document.getElementById('randompick_'+allidxs[i]).checked) {
8039: document.getElementById(param+'_'+allidxs[i]).value = rpick;
8040: if (rpick > 0) {
8041: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
8042: } else {
8043: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
8044: }
8045: }
8046: }
8047: } else {
8048: if (setcheck == 1) {
8049: document.getElementById(param+'_'+allidxs[i]).checked = true;
8050: } else {
8051: document.getElementById(param+'_'+allidxs[i]).checked = false;
8052: if (param == 'randompick') {
8053: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
8054: }
8055: }
8056: }
8057: }
8058: }
8059: if (setcheck == 1) {
8060: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
8061: var actions = new Array('copy','cut','remove');
8062: for (var i=0; i<actions.length; i++) {
8063: var otheractions;
8064: var otheridxs;
8065: if (actions[i] === param) {
8066: continue;
8067: } else {
8068: if (document.getElementById('all'+actions[i]+'idx')) {
8069: otheractions = document.getElementById('all'+actions[i]+'idx').value;
8070: otheridxs = otheractions.split(',');
8071: if (otheridxs.length > 1) {
8072: for (var j=0; j<otheridxs.length; j++) {
8073: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
8074: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
8075: }
8076: }
8077: }
8078: }
8079: }
8080: }
8081: }
8082: }
8083: }
8084: }
8085: }
8086: return;
8087: }
8088:
8089: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) {
8090: var canedit = '$canedit';
8091: if (canedit == '') {
8092: alert("$js_lt{'edri'}");
8093: return;
8094: }
8095: var dosettings;
8096: var doaction;
8097: var control = document.togglemultsettings;
8098: if (context == 'actions') {
8099: control = document.togglemultactions;
8100: doaction = 1;
8101: } else {
8102: dosettings = 1;
8103: }
8104: if (control) {
8105: if (control.showmultpick.length) {
8106: for (var i=0; i<control.showmultpick.length; i++) {
8107: if (control.showmultpick[i].checked) {
8108: if (control.showmultpick[i].value == 1) {
8109: if (context == 'settings') {
8110: dosettings = 0;
8111: } else {
8112: doaction = 0;
8113: }
8114: }
8115: }
8116: }
8117: }
8118: }
8119: if (context == 'settings') {
8120: if (dosettings == 1) {
8121: targetform.changeparms.value=param;
8122: targetform.submit();
8123: }
8124: }
8125: if (context == 'actions') {
8126: if (doaction == 1) {
8127: targetform.cmd.value=param+'_'+index;
8128: targetform.folderpath.value=folderpath;
8129: targetform.markcopy.value=idx+':'+param;
8130: targetform.copyfolder.value=folder+'.'+container;
8131: if (param == 'remove') {
8132: var doremove = 0;
8133: if (skip_confirm) {
8134: if (confirm_removal) {
8135: if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) {
8136: doremove = 1;
8137: }
8138: } else {
8139: doremove = 1;
8140: }
8141: } else {
8142: if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) {
8143: doremove = 1;
8144: }
8145: }
8146: if (doremove) {
8147: targetform.markcopy.value='';
8148: targetform.copyfolder.value='';
8149: targetform.submit();
8150: }
8151: }
8152: if (param == 'cut') {
8153: if (skip_confirm || confirm('$js_lt{"p_ctr1a"}\\n$js_lt{"p_ctr1b"}\\n\\n$js_lt{"p_ctr2a"} "'+oldtitle+'" $js_lt{"p_ctr2b"}')) {
8154: targetform.submit();
8155: return;
8156: }
8157: }
8158: if (param == 'copy') {
8159: targetform.submit();
8160: return;
8161: }
8162: targetform.markcopy.value='';
8163: targetform.copyfolder.value='';
8164: targetform.cmd.value='';
8165: targetform.folderpath.value='';
8166: return;
8167: } else {
8168: if (document.getElementById(param+'_'+idx)) {
8169: item = document.getElementById(param+'_'+idx);
8170: if (item.type == 'checkbox') {
8171: if (item.checked) {
8172: item.checked = false;
8173: } else {
8174: item.checked = true;
8175: singleCheck(item,idx,param);
8176: }
8177: }
8178: }
8179: }
8180: }
8181: return;
8182: }
8183:
8184: function singleCheck(caller,idx,action) {
8185: actions = new Array('cut','copy','remove');
8186: if (caller.checked) {
8187: for (var i=0; i<actions.length; i++) {
8188: if (actions[i] != action) {
8189: if (document.getElementById(actions[i]+'_'+idx)) {
8190: if (document.getElementById(actions[i]+'_'+idx).checked) {
8191: document.getElementById(actions[i]+'_'+idx).checked = false;
8192: }
8193: }
8194: }
8195: }
8196: }
8197: return;
8198: }
8199:
8200: function unselectInactive(nav) {
8201: currentNav = document.getElementById(nav);
8202: currentLis = currentNav.getElementsByTagName('LI');
8203: for (i = 0; i < currentLis.length; i++) {
8204: if (currentLis[i].className == 'goback') {
8205: currentLis[i].className = 'goback';
8206: } else {
8207: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
8208: currentLis[i].className = 'right';
8209: } else {
8210: currentLis[i].className = 'i';
8211: }
8212: }
8213: }
8214: }
8215:
8216: function hideAll(current, nav, data) {
8217: unselectInactive(nav);
8218: if (current) {
8219: if (current.className == 'right'){
8220: current.className = 'right active'
8221: } else {
8222: current.className = 'active';
8223: }
8224: }
8225: currentData = document.getElementById(data);
8226: currentDivs = currentData.getElementsByTagName('DIV');
8227: for (i = 0; i < currentDivs.length; i++) {
8228: if(currentDivs[i].className == 'LC_ContentBox'){
8229: currentDivs[i].style.display = 'none';
8230: }
8231: }
8232: }
8233:
8234: function openTabs(pageId) {
8235: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
8236: if(tabnav.length > 2 ){
8237: currentNav = document.getElementById(tabnav[1].id);
8238: currentLis = currentNav.getElementsByTagName('LI');
8239: for(i = 0; i< currentLis.length; i++){
8240: if(currentLis[i].className == 'active') {
8241: funcString = currentLis[i].onclick.toString();
8242: tab = funcString.split('"');
8243: if(tab.length < 2) {
8244: tab = funcString.split("'");
8245: }
8246: currentData = document.getElementById(tab[1]);
8247: currentData.style.display = 'block';
8248: }
8249: }
8250: }
8251: }
8252:
8253: function showPage(current, pageId, nav, data) {
8254: currstate = current.className;
8255: hideAll(current, nav, data);
8256: openTabs(pageId);
8257: unselectInactive(nav);
8258: if ((currstate == 'active') || (currstate == 'right active')) {
8259: if (currstate == 'active') {
8260: current.className = '';
8261: } else {
8262: current.className = 'right';
8263: }
8264: activeTab = '';
8265: toggleExternal();
8266: toggleUpload();
8267: toggleMap();
8268: toggleCrsRes();
8269: toggleImportCrsres();
8270: resize_scrollbox('contentscroll','1','0');
8271: return;
8272: } else {
8273: current.className = 'active';
8274: }
8275: currentData = document.getElementById(pageId);
8276: currentData.style.display = 'block';
8277: activeTab = pageId;
8278: toggleExternal();
8279: toggleUpload();
8280: toggleMap();
8281: toggleCrsRes();
8282: toggleImportCrsres();
8283: if (nav == 'mainnav') {
8284: var storedpath = "$docs_folderpath";
8285: var storedpage = "$main_container_page";
8286: var reg = new RegExp("^supplemental");
8287: if (pageId == 'mainCourseDocuments') {
8288: if (storedpage == 1) {
8289: document.simpleedit.folderpath.value = '';
8290: document.uploaddocument.folderpath.value = '';
8291: } else {
8292: if (reg.test(storedpath)) {
8293: document.simpleedit.folderpath.value = '$toplevelmain';
8294: document.uploaddocument.folderpath.value = '$toplevelmain';
8295: document.newext.folderpath.value = '$toplevelmain';
8296: } else {
8297: document.simpleedit.folderpath.value = storedpath;
8298: document.uploaddocument.folderpath.value = storedpath;
8299: document.newext.folderpath.value = storedpath;
8300: }
8301: }
8302: } else {
8303: if (reg.test(storedpath)) {
8304: document.simpleedit.folderpath.value = storedpath;
8305: document.supuploaddocument.folderpath.value = storedpath;
8306: document.supnewext.folderpath.value = storedpath;
8307: } else {
8308: document.simpleedit.folderpath.value = '$toplevelsupp';
8309: document.supuploaddocument.folderpath.value = '$toplevelsupp';
8310: document.supnewext.folderpath.value = '$toplevelsupp';
8311: }
8312: }
8313: }
8314: resize_scrollbox('contentscroll','1','0');
8315: return false;
8316: }
8317:
8318: function toContents(jumpto) {
8319: var newurl = '$backtourl';
8320: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
8321: newurl = newurl+'?postdata='+jumpto;
8322: }
8323: location.href=newurl;
8324: }
8325:
8326: function togglePick(caller,value) {
8327: var disp = 'none';
8328: if (document.getElementById('multi'+caller)) {
8329: var curr = document.getElementById('multi'+caller).style.display;
8330: if (value == 1) {
8331: disp='block';
8332: }
8333: if (curr == disp) {
8334: return;
8335: }
8336: document.getElementById('multi'+caller).style.display=disp;
8337: if (value == 1) {
8338: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
8339: } else {
8340: document.getElementById('more'+caller).innerHTML = '';
8341: }
8342: if (caller == 'actions') {
8343: setClass(value);
8344: setBoxes(value);
8345: }
8346: }
8347: var showButton = multiSettings();
8348: if (showButton != 1) {
8349: showButton = multiActions();
8350: }
8351: if (document.getElementById('multisave')) {
8352: if (showButton == 1) {
8353: document.getElementById('multisave').style.display='block';
8354: } else {
8355: document.getElementById('multisave').style.display='none';
8356: }
8357: }
8358: resize_scrollbox('contentscroll','1','1');
8359: return;
8360: }
8361:
8362: function toggleCheckUncheck(caller,more) {
8363: if (more == 1) {
8364: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$js_lt{'less'}</a>';
8365: document.getElementById('allfields'+caller).style.display='block';
8366: } else {
8367: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$js_lt{'more'}</a>';
8368: document.getElementById('allfields'+caller).style.display='none';
8369: }
8370: resize_scrollbox('contentscroll','1','1');
8371: }
8372:
8373: function multiSettings() {
8374: var inuse = 0;
8375: var settingsform = document.togglemultsettings;
8376: if (settingsform.showmultpick.length > 1) {
8377: for (var i=0; i<settingsform.showmultpick.length; i++) {
8378: if (settingsform.showmultpick[i].checked) {
8379: if (settingsform.showmultpick[i].value == 1) {
8380: inuse = 1;
8381: }
8382: }
8383: }
8384: }
8385: return inuse;
8386: }
8387:
8388: function multiActions() {
8389: var inuse = 0;
8390: var actionsform = document.togglemultactions;
8391: if (actionsform.showmultpick.length > 1) {
8392: for (var i=0; i<actionsform.showmultpick.length; i++) {
8393: if (actionsform.showmultpick[i].checked) {
8394: if (actionsform.showmultpick[i].value == 1) {
8395: inuse = 1;
8396: }
8397: }
8398: }
8399: }
8400: return inuse;
8401: }
8402:
8403: function checkSubmits() {
8404: var numchanges = 0;
8405: var form = document.saveactions;
8406: var doactions = multiActions();
8407: var cutwarnings = 0;
8408: var remwarnings = 0;
8409: var removalinfo = 0;
8410: if (doactions == 1) {
8411: var remidxlist = document.cumulativeactions.allremoveidx.value;
8412: if ((remidxlist != '') && (remidxlist != null)) {
8413: var remidxs = remidxlist.split(',');
8414: for (var i=0; i<remidxs.length; i++) {
8415: if (document.getElementById('remove_'+remidxs[i])) {
8416: if (document.getElementById('remove_'+remidxs[i]).checked) {
8417: form.multiremove.value += remidxs[i]+',';
8418: numchanges ++;
8419: if (document.getElementById('skip_remove_'+remidxs[i])) {
8420: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
8421: remwarnings ++;
8422: }
8423: }
8424: if (document.getElementById('confirm_removal_'+remidxs[i])) {
8425: if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) {
8426: removalinfo ++;
8427: }
8428: }
8429: }
8430: }
8431: }
8432: }
8433: var cutidxlist = document.cumulativeactions.allcutidx.value;
8434: if ((cutidxlist != '') && (cutidxlist != null)) {
8435: var cutidxs = cutidxlist.split(',');
8436: for (var i=0; i<cutidxs.length; i++) {
8437: if (document.getElementById('cut_'+cutidxs[i])) {
8438: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
8439: form.multicut.value += cutidxs[i]+',';
8440: numchanges ++;
8441: if (document.getElementById('skip_cut_'+cutidxs[i])) {
8442: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
8443: cutwarnings ++;
8444: }
8445: }
8446: }
8447: }
8448: }
8449: }
8450: var copyidxlist = document.cumulativeactions.allcopyidx.value;
8451: if ((copyidxlist != '') && (copyidxlist != null)) {
8452: var copyidxs = copyidxlist.split(',');
8453: for (var i=0; i<copyidxs.length; i++) {
8454: if (document.getElementById('copy_'+copyidxs[i])) {
8455: if (document.getElementById('copy_'+copyidxs[i]).checked) {
8456: form.multicopy.value += copyidxs[i]+',';
8457: numchanges ++;
8458: }
8459: }
8460: }
8461: }
8462: if (numchanges > 0) {
8463: form.multichange.value = numchanges;
8464: }
8465: }
8466: var dosettings = multiSettings();
8467: var haschanges = 0;
8468: if (dosettings == 1) {
8469: form.allencrypturl.value = '';
8470: form.allhiddenresource.value = '';
8471: form.changeparms.value = 'all';
8472: var patt=new RegExp(",\$");
8473: var allidxlist = document.cumulativesettings.allidx.value;
8474: if ((allidxlist != '') && (allidxlist != null)) {
8475: var allidxs = allidxlist.split(',');
8476: if (allidxs.length > 1) {
8477: for (var i=0; i<allidxs.length; i++) {
8478: if (document.getElementById('hiddenresource_'+allidxs[i])) {
8479: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
8480: form.allhiddenresource.value += allidxs[i]+',';
8481: }
8482: }
8483: if (document.getElementById('encrypturl_'+allidxs[i])) {
8484: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
8485: form.allencrypturl.value += allidxs[i]+',';
8486: }
8487: }
8488: }
8489: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
8490: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
8491: }
8492: }
8493: form.allrandompick.value = '';
8494: form.allrandomorder.value = '';
8495: var allmapidxlist = document.cumulativesettings.allmapidx.value;
8496: if ((allmapidxlist != '') && (allmapidxlist != null)) {
8497: var allmapidxs = allmapidxlist.split(',');
8498: for (var i=0; i<allmapidxs.length; i++) {
8499: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
8500: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
8501: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
8502: if ((randompick.checked) && (rpicknum.value != '')) {
8503: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
8504: }
8505: if (randorder.checked) {
8506: form.allrandomorder.value += allmapidxs[i]+',';
8507: }
8508: }
8509: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
8510: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
8511: }
8512: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
8513: haschanges = 1;
8514: }
8515: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
8516: haschanges = 1;
8517: }
8518: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
8519: haschanges = 1;
8520: }
8521: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
8522: haschanges = 1;
8523: }
8524: }
8525: if (doactions == 1) {
8526: if (numchanges > 0) {
8527: if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) {
8528: if (remwarnings > 0) {
8529: if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) {
8530: return false;
8531: }
8532: }
8533: if (removalinfo > 0) {
8534: if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) {
8535: return false;
8536: }
8537: }
8538: if (cutwarnings > 0) {
8539: if (!confirm('$js_lt{"p_ctr1a"}\\n$js_lt{"p_ctr1b"}\\n\\n$js_lt{"p_ctr3a"} '+cutwarnings+' $js_lt{"p_ctr3b"}')) {
8540: return false;
8541: }
8542: }
8543: }
8544: form.submit();
8545: return true;
8546: }
8547: }
8548: if (dosettings == 1) {
8549: if (haschanges == 1) {
8550: form.submit();
8551: return true;
8552: }
8553: }
8554: if ((dosettings == 1) && (doactions == 1)) {
8555: alert("$js_lt{'noor'}");
8556: } else {
8557: if (dosettings == 1) {
8558: alert("$js_lt{'noch'}");
8559: } else {
8560: alert("$js_lt{'noac'}");
8561: }
8562: }
8563: return false;
8564: }
8565:
8566: function setClass(value) {
8567: var cutclass = 'LC_docs_cut';
8568: var copyclass = 'LC_docs_copy';
8569: var removeclass = 'LC_docs_remove';
8570: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
8571: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
8572: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
8573: var links = document.getElementsByTagName('a');
8574: for (var i=0; i<links.length; i++) {
8575: var classes = links[i].className;
8576: if (cutreg.test(classes)) {
8577: links[i].className = cutclass;
8578: if (value == 1) {
8579: links[i].className += " LC_menubuttons_link";
8580: }
8581: } else {
8582: if (copyreg.test(classes)) {
8583: links[i].className = copyclass;
8584: if (value == 1) {
8585: links[i].className += " LC_menubuttons_link";
8586: }
8587: } else {
8588: if (removereg.test(classes)) {
8589: links[i].className = removeclass;
8590: if (value == 1) {
8591: links[i].className += " LC_menubuttons_link";
8592: }
8593: }
8594: }
8595: }
8596: }
8597: return;
8598: }
8599:
8600: function setBoxes(value) {
8601: var remidxlist = document.cumulativeactions.allremoveidx.value;
8602: if ((remidxlist != '') && (remidxlist != null)) {
8603: var remidxs = remidxlist.split(',');
8604: for (var i=0; i<remidxs.length; i++) {
8605: if (document.getElementById('remove_'+remidxs[i])) {
8606: var item = document.getElementById('remove_'+remidxs[i]);
8607: if (value == 1) {
8608: item.className = 'LC_docs_remove';
8609: } else {
8610: item.className = 'LC_hidden';
8611: }
8612: }
8613: }
8614: }
8615: var cutidxlist = document.cumulativeactions.allcutidx.value;
8616: if ((cutidxlist != '') && (cutidxlist != null)) {
8617: var cutidxs = cutidxlist.split(',');
8618: for (var i=0; i<cutidxs.length; i++) {
8619: if (document.getElementById('cut_'+cutidxs[i])) {
8620: var item = document.getElementById('cut_'+cutidxs[i]);
8621: if (value == 1) {
8622: item.className = 'LC_docs_cut';
8623: } else {
8624: item.className = 'LC_hidden';
8625: }
8626: }
8627: }
8628: }
8629: var copyidxlist = document.cumulativeactions.allcopyidx.value;
8630: if ((copyidxlist != '') && (copyidxlist != null)) {
8631: var copyidxs = copyidxlist.split(',');
8632: for (var i=0; i<copyidxs.length; i++) {
8633: if (document.getElementById('copy_'+copyidxs[i])) {
8634: var item = document.getElementById('copy_'+copyidxs[i]);
8635: if (value == 1) {
8636: item.className = 'LC_docs_copy';
8637: } else {
8638: item.className = 'LC_hidden';
8639: }
8640: }
8641: }
8642: }
8643: return;
8644: }
8645:
8646: function validImportCrsRes() {
8647: var path = document.crsresimportform.coursepath.options[document.crsresimportform.coursepath.selectedIndex].value;
8648: var fname = document.crsresimportform.coursefile.options[document.crsresimportform.coursefile.selectedIndex].value;
8649: if ((fname == '') || (fname == null)) {
8650: alert("$js_lt{'nofi'}");
8651: return false;
8652: }
8653: var url = '/res/$coursedom/$coursenum/';
8654: if (path && path != '/') {
8655: url += path+'/';
8656: }
8657: if (fname != '') {
8658: url += fname;
8659: }
8660: var title = document.crsresimportform.crsrestitle.value;
8661: document.crsresimportform.importdetail.value=encodeURIComponent(title)+'='+encodeURIComponent(url);
8662: return true;
8663: }
8664:
8665: function validateNewRes(caller) {
8666: if (caller == 'single') {
8667: var role = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value;
8668: var authorpath = document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value;
8669: var resname = document.courseresform.newresourcename.value;
8670: }
8671: }
8672:
8673: ENDSCRIPT
8674: }
8675:
8676: sub history_tab_js {
8677: return <<"ENDHIST";
8678: function toggleHistoryDisp(choice) {
8679: document.docslogform.docslog.value = choice;
8680: document.docslogform.submit();
8681: return;
8682: }
8683:
8684: ENDHIST
8685: }
8686:
8687: sub inject_data_js {
8688: return <<ENDINJECT;
8689:
8690: function injectData(current, hiddenField, name, value) {
8691: currentElement = document.getElementById(hiddenField);
8692: currentElement.name = name;
8693: currentElement.value = value;
8694: current.submit();
8695: }
8696:
8697: ENDINJECT
8698: }
8699:
8700: sub dump_switchserver_js {
8701: my @hosts = @_;
8702: my %js_lt = &Apache::lonlocal::texthash(
8703: dump => 'Copying content to Authoring Space requires switching server.',
8704: swit => 'Switch server?',
8705: );
8706: my %html_js_lt = &Apache::lonlocal::texthash(
8707: swit => 'Switch server?',
8708: duco => 'Copying Content to Authoring Space',
8709: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
8710: chos => 'Choose server',
8711: );
8712: &js_escape(\%js_lt);
8713: &html_escape(\%html_js_lt);
8714: &js_escape(\%html_js_lt);
8715: my $role = $env{'request.role'};
8716: my $js = <<"ENDSWJS";
8717: <script type="text/javascript">
8718: function write_switchserver() {
8719: var server;
8720: if (document.setserver.posshosts.length > 0) {
8721: for (var i=0; i<document.setserver.posshosts.length; i++) {
8722: if (document.setserver.posshosts[i].checked) {
8723: server = document.setserver.posshosts[i].value;
8724: }
8725: }
8726: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
8727: }
8728: window.close();
8729: }
8730: </script>
8731:
8732: ENDSWJS
8733:
8734: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
8735: {'only_body' => 1,
8736: 'js_ready' => 1,});
8737: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
8738:
8739: my $hostpicker;
8740: my $count = 0;
8741: foreach my $host (sort(@hosts)) {
8742: my $checked;
8743: if ($count == 0) {
8744: $checked = ' checked="checked"';
8745: }
8746: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
8747: $host.'"'.$checked.' />'.$host.'</label> ';
8748: $count++;
8749: }
8750:
8751: return <<"ENDSWITCHJS";
8752:
8753: function dump_needs_switchserver(url) {
8754: if (url!='' && url!= null) {
8755: if (confirm("$js_lt{'dump'}\\n$js_lt{'swit'}")) {
8756: go(url);
8757: }
8758: }
8759: return;
8760: }
8761:
8762: function choose_switchserver_window() {
8763: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
8764: newWindow.document.open();
8765: newWindow.document.writeln('$startpage');
8766: newWindow.document.write('<h3>$html_js_lt{'duco'}<\\/h3>\\n'+
8767: '<p>$html_js_lt{'yone'}<\\/p>\\n'+
8768: '<div class="LC_left_float"><fieldset><legend>$html_js_lt{'chos'}<\\/legend>\\n'+
8769: '<form name="setserver" method="post" action="" \\/>\\n'+
8770: '$hostpicker\\n'+
8771: '<br \\/><br \\/>\\n'+
8772: '<input type="button" name="makeswitch" value="$html_js_lt{'swit'}" '+
8773: 'onclick="write_switchserver();" \\/>\\n'+
8774: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
8775: newWindow.document.writeln('$endpage');
8776: newWindow.document.close();
8777: newWindow.focus();
8778: }
8779:
8780: ENDSWITCHJS
8781: }
8782:
8783: sub makedocslogform {
8784: my ($formelems,$docslog) = @_;
8785: return <<"LOGSFORM";
8786: <form action="/adm/coursedocs" method="post" name="docslogform">
8787: <input type="hidden" name="docslog" value="$docslog" />
8788: $formelems
8789: </form>
8790: LOGSFORM
8791: }
8792:
8793: sub makesimpleeditform {
8794: my ($formelems) = @_;
8795: return <<"SIMPFORM";
8796: <form name="simpleedit" method="post" action="/adm/coursedocs">
8797: <input type="hidden" name="importdetail" value="" />
8798: $formelems
8799: </form>
8800: SIMPFORM
8801: }
8802:
8803: sub makenewproblem {
8804: my ($r,$coursedom,$coursenum) = @_;
8805: # Creating a new problem
8806: my ($redirect,$error);
8807: if ($env{'form.authorrole'}) {
8808: my ($newsubdir,$filename);
8809: if ($env{'form.newsubdir'}) {
8810: if ($env{'form.newsubdirname'} ne '') {
8811: $newsubdir = $env{'form.newsubdirname'};
8812: }
8813: }
8814: if ($env{'form.newresourcename'}) {
8815: $filename = $env{'form.newresourcename'};
8816: $filename =~ s/\.(\d+)(\.\w+)$/$2/;
8817: $filename =~ s/`//g;
8818: $filename =~ s{/\.\./}{_}g;
8819: $filename =~ s/\.+/./g;
8820: $filename =~ s{/+}{_}g;
8821: if ($filename ne '') {
8822: my ($name,$ext) = ($filename =~ /(.+)\.([^.]+)$/);
8823: if (($ext) && ($ext ne '.problem')) {
8824: $filename = $name.'.problem';
8825: } elsif ($ext eq '') {
8826: $filename .= '.problem';
8827: }
8828: my $docroot = $r->dir_config('lonDocRoot');
8829: my @ids=&Apache::lonnet::current_machine_ids();
8830: if ($env{'form.authorrole'} eq 'author') {
8831: if ($env{'user.author'}) {
8832: if ($env{'user.home'} && grep(/^\Q$env{'user.home'}\E$/,@ids)) {
8833: my $url = "/priv/$env{'user.domain'}/$env{'user.name'}";
8834: my $path = $docroot.$url;
8835: my $subdir = $env{'form.authorpath'};
8836: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8837: }
8838: }
8839: } elsif ($env{'form.authorrole'} eq 'course') {
8840: my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
8841: if ($chome && grep(/^\Q$chome\E$/,@ids)) {
8842: my $url = "/priv/$coursedom/$coursenum";
8843: my $path=$docroot.$url;
8844: my $subdir = $env{'form.authorpath'};
8845: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8846: if ($redirect) {
8847: my $rightsfile = 'default.rights';
8848: my $sourcerights = "$path/$rightsfile";
8849: my $targetrights = $docroot."/res/$coursedom/$coursenum/$rightsfile";
8850: my $now = time;
8851: if (!-e $sourcerights) {
8852: my $cid = $coursedom.'_'.$coursenum;
8853: if (open(my $fh,">$sourcerights")) {
8854: print $fh <<END;
8855: <accessrule effect="deny" realm="" type="course" role="" />
8856: <accessrule effect="allow" realm="$cid" type="course" role="" />
8857: END
8858: close($fh);
8859: }
8860: }
8861: if (!-e "$sourcerights.meta") {
8862: if (open(my $fh,">$sourcerights.meta")) {
8863: my $author=$env{'environment.firstname'}.' '.
8864: $env{'environment.middlename'}.' '.
8865: $env{'environment.lastname'}.' '.
8866: $env{'environment.generation'};
8867: $author =~ s/\s+$//;
8868: print $fh <<"END";
8869:
8870: <abstract></abstract>
8871: <author>$author</author>
8872: <authorspace>$coursenum:$coursedom</authorspace>
8873: <copyright>private</copyright>
8874: <creationdate>$now</creationdate>
8875: <customdistributionfile></customdistributionfile>
8876: <dependencies></dependencies>
8877: <domain>$coursedom</domain>
8878: <highestgradelevel>0</highestgradelevel>
8879: <keywords></keywords>
8880: <language>notset </language>
8881: <lastrevisiondate>$now</lastrevisiondate>
8882: <lowestgradelevel>0</lowestgradelevel>
8883: <mime>rights</mime>
8884: <modifyinguser>$env{'user.name'}:$env{'user.domain'}</modifyinguser>
8885: <notes></notes>
8886: <obsolete></obsolete>
8887: <obsoletereplacement></obsoletereplacement>
8888: <owner>$coursenum:$coursedom</owner>
8889: <rule>deny:::course,allow:$cid::course</rule>
8890: <sourceavail></sourceavail>
8891: <standards></standards>
8892: <subject></subject>
8893: <title></title>
8894: END
8895: close($fh);
8896: }
8897: }
8898: if ((-e $sourcerights) && (-e "$sourcerights.meta")) {
8899: if (!-e "$docroot/res/$coursedom") {
8900: mkdir("$docroot/res/$coursedom",0755);
8901: }
8902: if (!-e "$docroot/res/$coursedom/$coursenum") {
8903: mkdir("$docroot/res/$coursedom/$coursenum",0755);
8904: }
8905: if ((-e "$docroot/res/$coursedom/$coursenum") && (!-e $targetrights)) {
8906: my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
8907: my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1);
8908: }
8909: }
8910: my $source = $docroot.$redirect;
8911: if (!-e "$source.meta") {
8912: my $cid = $coursedom.'_'.$coursenum;
8913: my $now = time;
8914: if (open(my $fh,">$source.meta")) {
8915: my $author=$env{'environment.firstname'}.' '.
8916: $env{'environment.middlename'}.' '.
8917: $env{'environment.lastname'}.' '.
8918: $env{'environment.generation'};
8919: $author =~ s/\s+$//;
8920: my $title = $env{'form.newresourcetitle'};
8921: $title =~ s/^\s+|\s+$//g;
8922: print $fh <<END;
8923:
8924: <abstract></abstract>
8925: <author>$author</author>
8926: <authorspace>$coursenum:$coursedom</authorspace>
8927: <copyright>custom</copyright>
8928: <creationdate>$now</creationdate>
8929: <customdistributionfile>/res/$coursedom/$coursenum/default.rights</customdistributionfile>
8930: <dependencies></dependencies>
8931: <domain>$coursedom</domain>
8932: <highestgradelevel>0</highestgradelevel>
8933: <keywords></keywords>
8934: <language>notset </language>
8935: <lastrevisiondate>$now</lastrevisiondate>
8936: <lowestgradelevel>0</lowestgradelevel>
8937: <mime>problem</mime>
8938: <modifyinguser>$coursenum:$coursedom</modifyinguser>
8939: <notes></notes>
8940: <obsolete></obsolete>
8941: <obsoletereplacement></obsoletereplacement>
8942: <owner>$coursenum:$coursedom</owner>
8943: <sourceavail></sourceavail>
8944: <standards></standards>
8945: <subject></subject>
8946: <title>$title</title>
8947: END
8948: close($fh);
8949: }
8950: }
8951: }
8952: }
8953: } else {
8954: my ($auname,$audom,$role) = split('___',$env{'form.authorrole'});
8955: my $rolehome = &Apache::lonnet::homeserver($auname,$audom);
8956: if (grep(/^\Q$rolehome\E$/,@ids)) {
8957: my $now = time;
8958: if (exists($env{'user.role.'.$role.'./'.$audom.'/'.$auname})) {
8959: my ($start,$end) = split(/\./,$env{'user.role.'.$role.'./'.$audom.'/'.$auname});
8960: if (($start <= $now) && (($end == 0) || ($end >= $now))) {
8961: my $url = "/priv/$audom/$auname";
8962: my $path = $r->dir_config('lonDocRoot').$url;
8963: my $subdir = $env{'form.authorpath'};
8964: $redirect = &finishnewprob($url,$path,$subdir,$newsubdir,$filename);
8965: }
8966: }
8967: }
8968: }
8969: }
8970: }
8971: }
8972: return ($redirect,$error);
8973: }
8974:
8975: sub finishnewprob {
8976: my ($url,$path,$subdir,$newsubdir,$filename,$context) = @_;
8977: unless (-d $path) {
8978: unless (mkdir($path,02770)) {
8979: return;
8980: }
8981: }
8982: my $redirect;
8983: if ($subdir ne '/') {
8984: $subdir = &cleandir($subdir);
8985: if (($subdir ne '') && (-d "$path/$subdir")) {
8986: $path .= "/$subdir";
8987: $url .= "/$subdir";
8988: }
8989: }
8990: my $dest;
8991: if ($newsubdir ne '') {
8992: $newsubdir = &cleandir($newsubdir);
8993: }
8994: if ($newsubdir ne '') {
8995: if (-d "$path/$newsubdir") {
8996: $dest = "$path/$newsubdir/$filename";
8997: } else {
8998: my $dirok;
8999: unless (-e "$path/$newsubdir") {
9000: if (mkdir("$path/$newsubdir",02770)) {
9001: if (chmod(02770,"$path/$newsubdir")) {
9002: $dirok = 1;
9003: }
9004: }
9005: }
9006: if ($dirok) {
9007: $dest = "$path/$newsubdir/$filename";
9008: }
9009: }
9010: if (($dest ne '') && (!-e $dest)) {
9011: $redirect = "$url/$newsubdir/$filename";
9012: }
9013: } else {
9014: $dest = "$path/$filename";
9015: if (($dest ne '') && (!-e $dest)) {
9016: $redirect = "$url/$filename";
9017: }
9018: }
9019: if ((!-e $dest) && ($context ne 'upload')) {
9020: my $template = $env{'form.template'};
9021: my $copyfrom;
9022: if ($template ne '') {
9023: my %templates;
9024: my @files = &Apache::lonhomework::get_template_list('problem');
9025: foreach my $poss (@files) {
9026: if (ref($poss) eq 'ARRAY') {
9027: if ($template eq $poss->[0]) {
9028: $templates{$template} = 1;
9029: last;
9030: }
9031: }
9032: }
9033: if ($templates{$template}) {
9034: $copyfrom = $template;
9035: }
9036: }
9037: if ($filename =~ /\.problem$/) {
9038: unless ($copyfrom) {
9039: $copyfrom = $Apache::lonnet::perlvar{'lonIncludes'}.'/templates/blank.problem';
9040: }
9041: &File::Copy::copy($copyfrom,$dest);
9042: }
9043: }
9044: return $redirect;
9045: }
9046:
9047: sub cleandir {
9048: my ($dir) = @_;
9049: $dir =~ s/^\s+//;
9050: $dir =~ s/\s+$//;
9051: $dir =~ s/\.+//g;
9052: $dir =~ s/[\#\?&%\":]//g;
9053: return $dir;
9054: }
9055:
9056: 1;
9057: __END__
9058:
9059:
9060: =head1 NAME
9061:
9062: Apache::londocs.pm
9063:
9064: =head1 SYNOPSIS
9065:
9066: This is part of the LearningOnline Network with CAPA project
9067: described at http://www.lon-capa.org.
9068:
9069: =head1 SUBROUTINES
9070:
9071: =over
9072:
9073: =item %help=()
9074:
9075: Available help topics
9076:
9077: =item mapread()
9078:
9079: Mapread read maps into LONCAPA::map:: global arrays
9080: @order and @resources, determines status
9081: sets @order - pointer to resources in right order
9082: sets @resources - array with the resources with correct idx
9083:
9084: =item authorhosts()
9085:
9086: Return hash with valid author names
9087:
9088: =item clean()
9089:
9090: =item dumpcourse()
9091:
9092: Actually dump course
9093:
9094: =item group_import()
9095:
9096: Imports the given (name, url) resources into the course
9097: coursenum, coursedom, and folder must precede the list
9098:
9099: =item breadcrumbs()
9100:
9101: =item log_docs()
9102:
9103: =item docs_change_log()
9104:
9105: =item update_paste_buffer()
9106:
9107: =item print_paste_buffer()
9108:
9109: =item do_paste_from_buffer()
9110:
9111: =item do_buffer_empty()
9112:
9113: =item clear_from_buffer()
9114:
9115: =item get_newmap_url()
9116:
9117: =item dbcopy()
9118:
9119: =item uniqueness_check()
9120:
9121: =item contained_map_check()
9122:
9123: =item url_paste_fixups()
9124:
9125: =item apply_fixups()
9126:
9127: =item copy_dependencies()
9128:
9129: =item update_parameter()
9130:
9131: =item handle_edit_cmd()
9132:
9133: =item editor()
9134:
9135: =item process_file_upload()
9136:
9137: =item process_secondary_uploads()
9138:
9139: =item is_supplemental_title()
9140:
9141: =item entryline()
9142:
9143: =item tiehash()
9144:
9145: =item untiehash()
9146:
9147: =item checkonthis()
9148:
9149: check on this
9150:
9151: =item verifycontent()
9152:
9153: Verify Content
9154:
9155: =item devalidateversioncache()
9156:
9157: =item checkversions()
9158:
9159: Check Versions
9160:
9161: =item mark_hash_old()
9162:
9163: =item is_hash_old()
9164:
9165: =item changewarning()
9166:
9167: =item init_breadcrumbs()
9168:
9169: Breadcrumbs for special functions
9170:
9171: =item create_list_elements()
9172:
9173: =item create_form_ul()
9174:
9175: =item startContentScreen()
9176:
9177: =item endContentScreen()
9178:
9179: =item supplemental_base()
9180:
9181: =item embedded_form_elems()
9182:
9183: =item embedded_destination()
9184:
9185: =item return_to_editor()
9186:
9187: =item decompression_info()
9188:
9189: =item decompression_phase_one()
9190:
9191: =item decompression_phase_two()
9192:
9193: =item remove_archive()
9194:
9195: =item generate_admin_menu()
9196:
9197: =item generate_edit_table()
9198:
9199: =item editing_js()
9200:
9201: =item history_tab_js()
9202:
9203: =item inject_data_js()
9204:
9205: =item dump_switchserver_js()
9206:
9207: =item resize_scrollbox_js()
9208:
9209: =item makedocslogform()
9210:
9211: =item makesimpleeditform()
9212:
9213: =back
9214:
9215: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>