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 252-258
my $verbose = 0;
Link Here
|
252 |
my $nomail = 0; |
254 |
my $nomail = 0; |
253 |
my $MAX = 90; |
255 |
my $MAX = 90; |
254 |
my @branchcodes; # Branch(es) passed as parameter |
256 |
my @branchcodes; # Branch(es) passed as parameter |
255 |
my $csvfilename; |
257 |
my $csvfilename = ''; |
256 |
my $htmlfilename; |
258 |
my $htmlfilename; |
257 |
my $triggered = 0; |
259 |
my $triggered = 0; |
258 |
my $listall = 0; |
260 |
my $listall = 0; |
Lines 278-284
GetOptions(
Link Here
|
278 |
pod2usage(1) if $help; |
280 |
pod2usage(1) if $help; |
279 |
pod2usage( -verbose => 2 ) if $man; |
281 |
pod2usage( -verbose => 2 ) if $man; |
280 |
|
282 |
|
281 |
if ( defined $csvfilename && $csvfilename =~ /^-/ ) { |
283 |
my $columns_def_hashref = C4::Reports::Guided::_get_column_defs(); |
|
|
284 |
|
285 |
# get column header definitions |
286 |
foreach my $key ( keys %$columns_def_hashref ) { |
287 |
my $initkey = $key; |
288 |
$key =~ s/[^\.]*\.//; |
289 |
#warn "KEY : $initkey = ".$columns_def_hashref->{$initkey}; |
290 |
if ($columns_def_hashref->{$initkey}) { |
291 |
$columns_def_hashref->{$initkey}=NormalizeString($columns_def_hashref->{$initkey}); |
292 |
$columns_def_hashref->{$initkey}=~s# #<br/>#; |
293 |
} |
294 |
$columns_def_hashref->{$key} = $columns_def_hashref->{$initkey}; |
295 |
} |
296 |
|
297 |
if ( $csvfilename =~ /^-/ ) { |
282 |
warn qq(using "$csvfilename" as filename, that seems odd); |
298 |
warn qq(using "$csvfilename" as filename, that seems odd); |
283 |
} |
299 |
} |
284 |
|
300 |
|
Lines 328-334
binmode( STDOUT, ':encoding(UTF-8)' );
Link Here
|
328 |
|
344 |
|
329 |
our $csv; # the Text::CSV_XS object |
345 |
our $csv; # the Text::CSV_XS object |
330 |
our $csv_fh; # the filehandle to the CSV file. |
346 |
our $csv_fh; # the filehandle to the CSV file. |
331 |
if ( defined $csvfilename ) { |
347 |
if ( $csvfilename ) { |
332 |
my $sep_char = C4::Context->preference('delimiter') || ','; |
348 |
my $sep_char = C4::Context->preference('delimiter') || ','; |
333 |
$sep_char = "\t" if ($sep_char eq 'tabulation'); |
349 |
$sep_char = "\t" if ($sep_char eq 'tabulation'); |
334 |
$csv = Text::CSV_XS->new( { binary => 1 , sep_char => $sep_char } ); |
350 |
$csv = Text::CSV_XS->new( { binary => 1 , sep_char => $sep_char } ); |
Lines 337-343
if ( defined $csvfilename ) {
Link Here
|
337 |
} else { |
353 |
} else { |
338 |
open $csv_fh, ">", $csvfilename or die "unable to open $csvfilename: $!"; |
354 |
open $csv_fh, ">", $csvfilename or die "unable to open $csvfilename: $!"; |
339 |
} |
355 |
} |
340 |
if ( $csv->combine(qw(name surname address1 address2 zipcode city country email itemcount itemsinfo)) ) { |
356 |
if ( $csvfilename && $csv->combine(qw(name surname address1 address2 zipcode city country email itemcount itemsinfo)) ) { |
341 |
print $csv_fh $csv->string, "\n"; |
357 |
print $csv_fh $csv->string, "\n"; |
342 |
} else { |
358 |
} else { |
343 |
$verbose and warn 'combine failed on argument: ' . $csv->error_input; |
359 |
$verbose and warn 'combine failed on argument: ' . $csv->error_input; |
Lines 467-474
END_SQL
Link Here
|
467 |
$verbose and warn "debarring $borrowernumber $firstname $lastname\n"; |
483 |
$verbose and warn "debarring $borrowernumber $firstname $lastname\n"; |
468 |
} |
484 |
} |
469 |
my @params = ($listall ? ( $borrowernumber , 1 , $MAX ) : ( $borrowernumber, $mindays, $maxdays )); |
485 |
my @params = ($listall ? ( $borrowernumber , 1 , $MAX ) : ( $borrowernumber, $mindays, $maxdays )); |
470 |
$verbose and warn "STH2 PARAMS: borrowernumber = $borrowernumber, mindays = $mindays, maxdays = $maxdays"; |
|
|
471 |
$sth2->execute(@params); |
486 |
$sth2->execute(@params); |
|
|
487 |
$verbose and warn "STH2 PARAMS: borrowernumber = $borrowernumber, mindays = $mindays, maxdays = $maxdays returns ".$sth2->rows." rows"; |
472 |
my $itemcount = 0; |
488 |
my $itemcount = 0; |
473 |
my $titles; |
489 |
my $titles; |
474 |
if ($htmlfilename) { |
490 |
if ($htmlfilename) { |
Lines 487-496
END_SQL
Link Here
|
487 |
} |
503 |
} |
488 |
$i++; |
504 |
$i++; |
489 |
my @item_info = map { $_ =~ /^date|date$/ ? format_date( $item_info->{$_} ) : $item_info->{$_} || '' } @item_content_fields; |
505 |
my @item_info = map { $_ =~ /^date|date$/ ? format_date( $item_info->{$_} ) : $item_info->{$_} || '' } @item_content_fields; |
490 |
$titles .= join("\t", @item_info) . "\n"; |
506 |
if ($htmlfilename) { |
|
|
507 |
$titles .= "<tr><td>" . join( "</td><td>", @item_info ) . "</td></tr>"; |
508 |
} else { |
509 |
$titles .= join("\t", @item_info) . "\n"; |
510 |
} |
491 |
$itemcount++; |
511 |
$itemcount++; |
492 |
push @items, $item_info; |
512 |
push @items, $item_info; |
493 |
} |
513 |
} |
|
|
514 |
$titles .= "</tbody></table>" if ($htmlfilename); |
515 |
$debug && warn $titles; |
494 |
$sth2->finish; |
516 |
$sth2->finish; |
495 |
|
517 |
|
496 |
my $letter = parse_letter( |
518 |
my $letter = parse_letter( |
Lines 513-531
END_SQL
Link Here
|
513 |
next PERIOD; |
535 |
next PERIOD; |
514 |
} |
536 |
} |
515 |
|
537 |
|
516 |
$letter->{'content-type'}="text/".($htmlfilename?"html":"plain"); |
538 |
$letter->{'content-type'}="text/".($htmlfilename?"html":"plain")."; charset=UTF8"; |
517 |
|
539 |
|
518 |
if ($exceededPrintNoticesMaxLines) { |
540 |
if ($exceededPrintNoticesMaxLines) { |
519 |
$letter->{'content'} .= "List too long for form; please check your account online for a complete list of your overdue items."; |
541 |
$letter->{'content'} .= "List too long for form; please check your account online for a complete list of your overdue items."; |
520 |
} |
542 |
} |
521 |
|
543 |
|
522 |
my @misses = grep { /./ } map { /^([^>]*)[>]+/; ( $1 || '' ); } split /\</, $letter->{'content'}; |
544 |
my @misses = grep { /./ } map { /^([^>]*)[>]{2,}/; ( $1 || '' ); } split /\<\</, $letter->{'content'}; |
523 |
if (@misses) { |
545 |
if (@misses) { |
524 |
$verbose and warn "The following terms were not matched and replaced: \n\t" . join "\n\t", @misses; |
546 |
$verbose and warn "The following terms were not matched and replaced: \n\t" . join "\n\t", @misses; |
525 |
} |
547 |
} |
526 |
$letter->{'content'} =~ s/\<[^<>]*?\>//g; # Now that we've warned about them, remove them. |
548 |
$letter->{'content'} =~ s/\<\<[^<>]*?\>\>//g; # Now that we've warned about them, remove them. |
527 |
$letter->{'content'} =~ s/\<[^<>]*?\>//g; # 2nd pass for the double nesting. |
|
|
528 |
|
549 |
|
|
|
550 |
# $letter->{'content'} =~ s/\<[^<>]*?\>//g; # 2nd pass for the double nesting. |
529 |
if ($nomail) { |
551 |
if ($nomail) { |
530 |
|
552 |
|
531 |
push @output_chunks, |
553 |
push @output_chunks, |
Lines 541-547
END_SQL
Link Here
|
541 |
email => $email, |
563 |
email => $email, |
542 |
itemcount => $itemcount, |
564 |
itemcount => $itemcount, |
543 |
titles => $titles, |
565 |
titles => $titles, |
544 |
outputformat => defined $csvfilename ? 'csv' : defined $htmlfilename ? 'html' : '', |
566 |
outputformat => $csvfilename ? 'csv' : defined $htmlfilename ? 'html' : '', |
545 |
} |
567 |
} |
546 |
); |
568 |
); |
547 |
} else { |
569 |
} else { |
Lines 569-575
END_SQL
Link Here
|
569 |
email => $email, |
591 |
email => $email, |
570 |
itemcount => $itemcount, |
592 |
itemcount => $itemcount, |
571 |
titles => $titles, |
593 |
titles => $titles, |
572 |
outputformat => defined $csvfilename ? 'csv' : defined $htmlfilename ? 'html' : '', |
594 |
outputformat => $csvfilename ? 'csv' : defined $htmlfilename ? 'html' : '', |
573 |
} |
595 |
} |
574 |
); |
596 |
); |
575 |
} |
597 |
} |
Lines 580-586
END_SQL
Link Here
|
580 |
} |
602 |
} |
581 |
|
603 |
|
582 |
if (@output_chunks) { |
604 |
if (@output_chunks) { |
583 |
if ( defined $csvfilename ) { |
605 |
if ( $csvfilename ) { |
584 |
print $csv_fh @output_chunks; |
606 |
print $csv_fh @output_chunks; |
585 |
} |
607 |
} |
586 |
elsif ( defined $htmlfilename ) { |
608 |
elsif ( defined $htmlfilename ) { |
Lines 738-743
sub prepare_letter_for_printing {
Link Here
|
738 |
} |
760 |
} |
739 |
} elsif ( exists $params->{'outputformat'} && $params->{'outputformat'} eq 'html' ) { |
761 |
} elsif ( exists $params->{'outputformat'} && $params->{'outputformat'} eq 'html' ) { |
740 |
$return = "<pre>\n"; |
762 |
$return = "<pre>\n"; |
|
|
763 |
$params->{'letter'}->{'content'} =~ s#
#<br/>#g; |
741 |
$return .= "$params->{'letter'}->{'content'}\n"; |
764 |
$return .= "$params->{'letter'}->{'content'}\n"; |
742 |
$return .= "\n</pre>\n"; |
765 |
$return .= "\n</pre>\n"; |
743 |
} else { |
766 |
} else { |
744 |
- |
|
|