Lines 22-27
use warnings;
Link Here
|
22 |
|
22 |
|
23 |
use MIME::Lite; |
23 |
use MIME::Lite; |
24 |
use Mail::Sendmail; |
24 |
use Mail::Sendmail; |
|
|
25 |
use Date::Calc qw( Add_Delta_Days ); |
26 |
use Encode; |
27 |
use Carp; |
28 |
use Template; |
29 |
use Module::Load::Conditional qw(can_load); |
25 |
|
30 |
|
26 |
use C4::Koha qw(GetAuthorisedValueByCode); |
31 |
use C4::Koha qw(GetAuthorisedValueByCode); |
27 |
use C4::Members; |
32 |
use C4::Members; |
Lines 31-41
use C4::Log;
Link Here
|
31 |
use C4::SMS; |
36 |
use C4::SMS; |
32 |
use C4::Debug; |
37 |
use C4::Debug; |
33 |
use Koha::DateUtils; |
38 |
use Koha::DateUtils; |
34 |
use Date::Calc qw( Add_Delta_Days ); |
|
|
35 |
use Encode; |
36 |
use Carp; |
37 |
use Koha::Email; |
39 |
use Koha::Email; |
38 |
use Koha::DateUtils qw( format_sqldatetime ); |
40 |
use Koha::DateUtils qw( format_sqldatetime dt_from_string ); |
39 |
|
41 |
|
40 |
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
42 |
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
41 |
|
43 |
|
Lines 713-720
sub GetPreparedLetter {
Link Here
|
713 |
} |
715 |
} |
714 |
} |
716 |
} |
715 |
|
717 |
|
|
|
718 |
$letter->{content} = _process_tt( |
719 |
{ |
720 |
content => $letter->{content}, |
721 |
tables => $tables, |
722 |
} |
723 |
); |
724 |
|
716 |
$letter->{content} =~ s/<<\S*>>//go; #remove any stragglers |
725 |
$letter->{content} =~ s/<<\S*>>//go; #remove any stragglers |
717 |
# $letter->{content} =~ s/<<[^>]*>>//go; |
|
|
718 |
|
726 |
|
719 |
return $letter; |
727 |
return $letter; |
720 |
} |
728 |
} |
Lines 1310-1315
sub _set_message_status {
Link Here
|
1310 |
return $result; |
1318 |
return $result; |
1311 |
} |
1319 |
} |
1312 |
|
1320 |
|
|
|
1321 |
sub _process_tt { |
1322 |
my ( $params ) = @_; |
1323 |
|
1324 |
my $content = $params->{content}; |
1325 |
my $tables = $params->{tables}; |
1326 |
|
1327 |
my $use_template_cache = C4::Context->config('template_cache_dir') && defined $ENV{GATEWAY_INTERFACE}; |
1328 |
my $template = Template->new( |
1329 |
{ |
1330 |
EVAL_PERL => 1, |
1331 |
ABSOLUTE => 1, |
1332 |
PLUGIN_BASE => 'Koha::Template::Plugin', |
1333 |
COMPILE_EXT => $use_template_cache ? '.ttc' : '', |
1334 |
COMPILE_DIR => $use_template_cache ? C4::Context->config('template_cache_dir') : '', |
1335 |
FILTERS => {}, |
1336 |
ENCODING => 'UTF-8', |
1337 |
} |
1338 |
) or die Template->error(); |
1339 |
|
1340 |
my $tt_params = _get_tt_params( $tables ); |
1341 |
|
1342 |
my $output; |
1343 |
$template->process( \$content, $tt_params, \$output ) || croak "ERROR PROCESSING TEMPLATE: " . $template->error(); |
1344 |
|
1345 |
return $output; |
1346 |
} |
1347 |
|
1348 |
sub _get_tt_params { |
1349 |
my ($tables) = @_; |
1350 |
|
1351 |
my $params; |
1352 |
|
1353 |
my $config = { |
1354 |
biblio => { |
1355 |
module => 'Koha::Biblios', |
1356 |
singular => 'biblio', |
1357 |
plural => 'biblios', |
1358 |
pk => 'biblionumber', |
1359 |
}, |
1360 |
borrowers => { |
1361 |
module => 'Koha::Borrowers', |
1362 |
singular => 'borrower', |
1363 |
plural => 'borrowers', |
1364 |
pk => 'borrowernumber', |
1365 |
}, |
1366 |
branches => { |
1367 |
module => 'Koha::Branches', |
1368 |
singular => 'branch', |
1369 |
plural => 'branches', |
1370 |
pk => 'branchcode', |
1371 |
}, |
1372 |
items => { |
1373 |
module => 'Koha::Items', |
1374 |
singular => 'item', |
1375 |
plural => 'items', |
1376 |
pk => 'itemnumber', |
1377 |
}, |
1378 |
opac_news => { |
1379 |
module => 'Koha::News', |
1380 |
singular => 'news', |
1381 |
plural => 'news', |
1382 |
pk => 'idnew', |
1383 |
}, |
1384 |
reserves => { |
1385 |
module => 'Koha::Holds', |
1386 |
singular => 'hold', |
1387 |
plural => 'holds', |
1388 |
pk => 'reserve_id', |
1389 |
}, |
1390 |
serial => { |
1391 |
module => 'Koha::Serials', |
1392 |
singular => 'serial', |
1393 |
plural => 'serials', |
1394 |
pk => 'serialid', |
1395 |
}, |
1396 |
subscription => { |
1397 |
module => 'Koha::Subscriptions', |
1398 |
singular => 'subscription', |
1399 |
plural => 'subscriptions', |
1400 |
pk => 'subscriptionid', |
1401 |
}, |
1402 |
suggestions => { |
1403 |
module => 'Koha::Suggestions', |
1404 |
singular => 'suggestion', |
1405 |
plural => 'suggestions', |
1406 |
pk => 'suggestionid', |
1407 |
}, |
1408 |
}; |
1409 |
|
1410 |
foreach my $table ( keys %$tables ) { |
1411 |
next unless $config->{$table}; |
1412 |
|
1413 |
my $ref = ref( $tables->{$table} ) || q{}; |
1414 |
my $module = $config->{$table}->{module}; |
1415 |
|
1416 |
if ( can_load( modules => { $module => undef } ) ) { |
1417 |
my $pk = $config->{$table}->{pk}; |
1418 |
|
1419 |
if ( $ref eq q{} || $ref eq 'HASH' ) { |
1420 |
my $id = ref eq 'HASH' ? $tables->{$table}->{$pk} : $tables->{$table}; |
1421 |
my $object = $module->find($id); |
1422 |
$params->{ $config->{$table}->{singular} } = $object; |
1423 |
} |
1424 |
else { # $ref eq 'ARRAY' |
1425 |
my $objects = $module->search( { $pk => $tables->{$table} } ); |
1426 |
$params->{ $config->{$table}->{plural} } = $objects; |
1427 |
} |
1428 |
} |
1429 |
else { |
1430 |
croak "ERROR LOADING MODULE $module: $Module::Load::Conditional::ERROR"; |
1431 |
} |
1432 |
} |
1433 |
|
1434 |
$params->{today} = dt_from_string(); |
1435 |
|
1436 |
return $params; |
1437 |
} |
1438 |
|
1313 |
|
1439 |
|
1314 |
1; |
1440 |
1; |
1315 |
__END__ |
1441 |
__END__ |