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.33 2003/12/19 17:28:03 tipaul
25 # Revision 1.32 2003/06/11 18:37:55 tonnesen
26 # Using boolean_preference instead of preference for 'marc' setting
28 # Revision 1.31 2003/05/11 07:31:37 rangi
29 # Removing duplicate use C4::Auth
40 use C4::Interface::CGI::Output;
43 my $type=$query->param('type');
45 #(-e "opac") && ($type='opac');
47 my ($loggedinuser, $cookie, $sessionID) = checkauth($query, ($type eq 'opac') ? (1) : (0));
49 my $startfrom=$query->param('startfrom');
50 ($startfrom) || ($startfrom=0);
52 my $subject=$query->param('subject');
53 # if it's a subject we need to use the subject.tmpl
54 my ($template, $loggedinuser, $cookie);
56 ($template, $loggedinuser, $cookie)
57 = get_template_and_user({template_name => "catalogue/subject.tmpl",
61 flagsrequired => {catalogue => 1},
65 ($template, $loggedinuser, $cookie)
66 = get_template_and_user({template_name => "catalogue/searchresults.tmpl",
70 flagsrequired => {catalogue => 1},
76 # Additional parameters for &catalogsearch
78 itemcount => 1, # If set to 1, &catalogsearch enumerates
79 # the results found and returns the number
80 # of items found, where they're located,
84 # get all the search variables
85 # we assume that C4::Search will validate these values for us
86 my %search; # Search terms. If the key is "author",
87 # then $search{author} is the author the
88 # user is looking for.
90 my @forminputs; # This is used in the form template.
92 foreach my $term (qw(keyword subject author illustrator itemnumber
93 isbn date-before class dewey branch title abstract
96 my $value = $query->param($term);
97 next unless defined $value && $value ne "";
98 # Skip blank search terms
99 $search{$term} = $value;
100 push @forminputs, { term => $term,
104 $template->param(FORMINPUTS => \@forminputs);
107 # I think it is (or was) a search from the "front" page... [st]
108 $search{'front'}=$query->param('front');
113 if (my $subject=$query->param('subjectitems')) {
115 @results=subsearch(\$blah,$subject);
118 ($count,@results)=catalogsearch(\%env,'',\%search,$num,$startfrom);
121 #my $resultsarray=\@results;
124 foreach my $result (@results) {
125 $result->{'authorhtmlescaped'}=$result->{'author'};
126 $result->{'authorhtmlescaped'}=~s/ /%20/g;
127 ($result->{'copyrightdate'}==0) && ($result->{'copyrightdate'}='');
128 ($type eq 'opac') ? ($result->{'opac'}=1) : ($result->{'opac'}=0);
129 push (@$resultsarray, $result);
131 ($resultsarray) || (@$resultsarray=());
134 if ($search{"keyword"}) {
135 $search .= "&keyword=$search{keyword}";
136 $searchdesc.="keyword $search{keyword}, ";
138 if (my $subjectitems=$query->param('subjectitems')){
139 $search .= "&subjectitems=$subjectitems";
140 $searchdesc.="subject $subjectitems, ";
143 $search .= "&subject=$subject";
144 $searchdesc.="subject $subject, ";
146 if ($search{"author"}){
147 $search .= "&author=$search{author}";
148 $searchdesc.="author $search{author}, ";
150 if ($search{"class"}){
151 $search .= "&class=$search{class}";
152 $searchdesc.="class $search{class}, ";
154 if ($search{"title"}){
155 $search .= "&title=$search{title}";
156 $searchdesc.="title $search{title}, ";
158 if ($search{"dewey"}){
159 $search .= "&dewey=$search{dewey}";
160 $searchdesc.="dewey $search{dewey}, ";
162 if ($search{"illustrator"}){
163 $search .= "&illustrator=$search{illustrator}";
164 $searchdesc.="illustrator $search{illustrator}, ";
166 if ($search{"itemnumber"}){
167 $search .= "&itemnumber=$search{itemnumber}";
168 $searchdesc.="barcode $search{itemnumber}, ";
170 $search.="&ttype=$search{ttype}";
173 $template->param(startfrom => $startfrom+1);
174 ($startfrom+$num<=$count) ? ($template->param(endat => $startfrom+$num)) : ($template->param(endat => $count));
175 $template->param(numrecords => $count);
176 my $nextstartfrom=($startfrom+$num<$count) ? ($startfrom+$num) : (-1);
177 my $prevstartfrom=($startfrom-$num>=0) ? ($startfrom-$num) : (-1);
178 $template->param(nextstartfrom => $nextstartfrom);
181 ($nextstartfrom==-1) ? ($displaynext=0) : ($displaynext=1);
182 ($prevstartfrom==-1) ? ($displayprev=0) : ($displayprev=1);
183 $template->param(displaynext => $displaynext);
184 $template->param(displayprev => $displayprev);
185 ($type eq 'opac') ? ($template->param(opac => 1)) : ($template->param(opac => 0));
186 $template->param(prevstartfrom => $prevstartfrom);
187 $template->param(search => $search);
188 $template->param(searchdesc => $searchdesc);
189 $template->param(SEARCH_RESULTS => $resultsarray);
190 #$template->param(includesdir => $includes);
194 for (my $i=1; $i<$count/10+1; $i++) {
196 if ($search{"title"})
198 push @forminputs, { line => "title=$search{title}"};
201 ($startfrom==($i-1)*10) && ($highlight=1);
203 foreach (@forminputs) {
205 $formelements.="$line&";
207 $formelements=~s/ /+/g;
208 push @numbers, { number => $i, highlight => $highlight , FORMELEMENTS => $formelements, FORMINPUTS => \@forminputs, startfrom => ($i-1)*10, opac => (($type eq 'opac') ? (1) : (0))};
213 $template->param(numbers => \@numbers);
214 if (C4::Context->boolean_preference('marc') eq '1') {
215 $template->param(script => "MARCdetail.pl");
217 $template->param(script => "detail.pl");
221 output_html_with_http_headers $query, $cookie, $template->output;