adding 'gettext' as this is requred by the translation utility
[koha.git] / labels / label-print-csv.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use CGI;
5 use C4::Labels;
6 use C4::Auth;
7 use C4::Output;
8 use C4::Context;
9 use C4::Biblio;
10 use Text::CSV_XS;
11
12 my $DEBUG = 0;
13 my $DEBUG_LPT = 0;
14
15 my $htdocs_path = C4::Context->config('intrahtdocs');
16 my $cgi         = new CGI;
17
18
19 # get the printing settings
20 my $template    = GetActiveLabelTemplate();
21 my $conf_data   = get_label_options();
22
23 my $batch_id =   $cgi->param('batch_id');
24 my $exportname = 'koha_label_' . $batch_id . '.csv';
25
26 print $cgi->header(-type => 'application/vnd.sun.xml.calc',
27                             -encoding    => 'utf-8',
28                             -attachment => $exportname,
29                             -filename => $exportname );
30
31 my $batch_type   = $conf_data->{'type'};
32 my $barcodetype  = $conf_data->{'barcodetype'};
33 my $printingtype = $conf_data->{'printingtype'};
34
35 my @resultsloop = GetLabelItems($batch_id);
36 my $csv = Text::CSV_XS->new();
37 my @str_fields = get_text_fields($conf_data->{'id'}, 'codes' );
38 for my $item (@resultsloop) {
39     my $record = GetMarcBiblio($item->{biblionumber});
40     my @datafields = ($conf_data->{'formatstring'})  ?
41                         map { C4::Labels::GetBarcodeData($_->{'code'},$item,$record) } @str_fields 
42                 : map { $_->{'code'} } @str_fields ;
43         my $csvout ;
44         if($csv->combine(@datafields)) {
45                 $csvout = $csv->string();
46                 print "$csvout\n";
47         } else {
48                 warn "CSV ERROR: " . $csv->error_input;
49         }
50
51 }    # end for item loop
52
53 exit(1);
54 # is that the right way to do this ?
55
56
57