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
61 use Koha
::SearchEngine
;
62 use Koha
::SearchEngine
::Search
;
65 my $op = $input->param('op') || q{};
66 my $dbh = C4
::Context
->dbh;
68 my $startfrom = $input->param('startfrom');
69 $startfrom = 0 unless $startfrom;
70 my ( $template, $loggedinuser, $cookie );
73 my $itype_or_itemtype =
74 ( C4
::Context
->preference("item-level_itypes") ) ?
'itype' : 'itemtype';
76 my $query = $input->param('q');
78 # don't run the search if no search term !
79 if ( $op eq "do_search" && $query ) {
81 ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
83 template_name
=> "serials/result.tt",
87 flagsrequired
=> { catalogue
=> 1, serials
=> '*' },
92 # add the limits if applicable
93 my $itemtypelimit = $input->param('itemtypelimit');
94 my $ccodelimit = $input->param('ccodelimit');
96 $query .= " $op $itype_or_itemtype:$itemtypelimit" if $itemtypelimit;
97 $query .= " $op ccode:$ccodelimit" if $ccodelimit;
98 $debug && warn $query;
99 $resultsperpage = $input->param('resultsperpage');
100 $resultsperpage = 20 if ( !defined $resultsperpage );
102 my $searcher = Koha
::SearchEngine
::Search
->new({index => $Koha::SearchEngine
::BIBLIOS_INDEX
});
103 my ( $error, $marcrecords, $total_hits ) =
104 $searcher->simple_search_compat( $query, $startfrom * $resultsperpage, $resultsperpage );
106 if ( defined $marcrecords ) {
107 $total = scalar @
{$marcrecords};
110 if ( defined $error ) {
111 $template->param( query_error
=> $error );
112 warn "error: " . $error;
113 output_html_with_http_headers
$input, $cookie, $template->output;
118 for ( my $i = 0 ; $i < $total ; $i++ ) {
120 my $marcrecord = C4
::Search
::new_record_from_zebra
( 'biblioserver', $marcrecords->[$i] );
121 my $biblio = TransformMarcToKoha
( $marcrecord, '' );
123 #build the hash for the template.
124 $resultsloop{highlight
} = ( $i % 2 ) ?
(1) : (0);
125 $resultsloop{title
} = $biblio->{'title'};
126 $resultsloop{subtitle
} = $biblio->{'subtitle'};
127 $resultsloop{medium
} = $biblio->{'medium'};
128 $resultsloop{part_number
} = $biblio->{'part_number'};
129 $resultsloop{part_name
} = $biblio->{'part_name'};
130 $resultsloop{biblionumber
} = $biblio->{'biblionumber'};
131 $resultsloop{author
} = $biblio->{'author'};
132 $resultsloop{publishercode
} = $biblio->{'publishercode'};
133 $resultsloop{publicationyear
} = $biblio->{'publicationyear'} ?
$biblio->{'publicationyear'} : $biblio->{'copyrightdate'};
134 $resultsloop{issn
} = $biblio->{'issn'};
136 push @results, \
%resultsloop;
139 # multi page display gestion
141 my $displayprev = $startfrom;
142 if ( ( $total_hits - ( ( $startfrom + 1 ) * ($resultsperpage) ) ) > 0 ) {
148 if ( $total_hits > $resultsperpage ) {
149 for ( my $i = 1 ; $i < $total / $resultsperpage + 1 ; $i++ ) {
152 ( $startfrom == ( $i - 1 ) ) && ( $highlight = 1 );
156 highlight
=> $highlight,
157 searchdata
=> \
@results,
158 startfrom
=> ( $i - 1 )
165 $from = $startfrom * $resultsperpage + 1 if ( $total_hits > 0 );
168 if ( $total_hits < ( ( $startfrom + 1 ) * $resultsperpage ) ) {
172 $to = ( ( $startfrom + 1 ) * $resultsperpage );
176 resultsloop
=> \
@results,
177 startfrom
=> $startfrom,
178 displaynext
=> $displaynext,
179 displayprev
=> $displayprev,
180 resultsperpage
=> $resultsperpage,
181 startfromnext
=> $startfrom + 1,
182 startfromprev
=> $startfrom - 1,
183 total
=> $total_hits,
186 numbers
=> \
@numbers,
188 } # end of if ($op eq "do_search" & $query)
190 ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
192 template_name
=> "serials/subscription-bib-search.tt",
195 authnotrequired
=> 0,
196 flagsrequired
=> { catalogue
=> 1, serials
=> '*' },
202 my $itemtypes = { map { $_->{itemtype
} => $_ } @
{ Koha
::ItemTypes
->search_with_localization->unblessed } };
204 # FIXME This is uselessly complex, the iterator should be send to the template
205 # FIXME The translated_description should be used
206 foreach my $thisitemtype (
208 $itemtypes->{$a}->{'description'}
209 cmp $itemtypes->{$b}->{'description'}
214 code
=> $thisitemtype,
215 description
=> $itemtypes->{$thisitemtype}->{'description'},
217 push @itemtypesloop, \
%row;
220 # load Collection Codes
221 my $authvalues = GetAuthorisedValues
('CCODE');
223 for my $thisauthvalue ( sort { $a->{'lib'} cmp $b->{'lib'} } @
$authvalues )
226 code
=> $thisauthvalue->{'authorised_value'},
227 description
=> $thisauthvalue->{'lib'},
229 push @ccodesloop, \
%row;
233 itemtypeloop
=> \
@itemtypesloop,
234 ccodeloop
=> \
@ccodesloop,
235 no_query
=> $op eq "do_search" ?
1 : 0,
240 output_html_with_http_headers
$input, $cookie, $template->output;