From fcef1ea273bbca6901bb65f6483951e7e71d3828 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 5 Feb 2014 16:44:24 +0100 Subject: [PATCH] Bug 12404: tools/export.pl allows CSV export Signed-off-by: Courret Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi --- .../prog/en/modules/circ/circulation.tt | 1 - .../intranet-tmpl/prog/en/modules/tools/export.tt | 21 ++++++++++++- tools/export.pl | 36 +++++++++++++++++++--- 3 files changed, 51 insertions(+), 7 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt index 49d910a0a7..acc8d93f7a 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt @@ -832,7 +832,6 @@ No patron matched [% message %] [% ELSE %] 0 Holds [% END %] -
  • [% debarments.size %] Restrictions
  • diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/export.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/export.tt index 36a25be257..bf7f8b6063 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/export.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/export.tt @@ -6,6 +6,17 @@ // @@ -123,8 +134,16 @@ $(document).ready(function() { + +
  • + + -
  • diff --git a/tools/export.pl b/tools/export.pl index 72b410cbee..f63e2c4f6f 100755 --- a/tools/export.pl +++ b/tools/export.pl @@ -48,6 +48,10 @@ my $output_format = $query->param("format") || $query->param("output_format") || # Checks if the script is called from commandline my $commandline = not defined $ENV{GATEWAY_INTERFACE}; + +# @biblionumbers is only use for csv export from circulation.pl +my @biblionumbers = uniq $query->param("biblionumbers"); + if ( $commandline ) { # Getting parameters @@ -149,10 +153,21 @@ my %branchmap = map { $_ => 1 } @branch; # for quick lookups my $backupdir = C4::Context->config('backupdir'); if ( $op eq "export" ) { - if ( $output_format eq "iso2709" or $output_format eq "xml" ) { + if ( + $output_format eq "iso2709" + or $output_format eq "xml" + or ( + $output_format eq 'csv' + and not @biblionumbers + ) + ) { my $charset = 'utf-8'; my $mimetype = 'application/octet-stream'; - binmode STDOUT, ':encoding(UTF-8)'; + + binmode STDOUT, ':encoding(UTF-8)' + if $filename =~ m/\.gz$/ + or $filename =~ m/\.bz2$/; + if ( $filename =~ m/\.gz$/ ) { $mimetype = 'application/x-gzip'; $charset = ''; @@ -166,7 +181,7 @@ if ( $op eq "export" ) { print $query->header( -type => $mimetype, -charset => $charset, - -attachment => $filename + -attachment => $filename, ) unless ($commandline); $record_type = $query->param("record_type") unless ($commandline); @@ -415,7 +430,7 @@ if ( $op eq "export" ) { print MARC::File::XML::record($record); print "\n"; } - else { + elsif ( $output_format eq 'iso2709' ) { my $errorcount_on_decode = eval { scalar(MARC::File::USMARC->decode( $record->as_usmarc )->warnings()) }; if ($errorcount_on_decode or $@){ warn $@ if $@; @@ -430,15 +445,25 @@ if ( $op eq "export" ) { print MARC::File::XML::footer(); print "\n"; } + if ( $output_format eq 'csv' ) { + my $csv_profile_id = $query->param('csv_profile') + || GetCsvProfileId( C4::Context->preference('ExportWithCsvProfile') ); + my $output = + marc2csv( \@recordids, + $csv_profile_id ); + + print $output; + } exit; } elsif ( $output_format eq "csv" ) { my @biblionumbers = uniq $query->param("biblionumbers"); my @itemnumbers = $query->param("itemnumbers"); + my $csv_profile_id = $query->param('csv_profile') || GetCsvProfileId( C4::Context->preference('ExportWithCsvProfile') ); my $output = marc2csv( \@biblionumbers, - GetCsvProfileId( C4::Context->preference('ExportWithCsvProfile') ), + $csv_profile_id, \@itemnumbers, ); print $query->header( -type => 'application/octet-stream', @@ -512,6 +537,7 @@ else { itemtypeloop => \@itemtypesloop, authtypeloop => \@authtypesloop, export_remove_fields => C4::Context->preference("ExportRemoveFields"), + csv_profiles => C4::Csv::GetCsvProfiles('marc'), ); output_html_with_http_headers $query, $cookie, $template->output; -- 2.11.4.GIT