Lines 124-130
sub GetLetterTemplates {
Link Here
|
124 |
my $dbh = C4::Context->dbh; |
124 |
my $dbh = C4::Context->dbh; |
125 |
my $letters = $dbh->selectall_hashref( |
125 |
my $letters = $dbh->selectall_hashref( |
126 |
q| |
126 |
q| |
127 |
SELECT module, code, branchcode, name, is_html, title, content, message_transport_type |
127 |
SELECT module, code, branchcode, name, is_html, title, content, message_transport_type, is_tt |
128 |
FROM letter |
128 |
FROM letter |
129 |
WHERE module = ? |
129 |
WHERE module = ? |
130 |
AND code = ? |
130 |
AND code = ? |
Lines 642-730
sub GetPreparedLetter {
Link Here
|
642 |
or warn( "No $module $letter_code letter transported by " . $mtt ), |
642 |
or warn( "No $module $letter_code letter transported by " . $mtt ), |
643 |
return; |
643 |
return; |
644 |
|
644 |
|
645 |
my $tables = $params{tables}; |
645 |
my $tables = $params{tables}; |
646 |
my $substitute = $params{substitute}; |
646 |
my $substitute = $params{substitute}; |
647 |
my $repeat = $params{repeat}; |
647 |
my $repeat = $params{repeat}; |
|
|
648 |
|
648 |
$tables || $substitute || $repeat |
649 |
$tables || $substitute || $repeat |
649 |
or carp( "ERROR: nothing to substitute - both 'tables' and 'substitute' are empty" ), |
650 |
or carp( "ERROR: nothing to substitute - both 'tables' and 'substitute' are empty" ), |
650 |
return; |
651 |
return; |
651 |
my $want_librarian = $params{want_librarian}; |
|
|
652 |
|
652 |
|
653 |
if ($substitute) { |
653 |
my $userenv = C4::Context->userenv; |
654 |
while ( my ($token, $val) = each %$substitute ) { |
|
|
655 |
if ( $token eq 'items.content' ) { |
656 |
$val =~ s|\n|<br/>|g if $letter->{is_html}; |
657 |
} |
658 |
|
654 |
|
659 |
$letter->{title} =~ s/<<$token>>/$val/g; |
655 |
if ( $letter->{is_tt} ) { |
660 |
$letter->{content} =~ s/<<$token>>/$val/g; |
656 |
$letter->{content} = _process_tt( |
661 |
} |
657 |
{ |
|
|
658 |
content => $letter->{content}, |
659 |
tables => $tables, |
660 |
tt_params => { |
661 |
today => dt_from_string(), |
662 |
librarian => { |
663 |
firstname => $userenv->{firstname}, |
664 |
surname => $userenv->{surname}, |
665 |
emailaddress => $userenv->{emailaddress}, |
666 |
}, |
667 |
} |
668 |
} |
669 |
); |
662 |
} |
670 |
} |
|
|
671 |
else { |
672 |
my $want_librarian = $params{want_librarian}; |
663 |
|
673 |
|
664 |
my $OPACBaseURL = C4::Context->preference('OPACBaseURL'); |
674 |
if ($substitute) { |
665 |
$letter->{content} =~ s/<<OPACBaseURL>>/$OPACBaseURL/go; |
675 |
while ( my ($token, $val) = each %$substitute ) { |
|
|
676 |
if ( $token eq 'items.content' ) { |
677 |
$val =~ s|\n|<br/>|g if $letter->{is_html}; |
678 |
} |
666 |
|
679 |
|
667 |
if ($want_librarian) { |
680 |
$letter->{title} =~ s/<<$token>>/$val/g; |
668 |
# parsing librarian name |
681 |
$letter->{content} =~ s/<<$token>>/$val/g; |
669 |
my $userenv = C4::Context->userenv; |
682 |
} |
670 |
$letter->{content} =~ s/<<LibrarianFirstname>>/$userenv->{firstname}/go; |
683 |
} |
671 |
$letter->{content} =~ s/<<LibrarianSurname>>/$userenv->{surname}/go; |
|
|
672 |
$letter->{content} =~ s/<<LibrarianEmailaddress>>/$userenv->{emailaddress}/go; |
673 |
} |
674 |
|
684 |
|
675 |
my ($repeat_no_enclosing_tags, $repeat_enclosing_tags); |
685 |
my $OPACBaseURL = C4::Context->preference('OPACBaseURL'); |
|
|
686 |
$letter->{content} =~ s/<<OPACBaseURL>>/$OPACBaseURL/go; |
676 |
|
687 |
|
677 |
if ($repeat) { |
688 |
if ($want_librarian) { |
678 |
if (ref ($repeat) eq 'ARRAY' ) { |
689 |
# parsing librarian name |
679 |
$repeat_no_enclosing_tags = $repeat; |
690 |
$letter->{content} =~ s/<<LibrarianFirstname>>/$userenv->{firstname}/go; |
680 |
} else { |
691 |
$letter->{content} =~ s/<<LibrarianSurname>>/$userenv->{surname}/go; |
681 |
$repeat_enclosing_tags = $repeat; |
692 |
$letter->{content} =~ s/<<LibrarianEmailaddress>>/$userenv->{emailaddress}/go; |
682 |
} |
693 |
} |
683 |
} |
|
|
684 |
|
694 |
|
685 |
if ($repeat_enclosing_tags) { |
695 |
my ($repeat_no_enclosing_tags, $repeat_enclosing_tags); |
686 |
while ( my ($tag, $tag_tables) = each %$repeat_enclosing_tags ) { |
696 |
|
687 |
if ( $letter->{content} =~ m!<$tag>(.*)</$tag>!s ) { |
697 |
if ($repeat) { |
688 |
my $subcontent = $1; |
698 |
if (ref ($repeat) eq 'ARRAY' ) { |
689 |
my @lines = map { |
699 |
$repeat_no_enclosing_tags = $repeat; |
690 |
my %subletter = ( title => '', content => $subcontent ); |
700 |
} else { |
691 |
_substitute_tables( \%subletter, $_ ); |
701 |
$repeat_enclosing_tags = $repeat; |
692 |
$subletter{content}; |
|
|
693 |
} @$tag_tables; |
694 |
$letter->{content} =~ s!<$tag>.*</$tag>!join( "\n", @lines )!se; |
695 |
} |
702 |
} |
696 |
} |
703 |
} |
697 |
} |
|
|
698 |
|
699 |
if ($tables) { |
700 |
_substitute_tables( $letter, $tables ); |
701 |
} |
702 |
|
704 |
|
703 |
if ($repeat_no_enclosing_tags) { |
705 |
if ($repeat_enclosing_tags) { |
704 |
if ( $letter->{content} =~ m/[^\n]*<<.*>>[^\n]*/so ) { |
706 |
while ( my ($tag, $tag_tables) = each %$repeat_enclosing_tags ) { |
705 |
my $line = $&; |
707 |
if ( $letter->{content} =~ m!<$tag>(.*)</$tag>!s ) { |
706 |
my $i = 1; |
708 |
my $subcontent = $1; |
707 |
my @lines = map { |
709 |
my @lines = map { |
708 |
my $c = $line; |
710 |
my %subletter = ( title => '', content => $subcontent ); |
709 |
$c =~ s/<<count>>/$i/go; |
711 |
_substitute_tables( \%subletter, $_ ); |
710 |
foreach my $field ( keys %{$_} ) { |
712 |
$subletter{content}; |
711 |
$c =~ s/(<<[^\.]+.$field>>)/$_->{$field}/; |
713 |
} @$tag_tables; |
|
|
714 |
$letter->{content} =~ s!<$tag>.*</$tag>!join( "\n", @lines )!se; |
712 |
} |
715 |
} |
713 |
$i++; |
716 |
} |
714 |
$c; |
717 |
} |
715 |
} @$repeat_no_enclosing_tags; |
|
|
716 |
|
718 |
|
717 |
my $replaceby = join( "\n", @lines ); |
719 |
if ($tables) { |
718 |
$letter->{content} =~ s/\Q$line\E/$replaceby/s; |
720 |
_substitute_tables( $letter, $tables ); |
719 |
} |
721 |
} |
720 |
} |
|
|
721 |
|
722 |
|
722 |
$letter->{content} = _process_tt( |
723 |
if ($repeat_no_enclosing_tags) { |
723 |
{ |
724 |
if ( $letter->{content} =~ m/[^\n]*<<.*>>[^\n]*/so ) { |
724 |
content => $letter->{content}, |
725 |
my $line = $&; |
725 |
tables => $tables, |
726 |
my $i = 1; |
|
|
727 |
my @lines = map { |
728 |
my $c = $line; |
729 |
$c =~ s/<<count>>/$i/go; |
730 |
foreach my $field ( keys %{$_} ) { |
731 |
$c =~ s/(<<[^\.]+.$field>>)/$_->{$field}/; |
732 |
} |
733 |
$i++; |
734 |
$c; |
735 |
} @$repeat_no_enclosing_tags; |
736 |
|
737 |
my $replaceby = join( "\n", @lines ); |
738 |
$letter->{content} =~ s/\Q$line\E/$replaceby/s; |
739 |
} |
726 |
} |
740 |
} |
727 |
); |
741 |
|
|
|
742 |
} |
728 |
|
743 |
|
729 |
$letter->{content} =~ s/<<\S*>>//go; #remove any stragglers |
744 |
$letter->{content} =~ s/<<\S*>>//go; #remove any stragglers |
730 |
|
745 |
|
Lines 1337-1344
sub _set_message_status {
Link Here
|
1337 |
sub _process_tt { |
1352 |
sub _process_tt { |
1338 |
my ( $params ) = @_; |
1353 |
my ( $params ) = @_; |
1339 |
|
1354 |
|
1340 |
my $content = $params->{content}; |
1355 |
my $content = $params->{content}; |
1341 |
my $tables = $params->{tables}; |
1356 |
my $tables = $params->{tables}; |
|
|
1357 |
my $tt_params = $params->{tt_params}; |
1342 |
|
1358 |
|
1343 |
my $use_template_cache = C4::Context->config('template_cache_dir') && defined $ENV{GATEWAY_INTERFACE}; |
1359 |
my $use_template_cache = C4::Context->config('template_cache_dir') && defined $ENV{GATEWAY_INTERFACE}; |
1344 |
my $template = Template->new( |
1360 |
my $template = Template->new( |
Lines 1353-1359
sub _process_tt {
Link Here
|
1353 |
} |
1369 |
} |
1354 |
) or die Template->error(); |
1370 |
) or die Template->error(); |
1355 |
|
1371 |
|
1356 |
my $tt_params = _get_tt_params( $tables ); |
1372 |
my $tt_objects = _get_tt_params( $tables ); |
|
|
1373 |
$tt_params = { %$tt_params, %$tt_objects }; |
1357 |
|
1374 |
|
1358 |
my $output; |
1375 |
my $output; |
1359 |
$template->process( \$content, $tt_params, \$output ) || croak "ERROR PROCESSING TEMPLATE: " . $template->error(); |
1376 |
$template->process( \$content, $tt_params, \$output ) || croak "ERROR PROCESSING TEMPLATE: " . $template->error(); |
Lines 1474-1481
sub _get_tt_params {
Link Here
|
1474 |
} |
1491 |
} |
1475 |
} |
1492 |
} |
1476 |
|
1493 |
|
1477 |
$params->{today} = dt_from_string(); |
|
|
1478 |
|
1479 |
return $params; |
1494 |
return $params; |
1480 |
} |
1495 |
} |
1481 |
|
1496 |
|