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

(-)a/Koha/Patron.pm (-9 / +15 lines)
Lines 1616-1634 sub notice_email_address{ Link Here
1616
    my ( $self ) = @_;
1616
    my ( $self ) = @_;
1617
1617
1618
    my $which_address = C4::Context->preference("EmailFieldPrimary");
1618
    my $which_address = C4::Context->preference("EmailFieldPrimary");
1619
    my @addresses;
1620
    for my $email_field ( split ",", $which_address ) {
1621
1619
1622
        # if syspref is set to 'first valid' (value == OFF), look up email address
1620
    # if syspref is set to 'first valid' (value == OFF), look up email address
1623
        if ( $email_field eq 'OFF' ) {
1621
    if ( $which_address eq 'OFF' ) {
1624
            return $self->first_valid_email_address;
1622
        return $self->first_valid_email_address;
1625
        }
1623
    }
1626
1624
1627
        my $email_address = $self->$email_field;
1625
    # if syspref is set to 'selected addresses' (value == MULTI), look up email addresses
1628
        push @addresses, $email_address if $email_address;
1626
    if ( $which_address eq 'MULTI' ) {
1627
        my @addresses;
1628
        my $selected_fields = C4::Context->preference("EmailFieldSelection");
1629
        for my $email_field ( split ",", $selected_fields ) {
1630
            my $email_address = $self->$email_field;
1631
            push @addresses, $email_address if $email_address;
1632
        }
1633
        return join(",",@addresses);
1629
    }
1634
    }
1630
1635
1631
    return join(",",@addresses);
1636
    return $self->$which_address || '';
1637
1632
}
1638
}
1633
1639
1634
=head3 first_valid_email_address
1640
=head3 first_valid_email_address
(-)a/installer/data/mysql/atomicupdate/bug_12802.pl (-2 / +9 lines)
Lines 7-14 return { Link Here
7
        my ($args) = @_;
7
        my ($args) = @_;
8
        my ( $dbh, $out ) = @$args{qw(dbh out)};
8
        my ( $dbh, $out ) = @$args{qw(dbh out)};
9
9
10
        $dbh->do("UPDATE systempreferences SET type='multiple' WHERE variable='EmailFieldPrimary'");
10
        $dbh->do(
11
            "UPDATE systempreferences SET options='email|emailpro|B_email|cardnumber|OFF|MULTI' WHERE variable='EmailFieldPrimary'"
12
        );
13
        say $out "Updated system preference 'EmailFieldPrimary' to include 'selected addresses' option";
11
14
12
        say $out "Updated system preference 'EmailFieldPrimary' to have type 'multiple'";
15
        $dbh->do(
16
            "INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES ('EmailFieldSelection','email|emailpro|B_email','','Selection list of patron email fields to use whern AutoEmailPrimaryAddress is set to selected addresses','multiple')"
17
        );
18
19
        say $out "Added new system preference 'EmailFieldSelection'";
13
    },
20
    },
