View | Details | Raw Unified | Return to bug 12532
Collapse All | Expand All

(-)a/C4/Letters.pm (-4 / +4 lines)
Lines 1179-1196 sub _send_message_by_email { Link Here
1179
    my ($username, $password, $method) = @_;
1179
    my ($username, $password, $method) = @_;
1180
1180
1181
    my $member = C4::Members::GetMember( 'borrowernumber' => $message->{'borrowernumber'} );
1181
    my $member = C4::Members::GetMember( 'borrowernumber' => $message->{'borrowernumber'} );
1182
    my $useGurantor = $member->{'guarantorid'} && C4::Context->preference("EnableRedirectGuaranteeEmail");
1182
    my $to_address = $message->{'to_address'};
1183
    my $to_address = $message->{'to_address'};
1183
    unless ($to_address) {
1184
    if ($useGurantor || !$to_address) {
1184
        unless ($member) {
1185
        unless ($member) {
1185
            warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})";
1186
            warn "FAIL: INVALID borrowernumber ($message->{borrowernumber})";
1186
            _set_message_status( { message_id => $message->{'message_id'},
1187
            _set_message_status( { message_id => $message->{'message_id'},
1187
                                   status     => 'failed' } );
1188
                                   status     => 'failed' } );
1188
            return;
1189
            return;
1189
        }
1190
        }
1190
        $to_address = C4::Members::GetNoticeEmailAddress( $message->{'borrowernumber'} );
1191
        $to_address = C4::Members::GetNoticeEmailAddress( $message->{'borrowernumber'} );
1191
        unless ($to_address) {  
1192
        unless ($to_address) {  
1192
            # warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})";
1193
            warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})";
1193
            # warning too verbose for this more common case?
1194
            _set_message_status( { message_id => $message->{'message_id'},
1194
            _set_message_status( { message_id => $message->{'message_id'},
1195
                                   status     => 'failed' } );
1195
                                   status     => 'failed' } );
1196
            return;
1196
            return;
(-)a/C4/Members.pm (-14 / +13 lines)
Lines 1402-1423 Returns the empty string if no email address. Link Here
1402
1402
1403
sub GetNoticeEmailAddress {
1403
sub GetNoticeEmailAddress {
1404
    my $borrowernumber = shift;
1404
    my $borrowernumber = shift;
1405
    my $dbh = C4::Context->dbh();
1406
1407
    my $member = C4::Members::GetMember( 'borrowernumber' => $borrowernumber );
1408
1409
    #  Determine who we send the email to.
1410
    my $guarantorid = $member->{'guarantorid'};
1411
    my $useGuarantor = $guarantorid && C4::Context->preference("EnableRedirectGuaranteeEmail");
1412
1413
    my $recipient = $useGuarantor ? C4::Members::GetMember( 'borrowernumber' => $guarantorid ) : $member;
1405
1414
1406
    my $which_address = C4::Context->preference("AutoEmailPrimaryAddress");
1407
    # if syspref is set to 'first valid' (value == OFF), look up email address
1415
    # if syspref is set to 'first valid' (value == OFF), look up email address
1408
    if ( $which_address eq 'OFF' ) {
1416
    my $which_address = C4::Context->preference("AutoEmailPrimaryAddress");
1409
        return GetFirstValidEmailAddress($borrowernumber);
1417
    my $to_address = $which_address eq 'OFF' ? GetFirstValidEmailAddress($recipient->{'borrowernumber'}) : $recipient->{ $which_address };
1410
    }
1418
1411
    # specified email address field
1419
   return $to_address || '';
1412
    my $dbh = C4::Context->dbh;
1413
    my $sth = $dbh->prepare( qq{
1414
        SELECT $which_address AS primaryemail
1415
        FROM borrowers
1416
        WHERE borrowernumber=?
1417
    } );
1418
    $sth->execute($borrowernumber);
1419
    my $data = $sth->fetchrow_hashref;
1420
    return $data->{'primaryemail'} || '';
1421
}
1420
}
1422
1421
1423
=head2 GetExpiryDate 
1422
=head2 GetExpiryDate 
(-)a/installer/data/mysql/atomicupdate/bug_12532-EnableRedirectGuaranteeEmail_syspref.sql (+2 lines)
Line 0 Link Here
1
INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type)
2
VALUES ('EnableRedirectGuaranteeEmail','0',NULL,'Enable the ability to redirect guarantee email messages to guarantor.','YesNo');
(-)a/installer/data/mysql/sysprefs.sql (+1 lines)
Lines 133-138 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
133
('EnableAdvancedCatalogingEditor','0','','Enable the Rancor advanced cataloging editor','YesNo'),
133
('EnableAdvancedCatalogingEditor','0','','Enable the Rancor advanced cataloging editor','YesNo'),
134
('EnableBorrowerFiles','0',NULL,'If enabled, allows librarians to upload and attach arbitrary files to a borrower record.','YesNo'),
134
('EnableBorrowerFiles','0',NULL,'If enabled, allows librarians to upload and attach arbitrary files to a borrower record.','YesNo'),
135
('EnableOpacSearchHistory','1','YesNo','Enable or disable opac search history',''),
135
('EnableOpacSearchHistory','1','YesNo','Enable or disable opac search history',''),
136
('EnableRedirectGuaranteeEmail', '0', NULL, 'Enable the ability to redirect guarantee email messages to guarantor.', 'YesNo'),
136
('EnableSearchHistory','0','','Enable or disable search history','YesNo'),
137
('EnableSearchHistory','0','','Enable or disable search history','YesNo'),
137
('EnhancedMessagingPreferences','0','','If ON, allows patrons to select to receive additional messages about items due or nearly due.','YesNo'),
138
('EnhancedMessagingPreferences','0','','If ON, allows patrons to select to receive additional messages about items due or nearly due.','YesNo'),
138
('expandedSearchOption','0',NULL,'If ON, set advanced search to be expanded by default','YesNo'),
139
('expandedSearchOption','0',NULL,'If ON, set advanced search to be expanded by default','YesNo'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref (+6 lines)
Lines 159-164 Patrons: Link Here
159
               yes: Do
159
               yes: Do
160
               no: "Don't"
160
               no: "Don't"
161
         - charge a fee when a patron changes to a category with an enrollment fee.
161
         - charge a fee when a patron changes to a category with an enrollment fee.
162
     -
163
         - pref: EnableRedirectGuaranteeEmail
164
           choices:
165
               yes: Do
166
               no: "Don't"
167
         - enable the ability to redirect guarantee email messages to guarantor. All email message placed in message_queue table will be affected.
162
    "Norwegian patron database":
168
    "Norwegian patron database":
163
     -
169
     -
164
         - pref: NorwegianPatronDBEnable
170
         - pref: NorwegianPatronDBEnable
(-)a/t/db_dependent/Letters.t (+55 lines)
Lines 137-142 is( Link Here
137
    'message marked failed if tried to send SMS message for borrower with no smsalertnumber set (bug 11208)'
137
    'message marked failed if tried to send SMS message for borrower with no smsalertnumber set (bug 11208)'
138
);
138
);
139
139
140
#Test guarantee-guarantor email redirection
141
my ($GUARANTEE_EMAIL, $GUARANTOR_EMAIL) = qw| guarantee@example.com guarantor@example.com |;
142
my $guarantor = {
143
    email        => $GUARANTOR_EMAIL,
144
    categorycode => 'PT',
145
    branchcode   => 'CPL',
146
    surname      => "Guarantor"
147
};
148
$guarantor->{'borrowernumber'} = AddMember(%$guarantor);
149
my $guarantee = {
150
    guarantorid  => $guarantor->{'borrowernumber'},
151
    email        => $GUARANTEE_EMAIL,
152
    categorycode => 'PT',
153
    branchcode   => 'CPL',
154
    surname      => "Guarantee"
155
};
156
$guarantee->{'borrowernumber'} = AddMember(%$guarantee);
157
158
my $GUARANTEE_TO_ADDRESS = 'toto@exemple.com';
159
my $guarantee_message = {
160
    borrowernumber         => $guarantee->{'borrowernumber'},
161
    message_transport_type => 'email',
162
    to_address             => $GUARANTEE_TO_ADDRESS,
163
    from_address           => 'from@example.com',
164
    letter                 => $my_message->{'letter'}
165
};
166
167
sub SendToGuarantor {
168
    my ($useGuarantor, $message) = @_;
169
    C4::Context->set_preference( 'AutoEmailPrimaryAddress', 'OFF' );
170
    C4::Context->set_preference( 'EnableRedirectGuaranteeEmail', $useGuarantor );
171
    C4::Context->clear_syspref_cache();
172
    my $id = C4::Letters::EnqueueLetter($message);
173
    C4::Letters::SendQueuedMessages();
174
    my $result = $dbh->selectrow_hashref( 'SELECT to_address, status FROM message_queue WHERE message_id = ?', undef, ($id) );
175
    return $result;
176
}
177
my $result = SendToGuarantor(0,$guarantee_message);
178
is($result->{'status'}, "sent", "With EnableRedirectGuaranteeEmail off, message is sent.");
179
is($result->{'to_address'}, $GUARANTEE_TO_ADDRESS, "With EnableRedirectGuaranteeEmail off, Message is sent to the specified to_address.");
180
181
$result = SendToGuarantor(1,$guarantee_message);
182
is($result->{'status'}, "sent", "With EnableRedirectGuaranteeEmail on, message is sent.");
183
is($result->{'to_address'}, $GUARANTOR_EMAIL, "With EnableRedirectGuaranteeEmail on, Message is sent to the guarantor's email address.");
184
185
$guarantor->{'email'} = undef;
186
ModMember(%$guarantor);
187
$result = SendToGuarantor(1,$guarantee_message);
188
is($result->{'status'}, "failed", "With EnableRedirectGuaranteeEmail on, message fails if guarantor has no address.");
189
190
$guarantee->{'guarantorid'} = undef;
191
ModMember(%$guarantee);
192
$result = SendToGuarantor(1,$guarantee_message);
193
is($result->{'to_address'}, $GUARANTEE_TO_ADDRESS, "With EnableRedirectGuaranteeEmail on, Message is sent to specicied to_address if he has no guarantor.");
194
140
# GetLetters
195
# GetLetters
141
my $letters = C4::Letters::GetLetters();
196
my $letters = C4::Letters::GetLetters();
142
is( @$letters, 0, 'GetLetters returns the correct number of letters' );
197
is( @$letters, 0, 'GetLetters returns the correct number of letters' );
(-)a/t/db_dependent/Members.t (-1 / +22 lines)
Lines 147-152 is ($checkcardnum, "2", "Card number is too long"); Link Here
147
147
148
148
149
149
150
C4::Context->set_preference( 'EnableRedirectGuaranteeEmail', 0 );
150
C4::Context->set_preference( 'AutoEmailPrimaryAddress', 'OFF' );
151
C4::Context->set_preference( 'AutoEmailPrimaryAddress', 'OFF' );
151
C4::Context->clear_syspref_cache();
152
C4::Context->clear_syspref_cache();
152
153
Lines 159-164 C4::Context->clear_syspref_cache(); Link Here
159
$notice_email = GetNoticeEmailAddress($member->{'borrowernumber'});
160
$notice_email = GetNoticeEmailAddress($member->{'borrowernumber'});
160
is ($notice_email, $EMAILPRO, "GetNoticeEmailAddress returns correct value when AutoEmailPrimaryAddress is emailpro");
161
is ($notice_email, $EMAILPRO, "GetNoticeEmailAddress returns correct value when AutoEmailPrimaryAddress is emailpro");
161
162
163
#Test guarantee-guarantor email redirection
164
my $GUARANTEE_EMAIL = 'guanrantee@email.test';
165
my $guarantee = {
166
    guarantorid  => $member->{'borrowernumber'},
167
    emailpro     => $GUARANTEE_EMAIL,
168
    categorycode => $CATEGORYCODE,
169
    branchcode   => $BRANCHCODE,
170
    surname      => "surname"
171
};
172
$guarantee->{'borrowernumber'} = AddMember(%$guarantee);
173
174
$notice_email = GetNoticeEmailAddress($guarantee->{'borrowernumber'});
175
is ($notice_email, $GUARANTEE_EMAIL, "GetNoticeEmailAddress returns correct value when EnableRedirectGuaranteeEmail is disabled");
176
177
C4::Context->set_preference( 'EnableRedirectGuaranteeEmail', 1 );
178
C4::Context->clear_syspref_cache();
179
180
$notice_email = GetNoticeEmailAddress($guarantee->{'borrowernumber'});
181
is ($notice_email, $EMAILPRO, "GetNoticeEmailAddress returns correct value when EnableRedirectGuaranteeEmail is activated");
182
183
162
ok(!$member->{is_expired}, "GetMemberDetails() indicates that patron is not expired");
184
ok(!$member->{is_expired}, "GetMemberDetails() indicates that patron is not expired");
163
ModMember(borrowernumber => $member->{'borrowernumber'}, dateexpiry => '2001-01-1');
185
ModMember(borrowernumber => $member->{'borrowernumber'}, dateexpiry => '2001-01-1');
164
$member = GetMemberDetails($member->{'borrowernumber'});
186
$member = GetMemberDetails($member->{'borrowernumber'});
165
- 

Return to bug 12532