|
Lines 31-36
use C4::SMS;
Link Here
|
| 31 |
use C4::Debug; |
31 |
use C4::Debug; |
| 32 |
use Date::Calc qw( Add_Delta_Days ); |
32 |
use Date::Calc qw( Add_Delta_Days ); |
| 33 |
use Encode; |
33 |
use Encode; |
|
|
34 |
use Unicode::Normalize; |
| 34 |
use Carp; |
35 |
use Carp; |
| 35 |
|
36 |
|
| 36 |
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
37 |
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
|
Lines 116-121
sub GetLetters (;$) {
Link Here
|
| 116 |
return \%letters; |
117 |
return \%letters; |
| 117 |
} |
118 |
} |
| 118 |
|
119 |
|
|
|
120 |
=head2 GetLetter( %params ) |
| 121 |
|
| 122 |
retrieves the letter template |
| 123 |
|
| 124 |
%params hash: |
| 125 |
module => letter module, mandatory |
| 126 |
letter_code => letter code, mandatory |
| 127 |
branchcode => for letter selection, if missing default system letter taken |
| 128 |
Return value: |
| 129 |
letter fields hashref (title & content useful) |
| 130 |
|
| 131 |
=cut |
| 132 |
|
| 133 |
sub GetLetter { |
| 134 |
my %params = @_; |
| 135 |
|
| 136 |
my $module = $params{module} or croak "No module"; |
| 137 |
my $letter_code = $params{letter_code} or croak "No letter_code"; |
| 138 |
my $branchcode = $params{branchcode} || ''; |
| 139 |
|
| 140 |
my $letter = getletter( $module, $letter_code, $branchcode ) |
| 141 |
or warn( "No $module $letter_code letter"), |
| 142 |
return; |
| 143 |
|
| 144 |
return $letter; |
| 145 |
} |
| 146 |
|
| 119 |
my %letter; |
147 |
my %letter; |
| 120 |
sub getletter ($$$) { |
148 |
sub getletter ($$$) { |
| 121 |
my ( $module, $code, $branchcode ) = @_; |
149 |
my ( $module, $code, $branchcode ) = @_; |
|
Lines 409-414
sub SendAlerts {
Link Here
|
| 409 |
|
437 |
|
| 410 |
=head2 GetPreparedLetter( %params ) |
438 |
=head2 GetPreparedLetter( %params ) |
| 411 |
|
439 |
|
|
|
440 |
retrieves letter template and performs substituion processing |
| 441 |
|
| 412 |
%params hash: |
442 |
%params hash: |
| 413 |
module => letter module, mandatory |
443 |
module => letter module, mandatory |
| 414 |
letter_code => letter code, mandatory |
444 |
letter_code => letter code, mandatory |
|
Lines 436-449
sub GetPreparedLetter {
Link Here
|
| 436 |
my $module = $params{module} or croak "No module"; |
466 |
my $module = $params{module} or croak "No module"; |
| 437 |
my $letter_code = $params{letter_code} or croak "No letter_code"; |
467 |
my $letter_code = $params{letter_code} or croak "No letter_code"; |
| 438 |
my $branchcode = $params{branchcode} || ''; |
468 |
my $branchcode = $params{branchcode} || ''; |
|
|
469 |
my $tables = $params{tables}; |
| 470 |
my $substitute = $params{substitute}; |
| 471 |
my $repeat = $params{repeat}; |
| 439 |
|
472 |
|
| 440 |
my $letter = getletter( $module, $letter_code, $branchcode ) |
473 |
my $letter = getletter( $module, $letter_code, $branchcode ) |
| 441 |
or warn( "No $module $letter_code letter"), |
474 |
or warn( "No $module $letter_code letter"), |
| 442 |
return; |
475 |
return; |
| 443 |
|
476 |
|
|
|
477 |
my $prepared_letter = GetProcessedLetter( |
| 478 |
module => $module, |
| 479 |
letter_code => $letter_code, |
| 480 |
letter => $letter, |
| 481 |
branchcode => $branchcode, |
| 482 |
tables => $tables, |
| 483 |
substitute => $substitute, |
| 484 |
repeat => $repeat |
| 485 |
); |
| 486 |
|
| 487 |
return $prepared_letter; |
| 488 |
} |
| 489 |
|
| 490 |
=head2 GetProcessedLetter( %params ) |
| 491 |
|
| 492 |
given a letter, with possible pre-processing do standard processing |
| 493 |
allows one to perform letter template processing beforehand |
| 494 |
|
| 495 |
%params hash: |
| 496 |
module => letter module, mandatory |
| 497 |
letter_code => letter code, mandatory |
| 498 |
letter => letter, mandatory |
| 499 |
branchcode => for letter selection, if missing default system letter taken |
| 500 |
tables => a hashref with table names as keys. Values are either: |
| 501 |
- a scalar - primary key value |
| 502 |
- an arrayref - primary key values |
| 503 |
- a hashref - full record |
| 504 |
substitute => custom substitution key/value pairs |
| 505 |
repeat => records to be substituted on consecutive lines: |
| 506 |
- an arrayref - tries to guess what needs substituting by |
| 507 |
taking remaining << >> tokensr; not recommended |
| 508 |
- a hashref token => @tables - replaces <token> << >> << >> </token> |
| 509 |
subtemplate for each @tables row; table is a hashref as above |
| 510 |
want_librarian => boolean, if set to true triggers librarian details |
| 511 |
substitution from the userenv |
| 512 |
Return value: |
| 513 |
letter fields hashref (title & content useful) |
| 514 |
|
| 515 |
=cut |
| 516 |
|
| 517 |
sub GetProcessedLetter { |
| 518 |
my %params = @_; |
| 519 |
|
| 520 |
my $module = $params{module} or croak "No module"; |
| 521 |
my $letter_code = $params{letter_code} or croak "No letter_code"; |
| 522 |
my $letter = $params{letter} or croak "No letter"; |
| 523 |
my $branchcode = $params{branchcode} || ''; |
| 444 |
my $tables = $params{tables}; |
524 |
my $tables = $params{tables}; |
| 445 |
my $substitute = $params{substitute}; |
525 |
my $substitute = $params{substitute}; |
| 446 |
my $repeat = $params{repeat}; |
526 |
my $repeat = $params{repeat}; |
|
|
527 |
|
| 447 |
$tables || $substitute || $repeat |
528 |
$tables || $substitute || $repeat |
| 448 |
or carp( "ERROR: nothing to substitute - both 'tables' and 'substitute' are empty" ), |
529 |
or carp( "ERROR: nothing to substitute - both 'tables' and 'substitute' are empty" ), |
| 449 |
return; |
530 |
return; |
|
Lines 675-680
sub EnqueueLetter ($) {
Link Here
|
| 675 |
return unless exists $params->{'borrowernumber'}; |
756 |
return unless exists $params->{'borrowernumber'}; |
| 676 |
return unless exists $params->{'message_transport_type'}; |
757 |
return unless exists $params->{'message_transport_type'}; |
| 677 |
|
758 |
|
|
|
759 |
my $content = $params->{letter}->{content}; |
| 760 |
$content =~ s/\s+//g if(defined $content); |
| 761 |
if ( not defined $content or $content eq '' ) { |
| 762 |
warn "Trying to add an empty message to the message queue" if $debug; |
| 763 |
return; |
| 764 |
} |
| 765 |
|
| 766 |
# It was found that the some utf8 codes, cause the text to be truncated from that point onward when stored, |
| 767 |
# so we normalize utf8 with NFC so that mysql will store 'all' of the content in its TEXT column type |
| 768 |
# Note: It is also done in _add_attachments accordingly. |
| 769 |
$params->{'letter'}->{'title'} = NFC($params->{'letter'}->{'title'}); # subject |
| 770 |
$params->{'letter'}->{'content'} = NFC($params->{'letter'}->{'content'}); |
| 771 |
|
| 678 |
# If we have any attachments we should encode then into the body. |
772 |
# If we have any attachments we should encode then into the body. |
| 679 |
if ( $params->{'attachments'} ) { |
773 |
if ( $params->{'attachments'} ) { |
| 680 |
$params->{'letter'} = _add_attachments( |
774 |
$params->{'letter'} = _add_attachments( |
|
Lines 844-854
sub _add_attachments {
Link Here
|
| 844 |
$message->attach( |
938 |
$message->attach( |
| 845 |
Type => $letter->{'content-type'} || 'TEXT', |
939 |
Type => $letter->{'content-type'} || 'TEXT', |
| 846 |
Data => $letter->{'is_html'} |
940 |
Data => $letter->{'is_html'} |
| 847 |
? _wrap_html($letter->{'content'}, $letter->{'title'}) |
941 |
? _wrap_html($letter->{'content'}, NFC($letter->{'title'})) |
| 848 |
: $letter->{'content'}, |
942 |
: NFC($letter->{'content'}), |
| 849 |
); |
943 |
); |
| 850 |
|
944 |
|
| 851 |
foreach my $attachment ( @$attachments ) { |
945 |
foreach my $attachment ( @$attachments ) { |
|
|
946 |
|
| 947 |
if ($attachment->{'content'} =~ m/text/o) { # NFC normailze any "text" related content-type attachments |
| 948 |
$attachment->{'content'} = NFC($attachment->{'content'}); |
| 949 |
} |
| 950 |
$attachment->{'filename'} = NFC($attachment->{'filename'}); |
| 951 |
|
| 852 |
$message->attach( |
952 |
$message->attach( |
| 853 |
Type => $attachment->{'type'}, |
953 |
Type => $attachment->{'type'}, |
| 854 |
Data => $attachment->{'content'}, |
954 |
Data => $attachment->{'content'}, |