Bugzilla – Attachment 4533 Details for
Bug 5878
overdue printing fixes and improvements
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
rebased patch
0001-Bug-5878-overdue-printing-fixes-and-improvements.patch (text/plain), 13.50 KB, created by
Paul Poulain
on 2011-06-29 19:36:01 UTC
(
hide
)
Description:
rebased patch
Filename:
MIME Type:
Creator:
Paul Poulain
Created:
2011-06-29 19:36:01 UTC
Size:
13.50 KB
patch
obsolete
>From fd7c42c92906c1ad1abcfd3df0c16157cf64e25a Mon Sep 17 00:00:00 2001 >From: Paul Poulain <paul.poulain@biblibre.com> >Date: Wed, 15 Dec 2010 13:49:35 +0100 >Subject: [PATCH] Bug 5878 : overdue printing fixes and improvements > >* misc/cronjob/printoverdues deals with utf-8 correctly >* misc/cronjob/overdue_notices >- display the due_date >- deals with a branchcode parameter limit >- deals with the various emails a patron has to select the 1st valid one (function in C4/Members) >--- > misc/cronjobs/overdue_notices.pl | 133 ++++++++++++++++++++++++-------------- > misc/cronjobs/printoverdues.sh | 9 ++- > 2 files changed, 89 insertions(+), 53 deletions(-) > >diff --git a/misc/cronjobs/overdue_notices.pl b/misc/cronjobs/overdue_notices.pl >index bc97ecb..40d83f5 100755 >--- a/misc/cronjobs/overdue_notices.pl >+++ b/misc/cronjobs/overdue_notices.pl >@@ -40,6 +40,9 @@ use C4::Dates qw/format_date/; > use C4::Debug; > use C4::Letters; > use C4::Overdues qw(GetFine); >+use C4::Reports::Guided; #_get_column_defs >+use open qw(:std :utf8); >+use YAML; > > =head1 NAME > >@@ -256,7 +259,7 @@ my $csvfilename; > my $htmlfilename; > my $triggered = 0; > my $listall = 0; >-my $itemscontent = join( ',', qw( date_due title barcode author itemnumber ) ); >+my $itemscontent = join( ',', qw( issuedate title barcode author biblionumber date_due) ); > my @myborcat; > my @myborcatout; > >@@ -267,17 +270,25 @@ GetOptions( > 'n' => \$nomail, > 'max=s' => \$MAX, > 'library=s' => \@branchcodes, >- 'csv:s' => \$csvfilename, # this optional argument gets '' if not supplied. >- 'html:s' => \$htmlfilename, # this optional argument gets '' if not supplied. >+ 'csv:s' => \$csvfilename, # this optional argument gets '' if not supplied. >+ 'html:s' => \$htmlfilename, # this optional argument gets '' if not supplied. > 'itemscontent=s' => \$itemscontent, >- 'list-all' => \$listall, >- 't|triggered' => \$triggered, >- 'borcat=s' => \@myborcat, >- 'borcatout=s' => \@myborcatout, >+ 'list-all' => \$listall, >+ 't|triggered' => \$triggered, >+ 'borcat=s' => \@myborcat, >+ 'borcatout=s' => \@myborcatout, > ) or pod2usage(2); > pod2usage(1) if $help; > pod2usage( -verbose => 2 ) if $man; > >+my $columns_def_hashref = C4::Reports::Guided::_get_column_defs(); >+ >+foreach my $key ( keys %$columns_def_hashref ) { >+ my $initkey = $key; >+ $key =~ s/[^\.]*\.//; >+ $columns_def_hashref->{$key} = $columns_def_hashref->{$initkey}; >+} >+print Dump($columns_def_hashref); > if ( defined $csvfilename && $csvfilename =~ /^-/ ) { > warn qq(using "$csvfilename" as filename, that seems odd); > } >@@ -313,7 +324,7 @@ if (@branchcodes) { > } else { > > $verbose and warn "No active overduerules for $branchcodes_word '@branchcodes'\n"; >- ( scalar grep { '' eq $_ } @branches ) >+ ( scalar grep { $_ eq ""} @overduebranches ) > or die "No active overduerules for DEFAULT either!"; > $verbose and warn "Falling back on default rules for @branchcodes\n"; > @branches = (''); >@@ -353,22 +364,26 @@ if ( defined $htmlfilename ) { > open $html_fh, ">",File::Spec->catdir ($htmlfilename,"notices-".$today->output('iso').".html"); > } > >- print $html_fh "<html>\n"; >- print $html_fh "<head>\n"; >- print $html_fh "<style type='text/css'>\n"; >- print $html_fh "pre {page-break-after: always;}\n"; >- print $html_fh "pre {white-space: pre-wrap;}\n"; >- print $html_fh "pre {white-space: -moz-pre-wrap;}\n"; >- print $html_fh "pre {white-space: -o-pre-wrap;}\n"; >- print $html_fh "pre {word-wrap: break-work;}\n"; >- print $html_fh "</style>\n"; >- print $html_fh "</head>\n"; >- print $html_fh "<body>\n"; >+ print $html_fh <<HEAD; >+<?xml version="1.0" encoding="UTF-8"?> >+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> >+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> >+<head> >+ <style type='text/css'> >+ pre {page-break-after: always;} >+ pre {white-space: pre-wrap;} >+ pre {white-space: -moz-pre-wrap;} >+ pre {white-space: -o-pre-wrap;} >+ pre {word-wrap: break-work;} >+ </style> >+</head> >+<body> >+HEAD > } > > foreach my $branchcode (@branches) { > >- my $branch_details = C4::Branch::GetBranchDetail($branchcode); >+ my $branch_details = C4::Branch::GetBranchDetail($branchcode) unless ($branchcode eq ""); > my $admin_email_address = $branch_details->{'branchemail'} || C4::Context->preference('KohaAdminEmailAddress'); > my @output_chunks; # may be sent to mail or stdout or csv file. > >@@ -431,7 +446,7 @@ WHERE issues.borrowernumber=borrowers.borrowernumber > AND borrowers.categorycode=categories.categorycode > END_SQL > my @borrower_parameters; >- if ($branchcode) { >+ if ($branchcode && $branchcode ne "") { > $borrower_sql .= ' AND issues.branchcode=? '; > push @borrower_parameters, $branchcode; > } >@@ -458,6 +473,7 @@ END_SQL > $address1, $address2, $city, $postcode, $country, $email, > $longest_issue ) = $sth->fetchrow ) > { >+ $email=C4::Members::GetFirstValidEmailAddress($borrowernumber); > $verbose and warn "borrower $firstname, $lastname ($borrowernumber) has $itemcount items triggering level $i."; > > my $letter = C4::Letters::getletter( 'circulation', $overdue_rules->{"letter$i"} ); >@@ -473,29 +489,43 @@ END_SQL > if ( $overdue_rules->{"debarred$i"} ) { > > #action taken is debarring >- C4::Members::DebarMember($borrowernumber); >+ C4::Members::DebarMember($borrowernumber, '9999-12-31'); > $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); > my $itemcount = 0; >- my $titles = ""; >+ >+ my $titles; >+ if ($htmlfilename) { >+ $titles = "<table id='itemscontent$borrowernumber'>"; >+ $titles .= "<thead><tr><th>" . join( "</th><th>", @$columns_def_hashref{@item_content_fields} ); >+ warn @item_content_fields; >+ warn map { "$columns_def_hashref->{$_};" } @item_content_fields; >+ $titles .= "</th></tr></thead><tbody>"; >+ } > my @items = (); >- >- my $i = 0; >+ >+ my $i = 0; > my $exceededPrintNoticesMaxLines = 0; > while ( my $item_info = $sth2->fetchrow_hashref() ) { > if ( ( !$email || $nomail ) && $PrintNoticesMaxLines && $i >= $PrintNoticesMaxLines ) { >- $exceededPrintNoticesMaxLines = 1; >- last; >+ $exceededPrintNoticesMaxLines = 1; >+ last; > } > $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 .= "<tr><td>" . join( "</td><td>", @item_info ) . "</td></tr>"; >+ } else { >+ $titles .= join( "\t", @item_info ) . "\n"; >+ } > $itemcount++; > push @items, { itemnumber => $item_info->{'itemnumber'}, biblionumber => $item_info->{'biblionumber'} }; > } >+ $titles .= "</tbody></table>" if ($htmlfilename); >+ $debug && warn $titles; > $sth2->finish; > $letter = parse_letter( > { letter => $letter, >@@ -508,20 +538,21 @@ END_SQL > } > } > ); >- >- if ( $exceededPrintNoticesMaxLines ) { >- $letter->{'content'} .= "List too long for form; please check your account online for a complete list of your overdue items."; >+ >+ 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 /\</, $letter->{'content'}; >+ my @misses = grep { /./ } map { /^([^>]*)[>]{2,}/; ( $1 || '' ); } split /\<\</, $letter->{'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, > prepare_letter_for_printing( > { letter => $letter, >@@ -531,6 +562,7 @@ END_SQL > address1 => $address1, > address2 => $address2, > city => $city, >+ country => $country, > postcode => $postcode, > email => $email, > itemcount => $itemcount, >@@ -548,7 +580,7 @@ END_SQL > } > ); > } else { >- >+ > # If we don't have an email address for this patron, send it to the admin to deal with. > push @output_chunks, > prepare_letter_for_printing( >@@ -559,6 +591,7 @@ END_SQL > address1 => $address1, > address2 => $address2, > city => $city, >+ country => $country, > postcode => $postcode, > email => $email, > itemcount => $itemcount, >@@ -575,15 +608,16 @@ END_SQL > > if (@output_chunks) { > if ( defined $csvfilename ) { >- print $csv_fh @output_chunks; >- } >- elsif ( defined $htmlfilename ) { >- print $html_fh @output_chunks; >- } >- elsif ($nomail){ >- local $, = "\f"; # pagebreak >- print @output_chunks; >+ print $csv_fh @output_chunks; >+ } elsif ( defined $htmlfilename ) { >+ print $html_fh @output_chunks; >+ } elsif ($nomail) { >+ local $, = "\f"; # pagebreak >+ print @output_chunks; > } >+ my $content = join(";", qw(title name surname address1 address2 zipcode city email itemcount itemsinfo due_date issue_date)) . "\n"; >+ $content .= join( "\n", @output_chunks ); >+ > my $attachment = { > filename => defined $csvfilename ? 'attachment.csv' : 'attachment.txt', > type => 'text/plain', >@@ -612,9 +646,9 @@ if ($csvfilename) { > } > > if ( defined $htmlfilename ) { >- print $html_fh "</body>\n"; >- print $html_fh "</html>\n"; >- close $html_fh; >+ print $html_fh "</body>\n"; >+ print $html_fh "</html>\n"; >+ close $html_fh; > } > > =head1 INTERNAL METHODS >@@ -713,7 +747,7 @@ sub prepare_letter_for_printing { > if ( exists $params->{'outputformat'} && $params->{'outputformat'} eq 'csv' ) { > if ($csv->combine( > $params->{'firstname'}, $params->{'lastname'}, $params->{'address1'}, $params->{'address2'}, $params->{'postcode'}, >- $params->{'city'}, $params->{'email'}, $params->{'itemcount'}, $params->{'titles'} >+ $params->{'city'}, $params->{'country'}, $params->{'email'}, $params->{'itemcount'}, $params->{'titles'} > ) > ) { > return $csv->string, "\n"; >@@ -722,6 +756,7 @@ sub prepare_letter_for_printing { > } > } elsif ( exists $params->{'outputformat'} && $params->{'outputformat'} eq 'html' ) { > $return = "<pre>\n"; >+ $params->{'letter'}->{'content'}=~s# #<br/>#g; > $return .= "$params->{'letter'}->{'content'}\n"; > $return .= "\n</pre>\n"; > } else { >diff --git a/misc/cronjobs/printoverdues.sh b/misc/cronjobs/printoverdues.sh >index 99bb878..6c7e2dc 100755 >--- a/misc/cronjobs/printoverdues.sh >+++ b/misc/cronjobs/printoverdues.sh >@@ -39,8 +39,9 @@ then > fi > for i in $1/*.html > do >- xhtml2pdf $optpisa $i >+ xhtml2pdf --encoding utf-8 $optpisa $i > done >-lp $optprinter $1/*.pdf >-tar cvfz $directory`date "+%Y%m%d"`.tar.gz $directory >-rm -rf $directory >+ >+#lp $optprinter $1/*.pdf >+#tar cvfz $directory`date "+%Y%m%d"`.tar.gz $directory >+#rm -rf $directory >-- >1.7.4.1 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 5878
:
3316
| 4533 |
4535
|
4601
|
4974