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

(-)a/C4/Csv.pm (-13 lines)
Lines 33-55 $VERSION = 3.07.00.049; Link Here
33
# only export API methods
33
# only export API methods
34
34
35
@EXPORT = qw(
35
@EXPORT = qw(
36
  &GetCsvProfile
37
  &GetMarcFieldsForCsv
36
  &GetMarcFieldsForCsv
38
);
37
);
39
38
40
39
41
# Returns all informations about a given csv profile
42
sub GetCsvProfile {
43
    my ($id) = @_;
44
    my $dbh = C4::Context->dbh;
45
    my $query = "SELECT * FROM export_format WHERE export_format_id=?";
46
47
    $sth = $dbh->prepare($query);
48
    $sth->execute($id);
49
50
    return ($sth->fetchrow_hashref);
51
}
52
53
# Returns fields to extract for the given csv profile
40
# Returns fields to extract for the given csv profile
54
sub GetMarcFieldsForCsv {
41
sub GetMarcFieldsForCsv {
55
42
(-)a/C4/Record.pm (-6 / +7 lines)
Lines 36-41 use YAML; #marcrecords2csv Link Here
36
use Template;
36
use Template;
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::CsvProfiles;
39
40
40
use vars qw($VERSION @ISA @EXPORT);
41
use vars qw($VERSION @ISA @EXPORT);
41
42
Lines 434-447 sub marcrecord2csv { Link Here
434
    my $frameworkcode = GetFrameworkCode($biblio);
435
    my $frameworkcode = GetFrameworkCode($biblio);
435
436
436
    # Getting information about the csv profile
437
    # Getting information about the csv profile
437
    my $profile = GetCsvProfile($id);
438
    my $profile = Koha::CsvProfiles->find($id);
438
439
439
    # Getting output encoding
440
    # Getting output encoding
440
    my $encoding          = $profile->{encoding} || 'utf8';
441
    my $encoding          = $profile->encoding || 'utf8';
441
    # Getting separators
442
    # Getting separators
442
    my $csvseparator      = $profile->{csv_separator}      || ',';
443
    my $csvseparator      = $profile->csv_separator      || ',';
443
    my $fieldseparator    = $profile->{field_separator}    || '#';
444
    my $fieldseparator    = $profile->field_separator    || '#';
444
    my $subfieldseparator = $profile->{subfield_separator} || '|';
445
    my $subfieldseparator = $profile->subfield_separator || '|';
445
446
446
    # TODO: Be more generic (in case we have to handle other protected chars or more separators)
447
    # TODO: Be more generic (in case we have to handle other protected chars or more separators)
447
    if ($csvseparator eq '\t') { $csvseparator = "\t" }
448
    if ($csvseparator eq '\t') { $csvseparator = "\t" }
Lines 455-461 sub marcrecord2csv { Link Here
455
    $csv->sep_char($csvseparator);
456
    $csv->sep_char($csvseparator);
456
457
457
    # Getting the marcfields
458
    # Getting the marcfields
458
    my $marcfieldslist = $profile->{content};
459
    my $marcfieldslist = $profile->content;
459
460
460
    # Getting the marcfields as an array
461
    # Getting the marcfields as an array
461
    my @marcfieldsarray = split('\|', $marcfieldslist);
462
    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->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