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