|
Lines 36-45
my $cgi = new CGI;
Link Here
|
| 36 |
my %params = $cgi->Vars; |
36 |
my %params = $cgi->Vars; |
| 37 |
|
37 |
|
| 38 |
my $format = $cgi->param('format'); |
38 |
my $format = $cgi->param('format'); |
| 39 |
my ($template_name, $content_type); |
39 |
my $template_name = 'catalogue/itemsearch.tt'; |
|
|
40 |
|
| 40 |
if (defined $format and $format eq 'json') { |
41 |
if (defined $format and $format eq 'json') { |
| 41 |
$template_name = 'catalogue/itemsearch_json.tt'; |
42 |
$template_name = 'catalogue/itemsearch_json.tt'; |
| 42 |
$content_type = 'json'; |
|
|
| 43 |
|
43 |
|
| 44 |
# Map DataTables parameters with 'regular' parameters |
44 |
# Map DataTables parameters with 'regular' parameters |
| 45 |
$cgi->param('rows', scalar $cgi->param('iDisplayLength')); |
45 |
$cgi->param('rows', scalar $cgi->param('iDisplayLength')); |
|
Lines 75-84
if (defined $format and $format eq 'json') {
Link Here
|
| 75 |
|
75 |
|
| 76 |
# Retrieve all results |
76 |
# Retrieve all results |
| 77 |
$cgi->param('rows', 0); |
77 |
$cgi->param('rows', 0); |
| 78 |
} else { |
78 |
} elsif (defined $format) { |
| 79 |
$format = 'html'; |
79 |
die "Unsupported format $format"; |
| 80 |
$template_name = 'catalogue/itemsearch.tt'; |
|
|
| 81 |
$content_type = 'html'; |
| 82 |
} |
80 |
} |
| 83 |
|
81 |
|
| 84 |
my ($template, $borrowernumber, $cookie) = get_template_and_user({ |
82 |
my ($template, $borrowernumber, $cookie) = get_template_and_user({ |
|
Lines 226-318
if (scalar keys %params > 0) {
Link Here
|
| 226 |
search_params => $search_params, |
224 |
search_params => $search_params, |
| 227 |
results => $results, |
225 |
results => $results, |
| 228 |
total_rows => $total_rows, |
226 |
total_rows => $total_rows, |
| 229 |
search_done => 1, |
|
|
| 230 |
); |
227 |
); |
| 231 |
|
228 |
|
| 232 |
if ($format eq 'html') { |
229 |
if ($format eq 'csv') { |
| 233 |
# Build pagination bar |
230 |
print $cgi->header({ |
| 234 |
my $url = '/cgi-bin/koha/catalogue/itemsearch.pl'; |
231 |
type => 'text/csv', |
| 235 |
my @params; |
232 |
attachment => 'items.csv', |
| 236 |
foreach my $p (keys %params) { |
233 |
}); |
| 237 |
my @v = $cgi->multi_param($p); |
|
|
| 238 |
push @params, map { "$p=" . $_ } @v; |
| 239 |
} |
| 240 |
$url .= '?' . join ('&', @params); |
| 241 |
my $nb_pages = 1 + int($total_rows / $search_params->{rows}); |
| 242 |
my $current_page = $search_params->{page}; |
| 243 |
my $pagination_bar = pagination_bar($url, $nb_pages, $current_page, 'page'); |
| 244 |
|
234 |
|
| 245 |
$template->param(pagination_bar => $pagination_bar); |
235 |
for my $line ( split '\n', $template->output ) { |
|
|
236 |
print "$line\n" unless $line =~ m|^\s*$|; |
| 237 |
} |
| 238 |
} elsif ($format eq 'json') { |
| 239 |
output_with_http_headers $cgi, $cookie, $template->output, 'json'; |
| 246 |
} |
240 |
} |
| 247 |
} |
|
|
| 248 |
|
241 |
|
| 249 |
if ($format eq 'html') { |
242 |
exit; |
| 250 |
# Retrieve data required for the form. |
243 |
} |
| 251 |
|
|
|
| 252 |
my @branches = map { value => $_->branchcode, label => $_->branchname }, Koha::Libraries->search( {}, { order_by => 'branchname' } ); |
| 253 |
my @locations; |
| 254 |
foreach my $location (@$location_values) { |
| 255 |
push @locations, { |
| 256 |
value => $location->{authorised_value}, |
| 257 |
label => $location->{lib} // $location->{authorised_value}, |
| 258 |
}; |
| 259 |
} |
| 260 |
my @itemtypes; |
| 261 |
foreach my $itemtype ( Koha::ItemTypes->search ) { |
| 262 |
push @itemtypes, { |
| 263 |
value => $itemtype->itemtype, |
| 264 |
label => $itemtype->translated_description, |
| 265 |
}; |
| 266 |
} |
| 267 |
|
244 |
|
| 268 |
my $mss = Koha::MarcSubfieldStructures->search({ frameworkcode => '', kohafield => 'items.ccode', authorised_value => { not => undef } }); |
245 |
# Display the search form |
| 269 |
my $ccode_avcode = $mss->count ? $mss->next->authorised_value : 'CCODE'; |
|
|
| 270 |
my $ccodes = GetAuthorisedValues($ccode_avcode); |
| 271 |
my @ccodes; |
| 272 |
foreach my $ccode (@$ccodes) { |
| 273 |
push @ccodes, { |
| 274 |
value => $ccode->{authorised_value}, |
| 275 |
label => $ccode->{lib}, |
| 276 |
}; |
| 277 |
} |
| 278 |
|
246 |
|
| 279 |
my @notforloans; |
247 |
my @branches = map { value => $_->branchcode, label => $_->branchname }, Koha::Libraries->search( {}, { order_by => 'branchname' } ); |
| 280 |
foreach my $value (@$notforloan_values) { |
248 |
my @locations; |
| 281 |
push @notforloans, { |
249 |
foreach my $location (@$location_values) { |
| 282 |
value => $value->{authorised_value}, |
250 |
push @locations, { |
| 283 |
label => $value->{lib}, |
251 |
value => $location->{authorised_value}, |
| 284 |
}; |
252 |
label => $location->{lib} // $location->{authorised_value}, |
| 285 |
} |
253 |
}; |
| 286 |
|
254 |
} |
| 287 |
my @items_search_fields = GetItemSearchFields(); |
255 |
my @itemtypes; |
|
|
256 |
foreach my $itemtype ( Koha::ItemTypes->search ) { |
| 257 |
push @itemtypes, { |
| 258 |
value => $itemtype->itemtype, |
| 259 |
label => $itemtype->translated_description, |
| 260 |
}; |
| 261 |
} |
| 288 |
|
262 |
|
| 289 |
my $authorised_values = {}; |
263 |
$mss = Koha::MarcSubfieldStructures->search({ frameworkcode => '', kohafield => 'items.ccode', authorised_value => { not => undef } }); |
| 290 |
foreach my $field (@items_search_fields) { |
264 |
my $ccode_avcode = $mss->count ? $mss->next->authorised_value : 'CCODE'; |
| 291 |
if (my $category = ($field->{authorised_values_category})) { |
265 |
my $ccodes = GetAuthorisedValues($ccode_avcode); |
| 292 |
$authorised_values->{$category} = GetAuthorisedValues($category); |
266 |
my @ccodes; |
| 293 |
} |
267 |
foreach my $ccode (@$ccodes) { |
| 294 |
} |
268 |
push @ccodes, { |
|
|
269 |
value => $ccode->{authorised_value}, |
| 270 |
label => $ccode->{lib}, |
| 271 |
}; |
| 272 |
} |
| 295 |
|
273 |
|
| 296 |
$template->param( |
274 |
my @notforloans; |
| 297 |
branches => \@branches, |
275 |
foreach my $value (@$notforloan_values) { |
| 298 |
locations => \@locations, |
276 |
push @notforloans, { |
| 299 |
itemtypes => \@itemtypes, |
277 |
value => $value->{authorised_value}, |
| 300 |
ccodes => \@ccodes, |
278 |
label => $value->{lib}, |
| 301 |
notforloans => \@notforloans, |
279 |
}; |
| 302 |
items_search_fields => \@items_search_fields, |
|
|
| 303 |
authorised_values_json => to_json($authorised_values), |
| 304 |
); |
| 305 |
} |
280 |
} |
| 306 |
|
281 |
|
| 307 |
if ($format eq 'csv') { |
282 |
my @items_search_fields = GetItemSearchFields(); |
| 308 |
print $cgi->header({ |
|
|
| 309 |
type => 'text/csv', |
| 310 |
attachment => 'items.csv', |
| 311 |
}); |
| 312 |
|
283 |
|
| 313 |
for my $line ( split '\n', $template->output ) { |
284 |
my $authorised_values = {}; |
| 314 |
print "$line\n" unless $line =~ m|^\s*$|; |
285 |
foreach my $field (@items_search_fields) { |
|
|
286 |
if (my $category = ($field->{authorised_values_category})) { |
| 287 |
$authorised_values->{$category} = GetAuthorisedValues($category); |
| 315 |
} |
288 |
} |
| 316 |
} else { |
|
|
| 317 |
output_with_http_headers $cgi, $cookie, $template->output, $content_type; |
| 318 |
} |
289 |
} |
|
|
290 |
|
| 291 |
$template->param( |
| 292 |
branches => \@branches, |
| 293 |
locations => \@locations, |
| 294 |
itemtypes => \@itemtypes, |
| 295 |
ccodes => \@ccodes, |
| 296 |
notforloans => \@notforloans, |
| 297 |
items_search_fields => \@items_search_fields, |
| 298 |
authorised_values_json => to_json($authorised_values), |
| 299 |
); |
| 300 |
|
| 301 |
output_html_with_http_headers $cgi, $cookie, $template->output; |