Lines 21-32
use Scalar::Util qw(looks_like_number);
Link Here
|
21 |
use List::Util qw( first ); |
21 |
use List::Util qw( first ); |
22 |
use C4::Koha; |
22 |
use C4::Koha; |
23 |
use C4::Output; |
23 |
use C4::Output; |
|
|
24 |
use C4::Context; |
24 |
use C4::Auth; |
25 |
use C4::Auth; |
|
|
26 |
use Text::CSV::Encoded; |
27 |
use C4::Reports::Guided; |
25 |
|
28 |
|
26 |
use Koha::SearchEngine::Elasticsearch; |
29 |
use Koha::SearchEngine::Elasticsearch; |
27 |
use Koha::SearchEngine::Elasticsearch::Indexer; |
30 |
use Koha::SearchEngine::Elasticsearch::Indexer; |
28 |
use Koha::SearchMarcMaps; |
31 |
use Koha::SearchMarcMaps; |
29 |
use Koha::SearchFields; |
32 |
use Koha::SearchFields; |
|
|
33 |
use Koha::Util::OpenDocument; |
30 |
|
34 |
|
31 |
use Try::Tiny; |
35 |
use Try::Tiny; |
32 |
|
36 |
|
Lines 151-156
elsif( $op eq 'reset_confirmed' ) {
Link Here
|
151 |
elsif( $op eq 'reset_confirm' ) { |
155 |
elsif( $op eq 'reset_confirm' ) { |
152 |
$template->param( reset_confirm => 1 ); |
156 |
$template->param( reset_confirm => 1 ); |
153 |
} |
157 |
} |
|
|
158 |
elsif ($op eq 'download'){ |
159 |
my $format = $input->param("format"); |
160 |
my $table = $input->param("table"); |
161 |
my ($type,$reportfilename, $csv, $ods_fh, $ods_filepath); |
162 |
|
163 |
if ($format eq "tab"){ |
164 |
$type = 'application/octet-stream'; |
165 |
|
166 |
} elsif ($format eq "csv"){ |
167 |
$type = 'application/csv'; |
168 |
my $delimiter = C4::Context->preference('delimiter') || ','; |
169 |
$delimiter = "\t" if ($delimiter eq 'tabulation'); |
170 |
$csv = Text::CSV::Encoded->new({ encoding_out => 'UTF-8', sep_char => $delimiter}); |
171 |
$csv or die "Text::CSV::Encoded->new({binary => 1}) FAILED: " . Text::CSV::Encoded->error_diag(); |
172 |
|
173 |
} elsif ($format eq "ods"){ |
174 |
$type = 'application/vnd.oasis.opendocument.spreadsheet'; |
175 |
$ods_fh = File::Temp->new( UNLINK => 0 ); |
176 |
$ods_filepath = $ods_fh->filename; |
177 |
} |
178 |
|
179 |
#search_fields var |
180 |
my (@search_field_names, @search_fileds_labels, @search_fileds_types, @search_field_weights); |
181 |
#facet_var |
182 |
my (@display_facet, @label_facet); |
183 |
#biblios and authorities var |
184 |
my (@sort, @facet, @suggestible, @marc_field); |
185 |
|
186 |
my @header_row; |
187 |
if ($table eq "search_fields"){ |
188 |
$reportfilename = "search_fields_table"; |
189 |
@search_field_names = $input->multi_param("search_field_name"); |
190 |
@search_fileds_labels = $input->multi_param("search_field_label"); |
191 |
@search_fileds_types = $input->multi_param("search_field_type"); |
192 |
@search_field_weights = $input->multi_param("search_field_weight"); |
193 |
@header_row = ("Name\t\t\t","Label\t\t\t","Type","Weight"); |
194 |
|
195 |
} elsif ($table eq "facet"){ |
196 |
$reportfilename = "facet_order_table"; |
197 |
@search_field_names = $input->multi_param("search_fields_facet"); |
198 |
@label_facet = $input->multi_param("label_facet"); |
199 |
@display_facet = $input->multi_param("display"); |
200 |
@header_row = ("Search field","Label\t\t","Display"); |
201 |
|
202 |
} else { |
203 |
$reportfilename = $table . "_table"; |
204 |
@search_field_names = $input->multi_param("search_field_names_". $table); |
205 |
@sort = $input->multi_param("sort_". $table); |
206 |
@facet = $input->multi_param("facet_". $table); |
207 |
@suggestible = $input->multi_param("suggestible_". $table); |
208 |
@marc_field = $input->multi_param("marc_field_". $table); |
209 |
@header_row = ("Search field\t","Sortable","Facetable","Suggestible","Mapping"); |
210 |
} |
211 |
|
212 |
my $i = 0; |
213 |
my ($content, $ods_content); |
214 |
|
215 |
if ($format eq 'tab') { |
216 |
$reportfilename .= ".tab"; |
217 |
$content .= join("\t\t", @header_row) . "\n"; |
218 |
$content = Encode::decode('UTF-8', $content); |
219 |
|
220 |
foreach my $search_field_name (@search_field_names){ |
221 |
my @row; |
222 |
if ($table eq "search_fields"){ |
223 |
$search_field_name .= ' ' while (length($search_field_name)< 25); |
224 |
$search_fileds_labels[$i] .= ' ' while (length($search_fileds_labels[$i])< 25); |
225 |
@row = ($search_field_name, $search_fileds_labels[$i], $search_fileds_types[$i], $search_field_weights[$i]); |
226 |
} elsif ($table eq "facet"){ |
227 |
$search_field_name .= ' ' while (length($search_field_name)< 15); |
228 |
$label_facet[$i] .= ' ' while (length($label_facet[$i])< 20); |
229 |
@row = ($search_field_name, $label_facet[$i], $display_facet[$i]); |
230 |
} else { |
231 |
$search_field_name .= ' ' while (length($search_field_name)< 20); |
232 |
$sort[$i] .= ' ' while (length($sort[$i])< 15); |
233 |
$facet[$i] .= ' ' while (length($facet[$i])< 15); |
234 |
$suggestible[$i] .= ' ' while (length($suggestible[$i])< 15); |
235 |
@row = ($search_field_name,$sort[$i],$facet[$i],$suggestible[$i],$marc_field[$i]); |
236 |
} |
237 |
$content .= join("\t\t", @row) . "\n"; |
238 |
$i++; |
239 |
} |
240 |
} elsif( $format eq 'csv' ) { |
241 |
$reportfilename .= ".csv"; |
242 |
if ($csv->combine(@header_row)) { |
243 |
$content .= Encode::decode('UTF-8', $csv->string()) . "\n"; |
244 |
foreach my $search_field_name (@search_field_names){ |
245 |
my @row; |
246 |
if ($table eq "search_fields"){ |
247 |
@row = ($search_field_name,$search_fileds_labels[$i],$search_fileds_types[$i],$search_field_weights[$i]); |
248 |
} elsif ($table eq "facet"){ |
249 |
@row = ($search_field_name, $label_facet[$i], $display_facet[$i]); |
250 |
} else { |
251 |
@row = ($search_field_name,$sort[$i],$facet[$i],$suggestible[$i],$marc_field[$i]); |
252 |
} |
253 |
if ($csv->combine(@row)) { |
254 |
$content .= $csv->string() . "\n"; |
255 |
} |
256 |
$i++; |
257 |
} |
258 |
} |
259 |
} elsif ( $format eq 'ods' ) { |
260 |
$reportfilename .= ".ods"; |
261 |
my @headers = @header_row; |
262 |
push @$ods_content, \@headers; |
263 |
|
264 |
foreach my $search_field_name (@search_field_names){ |
265 |
my @content_row; |
266 |
if ($table eq "search_fields"){ |
267 |
push @content_row, Encode::encode( 'UTF8', $search_field_name ), Encode::encode( 'UTF8', $search_fileds_labels[$i] ) , $search_fileds_types[$i],$search_field_weights[$i]; |
268 |
} elsif ($table eq "facet"){ |
269 |
push @content_row, Encode::encode( 'UTF8', $search_field_name ), Encode::encode( 'UTF8', $label_facet[$i] ) , $display_facet[$i]; |
270 |
} else { |
271 |
push @content_row, Encode::encode( 'UTF8', $search_field_name ), $sort[$i] , $facet[$i], $suggestible[$i], Encode::encode( 'UTF8', $marc_field[$i] ); |
272 |
} |
273 |
push @$ods_content, \@content_row; |
274 |
$i++; |
275 |
} |
276 |
generate_ods($ods_filepath, $ods_content); |
277 |
binmode(STDOUT); |
278 |
open $ods_fh, '<', $ods_filepath; |
279 |
$content .= $_ while <$ods_fh>; |
280 |
unlink $ods_filepath; |
281 |
} |
282 |
|
283 |
print $input->header( |
284 |
-type => $type, |
285 |
-attachment=> $reportfilename |
286 |
); |
287 |
print $content; |
288 |
exit; |
289 |
} |
154 |
|
290 |
|
155 |
|
291 |
|
156 |
my @indexes; |
292 |
my @indexes; |
Lines 215-225
while ( my $search_field = $search_fields->next ) {
Link Here
|
215 |
push @all_search_fields, $search_field_unblessed; |
351 |
push @all_search_fields, $search_field_unblessed; |
216 |
} |
352 |
} |
217 |
|
353 |
|
|
|
354 |
my @extensions = ("csv","tab","ods"); |
355 |
my @formats_and_extensions =("Semicolon separated test (.csv)","Tab separated text (.tab)","Open Document Spreadsheet (.ods)"); |
356 |
my @formats; |
357 |
my $j = 0; |
358 |
foreach my $extension (@extensions){ |
359 |
push (@formats , { extension => $extension, format_and_extension =>$formats_and_extensions[$j] }); |
360 |
$j++; |
361 |
} |
362 |
|
218 |
$template->param( |
363 |
$template->param( |
219 |
indexes => \@indexes, |
364 |
indexes => \@indexes, |
220 |
all_search_fields => \@all_search_fields, |
365 |
all_search_fields => \@all_search_fields, |
221 |
facetable_fields => \@facetable_fields, |
366 |
facetable_fields => \@facetable_fields, |
222 |
messages => \@messages, |
367 |
messages => \@messages, |
|
|
368 |
formats => \@formats, |
223 |
); |
369 |
); |
224 |
|
370 |
|
225 |
output_html_with_http_headers $input, $cookie, $template->output; |
371 |
output_html_with_http_headers $input, $cookie, $template->output; |