From 98d77a45d8a0aa407db2d0486dfac7c4b1a2135c Mon Sep 17 00:00:00 2001 From: Chris Cormack Date: Fri, 1 Apr 2011 11:20:58 +1300 Subject: [PATCH] Bug 6030 Allow html content in letters Squashed commit of the following: commit 8368e5de723ec7607402be341975014c8b7b0ea9 Author: Henri-Damien LAURENT Date: Tue Sep 21 14:41:07 2010 +0200 Bug 6030 : overdue_notices :Removing warning Two extra warnings were issued when using html commit 5984fc92772af68c51f7f5b5450fd5b27d5b6d37 Author: Henri-Damien LAURENT Date: Tue Sep 21 12:27:29 2010 +0200 Bug 6030 : Letters can be html in overdu_notices.pl Signed-off-by: Sophie Meynieux 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 Bug 6030 followup : add a condition to use getlanguage in bath mode Bug 6030 followup : Specify "biblio.title" as a column name to differentiate from borrowers.title Conflicts: misc/cronjobs/overdue_notices.pl --- C4/Templates.pm | 2 +- koha-tmpl/intranet-tmpl/prog/en/columns.def | 6 +++ misc/cronjobs/overdue_notices.pl | 62 ++++++++++++++++++++------- 3 files changed, 53 insertions(+), 17 deletions(-) diff --git a/C4/Templates.pm b/C4/Templates.pm index 507e077..c3b358a 100644 --- a/C4/Templates.pm +++ b/C4/Templates.pm @@ -325,7 +325,7 @@ sub getlanguage { my $lang; # cookie - if ( $query->cookie('KohaOpacLanguage') ) { + if ( defined $query and $query->cookie('KohaOpacLanguage') ) { $lang = $query->cookie('KohaOpacLanguage'); $lang =~ s/[^a-zA-Z_-]*//; # sanitize cookie } 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 e83bd39..8abf95a 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 @@ -256,7 +258,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; @@ -284,7 +286,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); } @@ -341,7 +357,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 } ); @@ -350,7 +366,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; @@ -389,7 +405,7 @@ foreach my $branchcode (@branches) { $verbose and warn sprintf "branchcode : '%s' using %s\n", $branchcode, $admin_email_address; my $sth2 = $dbh->prepare( <<"END_SQL" ); -SELECT biblio.*, items.*, issues.*, biblioitems.itemtype, TO_DAYS($date)-TO_DAYS(date_due) AS days_overdue +SELECT biblio.title as "biblio.title", biblio.*, items.*, issues.*, biblioitems.itemtype, TO_DAYS($date)-TO_DAYS(date_due) AS days_overdue FROM issues,items,biblio, biblioitems WHERE items.itemnumber=issues.itemnumber AND biblio.biblionumber = items.biblionumber @@ -486,10 +502,15 @@ 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 = ""; + my $titles; + if ($htmlfilename) { + $titles = ""; + $titles .= ""; + } my @items = (); my $j = 0; @@ -501,10 +522,16 @@ END_SQL } $j++; my @item_info = map { $_ =~ /^date|date$/ ? format_date( $item_info->{$_} ) : $item_info->{$_} || '' } @item_content_fields; - $titles .= join("\t", @item_info) . "\n"; + if ($htmlfilename) { + $titles .= ""; + } else { + $titles .= join("\t", @item_info) . "\n"; + } $itemcount++; push @items, $item_info; } + $titles .= "
" . join( "", @$columns_def_hashref{@item_content_fields} ); + $titles .= "
" . join( "", @item_info ) . "
" if ($htmlfilename); + $debug && warn $titles; $sth2->finish; my $letter = parse_letter( @@ -528,17 +555,19 @@ END_SQL next PERIOD; } - if ( $exceededPrintNoticesMaxLines ) { - $letter->{'content'} .= "List too long for form; please check your account online for a complete list of your overdue items."; + $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, @@ -554,7 +583,7 @@ END_SQL email => $email, itemcount => $itemcount, titles => $titles, - outputformat => defined $csvfilename ? 'csv' : defined $htmlfilename ? 'html' : '', + outputformat => $csvfilename ? 'csv' : defined $htmlfilename ? 'html' : '', } ); } else { @@ -582,7 +611,7 @@ END_SQL email => $email, itemcount => $itemcount, titles => $titles, - outputformat => defined $csvfilename ? 'csv' : defined $htmlfilename ? 'html' : '', + outputformat => $csvfilename ? 'csv' : defined $htmlfilename ? 'html' : '', } ); } @@ -593,7 +622,7 @@ END_SQL } if (@output_chunks) { - if ( defined $csvfilename ) { + if ( $csvfilename ) { print $csv_fh @output_chunks; } elsif ( defined $htmlfilename ) { @@ -753,6 +782,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