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

(-)a/C4/Members.pm (+33 lines)
Lines 64-69 BEGIN { Link Here
64
		&getidcity
64
		&getidcity
65
65
66
                &GetFirstValidEmailAddress
66
                &GetFirstValidEmailAddress
67
        &GetValidEmailAddresses
67
68
68
		&GetAge 
69
		&GetAge 
69
		&GetCities 
70
		&GetCities 
Lines 1315-1320 sub GetFirstValidEmailAddress { Link Here
1315
    }
1316
    }
1316
}
1317
}
1317
1318
1319
1320
=head2 GetValidEmailAddresses
1321
1322
  $email = GetValidEmailAddresses($borrowernumber);
1323
1324
Return all the valid email address for a borrower, given the borrowernumber. Returns an hash.
1325
1326
=cut
1327
1328
sub GetValidEmailAddresses {
1329
    my $borrowernumber = shift;
1330
    my $dbh            = C4::Context->dbh;
1331
    my $sth            = $dbh->prepare(
1332
"SELECT email, emailpro, B_email FROM borrowers where borrowernumber = ? "
1333
    );
1334
    $sth->execute($borrowernumber);
1335
    my $data = $sth->fetchrow_hashref;
1336
    my %mailhash;
1337
1338
    if ( $data->{'email'} ) {
1339
        $mailhash{'email'} = $data->{'email'};
1340
    }
1341
    if ( $data->{'emailpro'} ) {
1342
        $mailhash{'emailpro'} = $data->{'emailpro'};
1343
    }
1344
    if ( $data->{'B_email'} ) {
1345
        $mailhash{'B_email'} = $data->{'B_email'};
1346
    }
1347
    return \%mailhash;
1348
}
1349
1350
1318
=head2 GetExpiryDate 
1351
=head2 GetExpiryDate 
1319
1352
1320
  $expirydate = GetExpiryDate($categorycode, $dateenrolled);
1353
  $expirydate = GetExpiryDate($categorycode, $dateenrolled);
(-)a/misc/cronjobs/overdue_notices.pl (-4 / +40 lines)
Lines 47-53 overdue_notices.pl - prepare messages to be sent to patrons for overdue items Link Here
47
47
48
=head1 SYNOPSIS
48
=head1 SYNOPSIS
49
49
50
overdue_notices.pl [ -n ] [ -library <branchcode> ] [ -library <branchcode>...] [ -max <number of days> ] [ -csv [ <filename> ] ] [ -itemscontent <field list> ]
50
overdue_notices.pl 
51
  [ -n ][ -library <branchcode> ][ -library <branchcode> ... ]
52
  [ -max <number of days> ][ -csv [<filename>] ][ -itemscontent <field list> ]
53
  [ -email <email_type> ... ]
51
54
52
 Options:
55
 Options:
53
   -help                          brief help message
56
   -help                          brief help message
Lines 60-65 overdue_notices.pl [ -n ] [ -library <branchcode> ] [ -library <branchcode>...] Link Here
60
   -itemscontent <list of fields> item information in templates
63
   -itemscontent <list of fields> item information in templates
61
   -borcat       <categorycode>   category code that must be included
64
   -borcat       <categorycode>   category code that must be included
62
   -borcatout    <categorycode>   category code that must be excluded
65
   -borcatout    <categorycode>   category code that must be excluded
66
   -email        <email_type>     type of email that will be used. Can be 'email', 'emailpro' or 'B_email'. Repeatable.
