Bug 5867 : Improved the email checking when sending "Hold filled" notices.
authorFrédérick Capovilla <frederick.capovilla@sys-tech.net>
Tue, 15 Mar 2011 15:16:48 +0000 (11:16 -0400)
committerChris Cormack <chrisc@catalyst.net.nz>
Thu, 14 Jul 2011 23:10:00 +0000 (11:10 +1200)
The subroutine for sending HOLD and HOLD_PRINT notices only checked the
"email" field of the borrowers table and didn't check the value of the
AutoEmailPrimaryAddress preference. With this patch, "Hold filled"
notices can now be sent using the other email addresses of the member.

http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=5867
Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>
Signed-off-by: Ian Walls <ian.walls@bywatersolutions.com>
C4/Reserves.pm

index fde1223..8373840 100644 (file)
@@ -1662,10 +1662,21 @@ sub _koha_notify_reserve {
 
     my $dbh = C4::Context->dbh;
     my $borrower = C4::Members::GetMember(borrowernumber => $borrowernumber);
+    
+    # Try to get the borrower's email address
+    my $to_address;
+    my $which_address = C4::Context->preference('AutoEmailPrimaryAddress');
+    # If the system preference is set to 'first valid' (value == OFF), look up email address
+    if ($which_address eq 'OFF') {
+        $to_address = C4::Members::GetFirstValidEmailAddress( $borrowernumber );
+    } else {
+        $to_address = $borrower->{$which_address};
+    }
+    
     my $letter_code;
     my $print_mode = 0;
     my $messagingprefs;
-    if ( $borrower->{'email'} || $borrower->{'smsalertnumber'} ) {
+    if ( $to_address || $borrower->{'smsalertnumber'} ) {
         $messagingprefs = C4::Members::Messaging::GetMessagingPreferences( { borrowernumber => $borrowernumber, message_name => 'Hold_Filled' } );
 
         return if ( !defined( $messagingprefs->{'letter_code'} ) );