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(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
44 |
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
43 |
|
45 |
|
Lines 704-711
sub GetPreparedLetter {
Link Here
|
704 |
} |
706 |
} |
705 |
} |
707 |
} |
706 |
|
708 |
|
|
|
709 |
$letter->{content} = _process_tt( |
710 |
{ |
711 |
content => $letter->{content}, |
712 |
tables => $tables, |
713 |
} |
714 |
); |
715 |
|
707 |
$letter->{content} =~ s/<<\S*>>//go; #remove any stragglers |
716 |
$letter->{content} =~ s/<<\S*>>//go; #remove any stragglers |
708 |
# $letter->{content} =~ s/<<[^>]*>>//go; |
|
|
709 |
|
717 |
|
710 |
return $letter; |
718 |
return $letter; |
711 |
} |
719 |
} |
Lines 1363-1368
sub _set_message_status {
Link Here
|
1363 |
return $result; |
1371 |
return $result; |
1364 |
} |
1372 |
} |
1365 |
|
1373 |
|
|
|
1374 |
sub _process_tt { |
1375 |
my ( $params ) = @_; |
1376 |
|
1377 |
my $content = $params->{content}; |
1378 |
my $tables = $params->{tables}; |
1379 |
|
1380 |
my $use_template_cache = C4::Context->config('template_cache_dir') && defined $ENV{GATEWAY_INTERFACE}; |
1381 |
my $template = Template->new( |
1382 |
{ |
1383 |
EVAL_PERL => 1, |
1384 |
ABSOLUTE => 1, |
1385 |
PLUGIN_BASE => 'Koha::Template::Plugin', |
1386 |
COMPILE_EXT => $use_template_cache ? '.ttc' : '', |
1387 |
COMPILE_DIR => $use_template_cache ? C4::Context->config('template_cache_dir') : '', |
1388 |
FILTERS => {}, |
1389 |
ENCODING => 'UTF-8', |
1390 |
} |
1391 |
) or die Template->error(); |
1392 |
|
1393 |
my $tt_params = _get_tt_params( $tables ); |
1394 |
|
1395 |
my $output; |
1396 |
$template->process( \$content, $tt_params, \$output ) || croak "ERROR PROCESSING TEMPLATE: " . $template->error(); |
1397 |
|
1398 |
return $output; |
1399 |
} |
1400 |
|
1401 |
sub _get_tt_params { |
1402 |
my ($tables) = @_; |
1403 |
|
1404 |
my $params; |
1405 |
|
1406 |
my $config = { |
1407 |
biblio => { |
1408 |
module => 'Koha::Biblios', |
1409 |
singular => 'biblio', |
1410 |
plural => 'biblios', |
1411 |
pk => 'biblionumber', |
1412 |
}, |
1413 |
borrowers => { |
1414 |
module => 'Koha::Patrons', |
1415 |
singular => 'borrower', |
1416 |
plural => 'borrowers', |
1417 |
pk => 'borrowernumber', |
1418 |
}, |
1419 |
branches => { |
1420 |
module => 'Koha::Libraries', |
1421 |
singular => 'branch', |
1422 |
plural => 'branches', |
1423 |
pk => 'branchcode', |
1424 |
}, |
1425 |
items => { |
1426 |
module => 'Koha::Items', |
1427 |
singular => 'item', |
1428 |
plural => 'items', |
1429 |
pk => 'itemnumber', |
1430 |
}, |
1431 |
opac_news => { |
1432 |
module => 'Koha::News', |
1433 |
singular => 'news', |
1434 |
plural => 'news', |
1435 |
pk => 'idnew', |
1436 |
}, |
1437 |
reserves => { |
1438 |
module => 'Koha::Holds', |
1439 |
singular => 'hold', |
1440 |
plural => 'holds', |
1441 |
fk => [ 'borrowernumber', 'biblionumber' ], |
1442 |
}, |
1443 |
serial => { |
1444 |
module => 'Koha::Serials', |
1445 |
singular => 'serial', |
1446 |
plural => 'serials', |
1447 |
pk => 'serialid', |
1448 |
}, |
1449 |
subscription => { |
1450 |
module => 'Koha::Subscriptions', |
1451 |
singular => 'subscription', |
1452 |
plural => 'subscriptions', |
1453 |
pk => 'subscriptionid', |
1454 |
}, |
1455 |
suggestions => { |
1456 |
module => 'Koha::Suggestions', |
1457 |
singular => 'suggestion', |
1458 |
plural => 'suggestions', |
1459 |
pk => 'suggestionid', |
1460 |
}, |
1461 |
issues => { |
1462 |
module => 'Koha::Checkouts', |
1463 |
singular => 'checkout', |
1464 |
plural => 'checkouts', |
1465 |
fk => 'itemnumber', |
1466 |
}, |
1467 |
borrower_modifications => { |
1468 |
module => 'Koha::Patron::Modifications', |
1469 |
singular => 'patron_modification', |
1470 |
plural => 'patron_modifications', |
1471 |
fk => 'verification_token', |
1472 |
}, |
1473 |
}; |
1474 |
|
1475 |
foreach my $table ( keys %$tables ) { |
1476 |
next unless $config->{$table}; |
1477 |
|
1478 |
my $ref = ref( $tables->{$table} ) || q{}; |
1479 |
my $module = $config->{$table}->{module}; |
1480 |
|
1481 |
if ( can_load( modules => { $module => undef } ) ) { |
1482 |
my $pk = $config->{$table}->{pk}; |
1483 |
my $fk = $config->{$table}->{fk}; |
1484 |
|
1485 |
if ( $ref eq q{} || $ref eq 'HASH' ) { |
1486 |
my $id = ref $ref eq 'HASH' ? $tables->{$table}->{$pk} : $tables->{$table}; |
1487 |
my $object; |
1488 |
if ( $fk ) { # Using a foreign key for lookup |
1489 |
$object = $module->search( { $fk => $id } )->next(); |
1490 |
} else { # using the table's primary key for lookup |
1491 |
$object = $module->find($id); |
1492 |
} |
1493 |
$params->{ $config->{$table}->{singular} } = $object; |
1494 |
} |
1495 |
else { # $ref eq 'ARRAY' |
1496 |
my $object; |
1497 |
if ( @{ $tables->{$table} } == 1 ) { # Param is a single key |
1498 |
$object = $module->search( { $pk => $tables->{$table} } )->next(); |
1499 |
} |
1500 |
else { # Params are mutliple foreign keys |
1501 |
my @values = @{ $tables->{$table} }; |
1502 |
my @keys = @{ $config->{$table}->{fk} }; |
1503 |
my %params = map { $_ => shift(@values) } @keys; |
1504 |
$object = $module->search( \%params )->next(); |
1505 |
} |
1506 |
$params->{ $config->{$table}->{singular} } = $object; |
1507 |
} |
1508 |
} |
1509 |
else { |
1510 |
croak "ERROR LOADING MODULE $module: $Module::Load::Conditional::ERROR"; |
1511 |
} |
1512 |
} |
1513 |
|
1514 |
$params->{today} = dt_from_string(); |
1515 |
|
1516 |
return $params; |
1517 |
} |
1518 |
|
1366 |
|
1519 |
|
1367 |
1; |
1520 |
1; |
1368 |
__END__ |
1521 |
__END__ |