|
Lines 34-39
use C4::Biblio;
Link Here
|
| 34 |
use C4::Items; |
34 |
use C4::Items; |
| 35 |
|
35 |
|
| 36 |
use Koha::AuthorisedValues; |
36 |
use Koha::AuthorisedValues; |
|
|
37 |
use Koha::CsvProfiles; |
| 37 |
use Koha::DateUtils; |
38 |
use Koha::DateUtils; |
| 38 |
|
39 |
|
| 39 |
my $query = new CGI; |
40 |
my $query = new CGI; |
|
Lines 50-57
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
Link Here
|
| 50 |
|
51 |
|
| 51 |
my $params = $query->Vars; |
52 |
my $params = $query->Vars; |
| 52 |
my $get_items = $params->{'get_items'}; |
53 |
my $get_items = $params->{'get_items'}; |
| 53 |
|
54 |
my $op = $query->param('op') || ''; |
| 54 |
if ($get_items) { |
55 |
|
|
|
56 |
if ( $op eq 'export' ) { |
| 57 |
my @itemnumbers = $query->multi_param('itemnumber'); |
| 58 |
my $csv_profile_id = $query->param('csv_profile_id'); |
| 59 |
my @rows; |
| 60 |
if ($csv_profile_id) { |
| 61 |
# FIXME This following code has the same logic as GetBasketAsCSV |
| 62 |
# We should refactor all the CSV export code |
| 63 |
# Note: For MARC it is already done in Koha::Exporter::Record but not for SQL CSV profiles type |
| 64 |
my $csv_profile = Koha::CsvProfiles->find( $csv_profile_id ); |
| 65 |
die "There is no valid csv profile given" unless $csv_profile; |
| 66 |
|
| 67 |
my $csv = Text::CSV_XS->new({'quote_char'=>'"','escape_char'=>'"','sep_char'=>$csv_profile->csv_separator,'binary'=>1}); |
| 68 |
my $csv_profile_content = $csv_profile->content; |
| 69 |
my ( @headers, @fields ); |
| 70 |
while ( $csv_profile_content =~ / |
| 71 |
([^=\|]+) # header |
| 72 |
=? |
| 73 |
([^\|]*) # fieldname (table.row or row) |
| 74 |
\|? /gxms |
| 75 |
) { |
| 76 |
my $header = $1; |
| 77 |
my $field = ($2 eq '') ? $1 : $2; |
| 78 |
|
| 79 |
$header =~ s/^\s+|\s+$//g; # Trim whitespaces |
| 80 |
push @headers, $header; |
| 81 |
|
| 82 |
$field =~ s/[^\.]*\.{1}//; # Remove the table name if exists. |
| 83 |
$field =~ s/^\s+|\s+$//g; # Trim whitespaces |
| 84 |
push @fields, $field; |
| 85 |
} |
| 86 |
my $items = Koha::Items->search({ itemnumber => { -in => \@itemnumbers } }); |
| 87 |
while ( my $item = $items->next ) { |
| 88 |
my @row; |
| 89 |
my $all_fields = $item->unblessed; |
| 90 |
$all_fields = { %$all_fields, %{$item->biblio->unblessed}, %{$item->biblioitem->unblessed} }; |
| 91 |
for my $field (@fields) { |
| 92 |
push @row, $all_fields->{$field}; |
| 93 |
} |
| 94 |
push @rows, \@row; |
| 95 |
} |
| 96 |
my $content = join( $csv_profile->csv_separator, @headers ) . "\n"; |
| 97 |
for my $row ( @rows ) { |
| 98 |
$csv->combine(@$row); |
| 99 |
my $string = $csv->string; |
| 100 |
$content .= $string . "\n"; |
| 101 |
} |
| 102 |
print $query->header( |
| 103 |
-type => 'text/csv', |
| 104 |
-attachment => 'lost_items.csv', |
| 105 |
); |
| 106 |
print $content; |
| 107 |
exit; |
| 108 |
} |
| 109 |
} elsif ( $get_items ) { |
| 55 |
my $branchfilter = $params->{'branchfilter'} || undef; |
110 |
my $branchfilter = $params->{'branchfilter'} || undef; |
| 56 |
my $barcodefilter = $params->{'barcodefilter'} || undef; |
111 |
my $barcodefilter = $params->{'barcodefilter'} || undef; |
| 57 |
my $itemtypesfilter = $params->{'itemtypesfilter'} || undef; |
112 |
my $itemtypesfilter = $params->{'itemtypesfilter'} || undef; |
|
Lines 96-103
if ($get_items) {
Link Here
|
| 96 |
# getting all itemtypes |
151 |
# getting all itemtypes |
| 97 |
my $itemtypes = Koha::ItemTypes->search_with_localization; |
152 |
my $itemtypes = Koha::ItemTypes->search_with_localization; |
| 98 |
|
153 |
|
|
|
154 |
my $csv_profiles = Koha::CsvProfiles->search({ type => 'sql', used_for => 'export_lost_items' }); |
| 155 |
|
| 99 |
$template->param( |
156 |
$template->param( |
| 100 |
itemtypes => $itemtypes, |
157 |
itemtypes => $itemtypes, |
|
|
158 |
csv_profiles => $csv_profiles, |
| 101 |
); |
159 |
); |
| 102 |
|
160 |
|
| 103 |
# writing the template |
161 |
# writing the template |
| 104 |
- |
|
|