From af5ad339f71d80a48baad81d8038e58b1043d731 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Mon, 22 Feb 2010 10:21:31 -0500 Subject: [PATCH] Bug 3482 Print Notices via HTML Modified overdue_notices.pl to support output of html for printing. The -html option will e-mail notices to those with e-mail, and output html to print for borrowers without e-mail. When system preference PrintNoticesMaxLines is set to a positive integer, it will limit the number of items on the notice to that number, and append a message to the end telling the borrower to check his or her account for the full listing of items. This only affects print notices, not emailed ones. Mandatory SQL: INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` ) i VALUES ( 'PrintNoticesMaxLines', '0', '', i 'If greater than 0, sets the maximum number of lines an overdue notice will print. If the number of items is greater than this number, the notice will end with a warning asking the borrower to check their online account for a full list of overdue items.', 'Integer' ); Conflicts: installer/data/mysql/en/mandatory/sysprefs.sql installer/data/mysql/fr-FR/1-Obligatoire/unimarc_standard_systemprefs.sql misc/cronjobs/overdue_notices.pl --- .../data/mysql/en/mandatory/sysprefs.sql | 1 + .../unimarc_standard_systemprefs.sql | 1 + misc/cronjobs/overdue_notices.pl | 66 +++++++++++++++++-- 3 files changed, 63 insertions(+), 5 deletions(-) diff --git a/installer/data/mysql/en/mandatory/sysprefs.sql b/installer/data/mysql/en/mandatory/sysprefs.sql index 7cbbe9b38f..39a6b004a5 100644 --- a/installer/data/mysql/en/mandatory/sysprefs.sql +++ b/installer/data/mysql/en/mandatory/sysprefs.sql @@ -283,3 +283,4 @@ INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('A INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('AutoSelfCheckID','','Staff ID with circulation rights to be used for automatic web-based self-check. Only applies if AutoSelfCheckAllowed syspref is turned on.','','free'); INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('AutoSelfCheckPass','','Password to be used for automatic web-based self-check. Only applies if AutoSelfCheckAllowed syspref is turned on.','','free'); INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('soundon','0','Enable circulation sounds during checkin and checkout in the staff interface. Not supported by all web browsers yet.','','YesNo'); +INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` ) VALUES ( 'PrintNoticesMaxLines', '0', '', 'If greater than 0, sets the maximum number of lines an overdue notice will print. If the number of items is greater than this number, the notice will end with a warning asking the borrower to check their online account for a full list of overdue items.', 'Integer' ); diff --git a/installer/data/mysql/fr-FR/1-Obligatoire/unimarc_standard_systemprefs.sql b/installer/data/mysql/fr-FR/1-Obligatoire/unimarc_standard_systemprefs.sql index 2ee92a8bfb..57b808ba5b 100644 --- a/installer/data/mysql/fr-FR/1-Obligatoire/unimarc_standard_systemprefs.sql +++ b/installer/data/mysql/fr-FR/1-Obligatoire/unimarc_standard_systemprefs.sql @@ -286,3 +286,4 @@ INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('A INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('AutoSelfCheckID','','Identifiant Bibliothécaire avec droits de circulation qui sera utilisé pour les prêt auto-contré. Ne s''applique que dans les cas de l''activation de la préférence AutoSelfCheckout.','','free'); INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('AutoSelfCheckPass','','Mot de passe utilisé pour le prêt autocontrôlé. Ne s''applique que dans le cas de l''activation de la préférence AutoSelfCheckout.','','free'); INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('soundon','0','Activer les événements sonores de circulation pendant le prêt et le retour dans l''intranet. N''est pas encore supporté par tous les navigateurs web.','','YesNo'); +INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` ) VALUES ( 'PrintNoticesMaxLines', '0', '', 'If greater than 0, sets the maximum number of lines an overdue notice will print. If the number of items is greater than this number, the notice will end with a warning asking the borrower to check their online account for a full list of overdue items.', 'Integer' ); diff --git a/misc/cronjobs/overdue_notices.pl b/misc/cronjobs/overdue_notices.pl index a2f94a2309..75e8b519a1 100755 --- a/misc/cronjobs/overdue_notices.pl +++ b/misc/cronjobs/overdue_notices.pl @@ -56,6 +56,7 @@ overdue_notices.pl [ -n ] [ -library ] [ -library ...] -max maximum days overdue to deal with -library only deal with overdues from this library (repeatable : several libraries can be given) -csv populate CSV file + -html Output html to file -itemscontent item information in templates -borcat category code that must be included -borcatout category code that must be excluded @@ -246,6 +247,7 @@ my $nomail = 0; my $MAX = 90; my @branchcodes; # Branch(es) passed as parameter my $csvfilename; +my $htmlfilename; my $triggered = 0; my $listall = 0; my $itemscontent = join( ',', qw( issuedate title barcode author biblionumber ) ); @@ -260,6 +262,7 @@ GetOptions( '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. 'itemscontent=s' => \$itemscontent, 'list-all' => \$listall, 't|triggered' => \$triggered, @@ -280,6 +283,8 @@ my $branchcount = scalar(@overduebranches); my $overduebranch_word = scalar @overduebranches > 1 ? 'branches' : 'branch'; my $branchcodes_word = scalar @branchcodes > 1 ? 'branches' : 'branch'; +my $PrintNoticesMaxLines = C4::Context->preference('PrintNoticesMaxLines'); + if ($branchcount) { $verbose and warn "Found $branchcount $overduebranch_word with first message enabled: " . join( ', ', map { "'$_'" } @overduebranches ), "\n"; } else { @@ -314,6 +319,7 @@ my @item_content_fields = split( /,/, $itemscontent ); binmode( STDOUT, ":utf8" ); + our $csv; # the Text::CSV_XS object our $csv_fh; # the filehandle to the CSV file. if ( defined $csvfilename ) { @@ -332,6 +338,27 @@ if ( defined $csvfilename ) { } @branches = @overduebranches unless @branches; +our $html_fh; +if ( defined $htmlfilename ) { + if ( $htmlfilename eq '' ) { + $html_fh = *STDOUT; + } else { + open $html_fh, ">", $htmlfilename or die "unable to open $htmlfilename: $!"; + } + + print $html_fh "\n"; + print $html_fh "\n"; + print $html_fh "\n"; + print $html_fh "\n"; + print $html_fh "\n"; +} + foreach my $branchcode (@branches) { my $branch_details = C4::Branch::GetBranchDetail($branchcode); @@ -426,6 +453,7 @@ END_SQL $verbose and warn "borrower $firstname, $lastname ($borrowernumber) has $itemcount items triggering level $i."; my $letter = C4::Letters::getletter( 'circulation', $overdue_rules->{"letter$i"} ); + unless ($letter) { $verbose and warn "Message '$overdue_rules->{letter$i}' content not found"; @@ -445,7 +473,15 @@ END_SQL my $itemcount = 0; my $titles = ""; my @items = (); + + my $i = 0; + my $exceededPrintNoticesMaxLines = 0; while ( my $item_info = $sth2->fetchrow_hashref() ) { + if ( ( !$email || $nomail ) && $PrintNoticesMaxLines && $i >= $PrintNoticesMaxLines ) { + $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"; $itemcount++; @@ -463,7 +499,11 @@ END_SQL } } ); - + + 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'}; if (@misses) { $verbose and warn "The following terms were not matched and replaced: \n\t" . join "\n\t", @misses; @@ -486,7 +526,7 @@ END_SQL email => $email, itemcount => $itemcount, titles => $titles, - outputformat => defined $csvfilename ? 'csv' : '', + outputformat => defined $csvfilename ? 'csv' : defined $htmlfilename ? 'html' : '', } ); } else { @@ -514,7 +554,7 @@ END_SQL email => $email, itemcount => $itemcount, titles => $titles, - outputformat => defined $csvfilename ? 'csv' : '', + outputformat => defined $csvfilename ? 'csv' : defined $htmlfilename ? 'html' : '', } ); } @@ -528,11 +568,17 @@ END_SQL if ($nomail) { if ( defined $csvfilename ) { print $csv_fh @output_chunks; + } elsif ( defined $htmlfilename ) { + print $html_fh @output_chunks; } else { local $, = "\f"; # pagebreak print @output_chunks; } - } else { + } + elsif ( defined $htmlfilename ) { + print $html_fh @output_chunks; + } + else { my $attachment = { filename => defined $csvfilename ? 'attachment.csv' : 'attachment.txt', type => 'text/plain', @@ -556,12 +602,17 @@ END_SQL } if ($csvfilename) { - # note that we're not testing on $csv_fh to prevent closing # STDOUT. close $csv_fh; } +if ( defined $htmlfilename ) { + print $html_fh "\n"; + print $html_fh "\n"; + close $html_fh; +} + =head1 INTERNAL METHODS These methods are internal to the operation of overdue_notices.pl. @@ -589,6 +640,7 @@ sub parse_letter { # FIXME: this code should probably be moved to C4::Letters:pa return unless exists $params->{$required}; } + if ( $params->{'substitute'} ) { while ( my ( $key, $replacedby ) = each %{ $params->{'substitute'} } ) { my $replacefield = "<<$key>>"; @@ -667,6 +719,10 @@ sub prepare_letter_for_printing { } else { $verbose and warn 'combine failed on argument: ' . $csv->error_input; } + } elsif ( exists $params->{'outputformat'} && $params->{'outputformat'} eq 'html' ) { + $return = "
\n";
+      $return .= "$params->{'letter'}->{'content'}\n";
+      $return .= "\n
\n"; } else { $return .= "$params->{'letter'}->{'content'}\n"; -- 2.39.5