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 33-43
use C4::Debug;
Link Here
|
33 |
use Koha::DateUtils; |
38 |
use Koha::DateUtils; |
34 |
use Koha::SMS::Providers; |
39 |
use Koha::SMS::Providers; |
35 |
|
40 |
|
36 |
use Date::Calc qw( Add_Delta_Days ); |
|
|
37 |
use Encode; |
38 |
use Carp; |
39 |
use Koha::Email; |
41 |
use Koha::Email; |
40 |
use Koha::DateUtils qw( format_sqldatetime ); |
42 |
use Koha::DateUtils qw( format_sqldatetime dt_from_string ); |
41 |
|
43 |
|
42 |
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
44 |
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
43 |
|
45 |
|
Lines 717-724
sub GetPreparedLetter {
Link Here
|
717 |
} |
719 |
} |
718 |
} |
720 |
} |
719 |
|
721 |
|
|
|
722 |
$letter->{content} = _process_tt( |
723 |
{ |
724 |
content => $letter->{content}, |
725 |
tables => $tables, |
726 |
} |
727 |
); |
728 |
|
720 |
$letter->{content} =~ s/<<\S*>>//go; #remove any stragglers |
729 |
$letter->{content} =~ s/<<\S*>>//go; #remove any stragglers |
721 |
# $letter->{content} =~ s/<<[^>]*>>//go; |
|
|
722 |
|
730 |
|
723 |
return $letter; |
731 |
return $letter; |
724 |
} |
732 |
} |
Lines 1376-1381
sub _set_message_status {
Link Here
|
1376 |
return $result; |
1384 |
return $result; |
1377 |
} |
1385 |
} |
1378 |
|
1386 |
|
|
|
1387 |
sub _process_tt { |
1388 |
my ( $params ) = @_; |
1389 |
|
1390 |
my $content = $params->{content}; |
1391 |
my $tables = $params->{tables}; |
1392 |
|
1393 |
my $use_template_cache = C4::Context->config('template_cache_dir') && defined $ENV{GATEWAY_INTERFACE}; |
1394 |
my $template = Template->new( |
1395 |
{ |
1396 |
EVAL_PERL => 1, |
1397 |
ABSOLUTE => 1, |
1398 |
PLUGIN_BASE => 'Koha::Template::Plugin', |
1399 |
COMPILE_EXT => $use_template_cache ? '.ttc' : '', |
1400 |
COMPILE_DIR => $use_template_cache ? C4::Context->config('template_cache_dir') : '', |
1401 |
FILTERS => {}, |
1402 |
ENCODING => 'UTF-8', |
1403 |
} |
1404 |
) or die Template->error(); |
1405 |
|
1406 |
my $tt_params = _get_tt_params( $tables ); |
1407 |
|
1408 |
my $output; |
1409 |
$template->process( \$content, $tt_params, \$output ) || croak "ERROR PROCESSING TEMPLATE: " . $template->error(); |
1410 |
|
1411 |
return $output; |
1412 |
} |
1413 |
|
1414 |
sub _get_tt_params { |
1415 |
my ($tables) = @_; |
1416 |
|
1417 |
my $params; |
1418 |
|
1419 |
my $config = { |
1420 |
biblio => { |
1421 |
module => 'Koha::Biblios', |
1422 |
singular => 'biblio', |
1423 |
plural => 'biblios', |
1424 |
pk => 'biblionumber', |
1425 |
}, |
1426 |
borrowers => { #FIXME: Bug 15548 will require this to be updated |
1427 |
module => 'Koha::Borrowers', # to Koha::Patrons |
1428 |
singular => 'borrower', |
1429 |
plural => 'borrowers', |
1430 |
pk => 'borrowernumber', |
1431 |
}, |
1432 |
branches => { |
1433 |
module => 'Koha::Libraries', |
1434 |
singular => 'branch', |
1435 |
plural => 'branches', |
1436 |
pk => 'branchcode', |
1437 |
}, |
1438 |
items => { |
1439 |
module => 'Koha::Items', |
1440 |
singular => 'item', |
1441 |
plural => 'items', |
1442 |
pk => 'itemnumber', |
1443 |
}, |
1444 |
opac_news => { |
1445 |
module => 'Koha::News', |
1446 |
singular => 'news', |
1447 |
plural => 'news', |
1448 |
pk => 'idnew', |
1449 |
}, |
1450 |
reserves => { |
1451 |
module => 'Koha::Holds', |
1452 |
singular => 'hold', |
1453 |
plural => 'holds', |
1454 |
fk => [ 'borrowernumber', 'biblionumber' ], |
1455 |
}, |
1456 |
serial => { |
1457 |
module => 'Koha::Serials', |
1458 |
singular => 'serial', |
1459 |
plural => 'serials', |
1460 |
pk => 'serialid', |
1461 |
}, |
1462 |
subscription => { |
1463 |
module => 'Koha::Subscriptions', |
1464 |
singular => 'subscription', |
1465 |
plural => 'subscriptions', |
1466 |
pk => 'subscriptionid', |
1467 |
}, |
1468 |
suggestions => { |
1469 |
module => 'Koha::Suggestions', |
1470 |
singular => 'suggestion', |
1471 |
plural => 'suggestions', |
1472 |
pk => 'suggestionid', |
1473 |
}, |
1474 |
issues => { |
1475 |
module => 'Koha::Checkouts', |
1476 |
singular => 'checkout', |
1477 |
plural => 'checkouts', |
1478 |
fk => 'itemnumber', |
1479 |
}, |
1480 |
borrower_modifications => { |
1481 |
module => 'Koha::Borrower::Modifications', |
1482 |
singular => 'patron_modification', |
1483 |
plural => 'patron_modifications', |
1484 |
fk => 'verification_token', |
1485 |
}, |
1486 |
}; |
1487 |
|
1488 |
foreach my $table ( keys %$tables ) { |
1489 |
next unless $config->{$table}; |
1490 |
|
1491 |
my $ref = ref( $tables->{$table} ) || q{}; |
1492 |
my $module = $config->{$table}->{module}; |
1493 |
|
1494 |
if ( can_load( modules => { $module => undef } ) ) { |
1495 |
my $pk = $config->{$table}->{pk}; |
1496 |
my $fk = $config->{$table}->{fk}; |
1497 |
|
1498 |
if ( $ref eq q{} || $ref eq 'HASH' ) { |
1499 |
my $id = ref $ref eq 'HASH' ? $tables->{$table}->{$pk} : $tables->{$table}; |
1500 |
my $object; |
1501 |
if ( $fk ) { # Using a foreign key for lookup |
1502 |
$object = $module->search( { $fk => $id } )->next(); |
1503 |
} else { # using the table's primary key for lookup |
1504 |
$object = $module->find($id); |
1505 |
} |
1506 |
$params->{ $config->{$table}->{singular} } = $object; |
1507 |
} |
1508 |
else { # $ref eq 'ARRAY' |
1509 |
my $object; |
1510 |
if ( @{ $tables->{$table} } == 1 ) { # Param is a single key |
1511 |
$object = $module->search( { $pk => $tables->{$table} } )->next(); |
1512 |
} |
1513 |
else { # Params are mutliple foreign keys |
1514 |
my @values = @{ $tables->{$table} }; |
1515 |
my @keys = @{ $config->{$table}->{fk} }; |
1516 |
my %params = map { $_ => shift(@values) } @keys; |
1517 |
$object = $module->search( \%params )->next(); |
1518 |
} |
1519 |
$params->{ $config->{$table}->{singular} } = $object; |
1520 |
} |
1521 |
} |
1522 |
else { |
1523 |
croak "ERROR LOADING MODULE $module: $Module::Load::Conditional::ERROR"; |
1524 |
} |
1525 |
} |
1526 |
|
1527 |
$params->{today} = dt_from_string(); |
1528 |
|
1529 |
return $params; |
1530 |
} |
1531 |
|
1379 |
|
1532 |
|
1380 |
1; |
1533 |
1; |
1381 |
__END__ |
1534 |
__END__ |