Lines 29-36
use C4::Context;
Link Here
|
29 |
use C4::Auth; |
29 |
use C4::Auth; |
30 |
use C4::Output; |
30 |
use C4::Output; |
31 |
use C4::Members; |
31 |
use C4::Members; |
32 |
use C4::Debug; |
|
|
33 |
|
32 |
|
|
|
33 |
use Koha::Logger; |
34 |
use Koha::Patrons; |
34 |
use Koha::Patrons; |
35 |
use Koha::Patron::Images; |
35 |
use Koha::Patron::Images; |
36 |
use Koha::Token; |
36 |
use Koha::Token; |
Lines 61-67
my $op = $input->param('op') || '';
Link Here
|
61 |
# Other parts of this code could be optimized as well, I think. Perhaps the file upload could be done with YUI's upload |
61 |
# Other parts of this code could be optimized as well, I think. Perhaps the file upload could be done with YUI's upload |
62 |
# coded. -fbcit |
62 |
# coded. -fbcit |
63 |
|
63 |
|
64 |
$debug and warn "Params are: filetype=$filetype, cardnumber=$cardnumber, borrowernumber=$borrowernumber, uploadfile=$uploadfilename"; |
64 |
our $logger = Koha::Logger->get; |
|
|
65 |
$logger->debug("Params are: filetype=$filetype, cardnumber=$cardnumber, borrowernumber=$borrowernumber, uploadfile=$uploadfilename"); |
65 |
|
66 |
|
66 |
=head1 NAME |
67 |
=head1 NAME |
67 |
|
68 |
|
Lines 78-85
Files greater than 100K will be refused. Images should be 140x200 pixels. If the
Link Here
|
78 |
|
79 |
|
79 |
=cut |
80 |
=cut |
80 |
|
81 |
|
81 |
$debug and warn "Operation requested: $op"; |
|
|
82 |
|
83 |
my ( $total, $handled, $tempfile, $tfh ); |
82 |
my ( $total, $handled, $tempfile, $tfh ); |
84 |
our @counts = (); |
83 |
our @counts = (); |
85 |
our %errors = (); |
84 |
our %errors = (); |
Lines 94-107
if ( ( $op eq 'Upload' ) && $uploadfile ) {
Link Here
|
94 |
}); |
93 |
}); |
95 |
|
94 |
|
96 |
my $dirname = File::Temp::tempdir( CLEANUP => 1 ); |
95 |
my $dirname = File::Temp::tempdir( CLEANUP => 1 ); |
97 |
$debug and warn "dirname = $dirname"; |
|
|
98 |
my $filesuffix; |
96 |
my $filesuffix; |
99 |
if ( $uploadfilename =~ m/(\..+)$/i ) { |
97 |
if ( $uploadfilename =~ m/(\..+)$/i ) { |
100 |
$filesuffix = $1; |
98 |
$filesuffix = $1; |
101 |
} |
99 |
} |
102 |
( $tfh, $tempfile ) = |
100 |
( $tfh, $tempfile ) = |
103 |
File::Temp::tempfile( SUFFIX => $filesuffix, UNLINK => 1 ); |
101 |
File::Temp::tempfile( SUFFIX => $filesuffix, UNLINK => 1 ); |
104 |
$debug and warn "tempfile = $tempfile"; |
|
|
105 |
my ( @directories, $results ); |
102 |
my ( @directories, $results ); |
106 |
|
103 |
|
107 |
$errors{'NOTZIP'} = 1 |
104 |
$errors{'NOTZIP'} = 1 |
Lines 134-140
if ( ( $op eq 'Upload' ) && $uploadfile ) {
Link Here
|
134 |
while ( my $entry = readdir RECDIR ) { |
131 |
while ( my $entry = readdir RECDIR ) { |
135 |
push @directories, "$recursive_dir/$entry" |
132 |
push @directories, "$recursive_dir/$entry" |
136 |
if ( -d "$recursive_dir/$entry" and $entry !~ /^\./ ); |
133 |
if ( -d "$recursive_dir/$entry" and $entry !~ /^\./ ); |
137 |
$debug and warn "$recursive_dir/$entry"; |
|
|
138 |
} |
134 |
} |
139 |
closedir RECDIR; |
135 |
closedir RECDIR; |
140 |
} |
136 |
} |
Lines 158-165
if ( ( $op eq 'Upload' ) && $uploadfile ) {
Link Here
|
158 |
else { |
154 |
else { |
159 |
my $filecount; |
155 |
my $filecount; |
160 |
map { $filecount += $_->{count} } @counts; |
156 |
map { $filecount += $_->{count} } @counts; |
161 |
$debug and warn "Total directories processed: $total"; |
157 |
$logger->debug("Total directories processed: $total"); |
162 |
$debug and warn "Total files processed: $filecount"; |
158 |
$logger->debug("Total files processed: $filecount"); |
163 |
$template->param( |
159 |
$template->param( |
164 |
TOTAL => $total, |
160 |
TOTAL => $total, |
165 |
HANDLED => $handled, |
161 |
HANDLED => $handled, |
Lines 205-216
else {
Link Here
|
205 |
sub handle_dir { |
201 |
sub handle_dir { |
206 |
my ( $dir, $suffix, $template, $cardnumber, $source ) = @_; |
202 |
my ( $dir, $suffix, $template, $cardnumber, $source ) = @_; |
207 |
my ( %counts, %direrrors ); |
203 |
my ( %counts, %direrrors ); |
208 |
$debug and warn "Entering sub handle_dir; passed \$dir=$dir, \$suffix=$suffix"; |
204 |
$logger->debug("Entering sub handle_dir; passed \$dir=$dir, \$suffix=$suffix"); |
209 |
if ( $suffix =~ m/zip/i ) { |
205 |
if ( $suffix =~ m/zip/i ) { |
210 |
# If we were sent a zip file, process any included data/idlink.txt files |
206 |
# If we were sent a zip file, process any included data/idlink.txt files |
211 |
my ( $file, $filename ); |
207 |
my ( $file, $filename ); |
212 |
undef $cardnumber; |
208 |
undef $cardnumber; |
213 |
$debug and warn "Passed a zip file."; |
209 |
$logger->debug("Passed a zip file."); |
214 |
opendir DIR, $dir; |
210 |
opendir DIR, $dir; |
215 |
while ( my $filename = readdir DIR ) { |
211 |
while ( my $filename = readdir DIR ) { |
216 |
$file = "$dir/$filename" |
212 |
$file = "$dir/$filename" |
Lines 227-237
sub handle_dir {
Link Here
|
227 |
} |
223 |
} |
228 |
|
224 |
|
229 |
while ( my $line = <$fh> ) { |
225 |
while ( my $line = <$fh> ) { |
230 |
$debug and warn "Reading contents of $file"; |
226 |
$logger->debug("Reading contents of $file"); |
231 |
chomp $line; |
227 |
chomp $line; |
232 |
$debug and warn "Examining line: $line"; |
228 |
$logger->debug("Examining line: $line"); |
233 |
my $delim = ( $line =~ /\t/ ) ? "\t" : ( $line =~ /,/ ) ? "," : ""; |
229 |
my $delim = ( $line =~ /\t/ ) ? "\t" : ( $line =~ /,/ ) ? "," : ""; |
234 |
$debug and warn "Delimeter is \'$delim\'"; |
230 |
$logger->debug("Delimeter is \'$delim\'"); |
235 |
unless ( $delim eq "," || $delim eq "\t" ) { |
231 |
unless ( $delim eq "," || $delim eq "\t" ) { |
236 |
warn "Unrecognized or missing field delimeter. Please verify that you are using either a ',' or a 'tab'"; |
232 |
warn "Unrecognized or missing field delimeter. Please verify that you are using either a ',' or a 'tab'"; |
237 |
$direrrors{'DELERR'} = 1; |
233 |
$direrrors{'DELERR'} = 1; |
Lines 242-248
sub handle_dir {
Link Here
|
242 |
( $cardnumber, $filename ) = split $delim, $line; |
238 |
( $cardnumber, $filename ) = split $delim, $line; |
243 |
$cardnumber =~ s/[\"\r\n]//g; # remove offensive characters |
239 |
$cardnumber =~ s/[\"\r\n]//g; # remove offensive characters |
244 |
$filename =~ s/[\"\r\n\s]//g; |
240 |
$filename =~ s/[\"\r\n\s]//g; |
245 |
$debug and warn "Cardnumber: $cardnumber Filename: $filename"; |
241 |
$logger->debug("Cardnumber: $cardnumber Filename: $filename"); |
246 |
$source = "$dir/$filename"; |
242 |
$source = "$dir/$filename"; |
247 |
%counts = handle_file( $cardnumber, $source, $template, %counts ); |
243 |
%counts = handle_file( $cardnumber, $source, $template, %counts ); |
248 |
} |
244 |
} |
Lines 258-264
sub handle_dir {
Link Here
|
258 |
|
254 |
|
259 |
sub handle_file { |
255 |
sub handle_file { |
260 |
my ( $cardnumber, $source, $template, %count ) = @_; |
256 |
my ( $cardnumber, $source, $template, %count ) = @_; |
261 |
$debug and warn "Entering sub handle_file; passed \$cardnumber=$cardnumber, \$source=$source"; |
257 |
$logger->debug("Entering sub handle_file; passed \$cardnumber=$cardnumber, \$source=$source"); |
262 |
$count{filenames} = () if !$count{filenames}; |
258 |
$count{filenames} = () if !$count{filenames}; |
263 |
$count{source} = $source if !$count{source}; |
259 |
$count{source} = $source if !$count{source}; |
264 |
$count{count} = 0 unless exists $count{count}; |
260 |
$count{count} = 0 unless exists $count{count}; |
Lines 272-278
sub handle_file {
Link Here
|
272 |
} |
268 |
} |
273 |
if ( $cardnumber && $source ) { |
269 |
if ( $cardnumber && $source ) { |
274 |
# Now process any imagefiles |
270 |
# Now process any imagefiles |
275 |
$debug and warn "Source: $source"; |
271 |
$logger->debug("Source: $source"); |
276 |
my $size = ( stat($source) )[7]; |
272 |
my $size = ( stat($source) )[7]; |
277 |
if ( $size > 550000 ) { |
273 |
if ( $size > 550000 ) { |
278 |
# This check is necessary even with image resizing to avoid possible security/performance issues... |
274 |
# This check is necessary even with image resizing to avoid possible security/performance issues... |
Lines 299-308
sub handle_file {
Link Here
|
299 |
# we will convert all to PNG which is lossless... |
295 |
# we will convert all to PNG which is lossless... |
300 |
# Check the pixel size of the image we are about to import... |
296 |
# Check the pixel size of the image we are about to import... |
301 |
my ( $width, $height ) = $srcimage->getBounds(); |
297 |
my ( $width, $height ) = $srcimage->getBounds(); |
302 |
$debug and warn "$filename is $width pix X $height pix."; |
298 |
$logger->debug("$filename is $width pix X $height pix."); |
303 |
if ( $width > 200 || $height > 300 ) { |
299 |
if ( $width > 200 || $height > 300 ) { |
304 |
# MAX pixel dims are 200 X 300... |
300 |
# MAX pixel dims are 200 X 300... |
305 |
$debug and warn "$filename exceeds the maximum pixel dimensions of 200 X 300. Resizing..."; |
301 |
$logger->debug("$filename exceeds the maximum pixel dimensions of 200 X 300. Resizing..."); |
306 |
# Percent we will reduce the image dimensions by... |
302 |
# Percent we will reduce the image dimensions by... |
307 |
my $percent_reduce; |
303 |
my $percent_reduce; |
308 |
if ( $width > 200 ) { |
304 |
if ( $width > 200 ) { |
Lines 317-347
sub handle_file {
Link Here
|
317 |
sprintf( "%.0f", ( $width * $percent_reduce ) ); |
313 |
sprintf( "%.0f", ( $width * $percent_reduce ) ); |
318 |
my $height_reduce = |
314 |
my $height_reduce = |
319 |
sprintf( "%.0f", ( $height * $percent_reduce ) ); |
315 |
sprintf( "%.0f", ( $height * $percent_reduce ) ); |
320 |
$debug |
316 |
$logger->debug("Reducing $filename by " |
321 |
and warn "Reducing $filename by " |
|
|
322 |
. ( $percent_reduce * 100 ) |
317 |
. ( $percent_reduce * 100 ) |
323 |
. "\% or to $width_reduce pix X $height_reduce pix"; |
318 |
. "\% or to $width_reduce pix X $height_reduce pix"); |
324 |
#'1' creates true color image... |
319 |
#'1' creates true color image... |
325 |
$image = GD::Image->new( $width_reduce, $height_reduce, 1 ); |
320 |
$image = GD::Image->new( $width_reduce, $height_reduce, 1 ); |
326 |
$image->copyResampled( $srcimage, 0, 0, 0, 0, $width_reduce, |
321 |
$image->copyResampled( $srcimage, 0, 0, 0, 0, $width_reduce, |
327 |
$height_reduce, $width, $height ); |
322 |
$height_reduce, $width, $height ); |
328 |
$imgfile = $image->png(); |
323 |
$imgfile = $image->png(); |
329 |
$debug |
324 |
$logger->debug("$filename is " |
330 |
and warn "$filename is " |
|
|
331 |
. length($imgfile) |
325 |
. length($imgfile) |
332 |
. " bytes after resizing."; |
326 |
. " bytes after resizing."); |
333 |
undef $image; |
327 |
undef $image; |
334 |
undef $srcimage; # This object can get big... |
328 |
undef $srcimage; # This object can get big... |
335 |
} |
329 |
} |
336 |
else { |
330 |
else { |
337 |
$image = $srcimage; |
331 |
$image = $srcimage; |
338 |
$imgfile = $image->png(); |
332 |
$imgfile = $image->png(); |
339 |
$debug |
333 |
$logger->debug("$filename is " . length($imgfile) . " bytes."); |
340 |
and warn "$filename is " . length($imgfile) . " bytes."; |
|
|
341 |
undef $image; |
334 |
undef $image; |
342 |
undef $srcimage; # This object can get big... |
335 |
undef $srcimage; # This object can get big... |
343 |
} |
336 |
} |
344 |
$debug and warn "Image is of mimetype $mimetype"; |
337 |
$logger->debug("Image is of mimetype $mimetype"); |
345 |
if ($mimetype) { |
338 |
if ($mimetype) { |
346 |
my $patron = Koha::Patrons->find({ cardnumber => $cardnumber }); |
339 |
my $patron = Koha::Patrons->find({ cardnumber => $cardnumber }); |
347 |
if ( $patron ) { |
340 |
if ( $patron ) { |