From 61c8f9b44903edecc0b58b97c84bb3f290d50ed5 Mon Sep 17 00:00:00 2001 From: Alex Arnaud Date: Fri, 2 Sep 2011 11:40:40 +0200 Subject: [PATCH] Bug 6835 - Ability to specify types of email address in overdue_notices.pl - perltidy done - in production for a BibLibre customer - validated by the customer Signed-off-by: Claire Hernandez --- C4/Members.pm | 33 +++++++++++++++++++++++++++++++++ misc/cronjobs/overdue_notices.pl | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 63 insertions(+), 2 deletions(-) diff --git a/C4/Members.pm b/C4/Members.pm index 56718f0..4a66900 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -59,6 +59,7 @@ BEGIN { &getidcity &GetFirstValidEmailAddress + &GetValidEmailAddresses &GetAge &GetCities @@ -1324,6 +1325,38 @@ sub GetFirstValidEmailAddress { } } + +=head2 GetValidEmailAddresses + + $email = GetValidEmailAddresses($borrowernumber); + +Return all the valid email address for a borrower, given the borrowernumber. Returns an hash. + +=cut + +sub GetValidEmailAddresses { + my $borrowernumber = shift; + my $dbh = C4::Context->dbh; + my $sth = $dbh->prepare( +"SELECT email, emailpro, B_email FROM borrowers where borrowernumber = ? " + ); + $sth->execute($borrowernumber); + my $data = $sth->fetchrow_hashref; + my %mailhash; + + if ( $data->{'email'} ) { + $mailhash{'email'} = $data->{'email'}; + } + if ( $data->{'emailpro'} ) { + $mailhash{'emailpro'} = $data->{'emailpro'}; + } + if ( $data->{'B_email'} ) { + $mailhash{'B_email'} = $data->{'B_email'}; + } + return \%mailhash; +} + + =head2 GetExpiryDate $expirydate = GetExpiryDate($categorycode, $dateenrolled); diff --git a/misc/cronjobs/overdue_notices.pl b/misc/cronjobs/overdue_notices.pl index 37774b5..3dd25c8 100755 --- a/misc/cronjobs/overdue_notices.pl +++ b/misc/cronjobs/overdue_notices.pl @@ -47,7 +47,10 @@ overdue_notices.pl - prepare messages to be sent to patrons for overdue items =head1 SYNOPSIS -overdue_notices.pl [ -n ] [ -library ] [ -library ...] [ -max ] [ -csv [ ] ] [ -itemscontent ] +overdue_notices + . pl [ -n ][ -library ][ -library ... ] + [ -max ][ -csv [] ][ -itemscontent ] + [ -email ... ] Options: -help brief help message @@ -60,6 +63,7 @@ overdue_notices.pl [ -n ] [ -library ] [ -library ...] -itemscontent item information in templates -borcat category code that must be included -borcatout category code that must be excluded + -email type of email that will be used. Can be 'email', 'emailpro' or 'B_email'. Repeatable. =head1 OPTIONS @@ -143,6 +147,10 @@ Default items.content lists only those items that fall in the range of the currently processing notice. Choose list-all to include all overdue items in the list (limited by B<-max> setting). +=item B<-email> + +Allows to specify which type of email will be used. Can be email, emailpro or B_email. Repeatable. + =back =head1 DESCRIPTION @@ -252,6 +260,8 @@ my $verbose = 0; my $nomail = 0; my $MAX = 90; my @branchcodes; # Branch(es) passed as parameter +my @emails_to_use; # Emails to use for messaging +my @emails; # Emails given in command-line parameters my $csvfilename; my $htmlfilename; my $triggered = 0; @@ -274,6 +284,7 @@ GetOptions( 't|triggered' => \$triggered, 'borcat=s' => \@myborcat, 'borcatout=s' => \@myborcatout, + 'email=s' => \@emails, ) or pod2usage(2); pod2usage(1) if $help; pod2usage( -verbose => 2 ) if $man; @@ -458,6 +469,22 @@ END_SQL $address1, $address2, $city, $postcode, $country, $email, $longest_issue ) = $sth->fetchrow ) { + @emails_to_use = (); + if ( @emails && !$nomail ) { + my $validemails = + C4::Members::GetValidEmailAddresses($borrowernumber); + foreach (@emails) { + push @emails_to_use, $validemails->{$_} + if ( defined $validemails->{$_} ); + } + $email = 1 if (@emails_to_use); + } + else { + $email = + C4::Members::GetFirstValidEmailAddress($borrowernumber); + push @emails_to_use, $email; + } + $verbose and warn "borrower $firstname, $lastname ($borrowernumber) has $itemcount items triggering level $i."; my $letter = C4::Letters::getletter( 'circulation', $overdue_rules->{"letter$i"} ); @@ -539,12 +566,13 @@ END_SQL } ); } else { - if ($email) { + if (scalar(@emails_to_use) > 0 ) { C4::Letters::EnqueueLetter( { letter => $letter, borrowernumber => $borrowernumber, message_transport_type => 'email', from_address => $admin_email_address, + to_address => join(',', @emails_to_use), } ); } else { -- 1.7.4.1