|
Lines 829-835
elsif ($phase eq 'Run this report'){
Link Here
|
| 829 |
$template->param(header_types => $header_types); |
829 |
$template->param(header_types => $header_types); |
| 830 |
my ( $sth, $errors ) = execute_query( $sql, $offset, $limit, undef, $report_id ); |
830 |
my ( $sth, $errors ) = execute_query( $sql, $offset, $limit, undef, $report_id ); |
| 831 |
my ($sth2, $errors2) = execute_query($sql); |
831 |
my ($sth2, $errors2) = execute_query($sql); |
| 832 |
my $max_rows = C4::Context->preference('ReportsMaxRowsInChart'); |
832 |
my $max_rows = C4::Context->preference('ReportsMaxRowsReturned'); |
| 833 |
my $total = nb_rows($sql) || 0; |
833 |
my $total = nb_rows($sql) || 0; |
| 834 |
unless ($sth) { |
834 |
unless ($sth) { |
| 835 |
die "execute_query failed to return sth for report $report_id: $sql"; |
835 |
die "execute_query failed to return sth for report $report_id: $sql"; |
|
Lines 890-895
elsif ($phase eq 'Export'){
Link Here
|
| 890 |
my $format = $input->param('format'); |
890 |
my $format = $input->param('format'); |
| 891 |
my $reportname = $input->param('reportname'); |
891 |
my $reportname = $input->param('reportname'); |
| 892 |
my $reportfilename = $reportname ? "$reportname-reportresults.$format" : "reportresults.$format" ; |
892 |
my $reportfilename = $reportname ? "$reportname-reportresults.$format" : "reportresults.$format" ; |
|
|
893 |
my $max_rows = C4::Context->preference('ReportsMaxRowsReturned'); |
| 893 |
|
894 |
|
| 894 |
$sql = get_prepped_report( $sql, \@param_names, \@sql_params ); |
895 |
$sql = get_prepped_report( $sql, \@param_names, \@sql_params ); |
| 895 |
my ($sth, $q_errors) = execute_query($sql); |
896 |
my ($sth, $q_errors) = execute_query($sql); |
|
Lines 899-907
elsif ($phase eq 'Export'){
Link Here
|
| 899 |
$type = 'application/octet-stream'; |
900 |
$type = 'application/octet-stream'; |
| 900 |
$content .= join("\t", header_cell_values($sth)) . "\n"; |
901 |
$content .= join("\t", header_cell_values($sth)) . "\n"; |
| 901 |
$content = Encode::decode('UTF-8', $content); |
902 |
$content = Encode::decode('UTF-8', $content); |
|
|
903 |
my $n = 0; |
| 902 |
while (my $row = $sth->fetchrow_arrayref()) { |
904 |
while (my $row = $sth->fetchrow_arrayref()) { |
|
|
905 |
$n++; |
| 903 |
$content .= join("\t", @$row) . "\n"; |
906 |
$content .= join("\t", @$row) . "\n"; |
|
|
907 |
last if $max_rows && $n >= $max_rows; |
| 904 |
} |
908 |
} |
|
|
909 |
$sth->finish(); |
| 905 |
} else { |
910 |
} else { |
| 906 |
my $delimiter = C4::Context->preference('delimiter') || ','; |
911 |
my $delimiter = C4::Context->preference('delimiter') || ','; |
| 907 |
if ( $format eq 'csv' ) { |
912 |
if ( $format eq 'csv' ) { |
|
Lines 914-949
elsif ($phase eq 'Export'){
Link Here
|
| 914 |
} else { |
919 |
} else { |
| 915 |
push @$q_errors, { combine => 'HEADER ROW: ' . $csv->error_diag() } ; |
920 |
push @$q_errors, { combine => 'HEADER ROW: ' . $csv->error_diag() } ; |
| 916 |
} |
921 |
} |
|
|
922 |
my $n = 0; |
| 917 |
while (my $row = $sth->fetchrow_arrayref()) { |
923 |
while (my $row = $sth->fetchrow_arrayref()) { |
|
|
924 |
$n++; |
| 918 |
if ($csv->combine(@$row)) { |
925 |
if ($csv->combine(@$row)) { |
| 919 |
$content .= $csv->string() . "\n"; |
926 |
$content .= $csv->string() . "\n"; |
|
|
927 |
last if $max_rows && $n >= $max_rows; |
| 920 |
} else { |
928 |
} else { |
| 921 |
push @$q_errors, { combine => $csv->error_diag() } ; |
929 |
push @$q_errors, { combine => $csv->error_diag() } ; |
| 922 |
} |
930 |
} |
| 923 |
} |
931 |
} |
|
|
932 |
$sth->finish(); |
| 924 |
} |
933 |
} |
| 925 |
elsif ( $format eq 'ods' ) { |
934 |
elsif ( $format eq 'ods' ) { |
| 926 |
$type = 'application/vnd.oasis.opendocument.spreadsheet'; |
935 |
$type = 'application/vnd.oasis.opendocument.spreadsheet'; |
| 927 |
my $ods_fh = File::Temp->new( UNLINK => 0 ); |
936 |
my $ods_fh = File::Temp->new( UNLINK => 0 ); |
| 928 |
my $ods_filepath = $ods_fh->filename; |
937 |
my $ods_filepath = $ods_fh->filename; |
| 929 |
my $ods_content; |
938 |
my @ods_content; |
| 930 |
|
939 |
|
| 931 |
# First line is headers |
940 |
# First line is headers |
| 932 |
my @headers = header_cell_values($sth); |
941 |
my @headers = header_cell_values($sth); |
| 933 |
push @$ods_content, \@headers; |
942 |
push @ods_content, \@headers; |
| 934 |
|
943 |
|
| 935 |
# Other line in Unicode |
944 |
# Other line in Unicode |
| 936 |
my $sql_rows = $sth->fetchall_arrayref(); |
945 |
my $n = 0; |
| 937 |
foreach my $sql_row ( @$sql_rows ) { |
946 |
while (my $row = $sth->fetchrow_arrayref()) { |
| 938 |
my @content_row; |
947 |
$n++; |
| 939 |
foreach my $sql_cell ( @$sql_row ) { |
948 |
push @ods_content, [ map { Encode::encode( 'UTF8', $_ ) } @$row ]; |
| 940 |
push @content_row, Encode::encode( 'UTF8', $sql_cell ); |
949 |
last if $max_rows && $n >= $max_rows; |
| 941 |
} |
|
|
| 942 |
push @$ods_content, \@content_row; |
| 943 |
} |
950 |
} |
|
|
951 |
$sth->finish(); |
| 944 |
|
952 |
|
| 945 |
# Process |
953 |
# Process |
| 946 |
generate_ods($ods_filepath, $ods_content); |
954 |
generate_ods($ods_filepath, \@ods_content); |
| 947 |
|
955 |
|
| 948 |
# Output |
956 |
# Output |
| 949 |
binmode(STDOUT); |
957 |
binmode(STDOUT); |
| 950 |
- |
|
|