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, $content, $reportfilename, $csv, $ods_fh, $ods_filepath, $ods_content); |
162 |
my $i = 0; |
163 |
|
164 |
if ($format eq "tab"){ |
165 |
$type = 'application/octet-stream'; |
166 |
|
167 |
} elsif ($format eq "csv"){ |
168 |
$type = 'application/csv'; |
169 |
my $delimiter = C4::Context->preference('delimiter') || ','; |
170 |
$delimiter = "\t" if ($delimiter eq 'tabulation'); |
171 |
$csv = Text::CSV::Encoded->new({ encoding_out => 'UTF-8', sep_char => $delimiter}); |
172 |
$csv or die "Text::CSV::Encoded->new({binary => 1}) FAILED: " . Text::CSV::Encoded->error_diag(); |
173 |
|
174 |
} elsif ($format eq "ods"){ |
175 |
$type = 'application/vnd.oasis.opendocument.spreadsheet'; |
176 |
$ods_fh = File::Temp->new( UNLINK => 0 ); |
177 |
$ods_filepath = $ods_fh->filename; |
178 |
} |
179 |
|
180 |
if ($table eq "search_fields"){ |
181 |
$reportfilename = "search_fields_table"; |
182 |
my @search_field_names = $input->multi_param("search_field_name"); |
183 |
my @search_fileds_labels = $input->multi_param("search_field_label"); |
184 |
my @search_fileds_types = $input->multi_param("search_field_type"); |
185 |
my @search_field_weights = $input->multi_param("search_field_weight"); |
186 |
|
187 |
if ($format eq 'tab') { |
188 |
my @header_row = ("Name\t\t\t","Label\t\t\t","Type","Weight"); |
189 |
$content .= join("\t\t", @header_row) . "\n"; |
190 |
$content = Encode::decode('UTF-8', $content); |
191 |
|
192 |
foreach my $search_field_name (@search_field_names){ |
193 |
my @row; |
194 |
$search_field_name .= ' ' while (length($search_field_name)< 25); |
195 |
$search_fileds_labels[$i] .= ' ' while (length($search_fileds_labels[$i])< 25); |
196 |
@row = ($search_field_name, $search_fileds_labels[$i], $search_fileds_types[$i], $search_field_weights[$i]); |
197 |
$content .= join("\t\t", @row) . "\n"; |
198 |
$i++; |
199 |
} |
200 |
} else { |
201 |
my @header_row = ("Name","Label","Type","Weight"); |
202 |
|
203 |
if ( $format eq 'csv' ) { |
204 |
if ($csv->combine(@header_row)) { |
205 |
$content .= Encode::decode('UTF-8', $csv->string()) . "\n"; |
206 |
foreach my $search_field_name (@search_field_names){ |
207 |
my @row; |
208 |
@row = ($search_field_name,$search_fileds_labels[$i],$search_fileds_types[$i],$search_field_weights[$i]); |
209 |
if ($csv->combine(@row)) { |
210 |
$content .= $csv->string() . "\n"; |
211 |
} |
212 |
$i++; |
213 |
} |
214 |
} |
215 |
} elsif ( $format eq 'ods' ) { |
216 |
my @headers = @header_row; |
217 |
push @$ods_content, \@headers; |
218 |
|
219 |
foreach my $search_field_name (@search_field_names){ |
220 |
my @content_row; |
221 |
push @content_row, Encode::encode( 'UTF8', $search_field_name ), Encode::encode( 'UTF8', $search_fileds_labels[$i] ) , $search_fileds_types[$i],$search_field_weights[$i]; |
222 |
push @$ods_content, \@content_row; |
223 |
$i++; |
224 |
} |
225 |
generate_ods($ods_filepath, $ods_content); |
226 |
binmode(STDOUT); |
227 |
open $ods_fh, '<', $ods_filepath; |
228 |
$content .= $_ while <$ods_fh>; |
229 |
unlink $ods_filepath; |
230 |
} |
231 |
} |
232 |
} else { |
233 |
my (@search_field_names, @sort, @facet, @suggestible, @marc_field); |
234 |
if ($table eq "biblios"){ |
235 |
$reportfilename = "biblios_table"; |
236 |
@search_field_names = $input->multi_param("search_field_names_biblios"); |
237 |
@sort = $input->multi_param("sort_biblios"); |
238 |
@facet = $input->multi_param("facet_biblios"); |
239 |
@suggestible = $input->multi_param("suggestible_biblios"); |
240 |
@marc_field = $input->multi_param("marc_field_biblios"); |
241 |
|
242 |
} elsif ($table eq "authorities"){ |
243 |
$reportfilename = "authorities_table"; |
244 |
@search_field_names = $input->multi_param("search_field_names_authorities"); |
245 |
@sort = $input->multi_param("sort_authorities"); |
246 |
@facet = $input->multi_param("facet_authorities"); |
247 |
@suggestible = $input->multi_param("suggestible_authorities"); |
248 |
@marc_field = $input->multi_param("marc_field_authorities"); |
249 |
} |
250 |
if ($format eq "tab"){ |
251 |
my @header_row = ("Search field\t\t","Sortable","Facetable","Suggestible","Mapping"); |
252 |
$content .= join("\t", @header_row) . "\n"; |
253 |
$content = Encode::decode('UTF-8', $content); |
254 |
|
255 |
foreach my $search_field_name (@search_field_names){ |
256 |
my @row; |
257 |
$search_field_name .= ' ' while (length($search_field_name)< 20); |
258 |
@row = ($search_field_name,$sort[$i],$facet[$i],$suggestible[$i],$marc_field[$i]); |
259 |
$content .= join("\t\t", @row) . "\n"; |
260 |
$i++; |
261 |
} |
262 |
} else { |
263 |
my @header_row = ("Search field","Sortable","Facetable","Suggestible","Mapping "); |
264 |
if ( $format eq 'csv' ) { |
265 |
if ($csv->combine(@header_row)) { |
266 |
$content .= Encode::decode('UTF-8', $csv->string()) . "\n"; |
267 |
foreach my $search_field_name (@search_field_names){ |
268 |
my @row; |
269 |
@row = ($search_field_name,$sort[$i],$facet[$i],$suggestible[$i],$marc_field[$i]); |
270 |
if ($csv->combine(@row)) { |
271 |
$content .= $csv->string() . "\n"; |
272 |
} |
273 |
$i++; |
274 |
} |
275 |
} |
276 |
} elsif ( $format eq 'ods' ) { |
277 |
my @headers = @header_row; |
278 |
push @$ods_content, \@headers; |
279 |
|
280 |
foreach my $search_field_name (@search_field_names){ |
281 |
my @content_row; |
282 |
push @content_row, Encode::encode( 'UTF8', $search_field_name ), $sort[$i] , $facet[$i], $suggestible[$i], Encode::encode( 'UTF8', $marc_field[$i] ); |
283 |
push @$ods_content, \@content_row; |
284 |
$i++; |
285 |
} |
286 |
generate_ods($ods_filepath, $ods_content); |
287 |
binmode(STDOUT); |
288 |
open $ods_fh, '<', $ods_filepath; |
289 |
$content .= $_ while <$ods_fh>; |
290 |
unlink $ods_filepath; |
291 |
} |
292 |
} |
293 |
} |
294 |
|
295 |
if ($format eq "tab"){ |
296 |
$reportfilename .= ".tab"; |
297 |
} elsif ($format eq "csv"){ |
298 |
$reportfilename .= ".csv"; |
299 |
} elsif ($format eq "ods"){ |
300 |
$reportfilename .= ".ods"; |
301 |
} |
302 |
|
303 |
print $input->header( |
304 |
-type => $type, |
305 |
-attachment=> $reportfilename |
306 |
); |
307 |
print $content; |
308 |
exit; |
309 |
} |
154 |
|
310 |
|
155 |
|
311 |
|
156 |
my @indexes; |
312 |
my @indexes; |
Lines 215-225
while ( my $search_field = $search_fields->next ) {
Link Here
|
215 |
push @all_search_fields, $search_field_unblessed; |
371 |
push @all_search_fields, $search_field_unblessed; |
216 |
} |
372 |
} |
217 |
|
373 |
|
|
|
374 |
my @extensions = ("csv","tab","ods"); |
375 |
my @formats_and_extensions =("Semicolon separated test (.csv)","Tab separated text (.tab)","Open Document Spreadsheet (.ods)"); |
376 |
my @formats; |
377 |
my $j = 0; |
378 |
foreach my $extension (@extensions){ |
379 |
push (@formats , { extension => $extension, format_and_extension =>$formats_and_extensions[$j] }); |
380 |
$j++; |
381 |
} |
382 |
|
218 |
$template->param( |
383 |
$template->param( |
219 |
indexes => \@indexes, |
384 |
indexes => \@indexes, |
220 |
all_search_fields => \@all_search_fields, |
385 |
all_search_fields => \@all_search_fields, |
221 |
facetable_fields => \@facetable_fields, |
386 |
facetable_fields => \@facetable_fields, |
222 |
messages => \@messages, |
387 |
messages => \@messages, |
|
|
388 |
formats => \@formats, |
223 |
); |
389 |
); |
224 |
|
390 |
|
225 |
output_html_with_http_headers $input, $cookie, $template->output; |
391 |
output_html_with_http_headers $input, $cookie, $template->output; |