From 9a2a4fc0465dfba595919527ceda2dc4be9065c3 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 | 2 +- .../intranet-tmpl/prog/en/modules/tools/export.tt | 21 +++++++++- tools/export.pl | 46 ++++++++++++++++------ 3 files changed, 55 insertions(+), 14 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 6805126..b1ba0d7 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt @@ -953,7 +953,7 @@ No patron matched [% message %] - + 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 0ac62d1..bfddacb 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 601e8d5..3b567d9 100755 --- a/tools/export.pl +++ b/tools/export.pl @@ -33,7 +33,6 @@ use C4::Record; my $query = new CGI; my $clean; -my $output_format; my $dont_export_items; my $deleted_barcodes; my $timestamp; @@ -44,11 +43,15 @@ my $op = $query->param("op") || ''; my $filename = $query->param("filename") || 'koha.mrc'; my $dbh = C4::Context->dbh; my $marcflavour = C4::Context->preference("marcflavour"); -my $format = $query->param("format") || 'iso2709'; +my $output_format = $query->param("output_format") || 'iso2709'; # 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 @@ -94,7 +97,7 @@ _USAGE_ } # Default parameters values : - $output_format ||= 'marc'; + $output_format ||= 'iso2709'; $timestamp ||= ''; $dont_export_items ||= 0; $deleted_barcodes ||= 0; @@ -142,10 +145,21 @@ if ( C4::Context->preference("IndependentBranches") my $backupdir = C4::Context->config('backupdir'); if ( $op eq "export" ) { - if ( $format eq "iso2709" or $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 = ''; @@ -159,12 +173,10 @@ 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); - $output_format = $query->param("output_format") || 'marc' - unless ($commandline); my $export_remove_fields = $query->param("export_remove_fields"); my @biblionumbers = $query->param("biblionumbers"); my @itemnumbers = $query->param("itemnumbers"); @@ -415,7 +427,7 @@ if ( $op eq "export" ) { print MARC::File::XML::record($record); print "\n"; } - else { + elsif ( $output_format eq 'iso2709' ) { my (@result_build_tag) = MARC::File::USMARC::_build_tag_directory($record); if ($result_build_tag[2] > 99999) { warn "record (number $recordid) length ".$result_build_tag[2]." is larger than the MARC spec allows (99999 bytes)"; @@ -429,15 +441,24 @@ 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 ( $format eq "csv" ) { - my @biblionumbers = uniq $query->param("biblionumbers"); + elsif ( $output_format eq "csv" ) { 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', @@ -511,6 +532,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.0.0.rc2