Lines 53-58
runreport.pl [ -h | -m ] [ -v ] reportID [ reportID ... ]
Link Here
|
53 |
-m --man full documentation, same as --help --verbose |
53 |
-m --man full documentation, same as --help --verbose |
54 |
-v --verbose verbose output |
54 |
-v --verbose verbose output |
55 |
|
55 |
|
|
|
56 |
--format=s selects format. Choice of text, html, csv, or tsv |
57 |
|
58 |
-e --email whether to use e-mail (implied by --to or --from) |
59 |
--to=s e-mail address to send report to |
60 |
--from=s e-mail address to send report from |
61 |
--subject=s subject for the e-mail |
62 |
|
63 |
|
56 |
Arguments: |
64 |
Arguments: |
57 |
reportID report ID Number from saved_sql.id, multiple ID's may be specified |
65 |
reportID report ID Number from saved_sql.id, multiple ID's may be specified |
58 |
|
66 |
|
Lines 72-77
Prints the manual page and exits.
Link Here
|
72 |
|
80 |
|
73 |
Verbose. Without this flag set, only fatal errors are reported. |
81 |
Verbose. Without this flag set, only fatal errors are reported. |
74 |
|
82 |
|
|
|
83 |
=item B<-format> |
84 |
|
85 |
Current options are text, html, csv, and tsv. At the moment, text and tsv both produce tab-separated tab-separated output. |
86 |
|
87 |
=item B<-email> |
88 |
|
89 |
Whether to use e-mail (implied by --to or --from). |
90 |
|
91 |
=item B<-to> |
92 |
|
93 |
E-mail address to send report to. Defaults to KohaAdminEmailAddress. |
94 |
|
95 |
=item B<-from> |
96 |
|
97 |
E-mail address to send report from. Defaults to KohaAdminEmailAddress. |
98 |
|
99 |
=item B<-subject> |
100 |
|
101 |
Subject for the e-mail message. Defaults to "Koha Saved Report" |
102 |
|
75 |
=back |
103 |
=back |
76 |
|
104 |
|
77 |
=head1 DESCRIPTION |
105 |
=head1 DESCRIPTION |
Lines 93-109
Same as above, but also runs report #17.
Link Here
|
93 |
|
121 |
|
94 |
=over |
122 |
=over |
95 |
|
123 |
|
96 |
=item * |
|
|
97 |
|
98 |
Complete testing for Sendmail related options: --email, --to, and --from. |
99 |
|
124 |
|
100 |
=item * |
125 |
=item * |
101 |
|
126 |
|
102 |
Allow Saved Results option. |
127 |
Allow Saved Results option. |
103 |
|
128 |
|
104 |
=item * |
|
|
105 |
|
106 |
Possible --format option for CSV or tab-delimited output. |
107 |
|
129 |
|
108 |
=back |
130 |
=back |
109 |
|
131 |
|
Lines 120-137
my $help = 0;
Link Here
|
120 |
my $man = 0; |
142 |
my $man = 0; |
121 |
my $verbose = 0; |
143 |
my $verbose = 0; |
122 |
my $email = 0; |
144 |
my $email = 0; |
123 |
my $format = ""; |
145 |
my $format = "text"; |
124 |
my $to = ""; |
146 |
my $to = ""; |
125 |
my $from = ""; |
147 |
my $from = ""; |
126 |
my $subject = 'Koha Saved Report'; |
148 |
my $subject = 'Koha Saved Report'; |
|
|
149 |
my $separator = ','; |
150 |
my $quote = '"'; |
127 |
|
151 |
|
128 |
GetOptions( |
152 |
GetOptions( |
129 |
'help|?' => \$help, |
153 |
'help|?' => \$help, |
130 |
'man' => \$man, |
154 |
'man' => \$man, |
131 |
'verbose' => \$verbose, |
155 |
'verbose' => \$verbose, |
132 |
'format' => \$format, |
156 |
'format=s' => \$format, |
133 |
'to' => \$to, |
157 |
'to=s' => \$to, |
134 |
'from' => \$from, |
158 |
'from=s' => \$from, |
|
|
159 |
'subject=s' => \$subject, |
135 |
'email' => \$email, |
160 |
'email' => \$email, |
136 |
) or pod2usage(2); |
161 |
) or pod2usage(2); |
137 |
pod2usage( -verbose => 2 ) if ($man); |
162 |
pod2usage( -verbose => 2 ) if ($man); |
Lines 140-147
pod2usage(1) if $help;
Link Here
|
140 |
|
165 |
|
141 |
unless ($format) { |
166 |
unless ($format) { |
142 |
$verbose and print STDERR "No format specified, assuming 'text'\n"; |
167 |
$verbose and print STDERR "No format specified, assuming 'text'\n"; |
143 |
$format = ''; |
168 |
$format = 'text'; |
144 |
# $format = 'text'; |
169 |
} |
|
|
170 |
|
171 |
if ($format eq 'tsv' || $format eq 'text') { |
172 |
$format = 'csv'; |
173 |
$separator = "\t"; |
145 |
} |
174 |
} |
146 |
|
175 |
|
147 |
if ($to or $from or $email) { |
176 |
if ($to or $from or $email) { |
Lines 174-186
foreach my $report (@ARGV) {
Link Here
|
174 |
} |
203 |
} |
175 |
$verbose and print "$count results from execute_query\n"; |
204 |
$verbose and print "$count results from execute_query\n"; |
176 |
|
205 |
|
177 |
my $cgi = CGI->new(); |
206 |
my $message; |
178 |
my @rows = (); |
207 |
if ($format eq 'html') { |
179 |
while (my $line = $sth->fetchrow_arrayref) { |
208 |
my $cgi = CGI->new(); |
180 |
foreach (@$line) { defined($_) or $_ = ''; } # catch undef values, replace w/ '' |
209 |
my @rows = (); |
181 |
push @rows, $cgi->TR( join('', $cgi->td($line)) ) . "\n"; |
210 |
while (my $line = $sth->fetchrow_arrayref) { |
|
|
211 |
foreach (@$line) { defined($_) or $_ = ''; } # catch undef values, replace w/ '' |
212 |
push @rows, $cgi->TR( join('', $cgi->td($line)) ) . "\n"; |
213 |
} |
214 |
$message = $cgi->table(join "", @rows); |
215 |
} elsif ($format eq 'csv') { |
216 |
my $csv = Text::CSV_XS->new({ |
217 |
quote_char => $quote, |
218 |
sep_char => $separator, |
219 |
}); |
220 |
while (my $line = $sth->fetchrow_arrayref) { |
221 |
$csv->combine(@$line); |
222 |
# foreach (@$line) { |
223 |
# defined($_) or $_ = ''; |
224 |
# $_ =~ s/$quote/\\$quote/g; |
225 |
# $_ = "$quote$_$quote"; |
226 |
# } # catch undef values, replace w/ '' |
227 |
# $message .= join ($separator, @$line) . "\n"; |
228 |
$message .= $csv->string() . "\n"; |
229 |
} |
182 |
} |
230 |
} |
183 |
my $message = $cgi->table(join "", @rows); |
|
|
184 |
|
231 |
|
185 |
if ($email){ |
232 |
if ($email){ |
186 |
my %mail = ( |
233 |
my %mail = ( |
187 |
- |
|
|