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

(-)a/C4/Members.pm (+58 lines)
Lines 2478-2483 sub AddEnrolmentFeeIfNeeded { Link Here
2478
    }
2478
    }
2479
}
2479
}
2480
2480
2481
=head2 HasOverdues
2482
2483
    HasOverdues( $borrowernumber );
2484
2485
=cut
2486
2481
sub HasOverdues {
2487
sub HasOverdues {
2482
    my ( $borrowernumber ) = @_;
2488
    my ( $borrowernumber ) = @_;
2483
2489
Lines 2489-2494 sub HasOverdues { Link Here
2489
    return $count;
2495
    return $count;
2490
}
2496
}
2491
2497
2498
=head2 SendAutoEmail
2499
2500
    SendAutoEmail( $borrowerdata, $template );
2501
2502
    Send an alert with login detail (account notice) when userid or password
2503
    has been changed, if pref AutoEmailOpacUser has been enabled.
2504
    The hashref $borrowerdata should contain the keys:
2505
        borrowernumber, branchcode, userid, password, email, emailpro, B_email
2506
    The template parameter refers to a template object. Errors are passed
2507
    via the template.
2508
2509
=cut
2510
2511
sub SendAutoEmail { #optionally send account detail notice
2512
    my ( $dataref, $template ) = @_;
2513
2514
    # check AutoEmailOpacUser syspref first
2515
    return if !C4::Context->preference("AutoEmailOpacUser");
2516
    # no mail too if no userid or password
2517
    return if ref($dataref) ne 'HASH' || !$dataref->{userid} ||
2518
        !$dataref->{password};
2519
2520
    # first look for defined primary email addres, otherwise try others
2521
    my $emailaddr;
2522
    my $primary = C4::Context->preference("AutoEmailPrimaryAddress");
2523
    return if !$primary;
2524
    if( $primary ne 'OFF' && $dataref->{primary} &&
2525
      $dataref->{$primary} =~ /\w\@\w/ ) {
2526
        $emailaddr = $dataref->{$primary};
2527
    } elsif( $dataref->{email} && $dataref->{email} =~ /\w\@\w/ ) {
2528
        $emailaddr = $dataref->{email};
2529
    } elsif( $dataref->{emailpro} && $dataref->{emailpro} =~ /\w\@\w/ ) {
2530
        $emailaddr = $dataref->{emailpro};
2531
    } elsif( $dataref->{B_email} && $dataref->{B_email} =~ /\w\@\w/ ) {
2532
        $emailaddr = $dataref->{B_email};
2533
    }
2534
    return if !$emailaddr;
2535
2536
    # if we manage to find a valid email address, send notice
2537
    $dataref->{emailaddr} = $emailaddr;
2538
    my $err;
2539
    eval { $err = SendAlerts ( 'members', $dataref, "ACCTDETAILS" ); };
2540
    if ( $@ ) {
2541
        $template->param(error_alert => $@);
2542
    } elsif ( ref($err) eq "HASH" && defined $err->{error} &&
2543
      $err->{error} eq "no_email" ) {
2544
        $template->{VARS}->{'error_alert'} = "no_email";
2545
    } else {
2546
        $template->{VARS}->{'info_alert'} = 1;
2547
    }
2548
}
2549
2492
END { }    # module clean-up code here (global destructor)
2550
END { }    # module clean-up code here (global destructor)
2493
2551
2494
1;
2552
1;
(-)a/t/db_dependent/Members.t (-2 / +36 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 58;
20
use Test::More tests => 59;
21
use Test::MockModule;
21
use Test::MockModule;
22
use Data::Dumper;
22
use Data::Dumper;
23
use C4::Context;
23
use C4::Context;
Lines 337-342 subtest 'GetMemberAccountBalance' => sub { Link Here
337
    $dbh->rollback();
337
    $dbh->rollback();
338
};
338
};
339
339
340
# tests for routine SendAutoEmail
341
subtest 'SendAutoEmail' => sub {
342
    plan tests => 4;
343
    my $mock1 = new Test::MockModule('C4::Members'); #mocks imported routine
344
    my $mock2 = new Test::MockModule('C4::Templates');
345
    my $alerts = 0;
346
    $mock1->mock( 'SendAlerts', sub { $alerts++; } );
347
    $mock2->mock( 'param', sub { 1; } );
348
    my $data = { userid => 'marcel', password => 'N0t_MyPw' };
349
    my $template = { VARS => {} };
350
    bless $template, 'C4::Templates';
351
352
    C4::Context->set_preference( 'AutoEmailOpacUser' , '0' );
353
    C4::Members::SendAutoEmail( $data, $template );
354
    is( $alerts, 0, 'No mails when pref is disabled' );
355
356
    $data->{email} = 'something@domain.com';
357
    C4::Context->set_preference( 'AutoEmailOpacUser' , '1' );
358
    C4::Context->set_preference( 'AutoEmailPrimaryAddress' , 'OFF' );
359
    C4::Members::SendAutoEmail( $data, $template );
360
    is( $alerts, 1, 'Alert to first valid email address' );
361
362
    C4::Context->set_preference( 'AutoEmailPrimaryAddress' , 'emailpro' );
363
    C4::Members::SendAutoEmail( $data, $template );
364
    is( $alerts, 2, 'Fallback to email when emailpro missing' );
365
366
    delete $data->{email};
367
    C4::Members::SendAutoEmail( $data, $template );
368
    is( $alerts, 2, 'No fallback when emailpro missing' );
369
370
    $dbh->rollback();
371
};
372
373
# SUBROUTINES
374
340
sub _find_member {
375
sub _find_member {
341
    my ($resultset) = @_;
376
    my ($resultset) = @_;
342
    my $found = $resultset && grep( { $_->{cardnumber} && $_->{cardnumber} eq $CARDNUMBER } @$resultset );
377
    my $found = $resultset && grep( { $_->{cardnumber} && $_->{cardnumber} eq $CARDNUMBER } @$resultset );
343
- 

Return to bug 13096