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
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 with
18 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
19 # Suite 330, Boston, MA 02111-1307 USA
24 subscription-bib-search.pl
28 this script search among all existing subscriptions.
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
61 # my $type=$query->param('type');
62 my $op = $input->param('op');
63 my $dbh = C4::Context->dbh;
65 my $startfrom=$input->param('startfrom');
66 $startfrom=0 unless $startfrom;
67 my ($template, $loggedinuser, $cookie);
70 my $query = $input->param('q');
71 # don't run the search if no search term !
72 if ($op eq "do_search" && $query) {
74 # add the itemtype limit if applicable
75 my $itemtypelimit = $input->param('itemtypelimit');
76 if ( $itemtypelimit ) {
77 my $index = C4::Context->preference("item-level_itypes") ? 'itype' : 'itemtype';
78 $query .= " AND $index=$itemtypelimit";
81 $resultsperpage= $input->param('resultsperpage');
82 $resultsperpage = 19 if(!defined $resultsperpage);
84 my ($error, $marcrecords, $total_hits) = SimpleSearch($query, $startfrom, $resultsperpage);
85 my $total = scalar @$marcrecords;
88 $template->param(query_error => $error);
89 warn "error: ".$error;
90 output_html_with_http_headers $input, $cookie, $template->output;
95 for(my $i=0;$i<$total;$i++) {
97 my $marcrecord = MARC::File::USMARC::decode($marcrecords->[$i]);
98 my $biblio = TransformMarcToKoha(C4::Context->dbh,$marcrecord,'');
100 #build the hash for the template.
101 $resultsloop{highlight} = ($i % 2)?(1):(0);
102 $resultsloop{title} = $biblio->{'title'};
103 $resultsloop{subtitle} = $biblio->{'subtitle'};
104 $resultsloop{biblionumber} = $biblio->{'biblionumber'};
105 $resultsloop{author} = $biblio->{'author'};
106 $resultsloop{publishercode} = $biblio->{'publishercode'};
107 $resultsloop{publicationyear} = $biblio->{'publicationyear'};
109 push @results, \%resultsloop;
112 ($template, $loggedinuser, $cookie)
113 = get_template_and_user({template_name => "serials/result.tmpl",
116 authnotrequired => 0,
117 flagsrequired => {serials => 1},
118 flagsrequired => {catalogue => 1},
122 # multi page display gestion
124 my $displayprev=$startfrom;
125 if(($total - (($startfrom+1)*($resultsperpage))) > 0 ){
132 if ($total>$resultsperpage)
134 for (my $i=1; $i<$total/$resultsperpage+1; $i++)
139 ($startfrom==($i-1)) && ($highlight=1);
140 push @numbers, { number => $i,
141 highlight => $highlight ,
142 searchdata=> \@results,
143 startfrom => ($i-1)};
148 my $from = $startfrom*$resultsperpage+1;
151 if($total < (($startfrom+1)*$resultsperpage))
155 $to = (($startfrom+1)*$resultsperpage);
159 resultsloop => \@results,
160 startfrom=> $startfrom,
161 displaynext=> $displaynext,
162 displayprev=> $displayprev,
163 resultsperpage => $resultsperpage,
164 startfromnext => $startfrom+1,
165 startfromprev => $startfrom-1,
171 } # end of if ($op eq "do_search" & $query)
172 elsif ($op eq "do_search") {
173 ($template, $loggedinuser, $cookie)
174 = get_template_and_user({template_name => "serials/subscription-bib-search.tmpl",
177 authnotrequired => 0,
178 flagsrequired => {catalogue => 1, serials=>1},
182 my $itemtypes = GetItemTypes;
186 foreach my $thisitemtype ( sort {$itemtypes->{$a}->{'description'} cmp $itemtypes->{$b}->{'description'} } keys %$itemtypes ) {
188 code => $thisitemtype,
189 selected => $selected,
190 description => $itemtypes->{$thisitemtype}->{'description'},
192 $selected = 0 if ($selected) ;
193 push @itemtypesloop, \%row;
195 $template->param(itemtypeloop => \@itemtypesloop);
196 $template->param("no_query" => 1);
199 ($template, $loggedinuser, $cookie)
200 = get_template_and_user({template_name => "serials/subscription-bib-search.tmpl",
203 authnotrequired => 0,
204 flagsrequired => {catalogue => 1, serials=>1},
208 my $itemtypes = GetItemTypes;
212 foreach my $thisitemtype ( sort {$itemtypes->{$a}->{'description'} cmp $itemtypes->{$b}->{'description'} } keys %$itemtypes ) {
214 code => $thisitemtype,
215 selected => $selected,
216 description => $itemtypes->{$thisitemtype}->{'description'},
218 $selected = 0 if ($selected) ;
219 push @itemtypesloop, \%row;
221 $template->param(itemtypeloop => \@itemtypesloop);
222 $template->param("no_query" => 0);
226 output_html_with_http_headers $input, $cookie, $template->output;