|
Lines 23-34
use warnings;
Link Here
|
| 23 |
|
23 |
|
| 24 |
use C4::Reports::Guided; # 0.12 |
24 |
use C4::Reports::Guided; # 0.12 |
| 25 |
use C4::Context; |
25 |
use C4::Context; |
| 26 |
use Koha::Email; |
|
|
| 27 |
use C4::Log; |
26 |
use C4::Log; |
|
|
27 |
use Koha::Email; |
| 28 |
use Koha::DateUtils; |
| 28 |
|
29 |
|
| 29 |
use Getopt::Long qw(:config auto_help auto_version); |
30 |
use Getopt::Long qw(:config auto_help auto_version); |
| 30 |
use Pod::Usage; |
31 |
use Pod::Usage; |
| 31 |
use Mail::Sendmail; |
32 |
use MIME::Lite; |
| 32 |
use Text::CSV_XS; |
33 |
use Text::CSV_XS; |
| 33 |
use CGI qw ( -utf8 ); |
34 |
use CGI qw ( -utf8 ); |
| 34 |
use Carp; |
35 |
use Carp; |
|
Lines 60-65
runreport.pl [ -h | -m ] [ -v ] reportID [ reportID ... ]
Link Here
|
| 60 |
--format=s selects format. Choice of text, html, csv, or tsv |
61 |
--format=s selects format. Choice of text, html, csv, or tsv |
| 61 |
|
62 |
|
| 62 |
-e --email whether to use e-mail (implied by --to or --from) |
63 |
-e --email whether to use e-mail (implied by --to or --from) |
|
|
64 |
-a --attachment additionally attach the report as a file. cannot be used with html format |
| 63 |
--username username to pass to the SMTP server for authentication |
65 |
--username username to pass to the SMTP server for authentication |
| 64 |
--password password to pass to the SMTP server for authentication |
66 |
--password password to pass to the SMTP server for authentication |
| 65 |
--method method is the type of authentication. Ie. LOGIN, DIGEST-MD5, etc. |
67 |
--method method is the type of authentication. Ie. LOGIN, DIGEST-MD5, etc. |
|
Lines 161-166
my $help = 0;
Link Here
|
| 161 |
my $man = 0; |
163 |
my $man = 0; |
| 162 |
my $verbose = 0; |
164 |
my $verbose = 0; |
| 163 |
my $email = 0; |
165 |
my $email = 0; |
|
|
166 |
my $attachment = 0; |
| 164 |
my $format = "text"; |
167 |
my $format = "text"; |
| 165 |
my $to = ""; |
168 |
my $to = ""; |
| 166 |
my $from = ""; |
169 |
my $from = ""; |
|
Lines 181-186
GetOptions(
Link Here
|
| 181 |
'from=s' => \$from, |
184 |
'from=s' => \$from, |
| 182 |
'subject=s' => \$subject, |
185 |
'subject=s' => \$subject, |
| 183 |
'email' => \$email, |
186 |
'email' => \$email, |
|
|
187 |
'a|attachment' => \$attachment, |
| 184 |
'username:s' => \$username, |
188 |
'username:s' => \$username, |
| 185 |
'password:s' => \$password, |
189 |
'password:s' => \$password, |
| 186 |
'method:s' => \$method, |
190 |
'method:s' => \$method, |
|
Lines 214-219
unless (scalar(@ARGV)) {
Link Here
|
| 214 |
} |
218 |
} |
| 215 |
($verbose) and print scalar(@ARGV), " argument(s) after options: " . join(" ", @ARGV) . "\n"; |
219 |
($verbose) and print scalar(@ARGV), " argument(s) after options: " . join(" ", @ARGV) . "\n"; |
| 216 |
|
220 |
|
|
|
221 |
my $today = dt_from_string(); |
| 222 |
my $date = $today->ymd(); |
| 217 |
|
223 |
|
| 218 |
foreach my $report_id (@ARGV) { |
224 |
foreach my $report_id (@ARGV) { |
| 219 |
my $report = get_saved_report($report_id); |
225 |
my $report = get_saved_report($report_id); |
|
Lines 272-293
foreach my $report_id (@ARGV) {
Link Here
|
| 272 |
$message .= $csv->string() . "\n"; |
278 |
$message .= $csv->string() . "\n"; |
| 273 |
} |
279 |
} |
| 274 |
} |
280 |
} |
| 275 |
if ($email){ |
281 |
|
|
|
282 |
if ($email) { |
| 276 |
my $args = { to => $to, from => $from, subject => $subject }; |
283 |
my $args = { to => $to, from => $from, subject => $subject }; |
| 277 |
if ($format eq 'html') { |
284 |
if ( $format eq 'html' ) { |
| 278 |
$message = "<html><head><style>tr:nth-child(2n+1) { background-color: #ccc;}</style></head><body>$message</body></html>"; |
285 |
$message = "<html><head><style>tr:nth-child(2n+1) { background-color: #ccc;}</style></head><body>$message</body></html>"; |
| 279 |
$args->{contenttype} = 'text/html'; |
286 |
$args->{contenttype} = 'text/html'; |
| 280 |
} |
287 |
} |
| 281 |
$args->{message} = $message; |
|
|
| 282 |
my $email = Koha::Email->new(); |
288 |
my $email = Koha::Email->new(); |
| 283 |
my %mail = $email->create_message_headers($args); |
289 |
my %mail = $email->create_message_headers($args); |
| 284 |
$mail{'Auth'} = {user => $username, pass => $password, method => $method} if $username; |
290 |
$mail{Data} = $message; |
| 285 |
sendmail(%mail) or carp 'mail not sent:' . $Mail::Sendmail::error; |
291 |
$mail{Auth} = { user => $username, pass => $password, method => $method } if $username; |
| 286 |
} else { |
292 |
|
|
|
293 |
my $msg = MIME::Lite->new(%mail); |
| 294 |
|
| 295 |
$msg->attach( |
| 296 |
Type => "text/$format", |
| 297 |
Data => encode( 'utf8', $message ), |
| 298 |
Filename => "report$report_id-$date.$format", |
| 299 |
Disposition => 'attachment', |
| 300 |
) if $attachment; |
| 301 |
|
| 302 |
$msg->send(); |
| 303 |
carp "Mail not sent" unless $msg->last_send_successful(); |
| 304 |
} |
| 305 |
else { |
| 287 |
print $message; |
306 |
print $message; |
| 288 |
} |
307 |
} |
| 289 |
# my @xmlarray = ... ; |
|
|
| 290 |
# my $url = "/cgi-bin/koha/reports/guided_reports.pl?phase=retrieve%20results&id=$id"; |
| 291 |
# my $xml = XML::Dumper->new()->pl2xml( \@xmlarray ); |
| 292 |
# store_results($id,$xml); |
| 293 |
} |
308 |
} |
| 294 |
- |
|
|