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