From 63e871dd401c33f288202358639bf098af596148 Mon Sep 17 00:00:00 2001 From: Jesse Weaver Date: Thu, 11 Jun 2009 14:49:15 -0600 Subject: [PATCH] Bug 3482 Allow hold notices to be sent in print form This is done by saving the notices in the message_queue table with type 'print'. The notices are generated from a notice named HOLD_PRINT. At the end of the day, they are dumped to an HTML file and marked as sent by a new cronjob. This setup is intended to be temporary; modules/batch/ shouldn't be around forever. Mandatory SQL: INSERT INTO message_transport_types (message_transport_type) values ('print'); --- C4/Letters.pm | 22 ++++- C4/Reserves.pm | 41 ++++++--- .../en/mandatory/message_transport_types.sql | 1 + .../prog/en/modules/batch/print-notices.tmpl | 24 +++++ misc/cronjobs/gather_print_notices.pl | 90 +++++++++++++++++++ 5 files changed, 167 insertions(+), 11 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/batch/print-notices.tmpl create mode 100755 misc/cronjobs/gather_print_notices.pl diff --git a/C4/Letters.pm b/C4/Letters.pm index 3c6ff15196..cf3e215be1 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -41,7 +41,7 @@ BEGIN { $VERSION = 3.01; @ISA = qw(Exporter); @EXPORT = qw( - &GetLetters &getletter &addalert &getalert &delalert &findrelatedto &SendAlerts + &GetLetters &getletter &addalert &getalert &delalert &findrelatedto &SendAlerts GetPrintMessages ); } @@ -667,6 +667,26 @@ sub GetRSSMessages { borrowernumber => $params->{'borrowernumber'}, } ); } +=head2 GetPrintMessages + +=over 4 + +my $message_list = GetPrintMessages( { borrowernumber => $borrowernumber } ) + +Returns a arrayref of all queued print messages (optionally, for a particular +person). + +=back + +=cut + +sub GetPrintMessages { + my $params = shift || {}; + + return _get_unsent_messages( { message_transport_type => 'print', + borrowernumber => $params->{'borrowernumber'}, } ); +} + =head2 GetQueuedMessages ([$hashref]) =over 4 diff --git a/C4/Reserves.pm b/C4/Reserves.pm index f25764cb72..d8f3b0bbb5 100644 --- a/C4/Reserves.pm +++ b/C4/Reserves.pm @@ -32,7 +32,7 @@ use C4::Accounts; # for _koha_notify_reserve use C4::Members::Messaging; -use C4::Members qw( GetMember ); +use C4::Members qw(); use C4::Letters; use C4::Branch qw( GetBranchDetail ); use C4::Dates qw( format_date_in_iso ); @@ -1688,9 +1688,19 @@ sub _koha_notify_reserve { my ($itemnumber, $borrowernumber, $biblionumber) = @_; my $dbh = C4::Context->dbh; - my $messagingprefs = C4::Members::Messaging::GetMessagingPreferences( { borrowernumber => $borrowernumber, message_name => 'Hold Filled' } ); - - return if ( !defined( $messagingprefs->{'letter_code'} ) ); + my $borrower = C4::Members::GetMember( $borrowernumber ); + my $letter_code; + my $print_mode = 0; + my $messagingprefs; + if ( $borrower->{'email'} || $borrower->{'smsalertnumber'} ) { + $messagingprefs = C4::Members::Messaging::GetMessagingPreferences( { borrowernumber => $borrowernumber, message_name => 'Hold Filled' } ); + + return if ( !defined( $messagingprefs->{'letter_code'} ) ); + $letter_code = $messagingprefs->{'letter_code'}; + } else { + $letter_code = 'HOLD_PRINT'; + $print_mode = 1; + } my $sth = $dbh->prepare(" SELECT * @@ -1704,12 +1714,13 @@ sub _koha_notify_reserve { my $admin_email_address = $branch_details->{'branchemail'} || C4::Context->preference('KohaAdminEmailAddress'); - my $letter = getletter( 'reserves', $messagingprefs->{'letter_code'} ); + my $letter = getletter( 'reserves', $letter_code ); + die "Could not find a letter called '$letter_code' in the 'reserves' module" unless( $letter ); C4::Letters::parseletter( $letter, 'branches', $reserve->{'branchcode'} ); - C4::Letters::parseletter( $letter, 'borrowers', $reserve->{'borrowernumber'} ); - C4::Letters::parseletter( $letter, 'biblio', $reserve->{'biblionumber'} ); - C4::Letters::parseletter( $letter, 'reserves', $reserve->{'borrowernumber'}, $reserve->{'biblionumber'} ); + C4::Letters::parseletter( $letter, 'borrowers', $borrowernumber ); + C4::Letters::parseletter( $letter, 'biblio', $biblionumber ); + C4::Letters::parseletter( $letter, 'reserves', $borrowernumber, $biblionumber ); if ( $reserve->{'itemnumber'} ) { C4::Letters::parseletter( $letter, 'items', $reserve->{'itemnumber'} ); @@ -1719,7 +1730,17 @@ sub _koha_notify_reserve { $letter->{'content'} =~ s/<>/$today/g; $letter->{'content'} =~ s/<<[a-z0-9_]+\.[a-z0-9]+>>//g; #remove any stragglers - if ( -1 != firstidx { $_ eq 'email' } @{$messagingprefs->{transports}} ) { + if ( $print_mode ) { + C4::Letters::EnqueueLetter( { + letter => $letter, + borrowernumber => $borrowernumber, + message_transport_type => 'print', + } ); + + return; + } + + if ( grep { $_ eq 'email' } @{$messagingprefs->{transports}} ) { # aka, 'email' in ->{'transports'} C4::Letters::EnqueueLetter( { letter => $letter, @@ -1730,7 +1751,7 @@ sub _koha_notify_reserve { ); } - if ( -1 != firstidx { $_ eq 'sms' } @{$messagingprefs->{transports}} ) { + if ( grep { $_ eq 'sms' } @{$messagingprefs->{transports}} ) { C4::Letters::EnqueueLetter( { letter => $letter, borrowernumber => $borrowernumber, diff --git a/installer/data/mysql/en/mandatory/message_transport_types.sql b/installer/data/mysql/en/mandatory/message_transport_types.sql index 517f5cc96c..3b85a6017d 100644 --- a/installer/data/mysql/en/mandatory/message_transport_types.sql +++ b/installer/data/mysql/en/mandatory/message_transport_types.sql @@ -2,4 +2,5 @@ INSERT INTO message_transport_types (message_transport_type) values ('email'), +('print'), ('sms'); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/batch/print-notices.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/batch/print-notices.tmpl new file mode 100644 index 0000000000..762b15727c --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/batch/print-notices.tmpl @@ -0,0 +1,24 @@ + + Print Notices for <!-- TMPL_VAR NAME="today" --> + + + + + + + +
+
+
+ + + diff --git a/misc/cronjobs/gather_print_notices.pl b/misc/cronjobs/gather_print_notices.pl new file mode 100755 index 0000000000..62939c79e3 --- /dev/null +++ b/misc/cronjobs/gather_print_notices.pl @@ -0,0 +1,90 @@ +#!/usr/bin/perl -w + +# Copyright 2009 Jesse Weaver +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place, +# Suite 330, Boston, MA 02111-1307 USA + +use strict; +use warnings; + +BEGIN { + + # find Koha's Perl modules + # test carefully before changing this + use FindBin; + eval { require "$FindBin::Bin/../kohalib.pl" }; +} + +use CGI; # NOT a CGI script, this is just to keep C4::Output::gettemplate happy +use C4::Context; +use C4::Dates; +use C4::Debug; +use C4::Letters; +use C4::Output; +use File::Spec; +use Getopt::Long; + +sub usage { + print STDERR < \$stylesheet, + 'h|help' => \$help, +) || usage( 1 ); + +usage( 0 ) if ( $help ); + +my $output_directory = $ARGV[0]; + +if ( !$output_directory || !-d $output_directory ) { + print STDERR "Error: You must specify a valid directory to dump the print notices in.\n"; + usage( 1 ); +} + +my $today = C4::Dates->new(); +my @messages = @{ GetPrintMessages() }; +exit unless( @messages ); + +open OUTPUT, '>', File::Spec->catdir( $output_directory, "notices-" . $today->output( 'iso' ) . ".html" ); + +my $template = C4::Output::gettemplate( 'batch/print-notices.tmpl', 'intranet', new CGI ); +my $stylesheet_contents = ''; + +open STYLESHEET, '<', $stylesheet; +while ( ) { $stylesheet_contents .= $_ } +close STYLESHEET; + +$template->param( + stylesheet => $stylesheet_contents, + today => $today->output(), + messages => \@messages, +); + +print OUTPUT $template->output; + +foreach my $message ( @messages ) { + C4::Letters::_set_message_status( { message_id => $message->{'message_id'}, status => 'sent' } ); +} -- 2.39.5