Bug 10671: Add missing patron lists help
[koha.git] / serials / subscription-bib-search.pl
blob95e4aa770e068abe59bc310f208d7867fcb0bd8f
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 under the
10 # terms of the GNU General Public License as published by the Free Software
11 # Foundation; either version 2 of the License, or (at your option) any later
12 # version.
14 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License along
19 # with Koha; if not, write to the Free Software Foundation, Inc.,
20 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 =head1 NAME
25 subscription-bib-search.pl
27 =head1 DESCRIPTION
29 this script search among all existing subscriptions.
31 =head1 PARAMETERS
33 =over 4
35 =item op
36 op use to know the operation to do on this template.
37 * do_search : to search the subscription.
39 Note that if op = do_search there are some others params specific to the search :
40 marclist,and_or,excluding,operator,value
42 =item startfrom
43 to multipage gestion.
46 =back
48 =cut
51 use strict;
52 use warnings;
54 use CGI;
55 use C4::Koha;
56 use C4::Auth;
57 use C4::Context;
58 use C4::Output;
59 use C4::Search;
60 use C4::Biblio;
61 use C4::Debug;
63 my $input=new CGI;
64 # my $type=$query->param('type');
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);
71 my $resultsperpage;
73 my $advanced_search_types = C4::Context->preference("AdvancedSearchTypes");
74 my $itype_or_itemtype = (C4::Context->preference("item-level_itypes"))?'itype':'itemtype';
76 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(
81 { template_name => "serials/result.tmpl",
82 query => $input,
83 type => "intranet",
84 authnotrequired => 0,
85 flagsrequired => {catalogue => 1, serials => '*'},
86 debug => 1,
90 # add the itemtype limit if applicable
91 my $itemtypelimit = $input->param('itemtypelimit');
92 if ( $itemtypelimit ) {
93 my $QParser;
94 $QParser = C4::Context->queryparser if (C4::Context->preference('UseQueryParser'));
95 my $op;
96 if ($QParser) {
97 $op = '&&';
98 } else {
99 $op = 'and';
101 if (!$advanced_search_types or $advanced_search_types eq 'itemtypes') {
102 $query .= " $op $itype_or_itemtype:$itemtypelimit";
103 } else {
104 $query .= " $op $advanced_search_types:$itemtypelimit";
107 $debug && warn $query;
108 $resultsperpage= $input->param('resultsperpage');
109 $resultsperpage = 20 if(!defined $resultsperpage);
111 my ($error, $marcrecords, $total_hits) = SimpleSearch($query, $startfrom*$resultsperpage, $resultsperpage);
112 my $total = 0;
113 if (defined $marcrecords ) {
114 $total = scalar @{$marcrecords};
117 if (defined $error) {
118 $template->param(query_error => $error);
119 warn "error: ".$error;
120 output_html_with_http_headers $input, $cookie, $template->output;
121 exit;
123 my @results;
125 for(my $i=0;$i<$total;$i++) {
126 my %resultsloop;
127 my $marcrecord = MARC::File::USMARC::decode($marcrecords->[$i]);
128 my $biblio = TransformMarcToKoha(C4::Context->dbh,$marcrecord,'');
130 #build the hash for the template.
131 $resultsloop{highlight} = ($i % 2)?(1):(0);
132 $resultsloop{title} = $biblio->{'title'};
133 $resultsloop{subtitle} = $biblio->{'subtitle'};
134 $resultsloop{biblionumber} = $biblio->{'biblionumber'};
135 $resultsloop{author} = $biblio->{'author'};
136 $resultsloop{publishercode} = $biblio->{'publishercode'};
137 $resultsloop{publicationyear} = $biblio->{'publicationyear'};
138 $resultsloop{issn} = $biblio->{'issn'};
140 push @results, \%resultsloop;
143 # multi page display gestion
144 my $displaynext=0;
145 my $displayprev=$startfrom;
146 if(($total_hits - (($startfrom+1)*($resultsperpage))) > 0 ){
147 $displaynext = 1;
151 my @numbers = ();
153 if ($total_hits>$resultsperpage)
155 for (my $i=1; $i<$total/$resultsperpage+1; $i++)
157 if ($i<16)
159 my $highlight=0;
160 ($startfrom==($i-1)) && ($highlight=1);
161 push @numbers, { number => $i,
162 highlight => $highlight ,
163 searchdata=> \@results,
164 startfrom => ($i-1)};
169 my $from = 0;
170 $from = $startfrom*$resultsperpage+1 if($total_hits > 0);
171 my $to;
173 if($total_hits < (($startfrom+1)*$resultsperpage))
175 $to = $total;
176 } else {
177 $to = (($startfrom+1)*$resultsperpage);
179 $template->param(
180 query => $query,
181 resultsloop => \@results,
182 startfrom=> $startfrom,
183 displaynext=> $displaynext,
184 displayprev=> $displayprev,
185 resultsperpage => $resultsperpage,
186 startfromnext => $startfrom+1,
187 startfromprev => $startfrom-1,
188 total=>$total_hits,
189 from=>$from,
190 to=>$to,
191 numbers=>\@numbers,
193 } # end of if ($op eq "do_search" & $query)
194 else {
195 ($template, $loggedinuser, $cookie)
196 = get_template_and_user({template_name => "serials/subscription-bib-search.tmpl",
197 query => $input,
198 type => "intranet",
199 authnotrequired => 0,
200 flagsrequired => {catalogue => 1, serials => '*'},
201 debug => 1,
203 # load the itemtypes
204 my $itemtypes = GetItemTypes;
205 my @itemtypesloop;
206 if (!$advanced_search_types or $advanced_search_types eq 'itemtypes') {
207 # load the itemtypes
208 my $itemtypes = GetItemTypes;
209 my $selected=1;
210 my $cnt;
211 foreach my $thisitemtype ( sort {$itemtypes->{$a}->{'description'} cmp $itemtypes->{$b}->{'description'} } keys %$itemtypes ) {
212 my %row =(
213 code => $thisitemtype,
214 selected => $selected,
215 description => $itemtypes->{$thisitemtype}->{'description'},
217 $selected = 0 if ($selected) ;
218 push @itemtypesloop, \%row;
222 } else {
223 my $advsearchtypes = GetAuthorisedValues($advanced_search_types);
224 my $cnt;
225 my $selected=1;
226 for my $thisitemtype (sort {$a->{'lib'} cmp $b->{'lib'}} @$advsearchtypes) {
227 my %row =(
228 number=>$cnt++,
229 ccl => $advanced_search_types,
230 code => $thisitemtype->{authorised_value},
231 selected => $selected,
232 description => $thisitemtype->{'lib'},
233 count5 => $cnt % 4,
234 imageurl=> getitemtypeimagelocation( 'intranet', $thisitemtype->{'imageurl'} ),
236 push @itemtypesloop, \%row;
241 if ($op eq "do_search") {
242 $template->param("no_query" => 1);
243 } else {
244 $template->param("no_query" => 0);
246 $template->param(itemtypeloop => \@itemtypesloop);
248 # Print the page
249 output_html_with_http_headers $input, $cookie, $template->output;
251 # Local Variables:
252 # tab-width: 4
253 # End: