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; |
30 |
use C4::Output; |
31 |
use C4::Output; |
31 |
use C4::Debug; |
32 |
use C4::Debug; |
32 |
use C4::Log; |
33 |
use C4::Log; |
|
|
34 |
use Koha::Notice::Templates; |
35 |
use C4::Letters; |
33 |
|
36 |
|
34 |
use Koha::AuthorisedValues; |
37 |
use Koha::AuthorisedValues; |
35 |
use Koha::Patron::Categories; |
38 |
use Koha::Patron::Categories; |
Lines 975-980
sub ValidateSQLParameters {
Link Here
|
975 |
return \@problematic_parameters; |
978 |
return \@problematic_parameters; |
976 |
} |
979 |
} |
977 |
|
980 |
|
|
|
981 |
=head2 EmailReport |
982 |
|
983 |
EmailReport($report_id, $letter_code, $module, $branch, $email) |
984 |
|
985 |
Take a report and use it to process a Template Toolkit formatted notice |
986 |
|
987 |
=cut |
988 |
|
989 |
sub EmailReport { |
990 |
|
991 |
my $params = shift; |
992 |
my $report = $params->{report}; |
993 |
my $from = $params->{from}; |
994 |
my $email = $params->{email}; |
995 |
my $module = $params->{module}; |
996 |
my $code = $params->{code}; |
997 |
my $branch = $params->{branch} || ""; |
998 |
my $verbose = $params->{verbose} || 0; |
999 |
my $commit = $params->{commit} || 0; |
1000 |
|
1001 |
my @errors; |
1002 |
|
1003 |
return ( { FATAL => "MISSING_PARAMS" } ) unless ($report && $module && $code); |
1004 |
|
1005 |
return ( { FATAL => "NO_LETTER" } ) unless |
1006 |
my $letter = Koha::Notice::Templates->find({ |
1007 |
module =>$module, |
1008 |
code => $code, |
1009 |
branchcode => $branch, |
1010 |
message_transport_type => 'email', |
1011 |
}); |
1012 |
$letter = $letter->unblessed; |
1013 |
push ( @errors, { LETTER_FOUND => 1 } ) if $verbose; |
1014 |
|
1015 |
return ( { FATAL => "NO_REPORT" } ) unless my $sql = get_saved_report( $report )->{savedsql}; |
1016 |
push ( @errors, { REPORT_FOUND => 1 } ) if $verbose; |
1017 |
|
1018 |
my ( $sth, $errors ) = execute_query( $sql ); #don't pass offset or limit, hardcoded limit of 999,999 will be used |
1019 |
return ( { FATAL => "REPORT_FAIL" } ) if $errors; |
1020 |
push ( @errors, { REPORT_SUCCEED => 1 } ) if $verbose; |
1021 |
|
1022 |
my $counter = 0; |
1023 |
my $template = $letter->{content}; |
1024 |
|
1025 |
while ( my $row = $sth->fetchrow_hashref() ) { |
1026 |
my $err_count = scalar @errors; |
1027 |
push ( @errors, { NO_BOR_COL => $counter } ) unless defined $row->{borrowernumber}; |
1028 |
push ( @errors, { NO_EMAIL_COL => $counter } ) unless ( (defined $email && defined $row->{$email}) || defined $row->{email} ); |
1029 |
push ( @errors, { NO_FROM_COL => $counter } ) unless defined ( $from || $row->{from} ); |
1030 |
push ( @errors, { NO_BOR => $row->{borrowernumber} } ) unless Koha::Patrons->find({borrowernumber=>$row->{borrowernumber}}); |
1031 |
|
1032 |
my $from_address = $from || $row->{from}; |
1033 |
my $to_address = $email ? $row->{$email} : $row->{email}; |
1034 |
push ( @errors, { NOT_PARSE => $counter } ) unless my $content = _process_row_TT( $row, $template ); |
1035 |
$letter->{content}=$content; |
1036 |
|
1037 |
$counter++; |
1038 |
next if scalar @errors > $err_count; |
1039 |
push ( @errors, { SENDING_SUCCEED => $counter-1 } ) if $verbose; |
1040 |
|
1041 |
C4::Letters::EnqueueLetter({ |
1042 |
letter => $letter, |
1043 |
borrowernumber => $row->{borrowernumber}, |
1044 |
message_transport_type => 'email', |
1045 |
from_address => $from_address, |
1046 |
to_address => $to_address, |
1047 |
}) if $commit; |
1048 |
|
1049 |
} |
1050 |
|
1051 |
return @errors; |
1052 |
|
1053 |
} |
1054 |
|
1055 |
|
1056 |
|
1057 |
=head2 ProcessRowTT |
1058 |
|
1059 |
my $content = ProcessRowTT($row_hashref, $template); |
1060 |
|
1061 |
Accepts a hashref containing values and processes them against Template Toolkit |
1062 |
to produce content |
1063 |
|
1064 |
=cut |
1065 |
|
1066 |
sub _process_row_TT { |
1067 |
|
1068 |
my ($row, $template) = @_; |
1069 |
|
1070 |
return 0 unless ($row && $template); |
1071 |
my $content; |
1072 |
my $processor = Template->new(); |
1073 |
$processor->process( \$template, $row, \$content); |
1074 |
return $content; |
1075 |
|
1076 |
} |
1077 |
|
978 |
sub _get_display_value { |
1078 |
sub _get_display_value { |
979 |
my ( $original_value, $column ) = @_; |
1079 |
my ( $original_value, $column ) = @_; |
980 |
if ( $column eq 'periodicity' ) { |
1080 |
if ( $column eq 'periodicity' ) { |