63
67
64
=head1 OPTIONS
68
=head1 OPTIONS
65
69
Lines 143-148 Default items.content lists only those items that fall in the Link Here
143
range of the currently processing notice.
147
range of the currently processing notice.
144
Choose list-all to include all overdue items in the list (limited by B<-max> setting).
148
Choose list-all to include all overdue items in the list (limited by B<-max> setting).
145
149
150
=item B<-email>
151
152
Allows to specify which type of email will be used. Can be email, emailpro or B_email. Repeatable.
153
146
=back
154
=back
147
155
148
=head1 DESCRIPTION
156
=head1 DESCRIPTION
Lines 252-257 my $verbose = 0; Link Here
252
my $nomail  = 0;
260
my $nomail  = 0;
253
my $MAX     = 90;
261
my $MAX     = 90;
254
my @branchcodes; # Branch(es) passed as parameter
262
my @branchcodes; # Branch(es) passed as parameter
263
my @emails_to_use;    # Emails to use for messaging
264
my @emails;           # Emails given in command-line parameters
255
my $csvfilename;
265
my $csvfilename;
256
my $htmlfilename;
266
my $htmlfilename;
257
my $triggered = 0;
267
my $triggered = 0;
Lines 274-279 GetOptions( Link Here
274
    't|triggered'             => \$triggered,
284
    't|triggered'             => \$triggered,
275
    'borcat=s'      => \@myborcat,
285
    'borcat=s'      => \@myborcat,
276
    'borcatout=s'   => \@myborcatout,
286
    'borcatout=s'   => \@myborcatout,
287
    'email=s' => \@emails,
277
) or pod2usage(2);
288
) or pod2usage(2);
278
pod2usage(1) if $help;
289
pod2usage(1) if $help;
279
pod2usage( -verbose => 2 ) if $man;
290
pod2usage( -verbose => 2 ) if $man;
Lines 459-464 END_SQL Link Here
459
                    ) = $sth->fetchrow )
470
                    ) = $sth->fetchrow )
460
            {
471
            {
461
                $verbose and warn "borrower $firstname, $lastname ($borrowernumber) has items triggering level $i.";
472
                $verbose and warn "borrower $firstname, $lastname ($borrowernumber) has items triggering level $i.";
473
                @emails_to_use = ();
474
                if ( @emails && !$nomail ) {
475
                    my $validemails =
476
                      C4::Members::GetValidEmailAddresses($borrowernumber);
477
                    foreach (@emails) {
478
                        push @emails_to_use, $validemails->{$_}
479
                          if ( defined $validemails->{$_} );
480
                    }
481
                    $email = 1 if (@emails_to_use);
482
                }
483
                else {
484
                    $email =
485
                      C4::Members::GetFirstValidEmailAddress($borrowernumber);
486
                    push @emails_to_use, $email;
487
                }
488
489
                my $letter = C4::Letters::getletter( 'circulation', $overdue_rules->{"letter$i"}, $branchcode );
490
491
                unless ($letter) {
492
                    $verbose and warn "Message '$overdue_rules->{letter$i}' content not found";
493
    
494
                    # might as well skip while PERIOD, no other borrowers are going to work.
495
                    # FIXME : Does this mean a letter must be defined in order to trigger a debar ?
496
                    next PERIOD;
497
                }
462
    
498
    
463
                if ( $overdue_rules->{"debarred$i"} ) {
499
                if ( $overdue_rules->{"debarred$i"} ) {
464
    
500
    
Lines 488-494 END_SQL Link Here
488
                }
524
                }
489
                $sth2->finish;
525
                $sth2->finish;
490
526
491
                my $letter = parse_letter(
527
                $letter = parse_letter(
492
                    {   letter_code     => $overdue_rules->{"letter$i"},
528
                    {   letter_code     => $overdue_rules->{"letter$i"},
493
                        borrowernumber  => $borrowernumber,
529
                        borrowernumber  => $borrowernumber,
494
                        branchcode      => $branchcode,
530
                        branchcode      => $branchcode,
Lines 538-549 END_SQL Link Here
538
                        }
574
                        }
539
                      );
575
                      );
540
                } else {
576
                } else {
541
                    if ($email) {
577
                    if (scalar(@emails_to_use) > 0 ) {
542
                        C4::Letters::EnqueueLetter(
578
                        C4::Letters::EnqueueLetter(
543
                            {   letter                 => $letter,
579
                            {   letter                 => $letter,
544
                                borrowernumber         => $borrowernumber,
580
                                borrowernumber         => $borrowernumber,
545
                                message_transport_type => 'email',
581
                                message_transport_type => 'email',
546
                                from_address           => $admin_email_address,
582
                                from_address           => $admin_email_address,
583
                                to_address             => join(',', @emails_to_use),
547
                            }
584
                            }
548
                        );
585
                        );
549
                    } else {
586
                    } else {
550
- 

Return to bug 6835