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
22 # Revision 1.36 2005/06/20 14:39:11 tipaul
23 # synch'ing 2.2 and head
25 # Revision 1.35.2.1 2005/05/27 10:02:50 hdl
26 # Bug Fixing : Using old search.pl with subjectitems In normal mode display.
27 # Problem : Changing Page doesn't work.
29 # Revision 1.35 2004/04/07 22:43:04 rangi
32 # Revision 1.34 2004/02/11 08:35:31 tipaul
33 # synch'ing 2.0.0 branch and head
35 # Revision 1.33 2003/12/19 17:28:03 tipaul
38 # Revision 1.32.2.2 2004/01/13 17:33:39 tipaul
39 # removing useless (& buggy here) checkauth
41 # Revision 1.32.2.1 2003/12/19 17:28:42 tipaul
44 # Revision 1.32 2003/06/11 18:37:55 tonnesen
45 # Using boolean_preference instead of preference for 'marc' setting
47 # Revision 1.31 2003/05/11 07:31:37 rangi
48 # Removing duplicate use C4::Auth
59 use C4::Interface::CGI::Output;
62 my $type=$query->param('type');
64 my $startfrom=$query->param('startfrom');
65 ($startfrom) || ($startfrom=0);
67 my $subject=$query->param('subject');
68 # if it's a subject we need to use the subject.tmpl
69 my ($template, $loggedinuser, $cookie);
71 ($template, $loggedinuser, $cookie)
72 = get_template_and_user({template_name => "catalogue/subject.tmpl",
76 flagsrequired => {catalogue => 1},
80 ($template, $loggedinuser, $cookie)
81 = get_template_and_user({template_name => "catalogue/searchresults.tmpl",
85 flagsrequired => {catalogue => 1},
91 # Additional parameters for &catalogsearch
93 itemcount => 1, # If set to 1, &catalogsearch enumerates
94 # the results found and returns the number
95 # of items found, where they're located,
99 # get all the search variables
100 # we assume that C4::Search will validate these values for us
101 my %search; # Search terms. If the key is "author",
102 # then $search{author} is the author the
103 # user is looking for.
105 my @forminputs; # This is used in the form template.
107 foreach my $term (qw(keyword subject author illustrator itemnumber
108 isbn date-before class dewey branch title abstract
109 publisher ttype subjectitems))
111 my $value = $query->param($term);
112 next unless defined $value && $value ne "";
113 # Skip blank search terms
114 $search{$term} = $value;
115 push @forminputs, { term => $term,
119 $template->param(FORMINPUTS => \@forminputs);
122 # I think it is (or was) a search from the "front" page... [st]
123 $search{'front'}=$query->param('front');
128 if (my $subject=$query->param('subjectitems')) {
130 @results=subsearch(\$blah,$subject);
133 ($count,@results)=catalogsearch(\%env,'',\%search,$num,$startfrom);
136 #my $resultsarray=\@results;
139 foreach my $result (@results) {
140 $result->{'authorhtmlescaped'}=$result->{'author'};
141 $result->{'authorhtmlescaped'}=~s/ /%20/g;
142 ($result->{'copyrightdate'}==0) && ($result->{'copyrightdate'}='');
143 ($type eq 'opac') ? ($result->{'opac'}=1) : ($result->{'opac'}=0);
144 push (@$resultsarray, $result);
146 ($resultsarray) || (@$resultsarray=());
149 if ($search{"keyword"}) {
150 $search .= "&keyword=$search{keyword}";
151 $searchdesc.="keyword $search{keyword}, ";
153 if (my $subjectitems=$query->param('subjectitems')){
154 $search .= "&subjectitems=$subjectitems";
155 $searchdesc.="subject $subjectitems, ";
158 $search .= "&subject=$subject";
159 $searchdesc.="subject $subject, ";
161 if ($search{"author"}){
162 $search .= "&author=$search{author}";
163 $searchdesc.="author $search{author}, ";
165 if ($search{"class"}){
166 $search .= "&class=$search{class}";
167 $searchdesc.="class $search{class}, ";
169 if ($search{"title"}){
170 $search .= "&title=$search{title}";
171 $searchdesc.="title $search{title}, ";
173 if ($search{"dewey"}){
174 $search .= "&dewey=$search{dewey}";
175 $searchdesc.="dewey $search{dewey}, ";
177 if ($search{"illustrator"}){
178 $search .= "&illustrator=$search{illustrator}";
179 $searchdesc.="illustrator $search{illustrator}, ";
181 if ($search{"itemnumber"}){
182 $search .= "&itemnumber=$search{itemnumber}";
183 $searchdesc.="barcode $search{itemnumber}, ";
185 $search.="&ttype=$search{ttype}";
188 $template->param(startfrom => $startfrom+1);
189 ($startfrom+$num<=$count) ? ($template->param(endat => $startfrom+$num)) : ($template->param(endat => $count));
190 $template->param(numrecords => $count);
191 my $nextstartfrom=($startfrom+$num<$count) ? ($startfrom+$num) : (-1);
192 my $prevstartfrom=($startfrom-$num>=0) ? ($startfrom-$num) : (-1);
193 $template->param(nextstartfrom => $nextstartfrom);
196 ($nextstartfrom==-1) ? ($displaynext=0) : ($displaynext=1);
197 ($prevstartfrom==-1) ? ($displayprev=0) : ($displayprev=1);
198 $template->param(displaynext => $displaynext);
199 $template->param(displayprev => $displayprev);
200 ($type eq 'opac') ? ($template->param(opac => 1)) : ($template->param(opac => 0));
201 $template->param(prevstartfrom => $prevstartfrom);
202 $template->param(search => $search);
203 $template->param(searchdesc => $searchdesc);
204 $template->param(SEARCH_RESULTS => $resultsarray);
205 #$template->param(includesdir => $includes);
209 for (my $i=1; $i<$count/10+1; $i++) {
211 if ($search{"title"})
213 push @forminputs, { line => "title=$search{title}"};
216 ($startfrom==($i-1)*10) && ($highlight=1);
218 foreach (@forminputs) {
220 $formelements.="$line&";
222 $formelements=~s/ /+/g;
223 push @numbers, { number => $i, highlight => $highlight , FORMELEMENTS => $formelements, FORMINPUTS => \@forminputs, startfrom => ($i-1)*10, opac => (($type eq 'opac') ? (1) : (0))};
228 $template->param(numbers => \@numbers);
229 if (C4::Context->boolean_preference('marc') eq '1') {
230 $template->param(script => "MARCdetail.pl");
232 $template->param(script => "detail.pl");
235 if ($search{"itemnumber"} && $count == 1){
236 # if its a barcode search by definition we will only have one result.
237 # And if we have a result
238 # lets jump straight to the detail.pl page
239 print $query->redirect("/cgi-bin/koha/detail.pl?type=intra&bib=$results[0]->{'biblionumber'}");
244 output_html_with_http_headers $query, $cookie, $template->output;