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

(-)a/C4/Letters.pm (-4 / +4 lines)
Lines 1223-1240 sub _send_message_by_email { Link Here
1223
    my ($username, $password, $method) = @_;
1223
    my ($username, $password, $method) = @_;
1224
1224
1225
    my $member = C4::Members::GetMember( 'borrowernumber' => $message->{'borrowernumber'} );
1225
    my $member = C4::Members::GetMember( 'borrowernumber' => $message->{'borrowernumber'} );
1226
    my $useGurantor = $member->{'guarantorid'} && C4::Context->preference("EnableRedirectGuaranteeEmail");
1226
    my $to_address = $message->{'to_address'};
1227
    my $to_address = $message->{'to_address'};
1227
    unless ($to_address) {
1228
    if ($useGurantor || !$to_address) {
1228
        unless ($member) {
1229
        unless ($member) {
1229
            warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})";
1230
            warn "FAIL: INVALID borrowernumber ($message->{borrowernumber})";
1230
            _set_message_status( { message_id => $message->{'message_id'},
1231
            _set_message_status( { message_id => $message->{'message_id'},
1231
                                   status     => 'failed' } );
1232
                                   status     => 'failed' } );
1232
            return;
1233
            return;
1233
        }
1234
        }
1234
        $to_address = C4::Members::GetNoticeEmailAddress( $message->{'borrowernumber'} );
1235
        $to_address = C4::Members::GetNoticeEmailAddress( $message->{'borrowernumber'} );
1235
        unless ($to_address) {  
1236
        unless ($to_address) {  
1236
            # warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})";
1237
            warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})";
1237
            # warning too verbose for this more common case?
1238
            _set_message_status( { message_id => $message->{'message_id'},
1238
            _set_message_status( { message_id => $message->{'message_id'},
1239
                                   status     => 'failed' } );
1239
                                   status     => 'failed' } );
1240
            return;
1240
            return;
(-)a/C4/Members.pm (-14 / +13 lines)
Lines 1206-1227 Returns the empty string if no email address. Link Here
1206
1206
1207
sub GetNoticeEmailAddress {
1207
sub GetNoticeEmailAddress {
1208
    my $borrowernumber = shift;
1208
    my $borrowernumber = shift;
1209
    my $member = C4::Members::GetMember( 'borrowernumber' => $borrowernumber );
1210
1211
    #  Determine who we send the email to.
1212
    my $guarantorid = $member->{'guarantorid'};
1213
    my $useGuarantor = $guarantorid && C4::Context->preference("EnableRedirectGuaranteeEmail");
1214
1215
    my $guarantor =  C4::Members::GetMember( 'borrowernumber' => $guarantorid ) if $useGuarantor;
1209
1216
1210
    my $which_address = C4::Context->preference("AutoEmailPrimaryAddress");
1211
    # if syspref is set to 'first valid' (value == OFF), look up email address
1217
    # if syspref is set to 'first valid' (value == OFF), look up email address
1212
    if ( $which_address eq 'OFF' ) {
1218
    my $which_address = C4::Context->preference("AutoEmailPrimaryAddress");
1213
        return GetFirstValidEmailAddress($borrowernumber);
1219
    my $to_address = $which_address eq 'OFF' ? GetFirstValidEmailAddress($member->{'borrowernumber'}) : $member->{ $which_address };
1214
    }
1220
    my $guarantor_to_address = $which_address eq 'OFF' ? GetFirstValidEmailAddress($guarantor->{'borrowernumber'}) : $guarantor->{ $which_address } if $guarantor;
1215
    # specified email address field
1221
    $to_address .="," . $guarantor_to_address if $guarantor_to_address;
1216
    my $dbh = C4::Context->dbh;
1222
1217
    my $sth = $dbh->prepare( qq{
1223
   return $to_address || '';
1218
        SELECT $which_address AS primaryemail
1219
        FROM borrowers
1220
        WHERE borrowernumber=?
1221
    } );
1222
    $sth->execute($borrowernumber);
1223
    my $data = $sth->fetchrow_hashref;
1224
    return $data->{'primaryemail'} || '';
1225
}
1224
}
1226
1225
1227
=head2 GetExpiryDate 
1226
=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 137-142 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
137
('EnableAdvancedCatalogingEditor','0','','Enable the Rancor advanced cataloging editor','YesNo'),
137
('EnableAdvancedCatalogingEditor','0','','Enable the Rancor advanced cataloging editor','YesNo'),
138
('EnableBorrowerFiles','0',NULL,'If enabled, allows librarians to upload and attach arbitrary files to a borrower record.','YesNo'),
138
('EnableBorrowerFiles','0',NULL,'If enabled, allows librarians to upload and attach arbitrary files to a borrower record.','YesNo'),
139
('EnableOpacSearchHistory','1','YesNo','Enable or disable opac search history',''),
139
('EnableOpacSearchHistory','1','YesNo','Enable or disable opac search history',''),
140
('EnableRedirectGuaranteeEmail', '0', NULL, 'Enable the ability to redirect guarantee email messages to guarantor.', 'YesNo'),
140
('EnableSearchHistory','0','','Enable or disable search history','YesNo'),
141
('EnableSearchHistory','0','','Enable or disable search history','YesNo'),
141
('EnhancedMessagingPreferences','0','','If ON, allows patrons to select to receive additional messages about items due or nearly due.','YesNo'),
142
('EnhancedMessagingPreferences','0','','If ON, allows patrons to select to receive additional messages about items due or nearly due.','YesNo'),
142
('EnhancedMessagingPreferencesOPAC', '1', NULL, 'If ON, show patrons messaging setting on the OPAC.', 'YesNo'),
143
('EnhancedMessagingPreferencesOPAC', '1', NULL, 'If ON, show patrons messaging setting on the OPAC.', 'YesNo'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref (-1 / +6 lines)
Lines 179-185 Patrons: Link Here
179
               yes: Show
179
               yes: Show
180
               no: "Don't show"
180
               no: "Don't show"
181
         - "patron messaging setting on the OPAC (note: EnhancedMessagingPreferences must be enabled)."
181
         - "patron messaging setting on the OPAC (note: EnhancedMessagingPreferences must be enabled)."
182
182
     -
183
         - pref: EnableRedirectGuaranteeEmail
184
           choices:
185
               yes: Do
186
               no: "Don't"
187
         - enable the ability to redirect guarantee email messages to guarantor. All email message placed in message_queue table will be affected.
183
    "Norwegian patron database":
188
    "Norwegian patron database":
184
     -
189
     -
185
         - pref: NorwegianPatronDBEnable
190
         - pref: NorwegianPatronDBEnable
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt (+8 lines)
Lines 76-81 $(document).ready(function() { Link Here
76
            $("#entryform").submit();
76
            $("#entryform").submit();
77
        }
77
        }
78
    });
