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

(-)a/C4/Letters.pm (-1 / +3 lines)
Lines 1304-1310 sub _send_message_by_email { Link Here
1304
1304
1305
    my $patron = Koha::Patrons->find( $message->{borrowernumber} );
1305
    my $patron = Koha::Patrons->find( $message->{borrowernumber} );
1306
    my $to_address = $message->{'to_address'};
1306
    my $to_address = $message->{'to_address'};
1307
    unless ($to_address) {
1307
1308
    my $use_garantor = C4::Context->preference('RedirectGuaranteeEmail');
1309
    if($use_garantor || !$to_address) {
1308
        unless ($patron) {
1310
        unless ($patron) {
1309
            warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})";
1311
            warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})";
1310
            _set_message_status( { message_id => $message->{'message_id'},
1312
            _set_message_status( { message_id => $message->{'message_id'},
(-)a/C4/Members.pm (-11 / +34 lines)
Lines 949-968 sub GetNoticeEmailAddress { Link Here
949
    my $borrowernumber = shift;
949
    my $borrowernumber = shift;
950
950
951
    my $which_address = C4::Context->preference("AutoEmailPrimaryAddress");
951
    my $which_address = C4::Context->preference("AutoEmailPrimaryAddress");
952
    my $address;
953
952
    # if syspref is set to 'first valid' (value == OFF), look up email address
954
    # if syspref is set to 'first valid' (value == OFF), look up email address
953
    if ( $which_address eq 'OFF' ) {
955
    if ( $which_address eq 'OFF' ) {
954
        return GetFirstValidEmailAddress($borrowernumber);
956
        $address = GetFirstValidEmailAddress($borrowernumber);
955
    }
957
    }
956
    # specified email address field
958
    else {
957
    my $dbh = C4::Context->dbh;
959
        # specified address address field
958
    my $sth = $dbh->prepare( qq{
960
        my $dbh = C4::Context->dbh;
959
        SELECT $which_address AS primaryemail
961
        my $sth = $dbh->prepare( qq{
960
        FROM borrowers
962
            SELECT $which_address AS primaryaddress
961
        WHERE borrowernumber=?
963
            FROM borrowers
962
    } );
964
            WHERE borrowernumber=?
963
    $sth->execute($borrowernumber);
965
        } );
964
    my $data = $sth->fetchrow_hashref;
966
        $sth->execute($borrowernumber);
965
    return $data->{'primaryemail'} || '';
967
        $address = $sth->fetchrow_hashref->{'primaryaddress'};
968
    }
969
970
    # If RedirectGuaranteeEmail is enabled, (and user as guarantor) append guarantor's email
971
    my $use_guarantor = C4::Context->preference('RedirectGuaranteeEmail');
972
    if ($use_guarantor) {
973
        my ($guarantor_id, $guarantor_address );
974
        my $dbh = C4::Context->dbh;
975
        my $sth = $dbh->prepare( qq{
976
            SELECT guarantorid
977
            FROM borrowers
978
            WHERE borrowernumber=?
979
        });
980
        $sth->execute($borrowernumber);
981
        $guarantor_id = $sth->fetchrow_hashref->{'guarantorid'};
982
983
        if ($guarantor_id) {
984
            $guarantor_address = GetNoticeEmailAddress($guarantor_id);
985
            $address .= ', ' . $guarantor_address if $guarantor_address;
986
        }
987
    }
988
    return $address || '';
966
}
989
}
967
990
968
=head2 GetBorrowersToExpunge
991
=head2 GetBorrowersToExpunge
(-)a/installer/data/mysql/atomicupdate/bug_12532-RedirectGuaranteeEmail_syspref.sql (+2 lines)
Line 0 Link Here
1
INSERT IGNORE INTO systempreferences (variable, value, explanation, options, type) 
2
VALUES ('RedirectGuaranteeEmail','0',NULL,'Enable the ability to redirect guarantee email messages to guarantor.','YesNo'); 
(-)a/installer/data/mysql/sysprefs.sql (+1 lines)
Lines 439-444 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
439
('QuoteOfTheDay','0',NULL,'Enable or disable display of Quote of the Day on the OPAC home page','YesNo'),
439
('QuoteOfTheDay','0',NULL,'Enable or disable display of Quote of the Day on the OPAC home page','YesNo'),
440
('RandomizeHoldsQueueWeight','0',NULL,'if ON, the holds queue in circulation will be randomized, either based on all location codes, or by the location codes specified in StaticHoldsQueueWeight','YesNo'),
440
('RandomizeHoldsQueueWeight','0',NULL,'if ON, the holds queue in circulation will be randomized, either based on all location codes, or by the location codes specified in StaticHoldsQueueWeight','YesNo'),
441
('RecordLocalUseOnReturn','0',NULL,'If ON, statistically record returns of unissued items as local use, instead of return','YesNo'),
441
('RecordLocalUseOnReturn','0',NULL,'If ON, statistically record returns of unissued items as local use, instead of return','YesNo'),
442
('RedirectGuaranteeEmail', '0', NULL, 'Enable the ability to redirect guarantee email messages to guarantor.', 'YesNo'), 
442
('RefundLostOnReturnControl','CheckinLibrary','CheckinLibrary|ItemHomeBranch|ItemHoldingBranch','If a lost item is returned, choose which branch to pick rules for refunding.','Choice'),
443
('RefundLostOnReturnControl','CheckinLibrary','CheckinLibrary|ItemHomeBranch|ItemHoldingBranch','If a lost item is returned, choose which branch to pick rules for refunding.','Choice'),
443
('RenewalLog','0','','If ON, log information about renewals','YesNo'),
444
('RenewalLog','0','','If ON, log information about renewals','YesNo'),
444
('RenewalPeriodBase','date_due','date_due|now','Set whether the renewal date should be counted from the date_due or from the moment the Patron asks for renewal ','Choice'),
445
('RenewalPeriodBase','date_due','date_due|now','Set whether the renewal date should be counted from the date_due or from the moment the Patron asks for renewal ','Choice'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref (+6 lines)
Lines 193-198 Patrons: Link Here
193
               no: "Don't"
193
               no: "Don't"
194
         - track last patron activity.
194
         - track last patron activity.
195
         - Everytime a patron will connect, the borrowers.lastseen will be updated with the current time.
195
         - Everytime a patron will connect, the borrowers.lastseen will be updated with the current time.
196
     -
197
         - pref: RedirectGuaranteeEmail 
198
           choices: 
199
               yes: Enable
200
               no: Disable
201
         - sending emails to both guarantees and their guarantor. This does not affect patrons without guarantors.
196
    "Norwegian patron database":
202
    "Norwegian patron database":
197
     -
203
     -
198
         - pref: NorwegianPatronDBEnable
204
         - pref: NorwegianPatronDBEnable
(-)a/t/db_dependent/Members.t (-2 / +24 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 63;
20
use Test::More tests => 64;
21
use Test::MockModule;
21
use Test::MockModule;
22
use Data::Dumper qw/Dumper/;
22
use Data::Dumper qw/Dumper/;
23
use C4::Context;
23
use C4::Context;
Lines 137-143 $checkcardnum=C4::Members::checkcardnumber($IMPOSSIBLE_CARDNUMBER, ""); Link Here
137
is ($checkcardnum, "2", "Card number is too long");
137
is ($checkcardnum, "2", "Card number is too long");
138
138
139
139
140
# Test GetNoticeEmailAddress
141
# Add Guarantor for testing
142
my $GUARANTOR_EMAIL = "Robert\@email.com";
143
%data = (
144
    cardnumber => "2997924548",
145
    firstname =>  "Robert",
146
    surname => "Tables",
147
    categorycode => $patron_category->{categorycode},
148
    branchcode => $BRANCHCODE,
149
    dateofbirth => '',
150
    dateexpiry => '9999-12-31',
151
    userid => 'bobbytables',
152
    email => $GUARANTOR_EMAIL
153
);
154
$member->{guarantorid} = AddMember( %data );
155
ModMember( %$member );
140
156
157
t::lib::Mocks::mock_preference( 'RedirectGuaranteeEmail', '0' );
141
t::lib::Mocks::mock_preference( 'AutoEmailPrimaryAddress', 'OFF' );
158
t::lib::Mocks::mock_preference( 'AutoEmailPrimaryAddress', 'OFF' );
142
C4::Context->clear_syspref_cache();
159
C4::Context->clear_syspref_cache();
143
160
Lines 150-155 C4::Context->clear_syspref_cache(); Link Here
150
$notice_email = GetNoticeEmailAddress($member->{'borrowernumber'});
167
$notice_email = GetNoticeEmailAddress($member->{'borrowernumber'});
151
is ($notice_email, $EMAILPRO, "GetNoticeEmailAddress returns correct value when AutoEmailPrimaryAddress is emailpro");
168
is ($notice_email, $EMAILPRO, "GetNoticeEmailAddress returns correct value when AutoEmailPrimaryAddress is emailpro");
152
169
170
t::lib::Mocks::mock_preference( 'AutoEmailPrimaryAddress', 'OFF' );
171
t::lib::Mocks::mock_preference( 'RedirectGuaranteeEmail', '1' );
172
C4::Context->clear_syspref_cache();
173
$notice_email = GetNoticeEmailAddress($member->{'borrowernumber'});
174
is ($notice_email, $EMAIL . ", " . $GUARANTOR_EMAIL, "GetNoticeEmailAddress returns correct value when RedirectGuaranteeEmail is enabled");
175
153
# Check_Userid tests
176
# Check_Userid tests
154
%data = (
177
%data = (
155
    cardnumber   => "123456789",
178
    cardnumber   => "123456789",
156
- 

Return to bug 12532