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

(-)a/C4/Letters.pm (-1 / +3 lines)
Lines 1305-1311 sub _send_message_by_email { Link Here
1305
1305
1306
    my $patron = Koha::Patrons->find( $message->{borrowernumber} );
1306
    my $patron = Koha::Patrons->find( $message->{borrowernumber} );
1307
    my $to_address = $message->{'to_address'};
1307
    my $to_address = $message->{'to_address'};
1308
    unless ($to_address) {
1308
1309
    my $use_garantor = C4::Context->preference('RedirectGuaranteeEmail');
1310
    if($use_garantor || !$to_address) {
1309
        unless ($patron) {
1311
        unless ($patron) {
1310
            warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})";
1312
            warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})";
1311
            _set_message_status( { message_id => $message->{'message_id'},
1313
            _set_message_status( { message_id => $message->{'message_id'},
(-)a/C4/Members.pm (+72 lines)
Lines 71-76 BEGIN { Link Here
71
        &IssueSlip
71
        &IssueSlip
72
72
73
        GetOverduesForPatron
73
        GetOverduesForPatron
74
75
        &GetNoticeEmailAddress
74
    );
76
    );
75
77
76
    #Modify data
78
    #Modify data
Lines 876-881 sub get_cardnumber_length { Link Here
876
    return ( $min, $max );
878
    return ( $min, $max );
877
}
879
}
878
880
881
=head2 GetFirstValidEmailAddress
882
883
  $email = GetFirstValidEmailAddress($borrowernumber);
884
885
Return the first valid email address for a borrower, given the borrowernumber.  For now, the order 
886
is defined as email, emailpro, B_email.  Returns the empty string if the borrower has no email 
887
addresses.
888
889
=cut
890
891
sub GetFirstValidEmailAddress {
892
    my $borrowernumber = shift;
893
894
    my $borrower = Koha::Patrons->find( $borrowernumber );
895
896
    return $borrower->first_valid_email_address();
897
}
898
899
=head2 GetNoticeEmailAddress
900
901
  $email = GetNoticeEmailAddress($borrowernumber);
902
903
Return the email address of borrower used for notices, given the borrowernumber.
904
Returns the empty string if no email address.
905
906
=cut
907
908
sub GetNoticeEmailAddress {
909
    my $borrowernumber = shift;
910
911
    my $which_address = C4::Context->preference("AutoEmailPrimaryAddress");
912
    my $address;
913
914
    # if syspref is set to 'first valid' (value == OFF), look up email address
915
    if ( $which_address eq 'OFF' ) {
916
        $address = GetFirstValidEmailAddress($borrowernumber);
917
    }
918
    else {
919
        # specified address address field
920
        my $dbh = C4::Context->dbh;
921
        my $sth = $dbh->prepare( qq{
922
            SELECT $which_address AS primaryaddress
923
            FROM borrowers
924
            WHERE borrowernumber=?
925
        } );
926
        $sth->execute($borrowernumber);
927
        $address = $sth->fetchrow_hashref->{'primaryaddress'};
928
    }
929
930
    # If RedirectGuaranteeEmail is enabled, (and user as guarantor) append guarantor's email
931
    my $use_guarantor = C4::Context->preference('RedirectGuaranteeEmail');
932
    if ($use_guarantor) {
933
        my ($guarantor_id, $guarantor_address );
934
        my $dbh = C4::Context->dbh;
935
        my $sth = $dbh->prepare( qq{
936
            SELECT guarantorid
937
            FROM borrowers
938
            WHERE borrowernumber=?
939
        });
940
        $sth->execute($borrowernumber);
941
        $guarantor_id = $sth->fetchrow_hashref->{'guarantorid'};
942
943
        if ($guarantor_id) {
944
            $guarantor_address = GetNoticeEmailAddress($guarantor_id);
945
            $address .= ', ' . $guarantor_address if $guarantor_address;
946
        }
947
    }
948
    return $address || '';
949
}
950
879
=head2 GetBorrowersToExpunge
951
=head2 GetBorrowersToExpunge
880
952
881
  $borrowers = &GetBorrowersToExpunge(
953
  $borrowers = &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 445-450 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
445
('QuoteOfTheDay','0',NULL,'Enable or disable display of Quote of the Day on the OPAC home page','YesNo'),
445
('QuoteOfTheDay','0',NULL,'Enable or disable display of Quote of the Day on the OPAC home page','YesNo'),
446
('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'),
446
('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'),
447
('RecordLocalUseOnReturn','0',NULL,'If ON, statistically record returns of unissued items as local use, instead of return','YesNo'),
447
('RecordLocalUseOnReturn','0',NULL,'If ON, statistically record returns of unissued items as local use, instead of return','YesNo'),
448
('RedirectGuaranteeEmail', '0', NULL, 'Enable the ability to redirect guarantee email messages to guarantor.', 'YesNo'),
448
('RefundLostOnReturnControl','CheckinLibrary','CheckinLibrary|ItemHomeBranch|ItemHoldingBranch','If a lost item is returned, choose which branch to pick rules for refunding.','Choice'),
449
('RefundLostOnReturnControl','CheckinLibrary','CheckinLibrary|ItemHomeBranch|ItemHoldingBranch','If a lost item is returned, choose which branch to pick rules for refunding.','Choice'),
449
('RenewalLog','0','','If ON, log information about renewals','YesNo'),
450
('RenewalLog','0','','If ON, log information about renewals','YesNo'),
450
('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'),
451
('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 200-205 Patrons: Link Here
200
               no: "Don't"
200
               no: "Don't"
201
         - track last patron activity.
201
         - track last patron activity.
202
         - Everytime a patron will connect, the borrowers.lastseen will be updated with the current time.
202
         - Everytime a patron will connect, the borrowers.lastseen will be updated with the current time.
203
     -
204
         - pref: RedirectGuaranteeEmail
205
           choices:
206
               yes: Enable
207
               no: Disable
208
         - sending emails to both guarantees and their guarantor. This does not affect patrons without guarantors.
203
    "Norwegian patron database":
209
    "Norwegian patron database":
204
     -
210
     -
205
         - pref: NorwegianPatronDBEnable
211
         - pref: NorwegianPatronDBEnable
(-)a/t/db_dependent/Members.t (-2 / +37 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 62;
20
use Test::More tests => 65;
21
use Test::MockModule;
21
use Test::MockModule;
22
use Test::Exception;
22
use Test::Exception;
23
23
Lines 139-144 $checkcardnum=C4::Members::checkcardnumber($IMPOSSIBLE_CARDNUMBER, ""); Link Here
139
is ($checkcardnum, "2", "Card number is too long");
139
is ($checkcardnum, "2", "Card number is too long");
140
140
141
141
142
# Test GetNoticeEmailAddress
143
# Add Guarantor for testing
144
my $GUARANTOR_EMAIL = "Robert\@email.com";
145
%data = (
146
    cardnumber => "2997924548",
147
    firstname =>  "Robert",
148
    surname => "Tables",
149
    categorycode => $patron_category->{categorycode},
150
    branchcode => $BRANCHCODE,
151
    dateofbirth => '',
152
    dateexpiry => '9999-12-31',
153
    userid => 'bobbytables',
154
    email => $GUARANTOR_EMAIL
155
);
156
$member->{guarantorid} = AddMember( %data );
157
ModMember( %$member );
158
159
t::lib::Mocks::mock_preference( 'RedirectGuaranteeEmail', '0' );
160
t::lib::Mocks::mock_preference( 'AutoEmailPrimaryAddress', 'OFF' );
161
C4::Context->clear_syspref_cache();
162
163
my $notice_email = GetNoticeEmailAddress($member->{'borrowernumber'});
164
is ($notice_email, $EMAIL, "GetNoticeEmailAddress returns correct value when AutoEmailPrimaryAddress is off");
165
166
t::lib::Mocks::mock_preference( 'AutoEmailPrimaryAddress', 'emailpro' );
167
C4::Context->clear_syspref_cache();
168
169
$notice_email = GetNoticeEmailAddress($member->{'borrowernumber'});
170
is ($notice_email, $EMAILPRO, "GetNoticeEmailAddress returns correct value when AutoEmailPrimaryAddress is emailpro");
171
172
t::lib::Mocks::mock_preference( 'AutoEmailPrimaryAddress', 'OFF' );
173
t::lib::Mocks::mock_preference( 'RedirectGuaranteeEmail', '1' );
174
C4::Context->clear_syspref_cache();
175
$notice_email = GetNoticeEmailAddress($member->{'borrowernumber'});
176
is ($notice_email, $EMAIL . ", " . $GUARANTOR_EMAIL, "GetNoticeEmailAddress returns correct value when RedirectGuaranteeEmail is enabled");
177
142
# Check_Userid tests
178
# Check_Userid tests
143
%data = (
179
%data = (
144
    cardnumber   => "123456789",
180
    cardnumber   => "123456789",
145
- 

Return to bug 12532