Lines 116-121
sub GetLetters {
Link Here
|
116 |
return \%letters; |
116 |
return \%letters; |
117 |
} |
117 |
} |
118 |
|
118 |
|
|
|
119 |
=head2 GetLetter( %params ) |
120 |
|
121 |
retrieves the letter template |
122 |
|
123 |
%params hash: |
124 |
module => letter module, mandatory |
125 |
letter_code => letter code, mandatory |
126 |
branchcode => for letter selection, if missing default system letter taken |
127 |
Return value: |
128 |
letter fields hashref (title & content useful) |
129 |
|
130 |
=cut |
131 |
|
132 |
sub GetLetter { |
133 |
my %params = @_; |
134 |
|
135 |
my $module = $params{module} or croak "No module"; |
136 |
my $letter_code = $params{letter_code} or croak "No letter_code"; |
137 |
my $branchcode = $params{branchcode} || ''; |
138 |
|
139 |
my $letter = getletter( $module, $letter_code, $branchcode ) |
140 |
or warn( "No $module $letter_code letter"), |
141 |
return; |
142 |
|
143 |
return $letter; |
144 |
} |
145 |
|
119 |
my %letter; |
146 |
my %letter; |
120 |
sub getletter { |
147 |
sub getletter { |
121 |
my ( $module, $code, $branchcode ) = @_; |
148 |
my ( $module, $code, $branchcode ) = @_; |
Lines 409-414
sub SendAlerts {
Link Here
|
409 |
|
436 |
|
410 |
=head2 GetPreparedLetter( %params ) |
437 |
=head2 GetPreparedLetter( %params ) |
411 |
|
438 |
|
|
|
439 |
retrieves letter template and performs substituion processing |
440 |
|
412 |
%params hash: |
441 |
%params hash: |
413 |
module => letter module, mandatory |
442 |
module => letter module, mandatory |
414 |
letter_code => letter code, mandatory |
443 |
letter_code => letter code, mandatory |
Lines 436-449
sub GetPreparedLetter {
Link Here
|
436 |
my $module = $params{module} or croak "No module"; |
465 |
my $module = $params{module} or croak "No module"; |
437 |
my $letter_code = $params{letter_code} or croak "No letter_code"; |
466 |
my $letter_code = $params{letter_code} or croak "No letter_code"; |
438 |
my $branchcode = $params{branchcode} || ''; |
467 |
my $branchcode = $params{branchcode} || ''; |
|
|
468 |
my $tables = $params{tables}; |
469 |
my $substitute = $params{substitute}; |
470 |
my $repeat = $params{repeat}; |
439 |
|
471 |
|
440 |
my $letter = getletter( $module, $letter_code, $branchcode ) |
472 |
my $letter = getletter( $module, $letter_code, $branchcode ) |
441 |
or warn( "No $module $letter_code letter"), |
473 |
or warn( "No $module $letter_code letter"), |
442 |
return; |
474 |
return; |
443 |
|
475 |
|
|
|
476 |
my $prepared_letter = GetProcessedLetter( |
477 |
module => $module, |
478 |
letter_code => $letter_code, |
479 |
letter => $letter, |
480 |
branchcode => $branchcode, |
481 |
tables => $tables, |
482 |
substitute => $substitute, |
483 |
repeat => $repeat |
484 |
); |
485 |
|
486 |
return $prepared_letter; |
487 |
} |
488 |
|
489 |
=head2 GetProcessedLetter( %params ) |
490 |
|
491 |
given a letter, with possible pre-processing do standard processing |
492 |
allows one to perform letter template processing beforehand |
493 |
|
494 |
%params hash: |
495 |
module => letter module, mandatory |
496 |
letter_code => letter code, mandatory |
497 |
letter => letter, mandatory |
498 |
branchcode => for letter selection, if missing default system letter taken |
499 |
tables => a hashref with table names as keys. Values are either: |
500 |
- a scalar - primary key value |
501 |
- an arrayref - primary key values |
502 |
- a hashref - full record |
503 |
substitute => custom substitution key/value pairs |
504 |
repeat => records to be substituted on consecutive lines: |
505 |
- an arrayref - tries to guess what needs substituting by |
506 |
taking remaining << >> tokensr; not recommended |
507 |
- a hashref token => @tables - replaces <token> << >> << >> </token> |
508 |
subtemplate for each @tables row; table is a hashref as above |
509 |
want_librarian => boolean, if set to true triggers librarian details |
510 |
substitution from the userenv |
511 |
Return value: |
512 |
letter fields hashref (title & content useful) |
513 |
|
514 |
=cut |
515 |
|
516 |
sub GetProcessedLetter { |
517 |
my %params = @_; |
518 |
|
519 |
my $module = $params{module} or croak "No module"; |
520 |
my $letter_code = $params{letter_code} or croak "No letter_code"; |
521 |
my $letter = $params{letter} or croak "No letter"; |
522 |
my $branchcode = $params{branchcode} || ''; |
444 |
my $tables = $params{tables}; |
523 |
my $tables = $params{tables}; |
445 |
my $substitute = $params{substitute}; |
524 |
my $substitute = $params{substitute}; |
446 |
my $repeat = $params{repeat}; |
525 |
my $repeat = $params{repeat}; |
|
|
526 |
|
447 |
$tables || $substitute || $repeat |
527 |
$tables || $substitute || $repeat |
448 |
or carp( "ERROR: nothing to substitute - both 'tables' and 'substitute' are empty" ), |
528 |
or carp( "ERROR: nothing to substitute - both 'tables' and 'substitute' are empty" ), |
449 |
return; |
529 |
return; |