14
};
21
};
(-)a/installer/data/mysql/mandatory/sysprefs.sql (-1 / +2 lines)
Lines 225-231 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
225
('EmailAddressForPatronRegistrations', '', '', ' If you choose EmailAddressForPatronRegistrations you have to enter a valid email address: ', 'free'),
225
('EmailAddressForPatronRegistrations', '', '', ' If you choose EmailAddressForPatronRegistrations you have to enter a valid email address: ', 'free'),
226
('EmailAddressForSuggestions','','',' If you choose EmailAddressForSuggestions you have to enter a valid email address: ','free'),
226
('EmailAddressForSuggestions','','',' If you choose EmailAddressForSuggestions you have to enter a valid email address: ','free'),
227
('EmailFieldPrecedence','email|emailpro|B_email','','Ordered list of patron email fields to use when AutoEmailPrimaryAddress is set to first valid','multiple'),
227
('EmailFieldPrecedence','email|emailpro|B_email','','Ordered list of patron email fields to use when AutoEmailPrimaryAddress is set to first valid','multiple'),
228
('EmailFieldPrimary','OFF','email|emailpro|B_email|cardnumber|OFF','Defines the default email address field where patron email notices are sent.','multiple'),
228
('EmailFieldPrimary','OFF','email|emailpro|B_email|cardnumber|OFF|MULTI','Defines the default email address field where patron email notices are sent.','Choice'),
229
('EmailFieldSelection','email|emailpro|B_email','','Selection list of patron email fields to use whern AutoEmailPrimaryAddress is set to selected addresses','multiple'),
229
('emailLibrarianWhenHoldIsPlaced','0',NULL,'If ON, emails the librarian whenever a hold is placed','YesNo'),
230
('emailLibrarianWhenHoldIsPlaced','0',NULL,'If ON, emails the librarian whenever a hold is placed','YesNo'),
230
('EmailOverduesNoEmail','1',NULL,'Send send overdues of patrons without email address to staff','YesNo'),
231
('EmailOverduesNoEmail','1',NULL,'Send send overdues of patrons without email address to staff','YesNo'),
231
('EmailPatronRegistrations', '0', '0|EmailAddressForPatronRegistrations|BranchEmailAddress|KohaAdminEmailAddress', 'Choose email address that new patron registrations will be sent to: ', 'Choice'),
232
('EmailPatronRegistrations', '0', '0|EmailAddressForPatronRegistrations|BranchEmailAddress|KohaAdminEmailAddress', 'Choose email address that new patron registrations will be sent to: ', 'Choice'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref (-2 / +11 lines)
Lines 194-208 Patrons: Link Here
194
         - "Use the patron's"
194
         - "Use the patron's"
195
         - pref: EmailFieldPrimary
195
         - pref: EmailFieldPrimary
196
           default: "OFF"
196
           default: "OFF"
197
           multiple:
197
           choices:
198
               email: primary email
198
               email: primary email
199
               emailpro: secondary email
199
               emailpro: secondary email
200
               B_email: alternate email
200
               B_email: alternate email
201
               cardnumber: cardnumber
201
               cardnumber: cardnumber
202
               "OFF": first valid email address
202
               "OFF": first valid email address
203
               "MULTI": selected addresses
203
         - 'for sending out email notices.'
204
         - 'for sending out email notices.'
204
         - '<br><strong>NOTE:</strong> If set to "first valid", the order in which the email addresses are checked is set in <a href="/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=EmailFieldPrecedence">EmailFieldPrecedence</a>.'
205
         - '<br><strong>NOTE:</strong> If set to "first valid", the order in which the email addresses are checked is set in <a href="/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=EmailFieldPrecedence">EmailFieldPrecedence</a>.'
205
         - '<br><strong>NOTE:</strong> To send notices to multiple email fields, ensure "first valid" is <strong>unchecked</strong>.'
206
         - '<br><strong>NOTE:</strong> If set to "selected addresses", the selection refers to the email address fields set in <a href="/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=EmailFieldSelection">EmailFieldSelection</a>.'
206
     -
207
     -
207
         - "When <a href='/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=EmailFieldPrimary'>EmailFieldPrimary</a> is set to '<strong>first valid</strong>', check the patron email address fields in the following order and use the first valid email address found:"
208
         - "When <a href='/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=EmailFieldPrimary'>EmailFieldPrimary</a> is set to '<strong>first valid</strong>', check the patron email address fields in the following order and use the first valid email address found:"
208
         - pref: EmailFieldPrecedence
209
         - pref: EmailFieldPrecedence
Lines 210-215 Patrons: Link Here
210
         - '<br><strong>NOTE:</strong> All patron fields can be used, but to work correctly they must contain a valid email address or an empty string.'
211
         - '<br><strong>NOTE:</strong> All patron fields can be used, but to work correctly they must contain a valid email address or an empty string.'
211
         - "Valid options are the <a href='http://schema.koha-community.org/__VERSION__/tables/borrowers.html' target='blank'>database columns</a> of the borrowers table, separated by | (pipe)."
212
         - "Valid options are the <a href='http://schema.koha-community.org/__VERSION__/tables/borrowers.html' target='blank'>database columns</a> of the borrowers table, separated by | (pipe)."
212
         - "Example: email|emailpro|B_email"
213
         - "Example: email|emailpro|B_email"
214
     -
215
         - "When <a href='/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=EmailFieldPrimary'>EmailFieldPrimary</a> is set to '<strong>selected addresses</strong>', send email to all valid email addresses in the selected fields:"
216
         - pref: EmailFieldSelection
217
           default: "email"
218
           multiple:
219
               email: primary email
220
               emailpro: secondary email
221
               B_email: alternate email
213
     -
222
     -
214
         - pref: TalkingTechItivaPhoneNotification
223
         - pref: TalkingTechItivaPhoneNotification
215
           choices:
224
           choices:
(-)a/t/db_dependent/Koha/Patron.t (-7 / +16 lines)
Lines 1793-1809 subtest 'notice_email_address' => sub { Link Here
1793
    plan tests => 3;
1793
    plan tests => 3;
1794
    $schema->storage->txn_begin;
1794
    $schema->storage->txn_begin;
1795
1795
1796
    my $patron = $builder->build_object({ class => 'Koha::Patrons' });
1796
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
1797
1797
1798
    t::lib::Mocks::mock_preference( 'EmailFieldPrecedence', 'email|emailpro' );
1798
    t::lib::Mocks::mock_preference( 'EmailFieldPrecedence', 'email|emailpro' );
1799
    t::lib::Mocks::mock_preference( 'EmailFieldPrimary', 'OFF' );
1799
    t::lib::Mocks::mock_preference( 'EmailFieldPrimary',    'OFF' );
1800
    is ($patron->notice_email_address, $patron->email, "Koha::Patron->notice_email_address returns correct value when EmailFieldPrimary is off");
1800
    is(
1801
        $patron->notice_email_address, $patron->email,
1802
        "Koha::Patron->notice_email_address returns correct value when EmailFieldPrimary is off"
1803
    );
1801
1804
1802
    t::lib::Mocks::mock_preference( 'EmailFieldPrimary', 'emailpro' );
1805
    t::lib::Mocks::mock_preference( 'EmailFieldPrimary', 'emailpro' );
1803
    is ($patron->notice_email_address, $patron->emailpro, "Koha::Patron->notice_email_address returns correct value when EmailFieldPrimary is emailpro");
1806
    is(
1807
        $patron->notice_email_address, $patron->emailpro,
1808
        "Koha::Patron->notice_email_address returns correct value when EmailFieldPrimary is emailpro"
1809
    );
1804
1810
1805
    t::lib::Mocks::mock_preference( 'EmailFieldPrimary', 'email,emailpro' );
1811
    t::lib::Mocks::mock_preference( 'EmailFieldPrimary',   'MULTI' );
1806
    is ($patron->notice_email_address, $patron->email.",".$patron->emailpro, "Koha::Patron->notice_email_address returns correct value when EmailFieldPrimary is email|emailpro");
1812
    t::lib::Mocks::mock_preference( 'EmailFieldSelection', 'email,emailpro' );
1813
    is(
1814
        $patron->notice_email_address, $patron->email . "," . $patron->emailpro,
1815
        "Koha::Patron->notice_email_address returns correct value when EmailFieldPrimary is 'MULTI' and EmailFieldSelection is 'email,emailpro'"
1816
    );
1807
1817
1808
    $patron->delete;
1818
    $patron->delete;
1809
    $schema->storage->txn_rollback;
1819
    $schema->storage->txn_rollback;
1810
- 

Return to bug 12802