From 8e5d5b4d8b176b3c1d135e2dd43b3d63e428e208 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 --- .../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 b938724..f6d86f2 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt @@ -774,7 +774,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 2e85732..5e6f55a 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 @@ // @@ -130,8 +141,16 @@ $(document).ready(function() { + +
  • + + -
  • diff --git a/tools/export.pl b/tools/export.pl index bae6941..90fcaea 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 @@ -145,10 +149,21 @@ if ( C4::Context->preference("IndependentBranches") 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 = ''; @@ -162,7 +177,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); @@ -416,7 +431,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 $@; @@ -431,15 +446,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', @@ -513,6 +538,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.1.0