Lines 19-26
Link Here
|
19 |
# |
19 |
# |
20 |
# |
20 |
# |
21 |
|
21 |
|
22 |
#use strict; |
22 |
use strict; |
23 |
#use warnings; FIXME - Bug 2505 |
23 |
use warnings; |
24 |
|
24 |
|
25 |
use File::Temp; |
25 |
use File::Temp; |
26 |
use File::Copy; |
26 |
use File::Copy; |
Lines 74-79
Files greater than 100K will be refused. Images should be 140x200 pixels. If the
Link Here
|
74 |
$debug and warn "Operation requested: $op"; |
74 |
$debug and warn "Operation requested: $op"; |
75 |
|
75 |
|
76 |
my ( $total, $handled, @counts, $tempfile, $tfh ); |
76 |
my ( $total, $handled, @counts, $tempfile, $tfh ); |
|
|
77 |
my %errors; |
77 |
|
78 |
|
78 |
if ( ($op eq 'Upload') && $uploadfile ) { # Case is important in these operational values as the template must use case to be visually pleasing! |
79 |
if ( ($op eq 'Upload') && $uploadfile ) { # Case is important in these operational values as the template must use case to be visually pleasing! |
79 |
my $dirname = File::Temp::tempdir( CLEANUP => 1); |
80 |
my $dirname = File::Temp::tempdir( CLEANUP => 1); |
Lines 84-98
if ( ($op eq 'Upload') && $uploadfile ) { # Case is important in these ope
Link Here
|
84 |
} |
85 |
} |
85 |
( $tfh, $tempfile ) = File::Temp::tempfile( SUFFIX => $filesuffix, UNLINK => 1 ); |
86 |
( $tfh, $tempfile ) = File::Temp::tempfile( SUFFIX => $filesuffix, UNLINK => 1 ); |
86 |
$debug and warn "tempfile = $tempfile"; |
87 |
$debug and warn "tempfile = $tempfile"; |
87 |
my ( @directories, $errors ); |
|
|
88 |
|
88 |
|
89 |
$errors{'NOTZIP'} = 1 if ( $uploadfilename !~ /\.zip$/i && $filetype =~ m/zip/i ); |
89 |
$errors{'NOTZIP'} = 1 if ( $uploadfilename !~ /\.zip$/i && $filetype =~ m/zip/i ); |
90 |
$errors{'NOWRITETEMP'} = 1 unless ( -w $dirname ); |
90 |
$errors{'NOWRITETEMP'} = 1 unless ( -w $dirname ); |
91 |
$errors{'EMPTYUPLOAD'} = 1 unless ( length( $uploadfile ) > 0 ); |
91 |
$errors{'EMPTYUPLOAD'} = 1 unless ( length( $uploadfile ) > 0 ); |
92 |
|
92 |
|
93 |
if ( %errors ) { |
93 |
if ( %errors ) { |
94 |
$template->param( ERRORS => [ \%errors ] ); |
94 |
$template->param( ERRORS => [ \%errors ] ); |
95 |
} else { |
95 |
output_html_with_http_headers $input, $cookie, $template->output; |
|
|
96 |
exit; |
97 |
} |
96 |
while ( <$uploadfile> ) { |
98 |
while ( <$uploadfile> ) { |
97 |
print $tfh $_; |
99 |
print $tfh $_; |
98 |
} |
100 |
} |
Lines 104-132
if ( ($op eq 'Upload') && $uploadfile ) { # Case is important in these ope
Link Here
|
104 |
output_html_with_http_headers $input, $cookie, $template->output; # This error is fatal to the import, so bail out here |
106 |
output_html_with_http_headers $input, $cookie, $template->output; # This error is fatal to the import, so bail out here |
105 |
exit; |
107 |
exit; |
106 |
} |
108 |
} |
|
|
109 |
my @directories; |
107 |
push @directories, "$dirname"; |
110 |
push @directories, "$dirname"; |
108 |
foreach $recursive_dir ( @directories ) { |
111 |
foreach my $recursive_dir ( @directories ) { |
109 |
opendir $dir, $recursive_dir; |
112 |
opendir RECDIR, $recursive_dir; |
110 |
while ( my $entry = readdir $dir ) { |
113 |
while ( my $entry = readdir RECDIR ) { |
111 |
push @directories, "$recursive_dir/$entry" if ( -d "$recursive_dir/$entry" and $entry !~ /^\./ ); |
114 |
push @directories, "$recursive_dir/$entry" if ( -d "$recursive_dir/$entry" and $entry !~ /^\./ ); |
112 |
$debug and warn "$recursive_dir/$entry"; |
115 |
$debug and warn "$recursive_dir/$entry"; |
113 |
} |
116 |
} |
114 |
closedir $dir; |
117 |
closedir RECDIR; |
115 |
} |
118 |
} |
116 |
my $results; |
|
|
117 |
foreach my $dir ( @directories ) { |
119 |
foreach my $dir ( @directories ) { |
118 |
$results = handle_dir( $dir, $filesuffix ); |
120 |
my $result = handle_dir( $dir, $filesuffix ); |
119 |
$handled++ if $results == 1; |
121 |
$handled++ if $result == 1; |
120 |
} |
122 |
} |
121 |
$total = scalar @directories; |
123 |
$total = scalar @directories; |
122 |
} else { #if ($filetype eq 'zip' ) |
124 |
} else { |
123 |
$results = handle_dir( $dirname, $filesuffix ); |
125 |
my $result = handle_dir( $dirname, $filesuffix ); |
124 |
$handled = 1; |
126 |
$handled = 1 if $result; |
125 |
$total = 1; |
127 |
$total = 1; |
126 |
} |
128 |
} |
127 |
|
129 |
|
128 |
if ( %$results || %errors ) { |
130 |
if ( %errors ) { |
129 |
$template->param( ERRORS => [ \%$results ] ); |
131 |
$template->param( ERRORS => [ \%errors ] ); |
130 |
} else { |
132 |
} else { |
131 |
my $filecount; |
133 |
my $filecount; |
132 |
map {$filecount += $_->{count}} @counts; |
134 |
map {$filecount += $_->{count}} @counts; |
Lines 140-146
if ( ($op eq 'Upload') && $uploadfile ) { # Case is important in these ope
Link Here
|
140 |
); |
142 |
); |
141 |
$template->param( borrowernumber => $borrowernumber ) if $borrowernumber; |
143 |
$template->param( borrowernumber => $borrowernumber ) if $borrowernumber; |
142 |
} |
144 |
} |
143 |
} |
|
|
144 |
} elsif ( ($op eq 'Upload') && !$uploadfile ) { |
145 |
} elsif ( ($op eq 'Upload') && !$uploadfile ) { |
145 |
warn "Problem uploading file or no file uploaded."; |
146 |
warn "Problem uploading file or no file uploaded."; |
146 |
$template->param(cardnumber => $cardnumber); |
147 |
$template->param(cardnumber => $cardnumber); |
Lines 150-156
if ( ($op eq 'Upload') && $uploadfile ) { # Case is important in these ope
Link Here
|
150 |
$debug and warn "Patron image deleted for $cardnumber"; |
151 |
$debug and warn "Patron image deleted for $cardnumber"; |
151 |
warn "Database returned $dberror" if $dberror; |
152 |
warn "Database returned $dberror" if $dberror; |
152 |
} |
153 |
} |
153 |
if ( $borrowernumber && !$errors && !$template->param('ERRORS') ) { |
154 |
if ( $borrowernumber && !%errors && !$template->param('ERRORS') ) { |
154 |
print $input->redirect ("/cgi-bin/koha/members/moremember.pl?borrowernumber=$borrowernumber"); |
155 |
print $input->redirect ("/cgi-bin/koha/members/moremember.pl?borrowernumber=$borrowernumber"); |
155 |
} else { |
156 |
} else { |
156 |
output_html_with_http_headers $input, $cookie, $template->output; |
157 |
output_html_with_http_headers $input, $cookie, $template->output; |
Lines 159-176
if ( $borrowernumber && !$errors && !$template->param('ERRORS') ) {
Link Here
|
159 |
sub handle_dir { |
160 |
sub handle_dir { |
160 |
my ( $dir, $suffix ) = @_; |
161 |
my ( $dir, $suffix ) = @_; |
161 |
my $source; |
162 |
my $source; |
|
|
163 |
my %counts; |
162 |
$debug and warn "Entering sub handle_dir; passed \$dir=$dir, \$suffix=$suffix"; |
164 |
$debug and warn "Entering sub handle_dir; passed \$dir=$dir, \$suffix=$suffix"; |
163 |
if ($suffix =~ m/zip/i) { # If we were sent a zip file, process any included data/idlink.txt files |
165 |
if ($suffix =~ m/zip/i) { # If we were sent a zip file, process any included data/idlink.txt files |
164 |
my ( $file, $filename, $cardnumber ); |
166 |
my ( $file, $filename, $cardnumber ); |
165 |
$debug and warn "Passed a zip file."; |
167 |
$debug and warn "Passed a zip file."; |
166 |
opendir my $dirhandle, $dir; |
168 |
opendir DIR, $dir; |
167 |
while ( my $filename = readdir $dirhandle ) { |
169 |
while ( my $filename = readdir DIR ) { |
168 |
$file = "$dir/$filename" if ($filename =~ m/datalink\.txt/i || $filename =~ m/idlink\.txt/i); |
170 |
$file = "$dir/$filename" if ($filename =~ m/datalink\.txt/i || $filename =~ m/idlink\.txt/i); |
169 |
} |
171 |
} |
170 |
unless (open (FILE, $file)) { |
172 |
unless (open (FILE, $file)) { |
171 |
warn "Opening $dir/$file failed!"; |
173 |
warn "Opening $dir/$file failed!"; |
172 |
$errors{'OPNLINK'} = $file; |
174 |
$errors{'OPNLINK'} = $file; |
173 |
return $errors; # This error is fatal to the import of this directory contents, so bail and return the error to the caller |
175 |
return; # This error is fatal to the import of this directory contents, so bail and return the error to the caller |
174 |
}; |
176 |
}; |
175 |
|
177 |
|
176 |
while (my $line = <FILE>) { |
178 |
while (my $line = <FILE>) { |
Lines 182-188
sub handle_dir {
Link Here
|
182 |
unless ( $delim eq "," || $delim eq "\t" ) { |
184 |
unless ( $delim eq "," || $delim eq "\t" ) { |
183 |
warn "Unrecognized or missing field delimeter. Please verify that you are using either a ',' or a 'tab'"; |
185 |
warn "Unrecognized or missing field delimeter. Please verify that you are using either a ',' or a 'tab'"; |
184 |
$errors{'DELERR'} = 1; # This error is fatal to the import of this directory contents, so bail and return the error to the caller |
186 |
$errors{'DELERR'} = 1; # This error is fatal to the import of this directory contents, so bail and return the error to the caller |
185 |
return $errors; |
187 |
return; |
186 |
} |
188 |
} |
187 |
($cardnumber, $filename) = split $delim, $line; |
189 |
($cardnumber, $filename) = split $delim, $line; |
188 |
$cardnumber =~ s/[\"\r\n]//g; # remove offensive characters |
190 |
$cardnumber =~ s/[\"\r\n]//g; # remove offensive characters |
Lines 192-198
sub handle_dir {
Link Here
|
192 |
%counts = handle_file($cardnumber, $source, %counts); |
194 |
%counts = handle_file($cardnumber, $source, %counts); |
193 |
} |
195 |
} |
194 |
close FILE; |
196 |
close FILE; |
195 |
closedir ($dirhandle); |
197 |
closedir DIR; |
196 |
} else { |
198 |
} else { |
197 |
$source = $tempfile; |
199 |
$source = $tempfile; |
198 |
%counts = handle_file($cardnumber, $source, %counts); |
200 |
%counts = handle_file($cardnumber, $source, %counts); |
Lines 206-219
sub handle_file {
Link Here
|
206 |
$debug and warn "Entering sub handle_file; passed \$cardnumber=$cardnumber, \$source=$source"; |
208 |
$debug and warn "Entering sub handle_file; passed \$cardnumber=$cardnumber, \$source=$source"; |
207 |
$count{filenames} = () if !$count{filenames}; |
209 |
$count{filenames} = () if !$count{filenames}; |
208 |
$count{source} = $source if !$count{source}; |
210 |
$count{source} = $source if !$count{source}; |
|
|
211 |
my %filerrors; |
212 |
my $filename; |
213 |
if ($filetype eq 'image') { |
214 |
$filename = $uploadfilename; |
215 |
} else { |
216 |
$filename = $1 if ($source && $source =~ /\/([^\/]+)$/); |
217 |
} |
209 |
if ($cardnumber && $source) { # Now process any imagefiles |
218 |
if ($cardnumber && $source) { # Now process any imagefiles |
210 |
my %filerrors; |
|
|
211 |
my $filename; |
212 |
if ($filetype eq 'image') { |
213 |
$filename = $uploadfilename; |
214 |
} else { |
215 |
$filename = $1 if ($source =~ /\/([^\/]+)$/); |
216 |
} |
217 |
$debug and warn "Source: $source"; |
219 |
$debug and warn "Source: $source"; |
218 |
my $size = (stat($source))[7]; |
220 |
my $size = (stat($source))[7]; |
219 |
if ($size > 550000) { # This check is necessary even with image resizing to avoid possible security/performance issues... |
221 |
if ($size > 550000) { # This check is necessary even with image resizing to avoid possible security/performance issues... |
Lines 228-233
sub handle_file {
Link Here
|
228 |
$srcimage = GD::Image->new(*IMG); |
230 |
$srcimage = GD::Image->new(*IMG); |
229 |
close (IMG); |
231 |
close (IMG); |
230 |
if (defined $srcimage) { |
232 |
if (defined $srcimage) { |
|
|
233 |
my $imgfile; |
231 |
my $mimetype = 'image/png'; # GD autodetects three basic image formats: PNG, JPEG, XPM; we will convert all to PNG which is lossless... |
234 |
my $mimetype = 'image/png'; # GD autodetects three basic image formats: PNG, JPEG, XPM; we will convert all to PNG which is lossless... |
232 |
# Check the pixel size of the image we are about to import... |
235 |
# Check the pixel size of the image we are about to import... |
233 |
my ($width, $height) = $srcimage->getBounds(); |
236 |
my ($width, $height) = $srcimage->getBounds(); |
Lines 286-292
sub handle_file {
Link Here
|
286 |
$template->param( ERRORS => 1 ); |
289 |
$template->param( ERRORS => 1 ); |
287 |
} |
290 |
} |
288 |
} else { |
291 |
} else { |
289 |
warn "Opening $dir/$filename failed!"; |
292 |
warn "Opening $source failed!"; |
290 |
$filerrors{'OPNERR'} = 1; |
293 |
$filerrors{'OPNERR'} = 1; |
291 |
push my @filerrors, \%filerrors; |
294 |
push my @filerrors, \%filerrors; |
292 |
push @{ $count{filenames} }, { filerrors => \@filerrors, source => $filename, cardnumber => $cardnumber }; |
295 |
push @{ $count{filenames} }, { filerrors => \@filerrors, source => $filename, cardnumber => $cardnumber }; |
293 |
- |
|
|