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

(-)a/C4/Members.pm (+30 lines)
Lines 59-64 BEGIN { Link Here
59
		&getidcity
59
		&getidcity
60
60
61
                &GetFirstValidEmailAddress
61
                &GetFirstValidEmailAddress
62
		&GetValidEmailAddresses
62
63
63
		&GetAge 
64
		&GetAge 
64
		&GetCities 
65
		&GetCities 
Lines 1361-1366 sub GetFirstValidEmailAddress { Link Here
1361
    }
1362
    }
1362
}
1363
}
1363
1364
1365
=head2 GetValidEmailAddresses
1366
1367
  $email = GetValidEmailAddresses($borrowernumber);
1368
1369
Return all the valid email address for a borrower, given the borrowernumber. Returns an hash.
1370
1371
=cut
1372
1373
sub GetValidEmailAddresses {
1374
    my $borrowernumber = shift;
1375
    my $dbh = C4::Context->dbh;
1376
    my $sth = $dbh->prepare( "SELECT email, emailpro, B_email FROM borrowers where borrowernumber = ? ");
1377
    $sth->execute( $borrowernumber );
1378
    my $data = $sth->fetchrow_hashref;
1379
    my %mailhash;
1380
1381
    if ($data->{'email'}) {
1382
       $mailhash{'email'} = $data->{'email'};
1383
    } 
1384
    if ($data->{'emailpro'}) {
1385
       $mailhash{'emailpro'} = $data->{'emailpro'};
1386
    } 
1387
    if ($data->{'B_email'}) {
1388
       $mailhash{'B_email'} = $data->{'B_email'};
1389
    } 
1390
    return \%mailhash;
1391
}
1392
1393
1364
=head2 GetExpiryDate 
1394
=head2 GetExpiryDate 
1365
1395
1366
  $expirydate = GetExpiryDate($categorycode, $dateenrolled);
1396
  $expirydate = GetExpiryDate($categorycode, $dateenrolled);
(-)a/misc/cronjobs/overdue_notices.pl (-3 / +23 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 [ -n ] [ -library <branchcode> ] [ -library <branchcode>...] [ -max <number of days> ] [ -csv [ <filename> ] ] [ -itemscontent <field list> ] [ -email <email_type>...]
51
51
52
 Options:
52
 Options:
53
   -help                          brief help message
53
   -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
60
   -itemscontent <list of fields> item information in templates
61
   -borcat       <categorycode>   category code that must be included
61
   -borcat       <categorycode>   category code that must be included
62
   -borcatout    <categorycode>   category code that must be excluded
62
   -borcatout    <categorycode>   category code that must be excluded
63
   -email        <email_type>     type of email that will be used. Can be 'email', 'emailpro' or 'B_email'. Repeatable.
63
64
64
=head1 OPTIONS
65
=head1 OPTIONS
65
66
Lines 143-148 Default items.content lists only those items that fall in the Link Here
143
range of the currently processing notice.
144
range of the currently processing notice.
144
Choose list-all to include all overdue items in the list (limited by B<-max> setting).
145
Choose list-all to include all overdue items in the list (limited by B<-max> setting).
145
146
147
=item B<-email>
148
149
Allows to specify which type of email will be used. Can be email, emailpro or B_email. Repeatable.
150
146
=back
151
=back
147
152
148
=head1 DESCRIPTION
153
=head1 DESCRIPTION
Lines 252-257 my $verbose = 0; Link Here
252
my $nomail  = 0;
257
my $nomail  = 0;
253
my $MAX     = 90;
258
my $MAX     = 90;
254
my @branchcodes; # Branch(es) passed as parameter
259
my @branchcodes; # Branch(es) passed as parameter
260
my @emails_to_use; # Emails to use for messaging
261
my @emails;        # Emails given in command-line parameters
255
my $csvfilename;
262
my $csvfilename;
256
my $htmlfilename;
263
my $htmlfilename;
257
my $triggered = 0;
264
my $triggered = 0;
Lines 274-279 GetOptions( Link Here
274
    't|triggered'             => \$triggered,
281
    't|triggered'             => \$triggered,
275
    'borcat=s'      => \@myborcat,
282
    'borcat=s'      => \@myborcat,
276
    'borcatout=s'   => \@myborcatout,
283
    'borcatout=s'   => \@myborcatout,
284
    'email=s'        => \@emails,
277
) or pod2usage(2);
285
) or pod2usage(2);
278
pod2usage(1) if $help;
286
pod2usage(1) if $help;
279
pod2usage( -verbose => 2 ) if $man;
287
pod2usage( -verbose => 2 ) if $man;
Lines 458-463 END_SQL Link Here
458
                    $address1, $address2, $city, $postcode, $country, $email,
466
                    $address1, $address2, $city, $postcode, $country, $email,
459
                    $longest_issue ) = $sth->fetchrow )
467
                    $longest_issue ) = $sth->fetchrow )
460
            {
468
            {
469
                @emails_to_use = ();
470
                if (@emails && !$nomail) {
471
                    my $validemails = C4::Members::GetValidEmailAddresses($borrowernumber);
472
                    foreach (@emails) {
473
                        push @emails_to_use, $validemails->{$_} if (defined $validemails->{$_});
474
                    }
475
                    $email = 1 if (@emails_to_use);
476
                } else {
477
                    $email=C4::Members::GetFirstValidEmailAddress($borrowernumber);
478
                    push @emails_to_use, $email;
479
                }
480
461
                $verbose and warn "borrower $firstname, $lastname ($borrowernumber) has $itemcount items triggering level $i.";
481
                $verbose and warn "borrower $firstname, $lastname ($borrowernumber) has $itemcount items triggering level $i.";
462
    
482
    
463
                my $letter = C4::Letters::getletter( 'circulation', $overdue_rules->{"letter$i"} );
483
                my $letter = C4::Letters::getletter( 'circulation', $overdue_rules->{"letter$i"} );
Lines 539-550 END_SQL Link Here
539
                        }
559
                        }
540
                      );
560
                      );
541
                } else {
561
                } else {
542
                    if ($email) {
562
		    if (scalar(@emails_to_use) > 0 ) {
543
                        C4::Letters::EnqueueLetter(
563
                        C4::Letters::EnqueueLetter(
544
                            {   letter                 => $letter,
564
                            {   letter                 => $letter,
545
                                borrowernumber         => $borrowernumber,
565
                                borrowernumber         => $borrowernumber,
546
                                message_transport_type => 'email',
566
                                message_transport_type => 'email',
547
                                from_address           => $admin_email_address,
567
                                from_address           => $admin_email_address,
568
				to_address             => join(',', @emails_to_use),
548
                            }
569
                            }
549
                        );
570
                        );
550
                    } else {
571
                    } else {
551
- 

Return to bug 6835