|
Lines 27-35
use C4::Context;
Link Here
|
| 27 |
use C4::Templates qw/themelanguage/; |
27 |
use C4::Templates qw/themelanguage/; |
| 28 |
use C4::Koha; |
28 |
use C4::Koha; |
| 29 |
use Koha::DateUtils; |
29 |
use Koha::DateUtils; |
|
|
30 |
use Koha::Patrons; |
| 31 |
use Koha::Reports; |
| 30 |
use C4::Output; |
32 |
use C4::Output; |
| 31 |
use C4::Debug; |
33 |
use C4::Debug; |
| 32 |
use C4::Log; |
34 |
use C4::Log; |
|
|
35 |
use Koha::Notice::Templates; |
| 36 |
use C4::Letters; |
| 33 |
|
37 |
|
| 34 |
use Koha::AuthorisedValues; |
38 |
use Koha::AuthorisedValues; |
| 35 |
use Koha::Patron::Categories; |
39 |
use Koha::Patron::Categories; |
|
Lines 928-933
sub ValidateSQLParameters {
Link Here
|
| 928 |
return \@problematic_parameters; |
932 |
return \@problematic_parameters; |
| 929 |
} |
933 |
} |
| 930 |
|
934 |
|
|
|
935 |
=head2 EmailReport |
| 936 |
|
| 937 |
EmailReport($report_id, $letter_code, $module, $branch, $email) |
| 938 |
|
| 939 |
Take a report and use it to process a Template Toolkit formatted notice |
| 940 |
|
| 941 |
=cut |
| 942 |
|
| 943 |
sub EmailReport { |
| 944 |
|
| 945 |
my $params = shift; |
| 946 |
my $report = $params->{report}; |
| 947 |
my $from = $params->{from}; |
| 948 |
my $email = $params->{email}; |
| 949 |
my $module = $params->{module}; |
| 950 |
my $code = $params->{code}; |
| 951 |
my $branch = $params->{branch} || ""; |
| 952 |
my $verbose = $params->{verbose} || 0; |
| 953 |
my $commit = $params->{commit} || 0; |
| 954 |
|
| 955 |
my @errors; |
| 956 |
|
| 957 |
return ( { FATAL => "MISSING_PARAMS" } ) unless ($report && $module && $code); |
| 958 |
|
| 959 |
return ( { FATAL => "NO_LETTER" } ) unless |
| 960 |
my $letter = Koha::Notice::Templates->find({ |
| 961 |
module =>$module, |
| 962 |
code => $code, |
| 963 |
branchcode => $branch, |
| 964 |
message_transport_type => 'email', |
| 965 |
}); |
| 966 |
$letter = $letter->unblessed; |
| 967 |
push ( @errors, { LETTER_FOUND => 1 } ) if $verbose; |
| 968 |
|
| 969 |
my $report = Koha::Reports->find( $report ); |
| 970 |
my $sql = $report->savedsql; |
| 971 |
return ( { FATAL => "NO_REPORT" } ) unless $sql; |
| 972 |
push ( @errors, { REPORT_FOUND => 1 } ) if $verbose; |
| 973 |
|
| 974 |
my ( $sth, $errors ) = execute_query( $sql ); #don't pass offset or limit, hardcoded limit of 999,999 will be used |
| 975 |
return ( { FATAL => "REPORT_FAIL" } ) if $errors; |
| 976 |
push ( @errors, { REPORT_SUCCEED => 1 } ) if $verbose; |
| 977 |
|
| 978 |
my $counter = 1; |
| 979 |
my $template = $letter->{content}; |
| 980 |
|
| 981 |
while ( my $row = $sth->fetchrow_hashref() ) { |
| 982 |
my $err_count = scalar @errors; |
| 983 |
push ( @errors, { NO_BOR_COL => $counter } ) unless defined $row->{borrowernumber}; |
| 984 |
push ( @errors, { NO_EMAIL_COL => $counter } ) unless ( (defined $email && defined $row->{$email}) || defined $row->{email} ); |
| 985 |
push ( @errors, { NO_FROM_COL => $counter } ) unless defined ( $from || $row->{from} ); |
| 986 |
push ( @errors, { NO_BOR => $row->{borrowernumber} } ) unless Koha::Patrons->find({borrowernumber=>$row->{borrowernumber}}); |
| 987 |
|
| 988 |
my $from_address = $from || $row->{from}; |
| 989 |
my $to_address = $email ? $row->{$email} : $row->{email}; |
| 990 |
push ( @errors, { NOT_PARSE => $counter } ) unless my $content = _process_row_TT( $row, $template ); |
| 991 |
$letter->{content}=$content; |
| 992 |
|
| 993 |
$counter++; |
| 994 |
next if scalar @errors > $err_count; |
| 995 |
push ( @errors, { SENDING_SUCCEED => $counter-1 } ) if $verbose; |
| 996 |
|
| 997 |
C4::Letters::EnqueueLetter({ |
| 998 |
letter => $letter, |
| 999 |
borrowernumber => $row->{borrowernumber}, |
| 1000 |
message_transport_type => 'email', |
| 1001 |
from_address => $from_address, |
| 1002 |
to_address => $to_address, |
| 1003 |
}) if $commit; |
| 1004 |
|
| 1005 |
} |
| 1006 |
|
| 1007 |
return @errors; |
| 1008 |
|
| 1009 |
} |
| 1010 |
|
| 1011 |
|
| 1012 |
|
| 1013 |
=head2 ProcessRowTT |
| 1014 |
|
| 1015 |
my $content = ProcessRowTT($row_hashref, $template); |
| 1016 |
|
| 1017 |
Accepts a hashref containing values and processes them against Template Toolkit |
| 1018 |
to produce content |
| 1019 |
|
| 1020 |
=cut |
| 1021 |
|
| 1022 |
sub _process_row_TT { |
| 1023 |
|
| 1024 |
my ($row, $template) = @_; |
| 1025 |
|
| 1026 |
return 0 unless ($row && $template); |
| 1027 |
my $content; |
| 1028 |
my $processor = Template->new(); |
| 1029 |
$processor->process( \$template, $row, \$content); |
| 1030 |
return $content; |
| 1031 |
|
| 1032 |
} |
| 1033 |
|
| 931 |
sub _get_display_value { |
1034 |
sub _get_display_value { |
| 932 |
my ( $original_value, $column ) = @_; |
1035 |
my ( $original_value, $column ) = @_; |
| 933 |
if ( $column eq 'periodicity' ) { |
1036 |
if ( $column eq 'periodicity' ) { |