Lines 17-24
package C4::Letters;
Link Here
|
17 |
# You should have received a copy of the GNU General Public License |
17 |
# You should have received a copy of the GNU General Public License |
18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
19 |
|
19 |
|
20 |
use strict; |
20 |
use Modern::Perl; |
21 |
use warnings; |
|
|
22 |
|
21 |
|
23 |
use MIME::Lite; |
22 |
use MIME::Lite; |
24 |
use Mail::Sendmail; |
23 |
use Mail::Sendmail; |
Lines 365-376
sub findrelatedto {
Link Here
|
365 |
|
364 |
|
366 |
=head2 SendAlerts |
365 |
=head2 SendAlerts |
367 |
|
366 |
|
368 |
parameters : |
367 |
my $err = &SendAlerts($type, $externalid, $letter_code); |
369 |
- $type : the type of alert |
|
|
370 |
- $externalid : the id of the "object" to query |
371 |
- $letter_code : the letter to send. |
372 |
|
368 |
|
373 |
send an alert to all borrowers having put an alert on a given subject. |
369 |
Parameters: |
|
|
370 |
- $type : the type of alert |
371 |
- $externalid : the id of the "object" to query |
372 |
- $letter_code : the notice template to use |
373 |
|
374 |
C<&SendAlerts> sends an email notice directly to a patron or a vendor. |
375 |
Currently it supports ($type): |
376 |
- claim serial issues (claimissues) |
377 |
- claim acquisition orders (claimacquisition) |
378 |
- send acquisition orders to the vendor (orderacquisition) |
379 |
- notify patrons about newly received serial issues (issue) |
380 |
- notify patrons when their account is created (members) |
374 |
|
381 |
|
375 |
Returns undef or { error => 'message } on failure. |
382 |
Returns undef or { error => 'message } on failure. |
376 |
Returns true on success. |
383 |
Returns true on success. |
Lines 450-469
sub SendAlerts {
Link Here
|
450 |
} |
457 |
} |
451 |
} |
458 |
} |
452 |
} |
459 |
} |
453 |
elsif ( $type eq 'claimacquisition' or $type eq 'claimissues' ) { |
460 |
elsif ( $type eq 'claimacquisition' or $type eq 'claimissues' or $type eq 'orderacquisition' ) { |
454 |
|
461 |
|
455 |
# prepare the letter... |
462 |
# prepare the letter... |
456 |
# search the biblionumber |
463 |
my $strsth; |
457 |
my $strsth = $type eq 'claimacquisition' |
464 |
my $sthorders; |
458 |
? qq{ |
465 |
my $dataorders; |
|
|
466 |
my $action; |
467 |
if ( $type eq 'claimacquisition') { |
468 |
$strsth = qq{ |
459 |
SELECT aqorders.*,aqbasket.*,biblio.*,biblioitems.* |
469 |
SELECT aqorders.*,aqbasket.*,biblio.*,biblioitems.* |
460 |
FROM aqorders |
470 |
FROM aqorders |
461 |
LEFT JOIN aqbasket ON aqbasket.basketno=aqorders.basketno |
471 |
LEFT JOIN aqbasket ON aqbasket.basketno=aqorders.basketno |
462 |
LEFT JOIN biblio ON aqorders.biblionumber=biblio.biblionumber |
472 |
LEFT JOIN biblio ON aqorders.biblionumber=biblio.biblionumber |
463 |
LEFT JOIN biblioitems ON aqorders.biblionumber=biblioitems.biblionumber |
473 |
LEFT JOIN biblioitems ON aqorders.biblionumber=biblioitems.biblionumber |
464 |
WHERE aqorders.ordernumber IN ( |
474 |
WHERE aqorders.ordernumber IN ( |
|
|
475 |
}; |
476 |
|
477 |
if (!@$externalid){ |
478 |
carp "No order selected"; |
479 |
return { error => "no_order_selected" }; |
465 |
} |
480 |
} |
466 |
: qq{ |
481 |
$strsth .= join( ",", @$externalid ) . ")"; |
|
|
482 |
$action = "ACQUISITION CLAIM"; |
483 |
$sthorders = $dbh->prepare($strsth); |
484 |
$sthorders->execute; |
485 |
$dataorders = $sthorders->fetchall_arrayref( {} ); |
486 |
} |
487 |
|
488 |
if ($type eq 'claimissues') { |
489 |
$strsth = qq{ |
467 |
SELECT serial.*,subscription.*, biblio.*, aqbooksellers.*, |
490 |
SELECT serial.*,subscription.*, biblio.*, aqbooksellers.*, |
468 |
aqbooksellers.id AS booksellerid |
491 |
aqbooksellers.id AS booksellerid |
469 |
FROM serial |
492 |
FROM serial |
Lines 473-493
sub SendAlerts {
Link Here
|
473 |
WHERE serial.serialid IN ( |
496 |
WHERE serial.serialid IN ( |
474 |
}; |
497 |
}; |
475 |
|
498 |
|
476 |
if (!@$externalid){ |
499 |
if (!@$externalid){ |
477 |
carp "No Order selected"; |
500 |
carp "No Order selected"; |
478 |
return { error => "no_order_selected" }; |
501 |
return { error => "no_order_selected" }; |
|
|
502 |
} |
503 |
|
504 |
$strsth .= join( ",", @$externalid ) . ")"; |
505 |
$action = "CLAIM ISSUE"; |
506 |
$sthorders = $dbh->prepare($strsth); |
507 |
$sthorders->execute; |
508 |
$dataorders = $sthorders->fetchall_arrayref( {} ); |
479 |
} |
509 |
} |
480 |
|
510 |
|
481 |
$strsth .= join( ",", @$externalid ) . ")"; |
511 |
if ( $type eq 'orderacquisition') { |
482 |
my $sthorders = $dbh->prepare($strsth); |
512 |
$strsth = qq{ |
483 |
$sthorders->execute; |
513 |
SELECT aqorders.*,aqbasket.*,biblio.*,biblioitems.* |
484 |
my $dataorders = $sthorders->fetchall_arrayref( {} ); |
514 |
FROM aqorders |
|
|
515 |
LEFT JOIN aqbasket ON aqbasket.basketno=aqorders.basketno |
516 |
LEFT JOIN biblio ON aqorders.biblionumber=biblio.biblionumber |
517 |
LEFT JOIN biblioitems ON aqorders.biblionumber=biblioitems.biblionumber |
518 |
WHERE aqbasket.basketno = ? |
519 |
AND orderstatus IN ('new','ordered') |
520 |
}; |
521 |
|
522 |
if (!$externalid){ |
523 |
carp "No basketnumber given"; |
524 |
return { error => "no_basketno" }; |
525 |
} |
526 |
$action = "ACQUISITION ORDER"; |
527 |
$sthorders = $dbh->prepare($strsth); |
528 |
$sthorders->execute($externalid); |
529 |
$dataorders = $sthorders->fetchall_arrayref( {} ); |
530 |
} |
485 |
|
531 |
|
486 |
my $sthbookseller = |
532 |
my $sthbookseller = |
487 |
$dbh->prepare("select * from aqbooksellers where id=?"); |
533 |
$dbh->prepare("select * from aqbooksellers where id=?"); |
488 |
$sthbookseller->execute( $dataorders->[0]->{booksellerid} ); |
534 |
$sthbookseller->execute( $dataorders->[0]->{booksellerid} ); |
489 |
my $databookseller = $sthbookseller->fetchrow_hashref; |
535 |
my $databookseller = $sthbookseller->fetchrow_hashref; |
490 |
my $addressee = $type eq 'claimacquisition' ? 'acqprimary' : 'serialsprimary'; |
536 |
|
|
|
537 |
my $addressee = $type eq 'claimacquisition' || $type eq 'orderacquisition' ? 'acqprimary' : 'serialsprimary'; |
538 |
|
491 |
my $sthcontact = |
539 |
my $sthcontact = |
492 |
$dbh->prepare("SELECT * FROM aqcontacts WHERE booksellerid=? AND $type=1 ORDER BY $addressee DESC"); |
540 |
$dbh->prepare("SELECT * FROM aqcontacts WHERE booksellerid=? AND $type=1 ORDER BY $addressee DESC"); |
493 |
$sthcontact->execute( $dataorders->[0]->{booksellerid} ); |
541 |
$sthcontact->execute( $dataorders->[0]->{booksellerid} ); |
Lines 538-549
sub SendAlerts {
Link Here
|
538 |
: 'text/plain; charset="utf-8"', |
586 |
: 'text/plain; charset="utf-8"', |
539 |
); |
587 |
); |
540 |
|
588 |
|
541 |
$mail{'Reply-to'} = C4::Context->preference('ReplytoDefault') |
589 |
if ($type eq 'claimacquisition' || $type eq 'claimissues' ) { |
542 |
if C4::Context->preference('ReplytoDefault'); |
590 |
$mail{'Reply-to'} = C4::Context->preference('ReplytoDefault') |
543 |
$mail{'Sender'} = C4::Context->preference('ReturnpathDefault') |
591 |
if C4::Context->preference('ReplytoDefault'); |
544 |
if C4::Context->preference('ReturnpathDefault'); |
592 |
$mail{'Sender'} = C4::Context->preference('ReturnpathDefault') |
545 |
$mail{'Bcc'} = $userenv->{emailaddress} |
593 |
if C4::Context->preference('ReturnpathDefault'); |
546 |
if C4::Context->preference("ClaimsBccCopy"); |
594 |
$mail{'Bcc'} = $userenv->{emailaddress} |
|
|
595 |
if C4::Context->preference("ClaimsBccCopy"); |
596 |
} |
547 |
|
597 |
|
548 |
unless ( sendmail(%mail) ) { |
598 |
unless ( sendmail(%mail) ) { |
549 |
carp $Mail::Sendmail::error; |
599 |
carp $Mail::Sendmail::error; |
Lines 552-558
sub SendAlerts {
Link Here
|
552 |
|
602 |
|
553 |
logaction( |
603 |
logaction( |
554 |
"ACQUISITION", |
604 |
"ACQUISITION", |
555 |
$type eq 'claimissues' ? "CLAIM ISSUE" : "ACQUISITION CLAIM", |
605 |
$action, |
556 |
undef, |
606 |
undef, |
557 |
"To=" |
607 |
"To=" |
558 |
. join( ',', @email ) |
608 |
. join( ',', @email ) |