Lines 39-44
use Koha::Email;
Link Here
|
39 |
use Koha::Notice::Messages; |
39 |
use Koha::Notice::Messages; |
40 |
use Koha::DateUtils qw( format_sqldatetime dt_from_string ); |
40 |
use Koha::DateUtils qw( format_sqldatetime dt_from_string ); |
41 |
use Koha::Patrons; |
41 |
use Koha::Patrons; |
|
|
42 |
use Koha::Subscriptions; |
42 |
|
43 |
|
43 |
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
44 |
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
44 |
|
45 |
|
Lines 46-52
BEGIN {
Link Here
|
46 |
require Exporter; |
47 |
require Exporter; |
47 |
@ISA = qw(Exporter); |
48 |
@ISA = qw(Exporter); |
48 |
@EXPORT = qw( |
49 |
@EXPORT = qw( |
49 |
&GetLetters &GetLettersAvailableForALibrary &GetLetterTemplates &DelLetter &GetPreparedLetter &GetWrappedLetter &addalert &getalert &delalert &SendAlerts &GetPrintMessages &GetMessageTransportTypes |
50 |
&GetLetters &GetLettersAvailableForALibrary &GetLetterTemplates &DelLetter &GetPreparedLetter &GetWrappedLetter &SendAlerts &GetPrintMessages &GetMessageTransportTypes |
50 |
); |
51 |
); |
51 |
} |
52 |
} |
52 |
|
53 |
|
Lines 266-336
sub DelLetter {
Link Here
|
266 |
, undef, $branchcode, $module, $code, ( $mtt ? $mtt : () ), ( $lang ? $lang : () ) ); |
267 |
, undef, $branchcode, $module, $code, ( $mtt ? $mtt : () ), ( $lang ? $lang : () ) ); |
267 |
} |
268 |
} |
268 |
|
269 |
|
269 |
=head2 addalert ($borrowernumber, $subscriptionid) |
|
|
270 |
|
271 |
parameters : |
272 |
- $borrowernumber : the number of the borrower subscribing to the alert |
273 |
- $subscriptionid |
274 |
|
275 |
create an alert and return the alertid (primary key) |
276 |
|
277 |
=cut |
278 |
|
279 |
sub addalert { |
280 |
my ( $borrowernumber, $subscriptionid) = @_; |
281 |
my $dbh = C4::Context->dbh; |
282 |
my $sth = |
283 |
$dbh->prepare( |
284 |
"insert into alert (borrowernumber, externalid) values (?,?)"); |
285 |
$sth->execute( $borrowernumber, $subscriptionid ); |
286 |
|
287 |
# get the alert number newly created and return it |
288 |
my $alertid = $dbh->{'mysql_insertid'}; |
289 |
return $alertid; |
290 |
} |
291 |
|
292 |
=head2 delalert ($alertid) |
293 |
|
294 |
parameters : |
295 |
- alertid : the alert id |
296 |
deletes the alert |
297 |
|
298 |
=cut |
299 |
|
300 |
sub delalert { |
301 |
my $alertid = shift or die "delalert() called without valid argument (alertid)"; # it's gonna die anyway. |
302 |
$debug and warn "delalert: deleting alertid $alertid"; |
303 |
my $sth = C4::Context->dbh->prepare("delete from alert where alertid=?"); |
304 |
$sth->execute($alertid); |
305 |
} |
306 |
|
307 |
=head2 getalert ([$borrowernumber], [$subscriptionid]) |
308 |
|
309 |
parameters : |
310 |
- $borrowernumber : the number of the borrower subscribing to the alert |
311 |
- $subscriptionid |
312 |
all parameters NON mandatory. If a parameter is omitted, the query is done without the corresponding parameter. For example, without $subscriptionid, returns all alerts for a borrower on a topic. |
313 |
|
314 |
=cut |
315 |
|
316 |
sub getalert { |
317 |
my ( $borrowernumber, $subscriptionid ) = @_; |
318 |
my $dbh = C4::Context->dbh; |
319 |
my $query = "SELECT a.*, b.branchcode FROM alert a JOIN borrowers b USING(borrowernumber) WHERE 1"; |
320 |
my @bind; |
321 |
if ($borrowernumber and $borrowernumber =~ /^\d+$/) { |
322 |
$query .= " AND borrowernumber=?"; |
323 |
push @bind, $borrowernumber; |
324 |
} |
325 |
if ($subscriptionid) { |
326 |
$query .= " AND externalid=?"; |
327 |
push @bind, $subscriptionid; |
328 |
} |
329 |
my $sth = $dbh->prepare($query); |
330 |
$sth->execute(@bind); |
331 |
return $sth->fetchall_arrayref({}); |
332 |
} |
333 |
|
334 |
=head2 SendAlerts |
270 |
=head2 SendAlerts |
335 |
|
271 |
|
336 |
my $err = &SendAlerts($type, $externalid, $letter_code); |
272 |
my $err = &SendAlerts($type, $externalid, $letter_code); |
Lines 379-400
sub SendAlerts {
Link Here
|
379 |
return; |
315 |
return; |
380 |
|
316 |
|
381 |
my %letter; |
317 |
my %letter; |
382 |
# find the list of borrowers to alert |
318 |
# find the list of subscribers to notify |
383 |
my $alerts = getalert( '', $subscriptionid ); |
319 |
my $subscription = Koha::Subscriptions->find( $subscriptionid ); |
384 |
foreach (@$alerts) { |
320 |
my $subscribers = $subscription->subscribers; |
385 |
my $patron = Koha::Patrons->find( $_->{borrowernumber} ); |
321 |
while ( my $patron = $subscribers->next ) { |
386 |
next unless $patron; # Just in case |
|
|
387 |
my $email = $patron->email or next; |
322 |
my $email = $patron->email or next; |
388 |
|
323 |
|
389 |
# warn "sending issues..."; |
324 |
# warn "sending issues..."; |
390 |
my $userenv = C4::Context->userenv; |
325 |
my $userenv = C4::Context->userenv; |
391 |
my $library = Koha::Libraries->find( $_->{branchcode} ); |
326 |
my $library = $patron->library; |
392 |
my $letter = GetPreparedLetter ( |
327 |
my $letter = GetPreparedLetter ( |
393 |
module => 'serial', |
328 |
module => 'serial', |
394 |
letter_code => $letter_code, |
329 |
letter_code => $letter_code, |
395 |
branchcode => $userenv->{branch}, |
330 |
branchcode => $userenv->{branch}, |
396 |
tables => { |
331 |
tables => { |
397 |
'branches' => $_->{branchcode}, |
332 |
'branches' => $library->branchcode, |
398 |
'biblio' => $biblionumber, |
333 |
'biblio' => $biblionumber, |
399 |
'biblioitems' => $biblionumber, |
334 |
'biblioitems' => $biblionumber, |
400 |
'borrowers' => $patron->unblessed, |
335 |
'borrowers' => $patron->unblessed, |