View | Details | Raw Unified | Return to bug 15451
Collapse All | Expand All

(-)a/C4/Csv.pm (-13 lines)
Lines 31-53 use vars qw(@ISA @EXPORT); Link Here
31
# only export API methods
31
# only export API methods
32
32
33
@EXPORT = qw(
33
@EXPORT = qw(
34
  &GetCsvProfile
35
  &GetMarcFieldsForCsv
34
  &GetMarcFieldsForCsv
36
);
35
);
37
36
38
37
39
# Returns all informations about a given csv profile
40
sub GetCsvProfile {
41
    my ($id) = @_;
42
    my $dbh = C4::Context->dbh;
43
    my $query = "SELECT * FROM export_format WHERE export_format_id=?";
44
45
    $sth = $dbh->prepare($query);
46
    $sth->execute($id);
47
48
    return ($sth->fetchrow_hashref);
49
}
50
51
# Returns fields to extract for the given csv profile
38
# Returns fields to extract for the given csv profile
52
sub GetMarcFieldsForCsv {
39
sub GetMarcFieldsForCsv {
53
40
(-)a/C4/Record.pm (-6 / +7 lines)
Lines 37-42 use Template; Link Here
37
use Text::CSV::Encoded; #marc2csv
37
use Text::CSV::Encoded; #marc2csv
38
use Koha::SimpleMARC qw(read_field);
38
use Koha::SimpleMARC qw(read_field);
39
use Koha::XSLT_Handler;
39
use Koha::XSLT_Handler;
40
use Koha::CsvProfiles;
40
use Carp;
41
use Carp;
41
42
42
use vars qw(@ISA @EXPORT);
43
use vars qw(@ISA @EXPORT);
Lines 475-488 sub marcrecord2csv { Link Here
475
    my $frameworkcode = GetFrameworkCode($biblio);
476
    my $frameworkcode = GetFrameworkCode($biblio);
476
477
477
    # Getting information about the csv profile
478
    # Getting information about the csv profile
478
    my $profile = GetCsvProfile($id);
479
    my $profile = Koha::CsvProfiles->find($id);
479
480
480
    # Getting output encoding
481
    # Getting output encoding
481
    my $encoding          = $profile->{encoding} || 'utf8';
482
    my $encoding          = $profile->encoding || 'utf8';
482
    # Getting separators
483
    # Getting separators
483
    my $csvseparator      = $profile->{csv_separator}      || ',';
484
    my $csvseparator      = $profile->csv_separator      || ',';
484
    my $fieldseparator    = $profile->{field_separator}    || '#';
485
    my $fieldseparator    = $profile->field_separator    || '#';
485
    my $subfieldseparator = $profile->{subfield_separator} || '|';
486
    my $subfieldseparator = $profile->subfield_separator || '|';
486
487
487
    # TODO: Be more generic (in case we have to handle other protected chars or more separators)
488
    # TODO: Be more generic (in case we have to handle other protected chars or more separators)
488
    if ($csvseparator eq '\t') { $csvseparator = "\t" }
489
    if ($csvseparator eq '\t') { $csvseparator = "\t" }
Lines 496-502 sub marcrecord2csv { Link Here
496
    $csv->sep_char($csvseparator);
497
    $csv->sep_char($csvseparator);
497
498
498
    # Getting the marcfields
499
    # Getting the marcfields
499
    my $marcfieldslist = $profile->{content};
500
    my $marcfieldslist = $profile->content;
500
501
501
    # Getting the marcfields as an array
502
    # Getting the marcfields as an array
502
    my @marcfieldsarray = split('\|', $marcfieldslist);
503
    my @marcfieldsarray = split('\|', $marcfieldslist);
(-)a/serials/lateissues-export.pl (-6 / +7 lines)
Lines 22-28 use C4::Serials; Link Here
22
use C4::Acquisition;
22
use C4::Acquisition;
23
use C4::Output;
23
use C4::Output;
24
use C4::Context;
24
use C4::Context;
25
use C4::Csv qw( GetCsvProfile );
25
use C4::Csv;
26
27
use Koha::CsvProfiles;
26
28
27
use Text::CSV_XS;
29
use Text::CSV_XS;
28
30
Lines 32-48 my @serialids = $query->multi_param('serialid'); Link Here
32
my $op = $query->param('op') || q{};
34
my $op = $query->param('op') || q{};
33
35
34
my $csv_profile_id = $query->param('csv_profile');
36
my $csv_profile_id = $query->param('csv_profile');
35
my $csv_profile = C4::Csv::GetCsvProfile( $csv_profile_id );
37
my $csv_profile = Koha::CsvProfiles->find( $csv_profile_id );
36
die "There is no valid csv profile given" unless $csv_profile;
38
die "There is no valid csv profile given" unless $csv_profile;
37
39
38
my $csv = Text::CSV_XS->new({
40
my $csv = Text::CSV_XS->new({
39
    'quote_char'  => '"',
41
    'quote_char'  => '"',
40
    'escape_char' => '"',
42
    'escape_char' => '"',
41
    'sep_char'    => $csv_profile->{csv_separator},
43
    'sep_char'    => $csv_profile->csv_separator,
42
    'binary'      => 1
44
    'binary'      => 1
43
});
45
});
44
46
45
my $content = $csv_profile->{content};
47
my $content = $csv_profile->content;
46
my ( @headers, @fields );
48
my ( @headers, @fields );
47
while ( $content =~ /
49
while ( $content =~ /
48
    ([^=]+) # header
50
    ([^=]+) # header
Lines 75-81 print $query->header( Link Here
75
    -attachment => "serials-claims.csv",
77
    -attachment => "serials-claims.csv",
76
);
78
);
77
79
78
print join( $csv_profile->{csv_separator}, @headers ) . "\n";
80
print join( $csv_profile->csv_separator, @headers ) . "\n";
79
81
80
for my $row ( @rows ) {
82
for my $row ( @rows ) {
81
    $csv->combine(@$row);
83
    $csv->combine(@$row);
82
- 

Return to bug 15451