Lines 38-45
use Encode;
Link Here
|
38 |
use C4::Context; |
38 |
use C4::Context; |
39 |
use C4::Dates qw/format_date/; |
39 |
use C4::Dates qw/format_date/; |
40 |
use C4::Debug; |
40 |
use C4::Debug; |
|
|
41 |
use C4::Charset; |
41 |
use C4::Letters; |
42 |
use C4::Letters; |
42 |
use C4::Overdues qw(GetFine); |
43 |
use C4::Overdues qw(GetFine); |
|
|
44 |
use C4::Reports::Guided; |
43 |
|
45 |
|
44 |
=head1 NAME |
46 |
=head1 NAME |
45 |
|
47 |
|
Lines 256-262
my $verbose = 0;
Link Here
|
256 |
my $nomail = 0; |
258 |
my $nomail = 0; |
257 |
my $MAX = 90; |
259 |
my $MAX = 90; |
258 |
my @branchcodes; # Branch(es) passed as parameter |
260 |
my @branchcodes; # Branch(es) passed as parameter |
259 |
my $csvfilename; |
261 |
my $csvfilename = ''; |
260 |
my $htmlfilename; |
262 |
my $htmlfilename; |
261 |
my $triggered = 0; |
263 |
my $triggered = 0; |
262 |
my $listall = 0; |
264 |
my $listall = 0; |
Lines 284-290
GetOptions(
Link Here
|
284 |
pod2usage(1) if $help; |
286 |
pod2usage(1) if $help; |
285 |
pod2usage( -verbose => 2 ) if $man; |
287 |
pod2usage( -verbose => 2 ) if $man; |
286 |
|
288 |
|
287 |
if ( defined $csvfilename && $csvfilename =~ /^-/ ) { |
289 |
my $columns_def_hashref = C4::Reports::Guided::_get_column_defs(); |
|
|
290 |
|
291 |
# get column header definitions |
292 |
foreach my $key ( keys %$columns_def_hashref ) { |
293 |
my $initkey = $key; |
294 |
$key =~ s/[^\.]*\.//; |
295 |
#warn "KEY : $initkey = ".$columns_def_hashref->{$initkey}; |
296 |
if ($columns_def_hashref->{$initkey}) { |
297 |
$columns_def_hashref->{$initkey}=NormalizeString($columns_def_hashref->{$initkey}); |
298 |
$columns_def_hashref->{$initkey}=~s# #<br/>#; |
299 |
} |
300 |
$columns_def_hashref->{$key} = $columns_def_hashref->{$initkey}; |
301 |
} |
302 |
|
303 |
if ( $csvfilename =~ /^-/ ) { |
288 |
warn qq(using "$csvfilename" as filename, that seems odd); |
304 |
warn qq(using "$csvfilename" as filename, that seems odd); |
289 |
} |
305 |
} |
290 |
|
306 |
|
Lines 341-347
binmode( STDOUT, ':encoding(UTF-8)' );
Link Here
|
341 |
|
357 |
|
342 |
our $csv; # the Text::CSV_XS object |
358 |
our $csv; # the Text::CSV_XS object |
343 |
our $csv_fh; # the filehandle to the CSV file. |
359 |
our $csv_fh; # the filehandle to the CSV file. |
344 |
if ( defined $csvfilename ) { |
360 |
if ( $csvfilename ) { |
345 |
my $sep_char = C4::Context->preference('delimiter') || ','; |
361 |
my $sep_char = C4::Context->preference('delimiter') || ','; |
346 |
$sep_char = "\t" if ($sep_char eq 'tabulation'); |
362 |
$sep_char = "\t" if ($sep_char eq 'tabulation'); |
347 |
$csv = Text::CSV_XS->new( { binary => 1 , sep_char => $sep_char } ); |
363 |
$csv = Text::CSV_XS->new( { binary => 1 , sep_char => $sep_char } ); |
Lines 350-356
if ( defined $csvfilename ) {
Link Here
|
350 |
} else { |
366 |
} else { |
351 |
open $csv_fh, ">", $csvfilename or die "unable to open $csvfilename: $!"; |
367 |
open $csv_fh, ">", $csvfilename or die "unable to open $csvfilename: $!"; |
352 |
} |
368 |
} |
353 |
if ( $csv->combine(qw(name surname address1 address2 zipcode city country email itemcount itemsinfo)) ) { |
369 |
if ( $csvfilename && $csv->combine(qw(name surname address1 address2 zipcode city country email itemcount itemsinfo)) ) { |
354 |
print $csv_fh $csv->string, "\n"; |
370 |
print $csv_fh $csv->string, "\n"; |
355 |
} else { |
371 |
} else { |
356 |
$verbose and warn 'combine failed on argument: ' . $csv->error_input; |
372 |
$verbose and warn 'combine failed on argument: ' . $csv->error_input; |
Lines 480-487
END_SQL
Link Here
|
480 |
$verbose and warn "debarring $borrowernumber $firstname $lastname\n"; |
496 |
$verbose and warn "debarring $borrowernumber $firstname $lastname\n"; |
481 |
} |
497 |
} |
482 |
my @params = ($listall ? ( $borrowernumber , 1 , $MAX ) : ( $borrowernumber, $mindays, $maxdays )); |
498 |
my @params = ($listall ? ( $borrowernumber , 1 , $MAX ) : ( $borrowernumber, $mindays, $maxdays )); |
483 |
$verbose and warn "STH2 PARAMS: borrowernumber = $borrowernumber, mindays = $mindays, maxdays = $maxdays"; |
|
|
484 |
$sth2->execute(@params); |
499 |
$sth2->execute(@params); |
|
|
500 |
$verbose and warn "STH2 PARAMS: borrowernumber = $borrowernumber, mindays = $mindays, maxdays = $maxdays returns ".$sth2->rows." rows"; |
485 |
my $itemcount = 0; |
501 |
my $itemcount = 0; |
486 |
my $titles; |
502 |
my $titles; |
487 |
if ($htmlfilename) { |
503 |
if ($htmlfilename) { |
Lines 500-509
END_SQL
Link Here
|
500 |
} |
516 |
} |
501 |
$j++; |
517 |
$j++; |
502 |
my @item_info = map { $_ =~ /^date|date$/ ? format_date( $item_info->{$_} ) : $item_info->{$_} || '' } @item_content_fields; |
518 |
my @item_info = map { $_ =~ /^date|date$/ ? format_date( $item_info->{$_} ) : $item_info->{$_} || '' } @item_content_fields; |
503 |
$titles .= join("\t", @item_info) . "\n"; |
519 |
if ($htmlfilename) { |
|
|
520 |
$titles .= "<tr><td>" . join( "</td><td>", @item_info ) . "</td></tr>"; |
521 |
} else { |
522 |
$titles .= join("\t", @item_info) . "\n"; |
523 |
} |
504 |
$itemcount++; |
524 |
$itemcount++; |
505 |
push @items, $item_info; |
525 |
push @items, $item_info; |
506 |
} |
526 |
} |
|
|
527 |
$titles .= "</tbody></table>" if ($htmlfilename); |
528 |
$debug && warn $titles; |
507 |
$sth2->finish; |
529 |
$sth2->finish; |
508 |
|
530 |
|
509 |
my $letter = parse_letter( |
531 |
my $letter = parse_letter( |
Lines 526-544
END_SQL
Link Here
|
526 |
next PERIOD; |
548 |
next PERIOD; |
527 |
} |
549 |
} |
528 |
|
550 |
|
529 |
$letter->{'content-type'}="text/".($htmlfilename?"html":"plain"); |
551 |
$letter->{'content-type'}="text/".($htmlfilename?"html":"plain")."; charset=UTF8"; |
530 |
|
552 |
|
531 |
if ($exceededPrintNoticesMaxLines) { |
553 |
if ($exceededPrintNoticesMaxLines) { |
532 |
$letter->{'content'} .= "List too long for form; please check your account online for a complete list of your overdue items."; |
554 |
$letter->{'content'} .= "List too long for form; please check your account online for a complete list of your overdue items."; |
533 |
} |
555 |
} |
534 |
|
556 |
|
535 |
my @misses = grep { /./ } map { /^([^>]*)[>]+/; ( $1 || '' ); } split /\</, $letter->{'content'}; |
557 |
my @misses = grep { /./ } map { /^([^>]*)[>]{2,}/; ( $1 || '' ); } split /\<\</, $letter->{'content'}; |
536 |
if (@misses) { |
558 |
if (@misses) { |
537 |
$verbose and warn "The following terms were not matched and replaced: \n\t" . join "\n\t", @misses; |
559 |
$verbose and warn "The following terms were not matched and replaced: \n\t" . join "\n\t", @misses; |
538 |
} |
560 |
} |
539 |
$letter->{'content'} =~ s/\<[^<>]*?\>//g; # Now that we've warned about them, remove them. |
561 |
$letter->{'content'} =~ s/\<\<[^<>]*?\>\>//g; # Now that we've warned about them, remove them. |
540 |
$letter->{'content'} =~ s/\<[^<>]*?\>//g; # 2nd pass for the double nesting. |
|
|
541 |
|
562 |
|
|
|
563 |
# $letter->{'content'} =~ s/\<[^<>]*?\>//g; # 2nd pass for the double nesting. |
542 |
if ($nomail) { |
564 |
if ($nomail) { |
543 |
|
565 |
|
544 |
push @output_chunks, |
566 |
push @output_chunks, |
Lines 554-560
END_SQL
Link Here
|
554 |
email => $email, |
576 |
email => $email, |
555 |
itemcount => $itemcount, |
577 |
itemcount => $itemcount, |
556 |
titles => $titles, |
578 |
titles => $titles, |
557 |
outputformat => defined $csvfilename ? 'csv' : defined $htmlfilename ? 'html' : '', |
579 |
outputformat => $csvfilename ? 'csv' : defined $htmlfilename ? 'html' : '', |
558 |
} |
580 |
} |
559 |
); |
581 |
); |
560 |
} else { |
582 |
} else { |
Lines 582-588
END_SQL
Link Here
|
582 |
email => $email, |
604 |
email => $email, |
583 |
itemcount => $itemcount, |
605 |
itemcount => $itemcount, |
584 |
titles => $titles, |
606 |
titles => $titles, |
585 |
outputformat => defined $csvfilename ? 'csv' : defined $htmlfilename ? 'html' : '', |
607 |
outputformat => $csvfilename ? 'csv' : defined $htmlfilename ? 'html' : '', |
586 |
} |
608 |
} |
587 |
); |
609 |
); |
588 |
} |
610 |
} |
Lines 593-599
END_SQL
Link Here
|
593 |
} |
615 |
} |
594 |
|
616 |
|
595 |
if (@output_chunks) { |
617 |
if (@output_chunks) { |
596 |
if ( defined $csvfilename ) { |
618 |
if ( $csvfilename ) { |
597 |
print $csv_fh @output_chunks; |
619 |
print $csv_fh @output_chunks; |
598 |
} |
620 |
} |
599 |
elsif ( defined $htmlfilename ) { |
621 |
elsif ( defined $htmlfilename ) { |
Lines 751-756
sub prepare_letter_for_printing {
Link Here
|
751 |
} |
773 |
} |
752 |
} elsif ( exists $params->{'outputformat'} && $params->{'outputformat'} eq 'html' ) { |
774 |
} elsif ( exists $params->{'outputformat'} && $params->{'outputformat'} eq 'html' ) { |
753 |
$return = "<pre>\n"; |
775 |
$return = "<pre>\n"; |
|
|
776 |
$params->{'letter'}->{'content'} =~ s#
#<br/>#g; |
754 |
$return .= "$params->{'letter'}->{'content'}\n"; |
777 |
$return .= "$params->{'letter'}->{'content'}\n"; |
755 |
$return .= "\n</pre>\n"; |
778 |
$return .= "\n</pre>\n"; |
756 |
} else { |
779 |
} else { |
757 |
- |
|
|