3 # Copyright 2008 Liblime
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
23 use C4::Reports::Guided; # 0.12
26 use Getopt::Long qw(:config auto_help auto_version);
32 use vars qw($VERSION);
35 # find Koha's Perl modules
36 # test carefully before changing this
38 eval { require "$FindBin::Bin/../kohalib.pl" };
44 runreport.pl - Run a pre-existing saved report.
51 -h --help brief help message
52 -m --man full documentation, same as --help --verbose
53 -v --verbose verbose output
61 Print a brief help message and exits.
65 Prints the manual page and exits.
69 Verbose. Without this flag set, only fatal errors are reported.
75 This script is designed to run an existing Saved Report.
81 In the most basic form, runs the report specified by ID number from
82 saved_sql.id, in this case #16, outputting the results to STDOUT.
86 Reports - Guided Reports
90 # These variables can be set by command line options,
91 # initially set to default values.
97 my $to = C4::Context->preference('KohaAdminEmailAddress');
98 my $from = C4::Context->preference('KohaAdminEmailAddress');
99 my $subject = 'Koha Saved Report';
104 'verbose' => \$verbose,
105 'format' => \$format,
109 pod2usage( -verbose => 2 ) if ($man);
110 pod2usage( -verbose => 2 ) if ($help and $verbose);
111 pod2usage(1) if $help;
114 $verbose and print STDERR "No format specified, assuming 'text'\n";
119 unless (scalar(@ARGV)) {
120 print STDERR "ERROR: No reports specified\n";
123 print scalar(@ARGV), " argument(s) after options: " . join(" ", @ARGV) . "\n";
127 foreach my $report (@ARGV) {
128 my ($sql, $type) = get_saved_report($report);
130 warn "ERROR: No saved report $report found";
133 $verbose and print "SQL: $sql\n\n";
134 # my $results = execute_query($sql, undef, 0, 99999, $format, $report);
135 my ($sth) = execute_query($sql);
136 # execute_query(sql, , 0, 20, , )
137 my $count = scalar($sth->rows);
139 print "NO OUTPUT: 0 results from execute_query\n";
142 $verbose and print "$count results from execute_query\n";
144 my $cgi = CGI->new();
146 while (my $line = $sth->fetchrow_arrayref) {
147 foreach (@$line) { defined($_) or $_ = ''; } # catch undef values, replace w/ ''
148 push @rows, $cgi->TR( join('', $cgi->td($line)) ) . "\n";
150 my $message = $cgi->table(join "", @rows);
159 sendmail(%mail) or warn "mail not sent";
163 # my @xmlarray = ... ;
164 # my $url = "/cgi-bin/koha/reports/guided_reports.pl?phase=retrieve%20results&id=$id";
165 # my $xml = XML::Dumper->new()->pl2xml( \@xmlarray );
166 # store_results($id,$xml);