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.34 2004/02/11 08:35:31 tipaul
23 # synch'ing 2.0.0 branch and head
25 # Revision 1.33 2003/12/19 17:28:03 tipaul
28 # Revision 1.32.2.2 2004/01/13 17:33:39 tipaul
29 # removing useless (& buggy here) checkauth
31 # Revision 1.32.2.1 2003/12/19 17:28:42 tipaul
34 # Revision 1.32 2003/06/11 18:37:55 tonnesen
35 # Using boolean_preference instead of preference for 'marc' setting
37 # Revision 1.31 2003/05/11 07:31:37 rangi
38 # Removing duplicate use C4::Auth
49 use C4::Interface::CGI::Output;
52 my $type=$query->param('type');
54 my $startfrom=$query->param('startfrom');
55 ($startfrom) || ($startfrom=0);
57 my $subject=$query->param('subject');
58 # if it's a subject we need to use the subject.tmpl
59 my ($template, $loggedinuser, $cookie);
61 ($template, $loggedinuser, $cookie)
62 = get_template_and_user({template_name => "catalogue/subject.tmpl",
66 flagsrequired => {catalogue => 1},
70 ($template, $loggedinuser, $cookie)
71 = get_template_and_user({template_name => "catalogue/searchresults.tmpl",
75 flagsrequired => {catalogue => 1},
81 # Additional parameters for &catalogsearch
83 itemcount => 1, # If set to 1, &catalogsearch enumerates
84 # the results found and returns the number
85 # of items found, where they're located,
89 # get all the search variables
90 # we assume that C4::Search will validate these values for us
91 my %search; # Search terms. If the key is "author",
92 # then $search{author} is the author the
93 # user is looking for.
95 my @forminputs; # This is used in the form template.
97 foreach my $term (qw(keyword subject author illustrator itemnumber
98 isbn date-before class dewey branch title abstract
101 my $value = $query->param($term);
102 next unless defined $value && $value ne "";
103 # Skip blank search terms
104 $search{$term} = $value;
105 push @forminputs, { term => $term,
109 $template->param(FORMINPUTS => \@forminputs);
112 # I think it is (or was) a search from the "front" page... [st]
113 $search{'front'}=$query->param('front');
118 if (my $subject=$query->param('subjectitems')) {
120 @results=subsearch(\$blah,$subject);
123 ($count,@results)=catalogsearch(\%env,'',\%search,$num,$startfrom);
126 #my $resultsarray=\@results;
129 foreach my $result (@results) {
130 $result->{'authorhtmlescaped'}=$result->{'author'};
131 $result->{'authorhtmlescaped'}=~s/ /%20/g;
132 ($result->{'copyrightdate'}==0) && ($result->{'copyrightdate'}='');
133 ($type eq 'opac') ? ($result->{'opac'}=1) : ($result->{'opac'}=0);
134 push (@$resultsarray, $result);
136 ($resultsarray) || (@$resultsarray=());
139 if ($search{"keyword"}) {
140 $search .= "&keyword=$search{keyword}";
141 $searchdesc.="keyword $search{keyword}, ";
143 if (my $subjectitems=$query->param('subjectitems')){
144 $search .= "&subjectitems=$subjectitems";
145 $searchdesc.="subject $subjectitems, ";
148 $search .= "&subject=$subject";
149 $searchdesc.="subject $subject, ";
151 if ($search{"author"}){
152 $search .= "&author=$search{author}";
153 $searchdesc.="author $search{author}, ";
155 if ($search{"class"}){
156 $search .= "&class=$search{class}";
157 $searchdesc.="class $search{class}, ";
159 if ($search{"title"}){
160 $search .= "&title=$search{title}";
161 $searchdesc.="title $search{title}, ";
163 if ($search{"dewey"}){
164 $search .= "&dewey=$search{dewey}";
165 $searchdesc.="dewey $search{dewey}, ";
167 if ($search{"illustrator"}){
168 $search .= "&illustrator=$search{illustrator}";
169 $searchdesc.="illustrator $search{illustrator}, ";
171 if ($search{"itemnumber"}){
172 $search .= "&itemnumber=$search{itemnumber}";
173 $searchdesc.="barcode $search{itemnumber}, ";
175 $search.="&ttype=$search{ttype}";
178 $template->param(startfrom => $startfrom+1);
179 ($startfrom+$num<=$count) ? ($template->param(endat => $startfrom+$num)) : ($template->param(endat => $count));
180 $template->param(numrecords => $count);
181 my $nextstartfrom=($startfrom+$num<$count) ? ($startfrom+$num) : (-1);
182 my $prevstartfrom=($startfrom-$num>=0) ? ($startfrom-$num) : (-1);
183 $template->param(nextstartfrom => $nextstartfrom);
186 ($nextstartfrom==-1) ? ($displaynext=0) : ($displaynext=1);
187 ($prevstartfrom==-1) ? ($displayprev=0) : ($displayprev=1);
188 $template->param(displaynext => $displaynext);
189 $template->param(displayprev => $displayprev);
190 ($type eq 'opac') ? ($template->param(opac => 1)) : ($template->param(opac => 0));
191 $template->param(prevstartfrom => $prevstartfrom);
192 $template->param(search => $search);
193 $template->param(searchdesc => $searchdesc);
194 $template->param(SEARCH_RESULTS => $resultsarray);
195 #$template->param(includesdir => $includes);
199 for (my $i=1; $i<$count/10+1; $i++) {
201 if ($search{"title"})
203 push @forminputs, { line => "title=$search{title}"};
206 ($startfrom==($i-1)*10) && ($highlight=1);
208 foreach (@forminputs) {
210 $formelements.="$line&";
212 $formelements=~s/ /+/g;
213 push @numbers, { number => $i, highlight => $highlight , FORMELEMENTS => $formelements, FORMINPUTS => \@forminputs, startfrom => ($i-1)*10, opac => (($type eq 'opac') ? (1) : (0))};
218 $template->param(numbers => \@numbers);
219 if (C4::Context->boolean_preference('marc') eq '1') {
220 $template->param(script => "MARCdetail.pl");
222 $template->param(script => "detail.pl");
226 output_html_with_http_headers $query, $cookie, $template->output;