Lines 25-31
use C4::Context;
Link Here
|
25 |
|
25 |
|
26 |
use Getopt::Long qw(:config auto_help auto_version); |
26 |
use Getopt::Long qw(:config auto_help auto_version); |
27 |
use Pod::Usage; |
27 |
use Pod::Usage; |
28 |
use Mail::Sendmail; |
28 |
use MIME::Lite; |
29 |
use Text::CSV_XS; |
29 |
use Text::CSV_XS; |
30 |
use CGI; |
30 |
use CGI; |
31 |
use Carp; |
31 |
use Carp; |
Lines 149-154
my $from = "";
Link Here
|
149 |
my $subject = 'Koha Saved Report'; |
149 |
my $subject = 'Koha Saved Report'; |
150 |
my $separator = ','; |
150 |
my $separator = ','; |
151 |
my $quote = '"'; |
151 |
my $quote = '"'; |
|
|
152 |
my $message = ""; |
153 |
my $mail; |
154 |
my $outfile; |
152 |
|
155 |
|
153 |
GetOptions( |
156 |
GetOptions( |
154 |
'help|?' => \$help, |
157 |
'help|?' => \$help, |
Lines 169-179
unless ($format) {
Link Here
|
169 |
$format = 'text'; |
172 |
$format = 'text'; |
170 |
} |
173 |
} |
171 |
|
174 |
|
172 |
if ($format eq 'tsv' || $format eq 'text') { |
|
|
173 |
$format = 'csv'; |
174 |
$separator = "\t"; |
175 |
} |
176 |
|
177 |
if ($to or $from or $email) { |
175 |
if ($to or $from or $email) { |
178 |
$email = 1; |
176 |
$email = 1; |
179 |
$from or $from = C4::Context->preference('KohaAdminEmailAddress'); |
177 |
$from or $from = C4::Context->preference('KohaAdminEmailAddress'); |
Lines 216-223
foreach my $report_id (@ARGV) {
Link Here
|
216 |
} |
214 |
} |
217 |
$verbose and print "$count results from execute_query\n"; |
215 |
$verbose and print "$count results from execute_query\n"; |
218 |
|
216 |
|
219 |
my $message; |
217 |
if ($format eq 'text') { |
220 |
if ($format eq 'html') { |
|
|
221 |
my $cgi = CGI->new(); |
218 |
my $cgi = CGI->new(); |
222 |
my @rows = (); |
219 |
my @rows = (); |
223 |
while (my $line = $sth->fetchrow_arrayref) { |
220 |
while (my $line = $sth->fetchrow_arrayref) { |
Lines 225-230
foreach my $report_id (@ARGV) {
Link Here
|
225 |
push @rows, $cgi->TR( join('', $cgi->td($line)) ) . "\n"; |
222 |
push @rows, $cgi->TR( join('', $cgi->td($line)) ) . "\n"; |
226 |
} |
223 |
} |
227 |
$message = $cgi->table(join "", @rows); |
224 |
$message = $cgi->table(join "", @rows); |
|
|
225 |
if ( $email ) { |
226 |
$mail = MIME::Lite->new ( |
227 |
To => $to, |
228 |
From => $from, |
229 |
Subject => $subject, |
230 |
Data => $message, |
231 |
Type => 'text/html' |
232 |
); |
233 |
} |
228 |
} elsif ($format eq 'csv') { |
234 |
} elsif ($format eq 'csv') { |
229 |
my $csv = Text::CSV_XS->new({ |
235 |
my $csv = Text::CSV_XS->new({ |
230 |
quote_char => $quote, |
236 |
quote_char => $quote, |
Lines 240-258
foreach my $report_id (@ARGV) {
Link Here
|
240 |
# $message .= join ($separator, @$line) . "\n"; |
246 |
# $message .= join ($separator, @$line) . "\n"; |
241 |
$message .= $csv->string() . "\n"; |
247 |
$message .= $csv->string() . "\n"; |
242 |
} |
248 |
} |
|
|
249 |
if ($email) { |
250 |
$outfile = "/tmp/report$report.csv"; |
251 |
open( my $fh, ">:encoding(UTF-8)", $outfile ) or die "unable to open $outfile: $!"; |
252 |
print $fh $message; |
253 |
close $fh; |
254 |
|
255 |
$mail = MIME::Lite->new ( |
256 |
From => $from, |
257 |
To => $to, |
258 |
Subject => $subject, |
259 |
Type => 'multipart/mixed', |
260 |
); |
261 |
$mail->attach ( |
262 |
Type => 'application/csv', |
263 |
Path => $outfile, |
264 |
Filename => "report$report.csv", |
265 |
); |
266 |
} |
243 |
} |
267 |
} |
244 |
|
268 |
|
245 |
if ($email){ |
269 |
if ($email){ |
246 |
my %mail = ( |
270 |
$mail->send or carp 'mail not sent:'; |
247 |
To => $to, |
271 |
unlink $outfile if ($outfile); |
248 |
From => $from, |
|
|
249 |
Subject => encode('utf8', $subject ), |
250 |
Message => encode('utf8', $message ) |
251 |
); |
252 |
sendmail(%mail) or carp 'mail not sent:' . $Mail::Sendmail::error; |
253 |
} else { |
272 |
} else { |
254 |
print $message; |
273 |
print $message; |
255 |
} |
274 |
} |
|
|
275 |
|
256 |
# my @xmlarray = ... ; |
276 |
# my @xmlarray = ... ; |
257 |
# my $url = "/cgi-bin/koha/reports/guided_reports.pl?phase=retrieve%20results&id=$id"; |
277 |
# my $url = "/cgi-bin/koha/reports/guided_reports.pl?phase=retrieve%20results&id=$id"; |
258 |
# my $xml = XML::Dumper->new()->pl2xml( \@xmlarray ); |
278 |
# my $xml = XML::Dumper->new()->pl2xml( \@xmlarray ); |