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 376-382
foreach my $branchcode (@branches) {
Link Here
|
376 |
$verbose and warn sprintf "branchcode : '%s' using %s\n", $branchcode, $admin_email_address; |
392 |
$verbose and warn sprintf "branchcode : '%s' using %s\n", $branchcode, $admin_email_address; |
377 |
|
393 |
|
378 |
my $sth2 = $dbh->prepare( <<'END_SQL' ); |
394 |
my $sth2 = $dbh->prepare( <<'END_SQL' ); |
379 |
SELECT biblio.*, items.*, issues.*, biblioitems.itemtype, TO_DAYS(NOW())-TO_DAYS(date_due) AS days_overdue |
395 |
SELECT biblio.title as "biblio.title", biblio.*, items.*, issues.*, biblioitems.itemtype, TO_DAYS(NOW())-TO_DAYS(date_due) AS days_overdue |
380 |
FROM issues,items,biblio, biblioitems |
396 |
FROM issues,items,biblio, biblioitems |
381 |
WHERE items.itemnumber=issues.itemnumber |
397 |
WHERE items.itemnumber=issues.itemnumber |
382 |
AND biblio.biblionumber = items.biblionumber |
398 |
AND biblio.biblionumber = items.biblionumber |
Lines 467-476
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; |
|
|
490 |
if ($htmlfilename) { |
491 |
$titles = "<table id='itemscontent$borrowernumber'>"; |
492 |
$titles .= "<thead><tr><th>" . join( "</th><th>", @$columns_def_hashref{@item_content_fields} ); |
493 |
$titles .= "</th></tr></thead><tbody>"; |
494 |
} |
474 |
my @items = (); |
495 |
my @items = (); |
475 |
|
496 |
|
476 |
my $j = 0; |
497 |
my $j = 0; |
Lines 482-491
END_SQL
Link Here
|
482 |
} |
503 |
} |
483 |
$j++; |
504 |
$j++; |
484 |
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; |
485 |
$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 |
} |
486 |
$itemcount++; |
511 |
$itemcount++; |
487 |
push @items, $item_info; |
512 |
push @items, $item_info; |
488 |
} |
513 |
} |
|
|
514 |
$titles .= "</tbody></table>" if ($htmlfilename); |
515 |
$debug && warn $titles; |
489 |
$sth2->finish; |
516 |
$sth2->finish; |
490 |
|
517 |
|
491 |
my $letter = parse_letter( |
518 |
my $letter = parse_letter( |
Lines 508-524
END_SQL
Link Here
|
508 |
next PERIOD; |
535 |
next PERIOD; |
509 |
} |
536 |
} |
510 |
|
537 |
|
511 |
if ( $exceededPrintNoticesMaxLines ) { |
538 |
$letter->{'content-type'}="text/".($htmlfilename?"html":"plain")."; charset=UTF8"; |
512 |
$letter->{'content'} .= "List too long for form; please check your account online for a complete list of your overdue items."; |
539 |
|
|
|
540 |
if ($exceededPrintNoticesMaxLines) { |
541 |
$letter->{'content'} .= "List too long for form; please check your account online for a complete list of your overdue items."; |
513 |
} |
542 |
} |
514 |
|
543 |
|
515 |
my @misses = grep { /./ } map { /^([^>]*)[>]+/; ( $1 || '' ); } split /\</, $letter->{'content'}; |
544 |
my @misses = grep { /./ } map { /^([^>]*)[>]{2,}/; ( $1 || '' ); } split /\<\</, $letter->{'content'}; |
516 |
if (@misses) { |
545 |
if (@misses) { |
517 |
$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; |
518 |
} |
547 |
} |
519 |
$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. |
520 |
$letter->{'content'} =~ s/\<[^<>]*?\>//g; # 2nd pass for the double nesting. |
|
|
521 |
|
549 |
|
|
|
550 |
# $letter->{'content'} =~ s/\<[^<>]*?\>//g; # 2nd pass for the double nesting. |
522 |
if ($nomail) { |
551 |
if ($nomail) { |
523 |
|
552 |
|
524 |
push @output_chunks, |
553 |
push @output_chunks, |
Lines 534-540
END_SQL
Link Here
|
534 |
email => $email, |
563 |
email => $email, |
535 |
itemcount => $itemcount, |
564 |
itemcount => $itemcount, |
536 |
titles => $titles, |
565 |
titles => $titles, |
537 |
outputformat => defined $csvfilename ? 'csv' : defined $htmlfilename ? 'html' : '', |
566 |
outputformat => $csvfilename ? 'csv' : defined $htmlfilename ? 'html' : '', |
538 |
} |
567 |
} |
539 |
); |
568 |
); |
540 |
} else { |
569 |
} else { |
Lines 562-568
END_SQL
Link Here
|
562 |
email => $email, |
591 |
email => $email, |
563 |
itemcount => $itemcount, |
592 |
itemcount => $itemcount, |
564 |
titles => $titles, |
593 |
titles => $titles, |
565 |
outputformat => defined $csvfilename ? 'csv' : defined $htmlfilename ? 'html' : '', |
594 |
outputformat => $csvfilename ? 'csv' : defined $htmlfilename ? 'html' : '', |
566 |
} |
595 |
} |
567 |
); |
596 |
); |
568 |
} |
597 |
} |
Lines 573-579
END_SQL
Link Here
|
573 |
} |
602 |
} |
574 |
|
603 |
|
575 |
if (@output_chunks) { |
604 |
if (@output_chunks) { |
576 |
if ( defined $csvfilename ) { |
605 |
if ( $csvfilename ) { |
577 |
print $csv_fh @output_chunks; |
606 |
print $csv_fh @output_chunks; |
578 |
} |
607 |
} |
579 |
elsif ( defined $htmlfilename ) { |
608 |
elsif ( defined $htmlfilename ) { |
Lines 731-736
sub prepare_letter_for_printing {
Link Here
|
731 |
} |
760 |
} |
732 |
} elsif ( exists $params->{'outputformat'} && $params->{'outputformat'} eq 'html' ) { |
761 |
} elsif ( exists $params->{'outputformat'} && $params->{'outputformat'} eq 'html' ) { |
733 |
$return = "<pre>\n"; |
762 |
$return = "<pre>\n"; |
|
|
763 |
$params->{'letter'}->{'content'} =~ s#
#<br/>#g; |
734 |
$return .= "$params->{'letter'}->{'content'}\n"; |
764 |
$return .= "$params->{'letter'}->{'content'}\n"; |
735 |
$return .= "\n</pre>\n"; |
765 |
$return .= "\n</pre>\n"; |
736 |
} else { |
766 |
} else { |
737 |
- |
|
|