2 # WARNING: 4-character tab stops here
4 # Copyright 2000-2002 Katipo Communications
5 # Parts Copyright 2010 Biblibre
7 # This file is part of Koha.
9 # Koha is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
14 # Koha is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with Koha; if not, see <http://www.gnu.org/licenses>.
24 subscription-bib-search.pl
28 this script search among all existing subscriptions.
35 op use to know the operation to do on this template.
36 * do_search : to search the subscription.
38 Note that if op = do_search there are some others params specific to the search :
39 marclist,and_or,excluding,operator,value
52 use C4::Koha qw( GetAuthorisedValues );
53 use C4::Auth qw( get_template_and_user );
55 use C4::Output qw( output_html_with_http_headers );
56 use C4::Search qw( new_record_from_zebra );
57 use C4::Biblio qw( TransformMarcToKoha );
60 use Koha::SearchEngine;
61 use Koha::SearchEngine::Search;
64 my $op = $input->param('op') || q{};
65 my $dbh = C4::Context->dbh;
67 my $startfrom = $input->param('startfrom');
68 $startfrom = 0 unless $startfrom;
69 my ( $template, $loggedinuser, $cookie );
72 my $itype_or_itemtype =
73 ( C4::Context->preference("item-level_itypes") ) ? 'itype' : 'itemtype';
75 my $query = $input->param('q');
77 # don't run the search if no search term !
78 if ( $op eq "do_search" && $query ) {
80 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
82 template_name => "serials/result.tt",
85 flagsrequired => { catalogue => 1, serials => '*' },
89 # add the limits if applicable
90 my $itemtypelimit = $input->param('itemtypelimit');
91 my $ccodelimit = $input->param('ccodelimit');
93 $query .= " $op $itype_or_itemtype:$itemtypelimit" if $itemtypelimit;
94 $query .= " $op ccode:$ccodelimit" if $ccodelimit;
95 $resultsperpage = $input->param('resultsperpage');
96 $resultsperpage = 20 if ( !defined $resultsperpage );
98 my $searcher = Koha::SearchEngine::Search->new({index => $Koha::SearchEngine::BIBLIOS_INDEX});
99 my ( $error, $marcrecords, $total_hits ) =
100 $searcher->simple_search_compat( $query, $startfrom * $resultsperpage, $resultsperpage );
102 if ( defined $marcrecords ) {
103 $total = scalar @{$marcrecords};
106 if ( defined $error ) {
107 $template->param( query_error => $error );
108 warn "error: " . $error;
109 output_html_with_http_headers $input, $cookie, $template->output;
114 for ( my $i = 0 ; $i < $total ; $i++ ) {
116 my $marcrecord = C4::Search::new_record_from_zebra( 'biblioserver', $marcrecords->[$i] );
117 my $biblio = TransformMarcToKoha( $marcrecord, '' );
119 #build the hash for the template.
120 $resultsloop{highlight} = ( $i % 2 ) ? (1) : (0);
121 $resultsloop{title} = $biblio->{'title'};
122 $resultsloop{subtitle} = $biblio->{'subtitle'};
123 $resultsloop{medium} = $biblio->{'medium'};
124 $resultsloop{part_number} = $biblio->{'part_number'};
125 $resultsloop{part_name} = $biblio->{'part_name'};
126 $resultsloop{biblionumber} = $biblio->{'biblionumber'};
127 $resultsloop{author} = $biblio->{'author'};
128 $resultsloop{publishercode} = $biblio->{'publishercode'};
129 $resultsloop{publicationyear} = $biblio->{'publicationyear'} ? $biblio->{'publicationyear'} : $biblio->{'copyrightdate'};
130 $resultsloop{issn} = $biblio->{'issn'};
132 push @results, \%resultsloop;
135 # multi page display gestion
137 my $displayprev = $startfrom;
138 if ( ( $total_hits - ( ( $startfrom + 1 ) * ($resultsperpage) ) ) > 0 ) {
144 if ( $total_hits > $resultsperpage ) {
145 for ( my $i = 1 ; $i < $total / $resultsperpage + 1 ; $i++ ) {
148 ( $startfrom == ( $i - 1 ) ) && ( $highlight = 1 );
152 highlight => $highlight,
153 searchdata => \@results,
154 startfrom => ( $i - 1 )
161 $from = $startfrom * $resultsperpage + 1 if ( $total_hits > 0 );
164 if ( $total_hits < ( ( $startfrom + 1 ) * $resultsperpage ) ) {
168 $to = ( ( $startfrom + 1 ) * $resultsperpage );
172 resultsloop => \@results,
173 startfrom => $startfrom,
174 displaynext => $displaynext,
175 displayprev => $displayprev,
176 resultsperpage => $resultsperpage,
177 startfromnext => $startfrom + 1,
178 startfromprev => $startfrom - 1,
179 total => $total_hits,
182 numbers => \@numbers,
184 } # end of if ($op eq "do_search" & $query)
186 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
188 template_name => "serials/subscription-bib-search.tt",
191 flagsrequired => { catalogue => 1, serials => '*' },
196 my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } };
198 # FIXME This is uselessly complex, the iterator should be send to the template
199 # FIXME The translated_description should be used
200 foreach my $thisitemtype (
202 $itemtypes->{$a}->{'description'}
203 cmp $itemtypes->{$b}->{'description'}
208 code => $thisitemtype,
209 description => $itemtypes->{$thisitemtype}->{'description'},
211 push @itemtypesloop, \%row;
214 # load Collection Codes
215 my $authvalues = GetAuthorisedValues('CCODE');
217 for my $thisauthvalue ( sort { $a->{'lib'} cmp $b->{'lib'} } @$authvalues )
220 code => $thisauthvalue->{'authorised_value'},
221 description => $thisauthvalue->{'lib'},
223 push @ccodesloop, \%row;
227 itemtypeloop => \@itemtypesloop,
228 ccodeloop => \@ccodesloop,
229 no_query => $op eq "do_search" ? 1 : 0,
234 output_html_with_http_headers $input, $cookie, $template->output;