Merge remote branch 'kc/new/for-3.4/spelling' into kcmaster
[koha.git] / serials / subscription-bib-search.pl
blobd1b0f634d8fbc4c165961845a5b4f3ca4e67dd12
1 #!/usr/bin/perl
2 # WARNING: 4-character tab stops here
4 # Copyright 2000-2002 Katipo Communications
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
11 # version.
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along
18 # with Koha; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
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
50 use strict;
51 use warnings;
53 use CGI;
54 use C4::Koha;
55 use C4::Auth;
56 use C4::Context;
57 use C4::Output;
58 use C4::Search;
59 use C4::Biblio;
60 use C4::Debug;
62 my $input=new CGI;
63 # my $type=$query->param('type');
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);
70 my $resultsperpage;
72 my $advanced_search_types = C4::Context->preference("AdvancedSearchTypes");
73 my $itype_or_itemtype = (C4::Context->preference("item-level_itypes"))?'itype':'itemtype';
75 my $query = $input->param('q');
76 # don't run the search if no search term !
77 if ($op eq "do_search" && $query) {
79 # add the itemtype limit if applicable
80 my $itemtypelimit = $input->param('itemtypelimit');
81 if ( $itemtypelimit ) {
82 if (!$advanced_search_types or $advanced_search_types eq 'itemtypes') {
83 $query .= " AND $itype_or_itemtype=$itemtypelimit";
84 } else {
85 $query .= " AND $advanced_search_types=$itemtypelimit";
88 $debug && warn $query;
89 $resultsperpage= $input->param('resultsperpage');
90 $resultsperpage = 20 if(!defined $resultsperpage);
92 my ($error, $marcrecords, $total_hits) = SimpleSearch($query, $startfrom*$resultsperpage, $resultsperpage);
93 my $total = scalar @$marcrecords;
95 if (defined $error) {
96 $template->param(query_error => $error);
97 warn "error: ".$error;
98 output_html_with_http_headers $input, $cookie, $template->output;
99 exit;
101 my @results;
103 for(my $i=0;$i<$total;$i++) {
104 my %resultsloop;
105 my $marcrecord = MARC::File::USMARC::decode($marcrecords->[$i]);
106 my $biblio = TransformMarcToKoha(C4::Context->dbh,$marcrecord,'');
108 #build the hash for the template.
109 $resultsloop{highlight} = ($i % 2)?(1):(0);
110 $resultsloop{title} = $biblio->{'title'};
111 $resultsloop{subtitle} = $biblio->{'subtitle'};
112 $resultsloop{biblionumber} = $biblio->{'biblionumber'};
113 $resultsloop{author} = $biblio->{'author'};
114 $resultsloop{publishercode} = $biblio->{'publishercode'};
115 $resultsloop{publicationyear} = $biblio->{'publicationyear'};
117 push @results, \%resultsloop;
120 ($template, $loggedinuser, $cookie)
121 = get_template_and_user({template_name => "serials/result.tmpl",
122 query => $input,
123 type => "intranet",
124 authnotrequired => 0,
125 flagsrequired => {catalogue => 1, serials => '*'},
126 debug => 1,
129 # multi page display gestion
130 my $displaynext=0;
131 my $displayprev=$startfrom;
132 if(($total_hits - (($startfrom+1)*($resultsperpage))) > 0 ){
133 $displaynext = 1;
137 my @numbers = ();
139 if ($total_hits>$resultsperpage)
141 for (my $i=1; $i<$total/$resultsperpage+1; $i++)
143 if ($i<16)
145 my $highlight=0;
146 ($startfrom==($i-1)) && ($highlight=1);
147 push @numbers, { number => $i,
148 highlight => $highlight ,
149 searchdata=> \@results,
150 startfrom => ($i-1)};
155 my $from = 0;
156 $from = $startfrom*$resultsperpage+1 if($total_hits > 0);
157 my $to;
159 if($total_hits < (($startfrom+1)*$resultsperpage))
161 $to = $total;
162 } else {
163 $to = (($startfrom+1)*$resultsperpage);
165 $template->param(
166 query => $query,
167 resultsloop => \@results,
168 startfrom=> $startfrom,
169 displaynext=> $displaynext,
170 displayprev=> $displayprev,
171 resultsperpage => $resultsperpage,
172 startfromnext => $startfrom+1,
173 startfromprev => $startfrom-1,
174 total=>$total_hits,
175 from=>$from,
176 to=>$to,
177 numbers=>\@numbers,
179 } # end of if ($op eq "do_search" & $query)
180 else {
181 ($template, $loggedinuser, $cookie)
182 = get_template_and_user({template_name => "serials/subscription-bib-search.tmpl",
183 query => $input,
184 type => "intranet",
185 authnotrequired => 0,
186 flagsrequired => {catalogue => 1, serials => '*'},
187 debug => 1,
189 # load the itemtypes
190 my $itemtypes = GetItemTypes;
191 my @itemtypesloop;
192 if (!$advanced_search_types or $advanced_search_types eq 'itemtypes') {
193 # load the itemtypes
194 my $itemtypes = GetItemTypes;
195 my $selected=1;
196 my $cnt;
197 foreach my $thisitemtype ( sort {$itemtypes->{$a}->{'description'} cmp $itemtypes->{$b}->{'description'} } keys %$itemtypes ) {
198 my %row =(
199 code => $thisitemtype,
200 selected => $selected,
201 description => $itemtypes->{$thisitemtype}->{'description'},
203 $selected = 0 if ($selected) ;
204 push @itemtypesloop, \%row;
208 } else {
209 my $advsearchtypes = GetAuthorisedValues($advanced_search_types);
210 my $cnt;
211 my $selected=1;
212 for my $thisitemtype (sort {$a->{'lib'} cmp $b->{'lib'}} @$advsearchtypes) {
213 my %row =(
214 number=>$cnt++,
215 ccl => $advanced_search_types,
216 code => $thisitemtype->{authorised_value},
217 selected => $selected,
218 description => $thisitemtype->{'lib'},
219 count5 => $cnt % 4,
220 imageurl=> getitemtypeimagelocation( 'intranet', $thisitemtype->{'imageurl'} ),
222 push @itemtypesloop, \%row;
226 ($template, $loggedinuser, $cookie)
227 = get_template_and_user({template_name => "serials/subscription-bib-search.tmpl",
228 query => $input,
229 type => "intranet",
230 authnotrequired => 0,
231 flagsrequired => {catalogue => 1, serials => '*'},
232 debug => 1,
236 if ($op eq "do_search") {
237 $template->param("no_query" => 1);
238 } else {
239 $template->param("no_query" => 0);
241 $template->param(itemtypeloop => \@itemtypesloop);
243 # Print the page
244 output_html_with_http_headers $input, $cookie, $template->output;
246 # Local Variables:
247 # tab-width: 4
248 # End: