my %params = $cgi->Vars;
my $format = $cgi->param('format');
-my ($template_name, $content_type);
+my $template_name = 'catalogue/itemsearch.tt';
+
if (defined $format and $format eq 'json') {
$template_name = 'catalogue/itemsearch_json.tt';
- $content_type = 'json';
# Map DataTables parameters with 'regular' parameters
$cgi->param('rows', scalar $cgi->param('iDisplayLength'));
# Retrieve all results
$cgi->param('rows', 0);
-} else {
- $format = 'html';
- $template_name = 'catalogue/itemsearch.tt';
- $content_type = 'html';
+} elsif (defined $format) {
+ die "Unsupported format $format";
}
my ($template, $borrowernumber, $cookie) = get_template_and_user({
search_params => $search_params,
results => $results,
total_rows => $total_rows,
- search_done => 1,
);
- if ($format eq 'html') {
- # Build pagination bar
- my $url = '/cgi-bin/koha/catalogue/itemsearch.pl';
- my @params;
- foreach my $p (keys %params) {
- my @v = $cgi->multi_param($p);
- push @params, map { "$p=" . $_ } @v;
- }
- $url .= '?' . join ('&', @params);
- my $nb_pages = 1 + int($total_rows / $search_params->{rows});
- my $current_page = $search_params->{page};
- my $pagination_bar = pagination_bar($url, $nb_pages, $current_page, 'page');
+ if ($format eq 'csv') {
+ print $cgi->header({
+ type => 'text/csv',
+ attachment => 'items.csv',
+ });
- $template->param(pagination_bar => $pagination_bar);
+ for my $line ( split '\n', $template->output ) {
+ print "$line\n" unless $line =~ m|^\s*$|;
+ }
+ } elsif ($format eq 'json') {
+ output_with_http_headers $cgi, $cookie, $template->output, 'json';
}
-}
-if ($format eq 'html') {
- # Retrieve data required for the form.
-
- my @branches = map { value => $_->branchcode, label => $_->branchname }, Koha::Libraries->search( {}, { order_by => 'branchname' } );
- my @locations;
- foreach my $location (@$location_values) {
- push @locations, {
- value => $location->{authorised_value},
- label => $location->{lib} // $location->{authorised_value},
- };
- }
- my @itemtypes;
- foreach my $itemtype ( Koha::ItemTypes->search ) {
- push @itemtypes, {
- value => $itemtype->itemtype,
- label => $itemtype->translated_description,
- };
- }
+ exit;
+}
- my $mss = Koha::MarcSubfieldStructures->search({ frameworkcode => '', kohafield => 'items.ccode', authorised_value => { not => undef } });
- my $ccode_avcode = $mss->count ? $mss->next->authorised_value : 'CCODE';
- my $ccodes = GetAuthorisedValues($ccode_avcode);
- my @ccodes;
- foreach my $ccode (@$ccodes) {
- push @ccodes, {
- value => $ccode->{authorised_value},
- label => $ccode->{lib},
- };
- }
+# Display the search form
- my @notforloans;
- foreach my $value (@$notforloan_values) {
- push @notforloans, {
- value => $value->{authorised_value},
- label => $value->{lib},
- };
- }
-
- my @items_search_fields = GetItemSearchFields();
+my @branches = map { value => $_->branchcode, label => $_->branchname }, Koha::Libraries->search( {}, { order_by => 'branchname' } );
+my @locations;
+foreach my $location (@$location_values) {
+ push @locations, {
+ value => $location->{authorised_value},
+ label => $location->{lib} // $location->{authorised_value},
+ };
+}
+my @itemtypes;
+foreach my $itemtype ( Koha::ItemTypes->search ) {
+ push @itemtypes, {
+ value => $itemtype->itemtype,
+ label => $itemtype->translated_description,
+ };
+}
- my $authorised_values = {};
- foreach my $field (@items_search_fields) {
- if (my $category = ($field->{authorised_values_category})) {
- $authorised_values->{$category} = GetAuthorisedValues($category);
- }
- }
+$mss = Koha::MarcSubfieldStructures->search({ frameworkcode => '', kohafield => 'items.ccode', authorised_value => { not => undef } });
+my $ccode_avcode = $mss->count ? $mss->next->authorised_value : 'CCODE';
+my $ccodes = GetAuthorisedValues($ccode_avcode);
+my @ccodes;
+foreach my $ccode (@$ccodes) {
+ push @ccodes, {
+ value => $ccode->{authorised_value},
+ label => $ccode->{lib},
+ };
+}
- $template->param(
- branches => \@branches,
- locations => \@locations,
- itemtypes => \@itemtypes,
- ccodes => \@ccodes,
- notforloans => \@notforloans,
- items_search_fields => \@items_search_fields,
- authorised_values_json => to_json($authorised_values),
- );
+my @notforloans;
+foreach my $value (@$notforloan_values) {
+ push @notforloans, {
+ value => $value->{authorised_value},
+ label => $value->{lib},
+ };
}
-if ($format eq 'csv') {
- print $cgi->header({
- type => 'text/csv',
- attachment => 'items.csv',
- });
+my @items_search_fields = GetItemSearchFields();
- for my $line ( split '\n', $template->output ) {
- print "$line\n" unless $line =~ m|^\s*$|;
+my $authorised_values = {};
+foreach my $field (@items_search_fields) {
+ if (my $category = ($field->{authorised_values_category})) {
+ $authorised_values->{$category} = GetAuthorisedValues($category);
}
-} else {
- output_with_http_headers $cgi, $cookie, $template->output, $content_type;
}
+
+$template->param(
+ branches => \@branches,
+ locations => \@locations,
+ itemtypes => \@itemtypes,
+ ccodes => \@ccodes,
+ notforloans => \@notforloans,
+ items_search_fields => \@items_search_fields,
+ authorised_values_json => to_json($authorised_values),
+);
+
+output_html_with_http_headers $cgi, $cookie, $template->output;
+++ /dev/null
-[% names = CGI.param() %]
-[% params = [] %]
-[% FOREACH name IN names %]
- [% IF name != 'sortby' AND name != 'sortorder' %]
- [% params.push(name _ "=" _ CGI.param(name)) %]
- [% END %]
-[% END %]
-[% base_url = "/cgi-bin/koha/catalogue/itemsearch.pl?" _ params.join('&') %]
-
-[% BLOCK itemsearch_header %]
- [% sortorder = 'asc' %]
- [% classes = [] %]
- [% IF CGI.param('sortby') == name %]
- [% classes.push('active') %]
- [% classes.push('sort-' _ CGI.param('sortorder')) %]
- [% IF CGI.param('sortorder') == 'asc' %]
- [% sortorder = 'desc' %]
- [% END %]
- [% END %]
- [% url = base_url _ '&sortby=' _ name _ '&sortorder=' _ sortorder %]
- <th class="[% classes.join(' ') %]">
- <a href="[% url %]" title="Sort on [% label %] ([% sortorder %])">[% text %]</a>
- </th>
-[% END %]
-
-<table>
- <thead>
- <tr>
- [% INCLUDE itemsearch_header name='title' label='title' text='Title' %]
- [% INCLUDE itemsearch_header name='publicationyear' label='publication date' text='Publication date' %]
- [% INCLUDE itemsearch_header name='publishercode' label='publisher' text='Publisher' %]
- [% INCLUDE itemsearch_header name='collectiontitle' label='collection' text='Collection' %]
- [% INCLUDE itemsearch_header name='barcode' label='barcode' text='Barcode' %]
- [% INCLUDE itemsearch_header name='itemcallnumber' label='callnumber' text='Call number' %]
- [% INCLUDE itemsearch_header name='homebranch' label='home branch' text='Home library' %]
- [% INCLUDE itemsearch_header name='holdingbranch' label='holding branch' text='Current location' %]
- [% INCLUDE itemsearch_header name='location' label='location' text='Shelving location' %]
- [% INCLUDE itemsearch_header name='stocknumber' label='inventory number' text='Inventory number' %]
- [% INCLUDE itemsearch_header name='notforloan' label='status' text='Status' %]
- [% INCLUDE itemsearch_header name='issues' label='issues' text='Checkouts' %]
- <th></th>
- </tr>
- </thead>
- <tbody>
- [% FOREACH item IN items %]
- [% INCLUDE 'catalogue/itemsearch_item.inc' item = item %]
- [% END %]
- </tbody>
-</table>