use C4::Members;
use C4::Log;
use C4::SMS;
+use C4::Templates;
use C4::Debug;
use Koha::DateUtils;
use Koha::SMS::Providers;
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(
- &GetLetters &GetLettersAvailableForALibrary &GetLetterTemplates &DelLetter &GetPreparedLetter &GetWrappedLetter &SendAlerts &GetPrintMessages &GetMessageTransportTypes
+ &EnqueueLetter &GetLetters &GetLettersAvailableForALibrary &GetLetterTemplates &DelLetter &GetPreparedLetter &GetWrappedLetter &SendAlerts &GetPrintMessages &GetMessageTransportTypes
);
}
sub SendAlerts {
my ( $type, $externalid, $letter_code ) = @_;
my $dbh = C4::Context->dbh;
+ my $error;
+
if ( $type eq 'issue' ) {
# prepare the letter...
$mail->text_body( $letter->{content} );
}
- try {
+ my $success = try {
$mail->send_or_die({ transport => $library->smtp_server->transport });
}
catch {
+ # We expect ref($_) eq 'Email::Sender::Failure'
+ $error = $_->message;
+
carp "$_";
- return { error => "$_" };
+ return;
};
+
+ return { error => $error }
+ unless $success;
}
}
elsif ( $type eq 'claimacquisition' or $type eq 'claimissues' or $type eq 'orderacquisition' ) {
my $sthorders;
my $dataorders;
my $action;
+ my $basketno;
if ( $type eq 'claimacquisition') {
$strsth = qq{
SELECT aqorders.*,aqbasket.*,biblio.*,biblioitems.*
}
if ( $type eq 'orderacquisition') {
+ my $basketno = $externalid;
$strsth = qq{
SELECT aqorders.*,aqbasket.*,biblio.*,biblioitems.*
FROM aqorders
AND orderstatus IN ('new','ordered')
};
- if (!$externalid){
+ unless ( $basketno ) {
carp "No basketnumber given";
return { error => "no_basketno" };
}
$action = "ACQUISITION ORDER";
$sthorders = $dbh->prepare($strsth);
- $sthorders->execute($externalid);
+ $sthorders->execute($basketno);
$dataorders = $sthorders->fetchall_arrayref( {} );
}
'branches' => $userenv->{branch},
'aqbooksellers' => $databookseller,
'aqcontacts' => $datacontact,
- 'aqbasket' => $externalid,
+ 'aqbasket' => $basketno,
},
repeat => $dataorders,
want_librarian => 1,
$mail->text_body( "" . $letter->{content} );
}
- try {
+ my $success = try {
$mail->send_or_die({ transport => $library->smtp_server->transport });
}
catch {
+ # We expect ref($_) eq 'Email::Sender::Failure'
+ $error = $_->message;
+
carp "$_";
- return { error => "$_" };
+ return;
};
+ return { error => $error }
+ unless $success;
+
logaction(
"ACQUISITION",
$action,
want_librarian => 1,
) or return;
return { error => "no_email" } unless $externalid->{'emailaddr'};
- try {
+
+ my $success = try {
# FIXME: This 'default' behaviour should be moved to Koha::Email
my $mail = Koha::Email->create(
$mail->send_or_die({ transport => $library->smtp_server->transport });
}
catch {
+ # We expect ref($_) eq 'Email::Sender::Failure'
+ $error = $_->message;
+
carp "$_";
- return { error => "$_" };
+ return;
};
+
+ return { error => $error }
+ unless $success;
}
# If we come here, return an OK status
my %params = @_;
my $letter = $params{letter};
+ my $lang = $params{lang} || 'default';
unless ( $letter ) {
my $module = $params{module} or croak "No module";
my $letter_code = $params{letter_code} or croak "No letter_code";
my $branchcode = $params{branchcode} || '';
my $mtt = $params{message_transport_type} || 'email';
- my $lang = $params{lang} || 'default';
$letter = getletter( $module, $letter_code, $branchcode, $mtt, $lang );
tables => $tables,
loops => $loops,
substitute => $substitute,
+ lang => $lang
+ }
+ );
+
+ $letter->{title} = _process_tt(
+ {
+ content => $letter->{title},
+ tables => $tables,
+ loops => $loops,
+ substitute => $substitute,
}
);
# broke things for the rest of us. prepare_cached is a better
# way to cache statement handles anyway.
my $query =
+ ($table eq 'accountlines' ) ? "SELECT * FROM $table WHERE accountlines_id = ?" :
($table eq 'biblio' ) ? "SELECT * FROM $table WHERE biblionumber = ?" :
($table eq 'biblioitems' ) ? "SELECT * FROM $table WHERE biblionumber = ?" :
+ ($table eq 'credits' ) ? "SELECT * FROM accountlines WHERE accountlines_id = ?" :
+ ($table eq 'debits' ) ? "SELECT * FROM accountlines WHERE accountlines_id = ?" :
($table eq 'items' ) ? "SELECT * FROM $table WHERE itemnumber = ?" :
($table eq 'issues' ) ? "SELECT * FROM $table WHERE itemnumber = ?" :
($table eq 'old_issues' ) ? "SELECT * FROM $table WHERE itemnumber = ? ORDER BY timestamp DESC LIMIT 1" :
($table eq 'aqbooksellers') ? "SELECT * FROM $table WHERE id = ?" :
($table eq 'aqorders' ) ? "SELECT * FROM $table WHERE ordernumber = ?" :
($table eq 'aqbasket' ) ? "SELECT * FROM $table WHERE basketno = ?" :
+ ($table eq 'illrequests' ) ? "SELECT * FROM $table WHERE illrequest_id = ?" :
($table eq 'opac_news' ) ? "SELECT * FROM $table WHERE idnew = ?" :
($table eq 'article_requests') ? "SELECT * FROM $table WHERE id = ?" :
($table eq 'borrower_modifications') ? "SELECT * FROM $table WHERE verification_token = ?" :
# Dates replacement
my $replacedby = defined ($val) ? $val : '';
if ( $replacedby
- and not $replacedby =~ m|0000-00-00|
and not $replacedby =~ m|9999-12-31|
and $replacedby =~ m|^\d{4}-\d{2}-\d{2}( \d{2}:\d{2}:\d{2})?$| )
{
my $params = shift;
my $which_unsent_messages = {
+ 'message_id' => $params->{'message_id'},
'limit' => $params->{'limit'} // 0,
'borrowernumber' => $params->{'borrowernumber'} // q{},
'letter_code' => $params->{'letter_code'} // q{},
message_transport_type: method of message sending (e.g. email, sms, etc.)
borrowernumber : who the message is to be sent
letter_code : type of message being sent (e.g. PASSWORD_RESET)
+ message_id : the message_id of the message. In that case the sub will return only 1 result
limit : maximum number of messages to send
This function returns an array of matching hash referenced rows from
$statement .= ' AND message_transport_type = ? ';
push @query_params, $params->{'type'};
}
+ if ( $params->{message_id} ) {
+ $statement .= ' AND message_id = ?';
+ push @query_params, $params->{message_id};
+ }
if ( $params->{'limit'} ) {
$statement .= ' limit ? ';
push @query_params, $params->{'limit'};
}
}
- # Encode subject line separately
- $message->{subject} = encode('MIME-Header', $message->{'subject'} );
my $subject = $message->{'subject'};
- my $content = encode('UTF-8', $message->{'content'});
+ my $content = $message->{'content'};
my $content_type = $message->{'content_type'} || 'text/plain; charset="UTF-8"';
my $is_html = $content_type =~ m/html/io;
my $tables = $params->{tables};
my $loops = $params->{loops};
my $substitute = $params->{substitute} || {};
+ my $lang = defined($params->{lang}) && $params->{lang} ne 'default' ? $params->{lang} : 'en';
+ my ($theme, $activethemes);
+
+ my $htdocs = C4::Context->config('intrahtdocs');
+ ($theme, $lang, $activethemes)= C4::Templates::activethemes( $htdocs, 'about.tt', 'intranet', $lang);
+ my @includes;
+ foreach (@$activethemes) {
+ push @includes, "$htdocs/$_/$lang/includes";
+ push @includes, "$htdocs/$_/en/includes" unless $lang eq 'en';
+ }
my $use_template_cache = C4::Context->config('template_cache_dir') && defined $ENV{GATEWAY_INTERFACE};
my $template = Template->new(
PLUGIN_BASE => 'Koha::Template::Plugin',
COMPILE_EXT => $use_template_cache ? '.ttc' : '',
COMPILE_DIR => $use_template_cache ? C4::Context->config('template_cache_dir') : '',
+ INCLUDE_PATH => \@includes,
FILTERS => {},
ENCODING => 'UTF-8',
}
plural => 'branches',
pk => 'branchcode',
},
+ credits => {
+ module => 'Koha::Account::Lines',
+ singular => 'credit',
+ plural => 'credits',
+ pk => 'accountlines_id',
+ },
+ debits => {
+ module => 'Koha::Account::Lines',
+ singular => 'debit',
+ plural => 'debits',
+ pk => 'accountlines_id',
+ },
items => {
module => 'Koha::Items',
singular => 'item',
plural => 'patron_modifications',
fk => 'verification_token',
},
+ illrequests => {
+ module => 'Koha::Illrequests',
+ singular => 'illrequest',
+ plural => 'illrequests',
+ pk => 'illrequest_id'
+ }
};
foreach my $table ( keys %$tables ) {