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