78
    });
79
    $("#PatronMmessagingPreferences").click(function(){
80
        $("#entryform").submit();
81
    });
79
82
80
});
83
});
81
84
Lines 1054-1059 $(document).ready(function() { Link Here
1054
[% IF ( step_5 ) %][% IF ( EnhancedMessagingPreferences ) %]
1057
[% IF ( step_5 ) %][% IF ( EnhancedMessagingPreferences ) %]
1055
  <fieldset class="rows" id="memberentry_messaging_prefs">
1058
  <fieldset class="rows" id="memberentry_messaging_prefs">
1056
    <legend id="patron_messaging_prefs_lgd">Patron messaging preferences</legend>
1059
    <legend id="patron_messaging_prefs_lgd">Patron messaging preferences</legend>
1060
    [% IF ( !opadd ) && ( !opduplicate ) && !destination %]
1061
        <script type="text/javascript">
1062
            $("#saverecord").attr("id","PatronMmessagingPreferences");
1063
        </script>
1064
    [% END %]
1057
    [% IF ( opadd ) %]
1065
    [% IF ( opadd ) %]
1058
    <!-- handle changing prefs if creating new patron and changing
1066
    <!-- handle changing prefs if creating new patron and changing
1059
         the patron category
1067
         the patron category
(-)a/members/memberentry.pl (-2 / +2 lines)
Lines 322-329 if ($op eq 'save' || $op eq 'insert'){ Link Here
322
    push @errors, "ERROR_login_exist";
322
    push @errors, "ERROR_login_exist";
323
  }
323
  }
324
  
324
  
325
  my $password = $input->param('password');
325
  my $password = $input->param('password') || '';
326
  my $password2 = $input->param('password2');
326
  my $password2 = $input->param('password2') || '';
327
  push @errors, "ERROR_password_mismatch" if ( $password ne $password2 );
327
  push @errors, "ERROR_password_mismatch" if ( $password ne $password2 );
328
  push @errors, "ERROR_short_password" if( $password && $minpw && $password ne '****' && (length($password) < $minpw) );
328
  push @errors, "ERROR_short_password" if( $password && $minpw && $password ne '****' && (length($password) < $minpw) );
329
329
(-)a/t/db_dependent/Letters.t (+55 lines)
Lines 147-152 is( $resent, 0, 'The message should not have been resent again' ); Link Here
147
$resent = C4::Letters::ResendMessage();
147
$resent = C4::Letters::ResendMessage();
148
is( $resent, undef, 'ResendMessage should return undef if not message_id given' );
148
is( $resent, undef, 'ResendMessage should return undef if not message_id given' );
149
149
150
#Test guarantee-guarantor email redirection
151
my ($GUARANTEE_EMAIL, $GUARANTOR_EMAIL) = qw| guarantee@example.com guarantor@example.com |;
152
my $guarantor = {
153
    email        => $GUARANTOR_EMAIL,
154
    categorycode => 'PT',
155
    branchcode   => 'CPL',
156
    surname      => "Guarantor"
157
};
158
$guarantor->{'borrowernumber'} = AddMember(%$guarantor);
159
my $guarantee = {
160
    guarantorid  => $guarantor->{'borrowernumber'},
161
    email        => $GUARANTEE_EMAIL,
162
    categorycode => 'PT',
163
    branchcode   => 'CPL',
164
    surname      => "Guarantee"
165
};
166
$guarantee->{'borrowernumber'} = AddMember(%$guarantee);
167
168
my $GUARANTEE_TO_ADDRESS = 'toto@exemple.com';
169
my $guarantee_message = {
170
    borrowernumber         => $guarantee->{'borrowernumber'},
171
    message_transport_type => 'email',
172
    to_address             => $GUARANTEE_TO_ADDRESS,
173
    from_address           => 'from@example.com',
174
    letter                 => $my_message->{'letter'}
175
};
176
177
sub SendToGuarantor {
178
    my ($useGuarantor, $message) = @_;
179
    C4::Context->set_preference( 'AutoEmailPrimaryAddress', 'OFF' );
180
    C4::Context->set_preference( 'EnableRedirectGuaranteeEmail', $useGuarantor );
181
    C4::Context->clear_syspref_cache();
182
    my $id = C4::Letters::EnqueueLetter($message);
183
    C4::Letters::SendQueuedMessages();
184
    my $result = $dbh->selectrow_hashref( 'SELECT to_address, status FROM message_queue WHERE message_id = ?', undef, ($id) );
185
    return $result;
186
}
187
my $result = SendToGuarantor(0,$guarantee_message);
188
is($result->{'status'}, "sent", "With EnableRedirectGuaranteeEmail off, message is sent.");
189
is($result->{'to_address'}, $GUARANTEE_TO_ADDRESS, "With EnableRedirectGuaranteeEmail off, Message is sent to the specified to_address.");
190
191
$result = SendToGuarantor(1,$guarantee_message);
192
is($result->{'status'}, "sent", "With EnableRedirectGuaranteeEmail on, message is sent.");
193
is($result->{'to_address'}, $GUARANTOR_EMAIL, "With EnableRedirectGuaranteeEmail on, Message is sent to the guarantor's email address.");
194
195
$guarantor->{'email'} = undef;
196
ModMember(%$guarantor);
197
$result = SendToGuarantor(1,$guarantee_message);
198
is($result->{'status'}, "failed", "With EnableRedirectGuaranteeEmail on, message fails if guarantor has no address.");
199
200
$guarantee->{'guarantorid'} = undef;
201
ModMember(%$guarantee);
202
$result = SendToGuarantor(1,$guarantee_message);
203
is($result->{'to_address'}, $GUARANTEE_TO_ADDRESS, "With EnableRedirectGuaranteeEmail on, Message is sent to specicied to_address if he has no guarantor.");
204
150
# GetLetters
205
# GetLetters
151
my $letters = C4::Letters::GetLetters();
206
my $letters = C4::Letters::GetLetters();
152
is( @$letters, 0, 'GetLetters returns the correct number of letters' );
207
is( @$letters, 0, 'GetLetters returns the correct number of letters' );
(-)a/t/db_dependent/Members.t (-1 / +24 lines)
Lines 152-157 is ($checkcardnum, "2", "Card number is too long"); Link Here
152
152
153
153
154
t::lib::Mocks::mock_preference( 'AutoEmailPrimaryAddress', 'OFF' );
154
t::lib::Mocks::mock_preference( 'AutoEmailPrimaryAddress', 'OFF' );
155
156
C4::Context->set_preference( 'EnableRedirectGuaranteeEmail', 0 );
157
C4::Context->set_preference( 'AutoEmailPrimaryAddress', 'OFF' );
155
C4::Context->clear_syspref_cache();
158
C4::Context->clear_syspref_cache();
156
159
157
my $notice_email = GetNoticeEmailAddress($member->{'borrowernumber'});
160
my $notice_email = GetNoticeEmailAddress($member->{'borrowernumber'});
Lines 163-168 C4::Context->clear_syspref_cache(); Link Here
163
$notice_email = GetNoticeEmailAddress($member->{'borrowernumber'});
166
$notice_email = GetNoticeEmailAddress($member->{'borrowernumber'});
164
is ($notice_email, $EMAILPRO, "GetNoticeEmailAddress returns correct value when AutoEmailPrimaryAddress is emailpro");
167
is ($notice_email, $EMAILPRO, "GetNoticeEmailAddress returns correct value when AutoEmailPrimaryAddress is emailpro");
165
168
169
#Test guarantee-guarantor email redirection
170
my $GUARANTEE_EMAIL = 'guanrantee@email.test';
171
my $guarantee = {
172
    guarantorid  => $member->{'borrowernumber'},
173
    emailpro     => $GUARANTEE_EMAIL,
174
    categorycode => $CATEGORYCODE,
175
    branchcode   => $BRANCHCODE,
176
    surname      => "surname"
177
};
178
$guarantee->{'borrowernumber'} = AddMember(%$guarantee);
179
180
$notice_email = GetNoticeEmailAddress($guarantee->{'borrowernumber'});
181
is ($notice_email, $GUARANTEE_EMAIL, "GetNoticeEmailAddress returns correct value when EnableRedirectGuaranteeEmail is disabled");
182
183
C4::Context->set_preference( 'EnableRedirectGuaranteeEmail', 1 );
184
C4::Context->clear_syspref_cache();
185
186
$notice_email = GetNoticeEmailAddress($guarantee->{'borrowernumber'});
187
is ($notice_email, $EMAILPRO, "GetNoticeEmailAddress returns correct value when EnableRedirectGuaranteeEmail is activated");
188
189
166
ok(!$member->{is_expired}, "GetMemberDetails() indicates that patron is not expired");
190
ok(!$member->{is_expired}, "GetMemberDetails() indicates that patron is not expired");
167
ModMember(borrowernumber => $member->{'borrowernumber'}, dateexpiry => '2001-01-1');
191
ModMember(borrowernumber => $member->{'borrowernumber'}, dateexpiry => '2001-01-1');
168
$member = GetMemberDetails($member->{'borrowernumber'});
192
$member = GetMemberDetails($member->{'borrowernumber'});
169
- 

Return to bug 12532