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 $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",
85 flagsrequired => {catalogue => 1, serials => '*'},
90 # add the itemtype limit if applicable
91 my $itemtypelimit = $input->param('itemtypelimit');
92 if ( $itemtypelimit ) {
93 if (!$advanced_search_types or $advanced_search_types eq 'itemtypes') {
94 $query .= " AND $itype_or_itemtype=$itemtypelimit";
96 $query .= " AND $advanced_search_types=$itemtypelimit";
99 $debug && warn $query;
100 $resultsperpage= $input->param('resultsperpage');
101 $resultsperpage = 20 if(!defined $resultsperpage);
103 my ($error, $marcrecords, $total_hits) = SimpleSearch($query, $startfrom*$resultsperpage, $resultsperpage);
105 if (defined $marcrecords ) {
106 $total = scalar @{$marcrecords};
109 if (defined $error) {
110 $template->param(query_error => $error);
111 warn "error: ".$error;
112 output_html_with_http_headers $input, $cookie, $template->output;
117 for(my $i=0;$i<$total;$i++) {
119 my $marcrecord = MARC::File::USMARC::decode($marcrecords->[$i]);
120 my $biblio = TransformMarcToKoha(C4::Context->dbh,$marcrecord,'');
122 #build the hash for the template.
123 $resultsloop{highlight} = ($i % 2)?(1):(0);
124 $resultsloop{title} = $biblio->{'title'};
125 $resultsloop{subtitle} = $biblio->{'subtitle'};
126 $resultsloop{biblionumber} = $biblio->{'biblionumber'};
127 $resultsloop{author} = $biblio->{'author'};
128 $resultsloop{publishercode} = $biblio->{'publishercode'};
129 $resultsloop{publicationyear} = $biblio->{'publicationyear'};
131 push @results, \%resultsloop;
134 # multi page display gestion
136 my $displayprev=$startfrom;
137 if(($total_hits - (($startfrom+1)*($resultsperpage))) > 0 ){
144 if ($total_hits>$resultsperpage)
146 for (my $i=1; $i<$total/$resultsperpage+1; $i++)
151 ($startfrom==($i-1)) && ($highlight=1);
152 push @numbers, { number => $i,
153 highlight => $highlight ,
154 searchdata=> \@results,
155 startfrom => ($i-1)};
161 $from = $startfrom*$resultsperpage+1 if($total_hits > 0);
164 if($total_hits < (($startfrom+1)*$resultsperpage))
168 $to = (($startfrom+1)*$resultsperpage);
172 resultsloop => \@results,
173 startfrom=> $startfrom,
174 displaynext=> $displaynext,
175 displayprev=> $displayprev,
176 resultsperpage => $resultsperpage,
177 startfromnext => $startfrom+1,
178 startfromprev => $startfrom-1,
184 } # end of if ($op eq "do_search" & $query)
186 ($template, $loggedinuser, $cookie)
187 = get_template_and_user({template_name => "serials/subscription-bib-search.tmpl",
190 authnotrequired => 0,
191 flagsrequired => {catalogue => 1, serials => '*'},
195 my $itemtypes = GetItemTypes;
197 if (!$advanced_search_types or $advanced_search_types eq 'itemtypes') {
199 my $itemtypes = GetItemTypes;
202 foreach my $thisitemtype ( sort {$itemtypes->{$a}->{'description'} cmp $itemtypes->{$b}->{'description'} } keys %$itemtypes ) {
204 code => $thisitemtype,
205 selected => $selected,
206 description => $itemtypes->{$thisitemtype}->{'description'},
208 $selected = 0 if ($selected) ;
209 push @itemtypesloop, \%row;
214 my $advsearchtypes = GetAuthorisedValues($advanced_search_types);
217 for my $thisitemtype (sort {$a->{'lib'} cmp $b->{'lib'}} @$advsearchtypes) {
220 ccl => $advanced_search_types,
221 code => $thisitemtype->{authorised_value},
222 selected => $selected,
223 description => $thisitemtype->{'lib'},
225 imageurl=> getitemtypeimagelocation( 'intranet', $thisitemtype->{'imageurl'} ),
227 push @itemtypesloop, \%row;
232 if ($op eq "do_search") {
233 $template->param("no_query" => 1);
235 $template->param("no_query" => 0);
237 $template->param(itemtypeloop => \@itemtypesloop);
240 output_html_with_http_headers $input, $cookie, $template->output;