version 1.1055, 2012/01/31 23:47:15
|
version 1.1056, 2012/02/28 02:02:16
|
Line 9735 sub decompress_form {
|
Line 9735 sub decompress_form {
|
} |
} |
$output .= '</p>'; |
$output .= '</p>'; |
$output .= <<"START"; |
$output .= <<"START"; |
<p> |
|
$lt{'this'} $lt{'youm'} |
|
</p> |
|
<div id="uploadfileresult"> |
<div id="uploadfileresult"> |
<form name="uploaded_decompress" action="$action" method="post"> |
<form name="uploaded_decompress" action="$action" method="post"> |
<input type="hidden" name="archiveurl" value="$archiveurl" /> |
<input type="hidden" name="archiveurl" value="$archiveurl" /> |
Line 9857 sub process_decompression {
|
Line 9854 sub process_decompression {
|
} |
} |
} |
} |
if (@contents > 0) { |
if (@contents > 0) { |
my (%children,%parent); |
my (%children,%parent,%dirorder,%titles); |
my $wantform = 1; |
my $wantform = 1; |
my ($count,$datatable) = &get_extracted($docudom,$docuname, |
my ($count,$datatable) = &get_extracted($docudom,$docuname, |
$currdir,\%is_dir, |
$currdir,\%is_dir, |
\%children,\%parent, |
\%children,\%parent, |
\@contents,$wantform); |
\@contents,\%dirorder, |
|
\%titles,$wantform); |
if ($datatable ne '') { |
if ($datatable ne '') { |
$output .= &archive_options_form('decompressed',$datatable, |
$output .= &archive_options_form('decompressed',$datatable, |
$count,$hiddenelem); |
$count,$hiddenelem); |
my $startcount = 3; |
my $startcount = 4; |
$output .= &archive_javascript($startcount,$count, |
$output .= &archive_javascript($startcount,$count, |
%children); |
\%titles,\%children); |
} |
} |
} else { |
} else { |
$warning = &mt('No new items extracted from archive file.'); |
$warning = &mt('No new items extracted from archive file.'); |
Line 9891 sub process_decompression {
|
Line 9889 sub process_decompression {
|
} |
} |
|
|
sub get_extracted { |
sub get_extracted { |
my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$wantform) = @_; |
my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder, |
|
$titles,$wantform) = @_; |
my $count = 0; |
my $count = 0; |
my $lastcontainer = 0; |
|
my $depth = 0; |
my $depth = 0; |
my $datatable; |
my $datatable; |
|
my @hierarchy; |
return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') && |
return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') && |
(ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY')); |
(ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') && |
|
(ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH')); |
foreach my $item (@{$contents}) { |
foreach my $item (@{$contents}) { |
$count ++; |
$count ++; |
|
@{$dirorder->{$count}} = @hierarchy; |
|
$titles->{$count} = $item; |
&archive_hierarchy($depth,$count,$parent,$children); |
&archive_hierarchy($depth,$count,$parent,$children); |
if ($wantform) { |
if ($wantform) { |
$datatable .= &archive_row($is_dir->{$item},$item, |
$datatable .= &archive_row($is_dir->{$item},$item, |
Line 9907 sub get_extracted {
|
Line 9909 sub get_extracted {
|
} |
} |
if ($is_dir->{$item}) { |
if ($is_dir->{$item}) { |
$depth ++; |
$depth ++; |
$lastcontainer = $count; |
push(@hierarchy,$count); |
$parent->{$depth} = $lastcontainer; |
$parent->{$depth} = $count; |
$datatable .= |
$datatable .= |
&recurse_extracted_archive("$currdir/$item",$docudom,$docuname, |
&recurse_extracted_archive("$currdir/$item",$docudom,$docuname, |
\$depth,\$count,\$lastcontainer, |
\$depth,\$count,\@hierarchy,$dirorder, |
$children,$parent,$wantform); |
$children,$parent,$titles,$wantform); |
$depth --; |
$depth --; |
$lastcontainer = $parent->{$depth}; |
pop(@hierarchy); |
} |
} |
} |
} |
return ($count,$datatable); |
return ($count,$datatable); |
} |
} |
|
|
sub recurse_extracted_archive { |
sub recurse_extracted_archive { |
my ($currdir,$docudom,$docuname,$depth,$count,$lastcontainer, |
my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder, |
$children,$parent,$wantform) = @_; |
$children,$parent,$titles,$wantform) = @_; |
my $result=''; |
my $result=''; |
unless ((ref($depth)) && (ref($count)) && (ref($lastcontainer)) && |
unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') && |
(ref($children) eq 'HASH') && (ref($parent) eq 'HASH')) { |
(ref($children) eq 'HASH') && (ref($parent) eq 'HASH') && |
|
(ref($dirorder) eq 'HASH')) { |
return $result; |
return $result; |
} |
} |
my $dirptr = 16384; |
my $dirptr = 16384; |
Line 9936 sub recurse_extracted_archive {
|
Line 9939 sub recurse_extracted_archive {
|
my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5); |
my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5); |
unless ($item =~ /^\.+$/) { |
unless ($item =~ /^\.+$/) { |
$$count ++; |
$$count ++; |
|
@{$dirorder->{$$count}} = @{$hierarchy}; |
|
$titles->{$$count} = $item; |
&archive_hierarchy($$depth,$$count,$parent,$children); |
&archive_hierarchy($$depth,$$count,$parent,$children); |
|
|
my $is_dir; |
my $is_dir; |
if ($dirptr&$testdir) { |
if ($dirptr&$testdir) { |
$is_dir = 1; |
$is_dir = 1; |
Line 9946 sub recurse_extracted_archive {
|
Line 9952 sub recurse_extracted_archive {
|
} |
} |
if ($is_dir) { |
if ($is_dir) { |
$$depth ++; |
$$depth ++; |
$$lastcontainer = $$count; |
push(@{$hierarchy},$$count); |
$parent->{$$depth} = $$lastcontainer; |
$parent->{$$depth} = $$count; |
$result .= |
$result .= |
&recurse_extracted_archive("$currdir/$item",$docudom, |
&recurse_extracted_archive("$currdir/$item",$docudom, |
$docuname,$depth,$count, |
$docuname,$depth,$count, |
$lastcontainer,$children, |
$hierarchy,$dirorder,$children, |
$parent,$wantform); |
$parent,$titles,$wantform); |
$$depth --; |
$$depth --; |
$$lastcontainer = $parent->{$$depth}; |
pop(@{$hierarchy}); |
} |
} |
} |
} |
} |
} |
Line 9983 sub archive_row {
|
Line 9989 sub archive_row {
|
if ($is_dir) { |
if ($is_dir) { |
$choices{'display'} = &mt('Add as Folder'); |
$choices{'display'} = &mt('Add as Folder'); |
} |
} |
my $output = &start_data_table_row()."\n"; |
my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n"; |
|
my $offset = 0; |
foreach my $action ('display','dependency','discard') { |
foreach my $action ('display','dependency','discard') { |
|
$offset ++; |
$output .= '<td><span class="LC_nobreak">'. |
$output .= '<td><span class="LC_nobreak">'. |
'<label><input type="radio" name="archive_'.$count. |
'<label><input type="radio" name="archive_'.$count. |
'" id="archive_'.$action.'_'.$count.'" value="'.$action.'"'; |
'" id="archive_'.$action.'_'.$count.'" value="'.$action.'"'; |
Line 9994 sub archive_row {
|
Line 10002 sub archive_row {
|
if ($action eq 'display') { |
if ($action eq 'display') { |
$text = &mt('Add as Folder'); |
$text = &mt('Add as Folder'); |
} |
} |
|
} else { |
|
$output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"'; |
|
|
|
} |
|
$output .= ' /> '.$choices{$action}.'</label></span>'; |
|
if ($action eq 'dependency') { |
|
$output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n". |
|
&mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '. |
|
'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n". |
|
'<option value=""></option>'."\n". |
|
'</select>'."\n". |
|
'</div>'; |
} |
} |
$output .= ' /> '.$choices{$action}.'</label></span></td>'; |
$output .= '</td>'; |
} |
} |
$output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'. |
$output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'. |
&HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2); |
&HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2); |
Line 10039 sub archive_options_form {
|
Line 10059 sub archive_options_form {
|
} |
} |
|
|
sub archive_javascript { |
sub archive_javascript { |
my ($startcount,$numitems,%children) = @_; |
my ($startcount,$numitems,$titles,$children) = @_; |
|
return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH')); |
my $scripttag = <<START; |
my $scripttag = <<START; |
<script type="text/javascript"> |
<script type="text/javascript"> |
// <![CDATA[ |
// <![CDATA[ |
Line 10052 function checkAll(form,prefix) {
|
Line 10073 function checkAll(form,prefix) {
|
if (idstr.test(id)) { |
if (idstr.test(id)) { |
if (form.elements[i].type == 'radio') { |
if (form.elements[i].type == 'radio') { |
form.elements[i].checked = true; |
form.elements[i].checked = true; |
|
var nostart = i-$startcount; |
|
var offset = nostart%6; |
|
var count = (nostart-offset)/6; |
|
dependencyCheck(form,count,offset); |
} |
} |
} |
} |
} |
} |
Line 10060 function checkAll(form,prefix) {
|
Line 10085 function checkAll(form,prefix) {
|
|
|
function propagateCheck(form,count) { |
function propagateCheck(form,count) { |
if (count > 0) { |
if (count > 0) { |
var startelement = $startcount + (count-1) * 5; |
var startelement = $startcount + ((count-1) * 6); |
for (var j=1; j<4; j++) { |
for (var j=1; j<5; j++) { |
var item = startelement + j; |
if (j != 3) { |
if (form.elements[item].type == 'radio') { |
var item = startelement + j; |
if (form.elements[item].checked) { |
if (form.elements[item].type == 'radio') { |
containerCheck(form,count,j); |
if (form.elements[item].checked) { |
break; |
containerCheck(form,count,j); |
|
break; |
|
} |
} |
} |
} |
} |
} |
} |
Line 10074 function propagateCheck(form,count) {
|
Line 10101 function propagateCheck(form,count) {
|
} |
} |
|
|
numitems = $numitems |
numitems = $numitems |
var parents = new Array(numitems) |
var titles = new Array(numitems); |
|
var parents = new Array(numitems); |
for (var i=0; i<numitems; i++) { |
for (var i=0; i<numitems; i++) { |
parents[i] = new Array |
parents[i] = new Array; |
} |
} |
|
|
START |
START |
|
|
foreach my $container (sort { $a <=> $b } (keys(%children))) { |
foreach my $container (sort { $a <=> $b } (keys(%{$children}))) { |
my @contents = split(/:/,$children{$container}); |
my @contents = split(/:/,$children->{$container}); |
for (my $i=0; $i<@contents; $i ++) { |
for (my $i=0; $i<@contents; $i ++) { |
$scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n"; |
$scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n"; |
} |
} |
} |
} |
|
|
|
foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) { |
|
$scripttag .= "titles[$key] = '".$titles->{$key}."';\n"; |
|
} |
|
|
$scripttag .= <<END; |
$scripttag .= <<END; |
|
|
function containerCheck(form,count,offset) { |
function containerCheck(form,count,offset) { |
if (count > 0) { |
if (count > 0) { |
var item = $startcount + ((count-1) * 5) + offset; |
dependencyCheck(form,count,offset); |
|
var item = (offset+$startcount)+6*(count-1); |
form.elements[item].checked = true; |
form.elements[item].checked = true; |
if(Object.prototype.toString.call(parents[count]) === '[object Array]') { |
if(Object.prototype.toString.call(parents[count]) === '[object Array]') { |
if (parents[count].length > 0) { |
if (parents[count].length > 0) { |
for (var j=0; j<parents[count].length; j++) { |
for (var j=0; j<parents[count].length; j++) { |
containerCheck(form,parents[count][j],offset) |
containerCheck(form,parents[count][j],offset); |
|
} |
|
} |
|
} |
|
} |
|
} |
|
|
|
function dependencyCheck(form,count,offset) { |
|
if (count > 0) { |
|
var chosen = (offset+$startcount)+6*(count-1); |
|
var depitem = $startcount + ((count-1) * 6) + 3; |
|
var currtype = form.elements[depitem].type; |
|
if (form.elements[chosen].value == 'dependency') { |
|
document.getElementById('arc_depon_'+count).style.display='block'; |
|
form.elements[depitem].options.length = 0; |
|
form.elements[depitem].options[0] = new Option('Select','',true,true); |
|
for (var i=1; i<count; i++) { |
|
var startelement = $startcount + (i-1) * 6; |
|
for (var j=1; j<5; j++) { |
|
if (j != 3) { |
|
var item = startelement + j; |
|
if (form.elements[item].type == 'radio') { |
|
if (form.elements[item].checked) { |
|
if (form.elements[item].value == 'display') { |
|
var n = form.elements[depitem].options.length; |
|
form.elements[depitem].options[n] = new Option(titles[i],i,false,false); |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} else { |
|
document.getElementById('arc_depon_'+count).style.display='none'; |
|
form.elements[depitem].options.length = 0; |
|
form.elements[depitem].options[0] = new Option('Select','',true,true); |
|
} |
|
} |
|
} |
|
|
|
function propagateSelect(form,count,offset) { |
|
if (count > 0) { |
|
var item = (1+offset+$startcount)+6*(count-1); |
|
var picked = form.elements[item].options[form.elements[item].selectedIndex].value; |
|
if (Object.prototype.toString.call(parents[count]) === '[object Array]') { |
|
if (parents[count].length > 0) { |
|
for (var j=0; j<parents[count].length; j++) { |
|
containerSelect(form,parents[count][j],offset,picked); |
} |
} |
} |
} |
} |
} |
} |
} |
} |
} |
|
|
|
function containerSelect(form,count,offset,picked) { |
|
if (count > 0) { |
|
var item = (offset+$startcount)+6*(count-1); |
|
if (form.elements[item].type == 'radio') { |
|
if (form.elements[item].value == 'dependency') { |
|
if (form.elements[item+1].type == 'select-one') { |
|
for (var i=0; i<form.elements[item+1].options.length; i++) { |
|
if (form.elements[item+1].options[i].value == picked) { |
|
form.elements[item+1].selectedIndex = i; |
|
break; |
|
} |
|
} |
|
} |
|
if (Object.prototype.toString.call(parents[count]) === '[object Array]') { |
|
if (parents[count].length > 0) { |
|
for (var j=0; j<parents[count].length; j++) { |
|
containerSelect(form,parents[count][j],offset,picked); |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
|
// ]]> |
// ]]> |
</script> |
</script> |
END |
END |
Line 10151 sub process_extracted_files {
|
Line 10257 sub process_extracted_files {
|
} |
} |
} |
} |
} |
} |
my ($output,%children,%parent); |
my ($output,%children,%parent,%titles,%dirorder); |
if (keys(%toplevelitems) > 0) { |
if (keys(%toplevelitems) > 0) { |
my @contents = sort(keys(%toplevelitems)); |
my @contents = sort(keys(%toplevelitems)); |
my ($count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir, |
(my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children, |
\%children,\%parent,\@contents); |
\%parent,\@contents,\%dirorder,\%titles); |
} |
|
my (@above,%hierarchy,%referrer,%orphaned,%todelete); |
|
foreach my $depth (sort { $a <=> $b } keys(%parent)) { |
|
push(@above,$parent{$depth}); |
|
foreach my $item (split(/:/,$children{$parent{$depth}})) { |
|
$hierarchy{$item} = \@above; |
|
} |
|
} |
} |
|
my (%referrer,%orphaned,%todelete,%newdest,%newseqid); |
if ($numitems) { |
if ($numitems) { |
for (my $i=1; $i<=$numitems; $i++) { |
for (my $i=1; $i<=$numitems; $i++) { |
my $path = $env{'form.archive_content_'.$i}; |
my $path = $env{'form.archive_content_'.$i}; |
Line 10178 sub process_extracted_files {
|
Line 10278 sub process_extracted_files {
|
my ($title,$url,$outer); |
my ($title,$url,$outer); |
($title) = ($path =~ m{/([^/]+)$}); |
($title) = ($path =~ m{/([^/]+)$}); |
$outer = 0; |
$outer = 0; |
if (ref($hierarchy{$i}) eq 'ARRAY') { |
if (ref($dirorder{$i}) eq 'ARRAY') { |
if (@{$hierarchy{$i}} > 0) { |
if (@{$dirorder{$i}} > 0) { |
foreach my $item (reverse(@{$hierarchy{$i}})) { |
foreach my $item (reverse(@{$dirorder{$i}})) { |
if ($env{'form.archive_'.$item} eq 'display') { |
if ($env{'form.archive_'.$item} eq 'display') { |
$outer = $item; |
$outer = $item; |
last; |
last; |
Line 10195 sub process_extracted_files {
|
Line 10295 sub process_extracted_files {
|
next if ($fatal); |
next if ($fatal); |
if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) { |
if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) { |
if ($context eq 'coursedocs') { |
if ($context eq 'coursedocs') { |
$mapinner{$i} = time; |
$mapinner{$i} = time; |
$folders{$i} = 'default_'.$mapinner{$i}; |
$folders{$i} = 'default_'.$mapinner{$i}; |
$containers{$i} = 'sequence'; |
$containers{$i} = 'sequence'; |
my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'. |
my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'. |
Line 10208 sub process_extracted_files {
|
Line 10308 sub process_extracted_files {
|
&LONCAPA::map::storemap('/uploaded/'.$docudom.'/'. |
&LONCAPA::map::storemap('/uploaded/'.$docudom.'/'. |
$docuname.'/'.$folders{$outer}. |
$docuname.'/'.$folders{$outer}. |
'.'.$containers{$outer},1); |
'.'.$containers{$outer},1); |
|
$newseqid{$i} = $newidx; |
} |
} |
} else { |
} else { |
if ($context eq 'coursedocs') { |
if ($context eq 'coursedocs') { |
Line 10223 sub process_extracted_files {
|
Line 10324 sub process_extracted_files {
|
} |
} |
if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") { |
if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") { |
system("mv $prefix$path $prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title"); |
system("mv $prefix$path $prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title"); |
|
$newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx"; |
} |
} |
$LONCAPA::map::resources[$newidx]= |
$LONCAPA::map::resources[$newidx]= |
$title.':'.$url.':false:normal:res'; |
$title.':'.$url.':false:normal:res'; |
Line 10234 sub process_extracted_files {
|
Line 10336 sub process_extracted_files {
|
} |
} |
} |
} |
} elsif ($env{'form.archive_'.$i} eq 'dependency') { |
} elsif ($env{'form.archive_'.$i} eq 'dependency') { |
if (ref($hierarchy{$i}) eq 'ARRAY') { |
my ($title) = ($path =~ m{/([^/]+)$}); |
foreach my $item (reverse(@{$hierarchy{$i}})) { |
$referrer{$i} = $env{'form.archive_dependent_on_'.$i}; |
if ($env{'form.archive_'.$item} eq 'display') { |
if ($env{'form.archive_'.$referrer{$i}} eq 'display') { |
$referrer{$i} = $item; |
if (ref($dirorder{$i}) eq 'ARRAY') { |
last; |
my ($itemidx,$fullpath); |
#FIXME identify as dependency in db file |
for (my $j=0; $j<@{$dirorder{$i}}; $j++) { |
#FIXME need to move item to referrer location |
if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') { |
#FIXME need to setup httprefs so access allowed |
my $container = $dirorder{$referrer{$i}}->[-1]; |
} elsif ($env{'form.archive_'.$item} eq 'discard') { |
for (my $j=0; $j<@{$dirorder{$i}}; $j++) { |
$orphaned{$i} = $item; |
if ($dirorder{$i}->[$j] eq $container) { |
last; |
$itemidx = $j; |
|
} |
|
} |
|
} |
|
} |
|
if ($itemidx ne '') { |
|
if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) { |
|
if ($mapinner{$referrer{$i}}) { |
|
$fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}"; |
|
for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) { |
|
if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) { |
|
unless (defined($newseqid{$dirorder{$i}->[$j]})) { |
|
$fullpath .= '/'.$titles{$dirorder{$i}->[$j]}; |
|
if (!-e $fullpath) { |
|
mkdir($fullpath,0755); |
|
} |
|
} |
|
} else { |
|
last; |
|
} |
|
} |
|
} |
|
} elsif ($newdest{$referrer{$i}}) { |
|
$fullpath = $newdest{$referrer{$i}}; |
|
for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) { |
|
if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') { |
|
$orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]}; |
|
last; |
|
} elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) { |
|
unless (defined($newseqid{$dirorder{$i}->[$j]})) { |
|
$fullpath .= '/'.$titles{$dirorder{$i}->[$j]}; |
|
if (!-e $fullpath) { |
|
mkdir($fullpath,0755); |
|
} |
|
} |
|
} else { |
|
last; |
|
} |
|
} |
|
} |
|
if ($fullpath ne '') { |
|
system("mv $prefix$path $fullpath/$title"); |
|
} |
} |
} |
} |
} |
|
} elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') { |
|
$warning .= &mt('[_1] is a dependency of [_2], which was discarded.', |
|
$path,$env{'form.archive_content_'.$referrer{$i}}).'<br />'; |
} |
} |
} |
} |
} else { |
} else { |