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.35 2004/04/07 22:43:04 rangi
25 # Revision 1.34 2004/02/11 08:35:31 tipaul
26 # synch'ing 2.0.0 branch and head
28 # Revision 1.33 2003/12/19 17:28:03 tipaul
31 # Revision 1.32.2.2 2004/01/13 17:33:39 tipaul
32 # removing useless (& buggy here) checkauth
34 # Revision 1.32.2.1 2003/12/19 17:28:42 tipaul
37 # Revision 1.32 2003/06/11 18:37:55 tonnesen
38 # Using boolean_preference instead of preference for 'marc' setting
40 # Revision 1.31 2003/05/11 07:31:37 rangi
41 # Removing duplicate use C4::Auth
52 use C4::Interface::CGI::Output;
55 my $type=$query->param('type');
57 my $startfrom=$query->param('startfrom');
58 ($startfrom) || ($startfrom=0);
60 my $subject=$query->param('subject');
61 # if it's a subject we need to use the subject.tmpl
62 my ($template, $loggedinuser, $cookie);
64 ($template, $loggedinuser, $cookie)
65 = get_template_and_user({template_name => "catalogue/subject.tmpl",
69 flagsrequired => {catalogue => 1},
73 ($template, $loggedinuser, $cookie)
74 = get_template_and_user({template_name => "catalogue/searchresults.tmpl",
78 flagsrequired => {catalogue => 1},
84 # Additional parameters for &catalogsearch
86 itemcount => 1, # If set to 1, &catalogsearch enumerates
87 # the results found and returns the number
88 # of items found, where they're located,
92 # get all the search variables
93 # we assume that C4::Search will validate these values for us
94 my %search; # Search terms. If the key is "author",
95 # then $search{author} is the author the
96 # user is looking for.
98 my @forminputs; # This is used in the form template.
100 foreach my $term (qw(keyword subject author illustrator itemnumber
101 isbn date-before class dewey branch title abstract
104 my $value = $query->param($term);
105 next unless defined $value && $value ne "";
106 # Skip blank search terms
107 $search{$term} = $value;
108 push @forminputs, { term => $term,
112 $template->param(FORMINPUTS => \@forminputs);
115 # I think it is (or was) a search from the "front" page... [st]
116 $search{'front'}=$query->param('front');
121 if (my $subject=$query->param('subjectitems')) {
123 @results=subsearch(\$blah,$subject);
126 ($count,@results)=catalogsearch(\%env,'',\%search,$num,$startfrom);
129 #my $resultsarray=\@results;
132 foreach my $result (@results) {
133 $result->{'authorhtmlescaped'}=$result->{'author'};
134 $result->{'authorhtmlescaped'}=~s/ /%20/g;
135 ($result->{'copyrightdate'}==0) && ($result->{'copyrightdate'}='');
136 ($type eq 'opac') ? ($result->{'opac'}=1) : ($result->{'opac'}=0);
137 push (@$resultsarray, $result);
139 ($resultsarray) || (@$resultsarray=());
142 if ($search{"keyword"}) {
143 $search .= "&keyword=$search{keyword}";
144 $searchdesc.="keyword $search{keyword}, ";
146 if (my $subjectitems=$query->param('subjectitems')){
147 $search .= "&subjectitems=$subjectitems";
148 $searchdesc.="subject $subjectitems, ";
151 $search .= "&subject=$subject";
152 $searchdesc.="subject $subject, ";
154 if ($search{"author"}){
155 $search .= "&author=$search{author}";
156 $searchdesc.="author $search{author}, ";
158 if ($search{"class"}){
159 $search .= "&class=$search{class}";
160 $searchdesc.="class $search{class}, ";
162 if ($search{"title"}){
163 $search .= "&title=$search{title}";
164 $searchdesc.="title $search{title}, ";
166 if ($search{"dewey"}){
167 $search .= "&dewey=$search{dewey}";
168 $searchdesc.="dewey $search{dewey}, ";
170 if ($search{"illustrator"}){
171 $search .= "&illustrator=$search{illustrator}";
172 $searchdesc.="illustrator $search{illustrator}, ";
174 if ($search{"itemnumber"}){
175 $search .= "&itemnumber=$search{itemnumber}";
176 $searchdesc.="barcode $search{itemnumber}, ";
178 $search.="&ttype=$search{ttype}";
181 $template->param(startfrom => $startfrom+1);
182 ($startfrom+$num<=$count) ? ($template->param(endat => $startfrom+$num)) : ($template->param(endat => $count));
183 $template->param(numrecords => $count);
184 my $nextstartfrom=($startfrom+$num<$count) ? ($startfrom+$num) : (-1);
185 my $prevstartfrom=($startfrom-$num>=0) ? ($startfrom-$num) : (-1);
186 $template->param(nextstartfrom => $nextstartfrom);
189 ($nextstartfrom==-1) ? ($displaynext=0) : ($displaynext=1);
190 ($prevstartfrom==-1) ? ($displayprev=0) : ($displayprev=1);
191 $template->param(displaynext => $displaynext);
192 $template->param(displayprev => $displayprev);
193 ($type eq 'opac') ? ($template->param(opac => 1)) : ($template->param(opac => 0));
194 $template->param(prevstartfrom => $prevstartfrom);
195 $template->param(search => $search);
196 $template->param(searchdesc => $searchdesc);
197 $template->param(SEARCH_RESULTS => $resultsarray);
198 #$template->param(includesdir => $includes);
202 for (my $i=1; $i<$count/10+1; $i++) {
204 if ($search{"title"})
206 push @forminputs, { line => "title=$search{title}"};
209 ($startfrom==($i-1)*10) && ($highlight=1);
211 foreach (@forminputs) {
213 $formelements.="$line&";
215 $formelements=~s/ /+/g;
216 push @numbers, { number => $i, highlight => $highlight , FORMELEMENTS => $formelements, FORMINPUTS => \@forminputs, startfrom => ($i-1)*10, opac => (($type eq 'opac') ? (1) : (0))};
221 $template->param(numbers => \@numbers);
222 if (C4::Context->boolean_preference('marc') eq '1') {
223 $template->param(script => "MARCdetail.pl");
225 $template->param(script => "detail.pl");
228 if ($search{"itemnumber"} && $count == 1){
229 # if its a barcode search by definition we will only have one result.
230 # And if we have a result
231 # lets jump straight to the detail.pl page
232 print $query->redirect("/cgi-bin/koha/detail.pl?type=intra&bib=$results[0]->{'biblionumber'}");
237 output_html_with_http_headers $query, $cookie, $template->output;