3 # Copyright 2000-2002 Katipo Communications
4 # Parts Copyright 2010 Biblibre
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
23 subscription-bib-search.pl
27 this script search among all existing subscriptions.
34 op use to know the operation to do on this template.
35 * do_search : to search the subscription.
37 Note that if op = do_search there are some others params specific to the search :
38 marclist,and_or,excluding,operator,value
51 use C4::Koha qw( GetAuthorisedValues );
52 use C4::Auth qw( get_template_and_user );
54 use C4::Output qw( output_html_with_http_headers );
55 use C4::Search qw( new_record_from_zebra );
56 use C4::Biblio qw( TransformMarcToKoha );
59 use Koha::SearchEngine;
60 use Koha::SearchEngine::Search;
63 my $op = $input->param('op') || q{};
64 my $dbh = C4::Context->dbh;
66 my $startfrom = $input->param('startfrom');
67 $startfrom = 0 unless $startfrom;
68 my ( $template, $loggedinuser, $cookie );
71 my $itype_or_itemtype =
72 ( C4::Context->preference("item-level_itypes") ) ? 'itype' : 'itemtype';
74 my $query = $input->param('q');
76 # don't run the search if no search term !
77 if ( $op eq "do_search" && $query ) {
79 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
81 template_name => "serials/result.tt",
84 flagsrequired => { catalogue => 1, serials => '*' },
88 # add the limits if applicable
89 my $itemtypelimit = $input->param('itemtypelimit');
90 my $ccodelimit = $input->param('ccodelimit');
92 $query .= " $op $itype_or_itemtype:$itemtypelimit" if $itemtypelimit;
93 $query .= " $op ccode:$ccodelimit" if $ccodelimit;
94 $resultsperpage = $input->param('resultsperpage');
95 $resultsperpage = 20 if ( !defined $resultsperpage );
97 my $searcher = Koha::SearchEngine::Search->new({index => $Koha::SearchEngine::BIBLIOS_INDEX});
98 my ( $error, $marcrecords, $total_hits ) =
99 $searcher->simple_search_compat( $query, $startfrom * $resultsperpage, $resultsperpage );
101 if ( defined $marcrecords ) {
102 $total = scalar @{$marcrecords};
105 if ( defined $error ) {
106 $template->param( query_error => $error );
107 warn "error: " . $error;
108 output_html_with_http_headers $input, $cookie, $template->output;
113 for ( my $i = 0 ; $i < $total ; $i++ ) {
115 my $marcrecord = C4::Search::new_record_from_zebra( 'biblioserver', $marcrecords->[$i] );
116 my $biblio = TransformMarcToKoha({ record => $marcrecord });
118 #build the hash for the template.
119 $resultsloop{highlight} = ( $i % 2 ) ? (1) : (0);
120 $resultsloop{title} = $biblio->{'title'};
121 $resultsloop{subtitle} = $biblio->{'subtitle'};
122 $resultsloop{medium} = $biblio->{'medium'};
123 $resultsloop{part_number} = $biblio->{'part_number'};
124 $resultsloop{part_name} = $biblio->{'part_name'};
125 $resultsloop{biblionumber} = $biblio->{'biblionumber'};
126 $resultsloop{author} = $biblio->{'author'};
127 $resultsloop{publishercode} = $biblio->{'publishercode'};
128 $resultsloop{publicationyear} = $biblio->{'publicationyear'} ? $biblio->{'publicationyear'} : $biblio->{'copyrightdate'};
129 $resultsloop{issn} = $biblio->{'issn'};
131 push @results, \%resultsloop;
134 # multi page display gestion
136 my $displayprev = $startfrom;
137 if ( ( $total_hits - ( ( $startfrom + 1 ) * ($resultsperpage) ) ) > 0 ) {
143 if ( $total_hits > $resultsperpage ) {
144 for ( my $i = 1 ; $i < $total / $resultsperpage + 1 ; $i++ ) {
147 ( $startfrom == ( $i - 1 ) ) && ( $highlight = 1 );
151 highlight => $highlight,
152 searchdata => \@results,
153 startfrom => ( $i - 1 )
160 $from = $startfrom * $resultsperpage + 1 if ( $total_hits > 0 );
163 if ( $total_hits < ( ( $startfrom + 1 ) * $resultsperpage ) ) {
167 $to = ( ( $startfrom + 1 ) * $resultsperpage );
171 resultsloop => \@results,
172 startfrom => $startfrom,
173 displaynext => $displaynext,
174 displayprev => $displayprev,
175 resultsperpage => $resultsperpage,
176 startfromnext => $startfrom + 1,
177 startfromprev => $startfrom - 1,
178 total => $total_hits,
181 numbers => \@numbers,
183 } # end of if ($op eq "do_search" & $query)
185 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
187 template_name => "serials/subscription-bib-search.tt",
190 flagsrequired => { catalogue => 1, serials => '*' },
195 my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } };
197 # FIXME This is uselessly complex, the iterator should be send to the template
198 # FIXME The translated_description should be used
199 foreach my $thisitemtype (
201 $itemtypes->{$a}->{'description'}
202 cmp $itemtypes->{$b}->{'description'}
207 code => $thisitemtype,
208 description => $itemtypes->{$thisitemtype}->{'description'},
210 push @itemtypesloop, \%row;
213 # load Collection Codes
214 my $authvalues = GetAuthorisedValues('CCODE');
216 for my $thisauthvalue ( sort { $a->{'lib'} cmp $b->{'lib'} } @$authvalues )
219 code => $thisauthvalue->{'authorised_value'},
220 description => $thisauthvalue->{'lib'},
222 push @ccodesloop, \%row;
226 itemtypeloop => \@itemtypesloop,
227 ccodeloop => \@ccodesloop,
228 no_query => $op eq "do_search" ? 1 : 0,
233 output_html_with_http_headers $input, $cookie, $template->output;