Lines 122-128
sub GetLetterTemplates {
Link Here
|
122 |
my $dbh = C4::Context->dbh; |
122 |
my $dbh = C4::Context->dbh; |
123 |
my $letters = $dbh->selectall_hashref( |
123 |
my $letters = $dbh->selectall_hashref( |
124 |
q| |
124 |
q| |
125 |
SELECT module, code, branchcode, name, is_html, title, content, message_transport_type |
125 |
SELECT module, code, branchcode, name, is_html, title, content, message_transport_type, is_tt |
126 |
FROM letter |
126 |
FROM letter |
127 |
WHERE module = ? |
127 |
WHERE module = ? |
128 |
AND code = ? |
128 |
AND code = ? |
Lines 640-728
sub GetPreparedLetter {
Link Here
|
640 |
or warn( "No $module $letter_code letter transported by " . $mtt ), |
640 |
or warn( "No $module $letter_code letter transported by " . $mtt ), |
641 |
return; |
641 |
return; |
642 |
|
642 |
|
643 |
my $tables = $params{tables}; |
643 |
my $tables = $params{tables}; |
644 |
my $substitute = $params{substitute}; |
644 |
my $substitute = $params{substitute}; |
645 |
my $repeat = $params{repeat}; |
645 |
my $repeat = $params{repeat}; |
|
|
646 |
|
646 |
$tables || $substitute || $repeat |
647 |
$tables || $substitute || $repeat |
647 |
or carp( "ERROR: nothing to substitute - both 'tables' and 'substitute' are empty" ), |
648 |
or carp( "ERROR: nothing to substitute - both 'tables' and 'substitute' are empty" ), |
648 |
return; |
649 |
return; |
649 |
my $want_librarian = $params{want_librarian}; |
|
|
650 |
|
650 |
|
651 |
if ($substitute) { |
651 |
my $userenv = C4::Context->userenv; |
652 |
while ( my ($token, $val) = each %$substitute ) { |
|
|
653 |
if ( $token eq 'items.content' ) { |
654 |
$val =~ s|\n|<br/>|g if $letter->{is_html}; |
655 |
} |
656 |
|
652 |
|
657 |
$letter->{title} =~ s/<<$token>>/$val/g; |
653 |
if ( $letter->{is_tt} ) { |
658 |
$letter->{content} =~ s/<<$token>>/$val/g; |
654 |
$letter->{content} = _process_tt( |
659 |
} |
655 |
{ |
|
|
656 |
content => $letter->{content}, |
657 |
tables => $tables, |
658 |
tt_params => { |
659 |
today => dt_from_string(), |
660 |
librarian => { |
661 |
firstname => $userenv->{firstname}, |
662 |
surname => $userenv->{surname}, |
663 |
emailaddress => $userenv->{emailaddress}, |
664 |
}, |
665 |
} |
666 |
} |
667 |
); |
660 |
} |
668 |
} |
|
|
669 |
else { |
670 |
my $want_librarian = $params{want_librarian}; |
661 |
|
671 |
|
662 |
my $OPACBaseURL = C4::Context->preference('OPACBaseURL'); |
672 |
if ($substitute) { |
663 |
$letter->{content} =~ s/<<OPACBaseURL>>/$OPACBaseURL/go; |
673 |
while ( my ($token, $val) = each %$substitute ) { |
|
|
674 |
if ( $token eq 'items.content' ) { |
675 |
$val =~ s|\n|<br/>|g if $letter->{is_html}; |
676 |
} |
664 |
|
677 |
|
665 |
if ($want_librarian) { |
678 |
$letter->{title} =~ s/<<$token>>/$val/g; |
666 |
# parsing librarian name |
679 |
$letter->{content} =~ s/<<$token>>/$val/g; |
667 |
my $userenv = C4::Context->userenv; |
680 |
} |
668 |
$letter->{content} =~ s/<<LibrarianFirstname>>/$userenv->{firstname}/go; |
681 |
} |
669 |
$letter->{content} =~ s/<<LibrarianSurname>>/$userenv->{surname}/go; |
|
|
670 |
$letter->{content} =~ s/<<LibrarianEmailaddress>>/$userenv->{emailaddress}/go; |
671 |
} |
672 |
|
682 |
|
673 |
my ($repeat_no_enclosing_tags, $repeat_enclosing_tags); |
683 |
my $OPACBaseURL = C4::Context->preference('OPACBaseURL'); |
|
|
684 |
$letter->{content} =~ s/<<OPACBaseURL>>/$OPACBaseURL/go; |
674 |
|
685 |
|
675 |
if ($repeat) { |
686 |
if ($want_librarian) { |
676 |
if (ref ($repeat) eq 'ARRAY' ) { |
687 |
# parsing librarian name |
677 |
$repeat_no_enclosing_tags = $repeat; |
688 |
$letter->{content} =~ s/<<LibrarianFirstname>>/$userenv->{firstname}/go; |
678 |
} else { |
689 |
$letter->{content} =~ s/<<LibrarianSurname>>/$userenv->{surname}/go; |
679 |
$repeat_enclosing_tags = $repeat; |
690 |
$letter->{content} =~ s/<<LibrarianEmailaddress>>/$userenv->{emailaddress}/go; |
680 |
} |
691 |
} |
681 |
} |
|
|
682 |
|
692 |
|
683 |
if ($repeat_enclosing_tags) { |
693 |
my ($repeat_no_enclosing_tags, $repeat_enclosing_tags); |
684 |
while ( my ($tag, $tag_tables) = each %$repeat_enclosing_tags ) { |
694 |
|
685 |
if ( $letter->{content} =~ m!<$tag>(.*)</$tag>!s ) { |
695 |
if ($repeat) { |
686 |
my $subcontent = $1; |
696 |
if (ref ($repeat) eq 'ARRAY' ) { |
687 |
my @lines = map { |
697 |
$repeat_no_enclosing_tags = $repeat; |
688 |
my %subletter = ( title => '', content => $subcontent ); |
698 |
} else { |
689 |
_substitute_tables( \%subletter, $_ ); |
699 |
$repeat_enclosing_tags = $repeat; |
690 |
$subletter{content}; |
|
|
691 |
} @$tag_tables; |
692 |
$letter->{content} =~ s!<$tag>.*</$tag>!join( "\n", @lines )!se; |
693 |
} |
700 |
} |
694 |
} |
701 |
} |
695 |
} |
|
|
696 |
|
697 |
if ($tables) { |
698 |
_substitute_tables( $letter, $tables ); |
699 |
} |
700 |
|
702 |
|
701 |
if ($repeat_no_enclosing_tags) { |
703 |
if ($repeat_enclosing_tags) { |
702 |
if ( $letter->{content} =~ m/[^\n]*<<.*>>[^\n]*/so ) { |
704 |
while ( my ($tag, $tag_tables) = each %$repeat_enclosing_tags ) { |
703 |
my $line = $&; |
705 |
if ( $letter->{content} =~ m!<$tag>(.*)</$tag>!s ) { |
704 |
my $i = 1; |
706 |
my $subcontent = $1; |
705 |
my @lines = map { |
707 |
my @lines = map { |
706 |
my $c = $line; |
708 |
my %subletter = ( title => '', content => $subcontent ); |
707 |
$c =~ s/<<count>>/$i/go; |
709 |
_substitute_tables( \%subletter, $_ ); |
708 |
foreach my $field ( keys %{$_} ) { |
710 |
$subletter{content}; |
709 |
$c =~ s/(<<[^\.]+.$field>>)/$_->{$field}/; |
711 |
} @$tag_tables; |
|
|
712 |
$letter->{content} =~ s!<$tag>.*</$tag>!join( "\n", @lines )!se; |
710 |
} |
713 |
} |
711 |
$i++; |
714 |
} |
712 |
$c; |
715 |
} |
713 |
} @$repeat_no_enclosing_tags; |
|
|
714 |
|
716 |
|
715 |
my $replaceby = join( "\n", @lines ); |
717 |
if ($tables) { |
716 |
$letter->{content} =~ s/\Q$line\E/$replaceby/s; |
718 |
_substitute_tables( $letter, $tables ); |
717 |
} |
719 |
} |
718 |
} |
|
|
719 |
|
720 |
|
720 |
$letter->{content} = _process_tt( |
721 |
if ($repeat_no_enclosing_tags) { |
721 |
{ |
722 |
if ( $letter->{content} =~ m/[^\n]*<<.*>>[^\n]*/so ) { |
722 |
content => $letter->{content}, |
723 |
my $line = $&; |
723 |
tables => $tables, |
724 |
my $i = 1; |
|
|
725 |
my @lines = map { |
726 |
my $c = $line; |
727 |
$c =~ s/<<count>>/$i/go; |
728 |
foreach my $field ( keys %{$_} ) { |
729 |
$c =~ s/(<<[^\.]+.$field>>)/$_->{$field}/; |
730 |
} |
731 |
$i++; |
732 |
$c; |
733 |
} @$repeat_no_enclosing_tags; |
734 |
|
735 |
my $replaceby = join( "\n", @lines ); |
736 |
$letter->{content} =~ s/\Q$line\E/$replaceby/s; |
737 |
} |
724 |
} |
738 |
} |
725 |
); |
739 |
|
|
|
740 |
} |
726 |
|
741 |
|
727 |
$letter->{content} =~ s/<<\S*>>//go; #remove any stragglers |
742 |
$letter->{content} =~ s/<<\S*>>//go; #remove any stragglers |
728 |
|
743 |
|
Lines 1327-1334
sub _set_message_status {
Link Here
|
1327 |
sub _process_tt { |
1342 |
sub _process_tt { |
1328 |
my ( $params ) = @_; |
1343 |
my ( $params ) = @_; |
1329 |
|
1344 |
|
1330 |
my $content = $params->{content}; |
1345 |
my $content = $params->{content}; |
1331 |
my $tables = $params->{tables}; |
1346 |
my $tables = $params->{tables}; |
|
|
1347 |
my $tt_params = $params->{tt_params}; |
1332 |
|
1348 |
|
1333 |
my $use_template_cache = C4::Context->config('template_cache_dir') && defined $ENV{GATEWAY_INTERFACE}; |
1349 |
my $use_template_cache = C4::Context->config('template_cache_dir') && defined $ENV{GATEWAY_INTERFACE}; |
1334 |
my $template = Template->new( |
1350 |
my $template = Template->new( |
Lines 1343-1349
sub _process_tt {
Link Here
|
1343 |
} |
1359 |
} |
1344 |
) or die Template->error(); |
1360 |
) or die Template->error(); |
1345 |
|
1361 |
|
1346 |
my $tt_params = _get_tt_params( $tables ); |
1362 |
my $tt_objects = _get_tt_params( $tables ); |
|
|
1363 |
$tt_params = { %$tt_params, %$tt_objects }; |
1347 |
|
1364 |
|
1348 |
my $output; |
1365 |
my $output; |
1349 |
$template->process( \$content, $tt_params, \$output ) || croak "ERROR PROCESSING TEMPLATE: " . $template->error(); |
1366 |
$template->process( \$content, $tt_params, \$output ) || croak "ERROR PROCESSING TEMPLATE: " . $template->error(); |
Lines 1464-1471
sub _get_tt_params {
Link Here
|
1464 |
} |
1481 |
} |
1465 |
} |
1482 |
} |
1466 |
|
1483 |
|
1467 |
$params->{today} = dt_from_string(); |
|
|
1468 |
|
1469 |
return $params; |
1484 |
return $params; |
1470 |
} |
1485 |
} |
1471 |
|
1486 |
|