Bug 12404: tools/export.pl allows CSV export

Signed-off-by: Courret <scourret@gmail.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
This commit is contained in:
Jonathan Druart 2014-02-05 16:44:24 +01:00 committed by Tomas Cohen Arazi
parent 4bb4b31159
commit fcef1ea273
3 changed files with 51 additions and 7 deletions

View File

@ -832,7 +832,6 @@ No patron matched <span class="ex">[% message %]</span>
[% ELSE %]
<a href="#reserves" id="holds-tab">0 Holds</a>
[% END %]
</li>
<li><a id="debarments-tab-link" href="#reldebarments">[% debarments.size %] Restrictions</a></li>
</ul>

View File

@ -6,6 +6,17 @@
//<![CDATA[
$(document).ready(function() {
$('#exporttype').tabs();
$("li.csv_profiles").hide();
$("#bibs select[name='output_format']").on('change', function(){
var format = $(this).val();
if ( format == 'csv' ) {
$("#bibs li.csv_profiles").show();
} else {
$("#bibs li.csv_profiles").hide();
}
});
});
//]]>
</script>
@ -123,8 +134,16 @@ $(document).ready(function() {
<select id="output_format" name="output_format">
<option value="iso2709">marc</option>
<option value="xml">xml</option>
<option value="csv">csv</option>
</select>
</li>
<li class="csv_profiles">
<label for="bibs_csv_profile">CSV profile: </label>
<select id="bibs_csv_profile" name="csv_profile">
[% FOR csv_profile IN csv_profiles %]
<option value="[% csv_profile.export_format_id %]">[% csv_profile.profile %]</option>
[% END %]
</select>
</li>
<li>
<label for="filename">File name:</label><input id="filename" type="text" name="filename" value="koha.mrc" />

View File

@ -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;