From e2bc35e7888d3076e8d51301baebcc1d1e9205a2 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 | 46 ++++++++++++++++------ 3 files changed, 54 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 94ef257..edb781f 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt @@ -760,7 +760,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 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 658aef7..3664321b 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") || $query->param("output_format") || 'iso2709'; +my $output_format = $query->param("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.1.0