From ebe46bbf94c98d387fb1ffce659bcd3050762d3f Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Thu, 6 Apr 2017 14:26:08 +0200 Subject: [PATCH] Bug 18394: Remove useless code from item search The item search was originally designed to work even with JS disabled. Since bug 15111, the staff interface does not work at all without JS, so some parts of this code are useless and should be removed --- catalogue/itemsearch.pl | 147 +++++++++------------ .../prog/en/includes/catalogue/itemsearch_item.inc | 24 ---- .../en/includes/catalogue/itemsearch_items.inc | 49 ------- .../prog/en/modules/catalogue/itemsearch.tt | 19 +-- 4 files changed, 66 insertions(+), 173 deletions(-) delete mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/catalogue/itemsearch_item.inc delete mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/catalogue/itemsearch_items.inc diff --git a/catalogue/itemsearch.pl b/catalogue/itemsearch.pl index fa6b357b9f..66a9cf7395 100755 --- a/catalogue/itemsearch.pl +++ b/catalogue/itemsearch.pl @@ -36,10 +36,10 @@ my $cgi = new CGI; 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')); @@ -75,10 +75,8 @@ if (defined $format and $format eq 'json') { # 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({ @@ -226,93 +224,78 @@ if (scalar keys %params > 0) { 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; diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/catalogue/itemsearch_item.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/catalogue/itemsearch_item.inc deleted file mode 100644 index 8f659134a8..0000000000 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/catalogue/itemsearch_item.inc +++ /dev/null @@ -1,24 +0,0 @@ -[%- USE Branches -%] -[%- USE Koha -%] -[% biblio = item.biblio %] -[% biblioitem = item.biblioitem %] - - - [% biblio.title %] - [% IF ( Koha.Preference( 'marcflavour' ) == 'UNIMARC' && biblio.author ) %] by[% END %] [% biblio.author |html %] - - [% biblioitem.publicationyear || biblio.copyrightdate %] - [% biblioitem.publishercode %] - [% biblioitem.collectiontitle %] - - [% item.barcode %] - - [% item.itemcallnumber %] - [% Branches.GetName(item.homebranch) %] - [% Branches.GetName(item.holdingbranch) %] - [% item.location %] - [% item.stocknumber %] - [% item.status %] - [% item.issues || 0 %] - Edit - diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/catalogue/itemsearch_items.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/catalogue/itemsearch_items.inc deleted file mode 100644 index 33aa9de64e..0000000000 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/catalogue/itemsearch_items.inc +++ /dev/null @@ -1,49 +0,0 @@ -[% 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 %] - - [% text %] - -[% END %] - - - - - [% 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' %] - - - - - [% FOREACH item IN items %] - [% INCLUDE 'catalogue/itemsearch_item.inc' item = item %] - [% END %] - -
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/itemsearch.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/itemsearch.tt index e88d77452b..a90414666a 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/itemsearch.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/itemsearch.tt @@ -487,23 +487,6 @@
-
- [% IF search_done %] - [% IF total_rows > 0 %] -

Found [% total_rows %] results.

- [% ELSE %] -

No results found.

- [% END %] - - [% IF results %] - [% INCLUDE 'catalogue/itemsearch_items.inc' items = results %] - [% END %] - -
- [% pagination_bar %] -
- - [% END %] -
+
[% INCLUDE 'intranet-bottom.inc' %] -- 2.11.0