From 4ec5686f5e747a2db327ac3d7bedcf47818047d7 Mon Sep 17 00:00:00 2001 From: Paul Poulain Date: Wed, 31 Aug 2011 16:11:39 +0200 Subject: [PATCH] Bug 6030 follow-up Fixing problem detected previously: * add column_def retrieval, to have header displaying the "explained" row name, not the table name. (the name is not expanded for CSV exports) * removed some warnings. * fixed some problems with csvfilename being defined/empty. Now, csvfilename is always defined, and set to '' by default. Some tests have been updated accordingly * added the charset=UTF8 on mail headers. This patch also adds some missing columns to columns.def Signed-off-by: Sophie Meynieux --- koha-tmpl/intranet-tmpl/prog/en/columns.def | 6 +++ misc/cronjobs/overdue_notices.pl | 49 +++++++++++++++++++------- 2 files changed, 42 insertions(+), 13 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/columns.def b/koha-tmpl/intranet-tmpl/prog/en/columns.def index 726ecc6..f4be00a 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/columns.def +++ b/koha-tmpl/intranet-tmpl/prog/en/columns.def @@ -66,6 +66,11 @@ borrowers.privacy Privacy settings items.itemnumber Item number (internal) items.biblionumber Biblio number (internal) items.biblioitemnumber Biblioitem number (internal) +issues.date_due Due date +items.itemnumber Item Number (koha internal) +items.biblionumber Biblio Number (koha internal) +items.multivolumepart Item one part of a Multi volume set +items.biblioitemnumber Biblioitem Number (koha internal) items.barcode Barcode items.dateaccessioned Date acquired items.booksellerid Source of acquisition @@ -112,6 +117,7 @@ statistics.itemnumber Item number statistics.itemtype Itemtype statistics.borrowernumber Borrower number biblio.frameworkcode Framework code +biblio.title Title biblio.author Author biblio.datecreated Creation date biblio.timestamp Modification date diff --git a/misc/cronjobs/overdue_notices.pl b/misc/cronjobs/overdue_notices.pl index 247e04f..07ccdef 100755 --- a/misc/cronjobs/overdue_notices.pl +++ b/misc/cronjobs/overdue_notices.pl @@ -38,8 +38,10 @@ use Encode; use C4::Context; use C4::Dates qw/format_date/; use C4::Debug; +use C4::Charset; use C4::Letters; use C4::Overdues qw(GetFine); +use C4::Reports::Guided; =head1 NAME @@ -252,7 +254,7 @@ my $verbose = 0; my $nomail = 0; my $MAX = 90; my @branchcodes; # Branch(es) passed as parameter -my $csvfilename; +my $csvfilename = ''; my $htmlfilename; my $triggered = 0; my $listall = 0; @@ -278,7 +280,21 @@ GetOptions( pod2usage(1) if $help; pod2usage( -verbose => 2 ) if $man; -if ( defined $csvfilename && $csvfilename =~ /^-/ ) { +my $columns_def_hashref = C4::Reports::Guided::_get_column_defs(); + +# get column header definitions +foreach my $key ( keys %$columns_def_hashref ) { + my $initkey = $key; + $key =~ s/[^\.]*\.//; + #warn "KEY : $initkey = ".$columns_def_hashref->{$initkey}; + if ($columns_def_hashref->{$initkey}) { + $columns_def_hashref->{$initkey}=NormalizeString($columns_def_hashref->{$initkey}); + $columns_def_hashref->{$initkey}=~s# #
#; + } + $columns_def_hashref->{$key} = $columns_def_hashref->{$initkey}; +} + +if ( $csvfilename =~ /^-/ ) { warn qq(using "$csvfilename" as filename, that seems odd); } @@ -328,7 +344,7 @@ binmode( STDOUT, ':encoding(UTF-8)' ); our $csv; # the Text::CSV_XS object our $csv_fh; # the filehandle to the CSV file. -if ( defined $csvfilename ) { +if ( $csvfilename ) { my $sep_char = C4::Context->preference('delimiter') || ','; $sep_char = "\t" if ($sep_char eq 'tabulation'); $csv = Text::CSV_XS->new( { binary => 1 , sep_char => $sep_char } ); @@ -337,7 +353,7 @@ if ( defined $csvfilename ) { } else { open $csv_fh, ">", $csvfilename or die "unable to open $csvfilename: $!"; } - if ( $csv->combine(qw(name surname address1 address2 zipcode city country email itemcount itemsinfo)) ) { + if ( $csvfilename && $csv->combine(qw(name surname address1 address2 zipcode city country email itemcount itemsinfo)) ) { print $csv_fh $csv->string, "\n"; } else { $verbose and warn 'combine failed on argument: ' . $csv->error_input; @@ -467,8 +483,8 @@ END_SQL $verbose and warn "debarring $borrowernumber $firstname $lastname\n"; } my @params = ($listall ? ( $borrowernumber , 1 , $MAX ) : ( $borrowernumber, $mindays, $maxdays )); - $verbose and warn "STH2 PARAMS: borrowernumber = $borrowernumber, mindays = $mindays, maxdays = $maxdays"; $sth2->execute(@params); + $verbose and warn "STH2 PARAMS: borrowernumber = $borrowernumber, mindays = $mindays, maxdays = $maxdays returns ".$sth2->rows." rows"; my $itemcount = 0; my $titles; if ($htmlfilename) { @@ -487,10 +503,16 @@ END_SQL } $i++; my @item_info = map { $_ =~ /^date|date$/ ? format_date( $item_info->{$_} ) : $item_info->{$_} || '' } @item_content_fields; - $titles .= join("\t", @item_info) . "\n"; + if ($htmlfilename) { + $titles .= "" . join( "", @item_info ) . ""; + } else { + $titles .= join("\t", @item_info) . "\n"; + } $itemcount++; push @items, $item_info; } + $titles .= "" if ($htmlfilename); + $debug && warn $titles; $sth2->finish; my $letter = parse_letter( @@ -513,19 +535,19 @@ END_SQL next PERIOD; } - $letter->{'content-type'}="text/".($htmlfilename?"html":"plain"); + $letter->{'content-type'}="text/".($htmlfilename?"html":"plain")."; charset=UTF8"; if ($exceededPrintNoticesMaxLines) { $letter->{'content'} .= "List too long for form; please check your account online for a complete list of your overdue items."; } - my @misses = grep { /./ } map { /^([^>]*)[>]+/; ( $1 || '' ); } split /\{'content'}; + my @misses = grep { /./ } map { /^([^>]*)[>]{2,}/; ( $1 || '' ); } split /\<\{'content'}; if (@misses) { $verbose and warn "The following terms were not matched and replaced: \n\t" . join "\n\t", @misses; } - $letter->{'content'} =~ s/\<[^<>]*?\>//g; # Now that we've warned about them, remove them. - $letter->{'content'} =~ s/\<[^<>]*?\>//g; # 2nd pass for the double nesting. + $letter->{'content'} =~ s/\<\<[^<>]*?\>\>//g; # Now that we've warned about them, remove them. + # $letter->{'content'} =~ s/\<[^<>]*?\>//g; # 2nd pass for the double nesting. if ($nomail) { push @output_chunks, @@ -541,7 +563,7 @@ END_SQL email => $email, itemcount => $itemcount, titles => $titles, - outputformat => defined $csvfilename ? 'csv' : defined $htmlfilename ? 'html' : '', + outputformat => $csvfilename ? 'csv' : defined $htmlfilename ? 'html' : '', } ); } else { @@ -569,7 +591,7 @@ END_SQL email => $email, itemcount => $itemcount, titles => $titles, - outputformat => defined $csvfilename ? 'csv' : defined $htmlfilename ? 'html' : '', + outputformat => $csvfilename ? 'csv' : defined $htmlfilename ? 'html' : '', } ); } @@ -580,7 +602,7 @@ END_SQL } if (@output_chunks) { - if ( defined $csvfilename ) { + if ( $csvfilename ) { print $csv_fh @output_chunks; } elsif ( defined $htmlfilename ) { @@ -738,6 +760,7 @@ sub prepare_letter_for_printing { } } elsif ( exists $params->{'outputformat'} && $params->{'outputformat'} eq 'html' ) { $return = "
\n";
+        $params->{'letter'}->{'content'} =~ s#
#
#g; $return .= "$params->{'letter'}->{'content'}\n"; $return .= "\n
\n"; } else { -- 1.7.5.4