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
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.
25 subscription-bib-search.pl
29 this script search among all existing subscriptions.
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
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);
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 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
80 { template_name => "serials/result.tmpl",
84 flagsrequired => {catalogue => 1, serials => '*'},
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) = SimpleSearch($query, $startfrom*$resultsperpage, $resultsperpage);
101 if (defined $marcrecords ) {
102 $total = scalar @{$marcrecords};
105 if (defined $error) {
106 $template->param(query_error => $error);
107 warn "error: ".$error;
108 output_html_with_http_headers $input, $cookie, $template->output;
113 for(my $i=0;$i<$total;$i++) {
115 my $marcrecord = MARC::File::USMARC::decode($marcrecords->[$i]);
116 my $biblio = TransformMarcToKoha(C4::Context->dbh,$marcrecord,'');
118 #build the hash for the template.
119 $resultsloop{highlight} = ($i % 2)?(1):(0);
120 $resultsloop{title} = $biblio->{'title'};
121 $resultsloop{subtitle} = $biblio->{'subtitle'};
122 $resultsloop{biblionumber} = $biblio->{'biblionumber'};
123 $resultsloop{author} = $biblio->{'author'};
124 $resultsloop{publishercode} = $biblio->{'publishercode'};
125 $resultsloop{publicationyear} = $biblio->{'publicationyear'};
126 $resultsloop{issn} = $biblio->{'issn'};
128 push @results, \%resultsloop;
131 # multi page display gestion
133 my $displayprev=$startfrom;
134 if(($total_hits - (($startfrom+1)*($resultsperpage))) > 0 ){
141 if ($total_hits>$resultsperpage)
143 for (my $i=1; $i<$total/$resultsperpage+1; $i++)
148 ($startfrom==($i-1)) && ($highlight=1);
149 push @numbers, { number => $i,
150 highlight => $highlight ,
151 searchdata=> \@results,
152 startfrom => ($i-1)};
158 $from = $startfrom*$resultsperpage+1 if($total_hits > 0);
161 if($total_hits < (($startfrom+1)*$resultsperpage))
165 $to = (($startfrom+1)*$resultsperpage);
169 resultsloop => \@results,
170 startfrom=> $startfrom,
171 displaynext=> $displaynext,
172 displayprev=> $displayprev,
173 resultsperpage => $resultsperpage,
174 startfromnext => $startfrom+1,
175 startfromprev => $startfrom-1,
181 } # end of if ($op eq "do_search" & $query)
183 ($template, $loggedinuser, $cookie)
184 = get_template_and_user({template_name => "serials/subscription-bib-search.tmpl",
187 authnotrequired => 0,
188 flagsrequired => {catalogue => 1, serials => '*'},
193 my $itemtypes = GetItemTypes();
195 foreach my $thisitemtype ( sort {$itemtypes->{$a}->{'description'} cmp $itemtypes->{$b}->{'description'} } keys %$itemtypes ) {
197 code => $thisitemtype,
198 description => $itemtypes->{$thisitemtype}->{'description'},
200 push @itemtypesloop, \%row;
203 # load Collection Codes
204 my $authvalues = GetAuthorisedValues('CCODE');
206 for my $thisauthvalue (sort {$a->{'lib'} cmp $b->{'lib'}} @$authvalues) {
208 code => $thisauthvalue->{'authorised_value'},
209 description => $thisauthvalue->{'lib'},
211 push @ccodesloop, \%row;
215 itemtypeloop => \@itemtypesloop,
216 ccodeloop => \@ccodesloop,
217 no_query => $op eq "do_search" ? 1 : 0,
221 output_html_with_http_headers $input, $cookie, $template->output;