View | Details | Raw Unified | Return to bug 12544
Collapse All | Expand All

(-)a/misc/cronjobs/runreport.pl (-28 / +42 lines)
Lines 28-34 use C4::Log; Link Here
28
28
29
use Getopt::Long qw(:config auto_help auto_version);
29
use Getopt::Long qw(:config auto_help auto_version);
30
use Pod::Usage;
30
use Pod::Usage;
31
use Mail::Sendmail;
31
use MIME::Lite;
32
use Text::CSV_XS;
32
use Text::CSV_XS;
33
use CGI qw ( -utf8 );
33
use CGI qw ( -utf8 );
34
use Carp;
34
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
60
   --format=s      selects format. Choice of text, html, csv, or tsv
61
61
62
   -e --email      whether to use e-mail (implied by --to or --from)
62
   -e --email      whether to use e-mail (implied by --to or --from)
63
   -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
64
   --username      username to pass to the SMTP server for authentication
64
   --password      password to pass to the SMTP server for authentication
65
   --password      password to pass to the SMTP server for authentication
65
   --method        method is the type of authentication. Ie. LOGIN, DIGEST-MD5, etc.
66
   --method        method is the type of authentication. Ie. LOGIN, DIGEST-MD5, etc.
Lines 161-166 my $help = 0; Link Here
161
my $man     = 0;
162
my $man     = 0;
162
my $verbose = 0;
163
my $verbose = 0;
163
my $email   = 0;
164
my $email   = 0;
165
my $attachment = 0;
164
my $format  = "text";
166
my $format  = "text";
165
my $to      = "";
167
my $to      = "";
166
my $from    = "";
168
my $from    = "";
Lines 181-186 GetOptions( Link Here
181
    'from=s'            => \$from,
183
    'from=s'            => \$from,
182
    'subject=s'         => \$subject,
184
    'subject=s'         => \$subject,
183
    'email'             => \$email,
185
    'email'             => \$email,
186
    'a|attachment'      => \$attachment,
184
    'username:s'        => \$username,
187
    'username:s'        => \$username,
185
    'password:s'        => \$password,
188
    'password:s'        => \$password,
186
    'method:s'          => \$method,
189
    'method:s'          => \$method,
Lines 269-303 foreach my $report_id (@ARGV) { Link Here
269
            $message .= $csv->string() . "\n";
272
            $message .= $csv->string() . "\n";
270
        }
273
        }
271
    }
274
    }
272
    if ($email){
275
276
    if ($email) {
273
        my $email = Koha::Email->new();
277
        my $email = Koha::Email->new();
274
        my %mail;
278
        my %mail;
275
        if ($format eq 'html') {
279
        if ( $format eq 'html' ) {
276
                $message = "<html><head><style>tr:nth-child(2n+1) { background-color: #ccc;}</style></head><body>$message</body></html>";
280
            $message = "<html><head><style>tr:nth-child(2n+1) { background-color: #ccc;}</style></head><body>$message</body></html>";
277
           %mail = $email->create_message_headers({
281
            %mail = $email->create_message_headers(
278
              to      => $to,
282
                {
279
              from    => $from,
283
                    to          => $to,
280
              contenttype => 'text/html',
284
                    from        => $from,
281
              subject => encode('utf8', $subject ),
285
                    contenttype => 'text/html',
282
              message => encode('utf8', $message )
286
                    subject     => encode( 'utf8', $subject ),
283
           }
287
                }
284
          );
288
            );
285
        } else {
289
        }
286
          %mail = $email->create_message_headers ({
290
        else {
287
              to      => $to,
291
            %mail = $email->create_message_headers(
288
              from    => $from,
292
                {
289
              subject => encode('utf8', $subject ),
293
                    to      => $to,
290
              message => encode('utf8', $message )
294
                    from    => $from,
291
          }
295
                    subject => encode( 'utf8', $subject ),
292
          );
296
                }
297
            );
293
        }
298
        }
294
        $mail{'Auth'} = {user => $username, pass => $password, method => $method} if $username;
299
295
        sendmail(%mail) or carp 'mail not sent:' . $Mail::Sendmail::error;
300
        $mail{Data} = encode( 'utf8', $message );
296
    } else {
301
        $mail{Auth} = { user => $username, pass => $password, method => $method } if $username;
302
303
        my $msg = MIME::Lite->new(%mail);
304
305
        $msg->attach(
306
            Type        => "text/$format",
307
            Data        => encode( 'utf8', $message ),
308
            Filename    => "report.$format",
309
            Disposition => 'attachment',
310
        ) if $attachment;
311
312
        $msg->send();
313
        carp "Mail not sent" unless $msg->last_send_successful();
314
    }
315
    else {
297
        print $message;
316
        print $message;
298
    }
317
    }
299
    # my @xmlarray = ... ;
300
    # my $url = "/cgi-bin/koha/reports/guided_reports.pl?phase=retrieve%20results&id=$id";
301
    # my $xml = XML::Dumper->new()->pl2xml( \@xmlarray );
302
    # store_results($id,$xml);
303
}
318
}
304
- 

Return to bug 12544