Bug 15274: Putting <span> tags around entire string where the originally split the...
[koha.git] / serials / subscription-bib-search.pl
bloba74afb0891ee0c2afc67c6f1b4ad892c151993fe
1 #!/usr/bin/perl
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>.
22 =head1 NAME
24 subscription-bib-search.pl
26 =head1 DESCRIPTION
28 this script search among all existing subscriptions.
30 =head1 PARAMETERS
32 =over 4
34 =item op
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
41 =item startfrom
42 to multipage gestion.
45 =back
47 =cut
49 use strict;
50 use warnings;
52 use CGI qw ( -utf8 );
53 use C4::Koha;
54 use C4::Auth;
55 use C4::Context;
56 use C4::Output;
57 use C4::Search;
58 use C4::Biblio;
59 use C4::Debug;
61 my $input = new CGI;
62 my $op = $input->param('op') || q{};
63 my $dbh = C4::Context->dbh;
65 my $startfrom = $input->param('startfrom');
66 $startfrom = 0 unless $startfrom;
67 my ( $template, $loggedinuser, $cookie );
68 my $resultsperpage;
70 my $itype_or_itemtype =
71 ( C4::Context->preference("item-level_itypes") ) ? 'itype' : 'itemtype';
73 my $query = $input->param('q');
75 # don't run the search if no search term !
76 if ( $op eq "do_search" && $query ) {
78 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
80 template_name => "serials/result.tt",
81 query => $input,
82 type => "intranet",
83 authnotrequired => 0,
84 flagsrequired => { catalogue => 1, serials => '*' },
85 debug => 1,
89 # add the limits if applicable
90 my $itemtypelimit = $input->param('itemtypelimit');
91 my $ccodelimit = $input->param('ccodelimit');
92 my $op = C4::Context->preference('UseQueryParser') ? '&&' : 'and';
93 $query .= " $op $itype_or_itemtype:$itemtypelimit" if $itemtypelimit;
94 $query .= " $op ccode:$ccodelimit" if $ccodelimit;
95 $debug && warn $query;
96 $resultsperpage = $input->param('resultsperpage');
97 $resultsperpage = 20 if ( !defined $resultsperpage );
99 my ( $error, $marcrecords, $total_hits ) =
100 SimpleSearch( $query, $startfrom * $resultsperpage, $resultsperpage );
101 my $total = 0;
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;
110 exit;
112 my @results;
114 for ( my $i = 0 ; $i < $total ; $i++ ) {
115 my %resultsloop;
116 my $marcrecord = C4::Search::new_record_from_zebra( 'biblioserver', $marcrecords->[$i] );
117 my $biblio = TransformMarcToKoha( C4::Context->dbh, $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{biblionumber} = $biblio->{'biblionumber'};
124 $resultsloop{author} = $biblio->{'author'};
125 $resultsloop{publishercode} = $biblio->{'publishercode'};
126 $resultsloop{publicationyear} = $biblio->{'publicationyear'};
127 $resultsloop{issn} = $biblio->{'issn'};
129 push @results, \%resultsloop;
132 # multi page display gestion
133 my $displaynext = 0;
134 my $displayprev = $startfrom;
135 if ( ( $total_hits - ( ( $startfrom + 1 ) * ($resultsperpage) ) ) > 0 ) {
136 $displaynext = 1;
139 my @numbers = ();
141 if ( $total_hits > $resultsperpage ) {
142 for ( my $i = 1 ; $i < $total / $resultsperpage + 1 ; $i++ ) {
143 if ( $i < 16 ) {
144 my $highlight = 0;
145 ( $startfrom == ( $i - 1 ) ) && ( $highlight = 1 );
146 push @numbers,
148 number => $i,
149 highlight => $highlight,
150 searchdata => \@results,
151 startfrom => ( $i - 1 )
157 my $from = 0;
158 $from = $startfrom * $resultsperpage + 1 if ( $total_hits > 0 );
159 my $to;
161 if ( $total_hits < ( ( $startfrom + 1 ) * $resultsperpage ) ) {
162 $to = $total;
164 else {
165 $to = ( ( $startfrom + 1 ) * $resultsperpage );
167 $template->param(
168 query => $query,
169 resultsloop => \@results,
170 startfrom => $startfrom,
171 displaynext => $displaynext,
172 displayprev => $displayprev,
173 resultsperpage => $resultsperpage,
174 startfromnext => $startfrom + 1,
175 startfromprev => $startfrom - 1,
176 total => $total_hits,
177 from => $from,
178 to => $to,
179 numbers => \@numbers,
181 } # end of if ($op eq "do_search" & $query)
182 else {
183 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
185 template_name => "serials/subscription-bib-search.tt",
186 query => $input,
187 type => "intranet",
188 authnotrequired => 0,
189 flagsrequired => { catalogue => 1, serials => '*' },
190 debug => 1,
194 # load the itemtypes
195 my $itemtypes = GetItemTypes();
196 my @itemtypesloop;
197 foreach my $thisitemtype (
198 sort {
199 $itemtypes->{$a}->{'description'}
200 cmp $itemtypes->{$b}->{'description'}
201 } keys %$itemtypes
204 my %row = (
205 code => $thisitemtype,
206 description => $itemtypes->{$thisitemtype}->{'description'},
208 push @itemtypesloop, \%row;
211 # load Collection Codes
212 my $authvalues = GetAuthorisedValues('CCODE');
213 my @ccodesloop;
214 for my $thisauthvalue ( sort { $a->{'lib'} cmp $b->{'lib'} } @$authvalues )
216 my %row = (
217 code => $thisauthvalue->{'authorised_value'},
218 description => $thisauthvalue->{'lib'},
220 push @ccodesloop, \%row;
223 $template->param(
224 itemtypeloop => \@itemtypesloop,
225 ccodeloop => \@ccodesloop,
226 no_query => $op eq "do_search" ? 1 : 0,
230 # Print the page
231 output_html_with_http_headers $input, $cookie, $template->output;
233 # Local Variables:
234 # tab-width: 4
235 # End: