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.32 2003/06/11 18:37:55 tonnesen
23 # Using boolean_preference instead of preference for 'marc' setting
25 # Revision 1.31 2003/05/11 07:31:37 rangi
26 # Removing duplicate use C4::Auth
37 use C4::Interface::CGI::Output;
40 my $type=$query->param('type');
42 #(-e "opac") && ($type='opac');
44 my ($loggedinuser, $cookie, $sessionID) = checkauth($query, ($type eq 'opac') ? (1) : (0));
46 my $startfrom=$query->param('startfrom');
47 ($startfrom) || ($startfrom=0);
49 my $subject=$query->param('subject');
50 # if it's a subject we need to use the subject.tmpl
51 my ($template, $loggedinuser, $cookie);
53 ($template, $loggedinuser, $cookie)
54 = get_template_and_user({template_name => "catalogue/subject.tmpl",
58 flagsrequired => {catalogue => 1},
62 ($template, $loggedinuser, $cookie)
63 = get_template_and_user({template_name => "catalogue/searchresults.tmpl",
67 flagsrequired => {catalogue => 1},
73 # Additional parameters for &catalogsearch
75 itemcount => 1, # If set to 1, &catalogsearch enumerates
76 # the results found and returns the number
77 # of items found, where they're located,
81 # get all the search variables
82 # we assume that C4::Search will validate these values for us
83 my %search; # Search terms. If the key is "author",
84 # then $search{author} is the author the
85 # user is looking for.
87 my @forminputs; # This is used in the form template.
89 foreach my $term (qw(keyword subject author illustrator itemnumber
90 isbn date-before class dewey branch title abstract
93 my $value = $query->param($term);
94 next unless defined $value && $value ne "";
95 # Skip blank search terms
96 $search{$term} = $value;
97 push @forminputs, { term => $term,
101 $template->param(FORMINPUTS => \@forminputs);
104 # I think it is (or was) a search from the "front" page... [st]
105 $search{'front'}=$query->param('front');
110 if (my $subject=$query->param('subjectitems')) {
112 @results=subsearch(\$blah,$subject);
115 ($count,@results)=catalogsearch(\%env,'',\%search,$num,$startfrom);
118 #my $resultsarray=\@results;
121 foreach my $result (@results) {
122 $result->{'authorhtmlescaped'}=$result->{'author'};
123 $result->{'authorhtmlescaped'}=~s/ /%20/g;
124 ($result->{'copyrightdate'}==0) && ($result->{'copyrightdate'}='');
125 ($type eq 'opac') ? ($result->{'opac'}=1) : ($result->{'opac'}=0);
126 push (@$resultsarray, $result);
128 ($resultsarray) || (@$resultsarray=());
131 if ($search{"keyword"}) {
132 $search .= "&keyword=$search{keyword}";
133 $searchdesc.="keyword $search{keyword}, ";
135 if (my $subjectitems=$query->param('subjectitems')){
136 $search .= "&subjectitems=$subjectitems";
137 $searchdesc.="subject $subjectitems, ";
140 $search .= "&subject=$subject";
141 $searchdesc.="subject $subject, ";
143 if ($search{"author"}){
144 $search .= "&author=$search{author}";
145 $searchdesc.="author $search{author}, ";
147 if ($search{"class"}){
148 $search .= "&class=$search{class}";
149 $searchdesc.="class $search{class}, ";
151 if ($search{"title"}){
152 $search .= "&title=$search{title}";
153 $searchdesc.="title $search{title}, ";
155 if ($search{"dewey"}){
156 $search .= "&dewey=$search{dewey}";
157 $searchdesc.="dewey $search{dewey}, ";
159 $search.="&ttype=$search{ttype}";
162 $template->param(startfrom => $startfrom+1);
163 ($startfrom+$num<=$count) ? ($template->param(endat => $startfrom+$num)) : ($template->param(endat => $count));
164 $template->param(numrecords => $count);
165 my $nextstartfrom=($startfrom+$num<$count) ? ($startfrom+$num) : (-1);
166 my $prevstartfrom=($startfrom-$num>=0) ? ($startfrom-$num) : (-1);
167 $template->param(nextstartfrom => $nextstartfrom);
170 ($nextstartfrom==-1) ? ($displaynext=0) : ($displaynext=1);
171 ($prevstartfrom==-1) ? ($displayprev=0) : ($displayprev=1);
172 $template->param(displaynext => $displaynext);
173 $template->param(displayprev => $displayprev);
174 ($type eq 'opac') ? ($template->param(opac => 1)) : ($template->param(opac => 0));
175 $template->param(prevstartfrom => $prevstartfrom);
176 $template->param(search => $search);
177 $template->param(searchdesc => $searchdesc);
178 $template->param(SEARCH_RESULTS => $resultsarray);
179 #$template->param(includesdir => $includes);
183 for (my $i=1; $i<$count/10+1; $i++) {
185 if ($search{"title"})
187 push @forminputs, { line => "title=$search{title}"};
190 ($startfrom==($i-1)*10) && ($highlight=1);
192 foreach (@forminputs) {
194 $formelements.="$line&";
196 $formelements=~s/ /+/g;
197 push @numbers, { number => $i, highlight => $highlight , FORMELEMENTS => $formelements, FORMINPUTS => \@forminputs, startfrom => ($i-1)*10, opac => (($type eq 'opac') ? (1) : (0))};
202 $template->param(numbers => \@numbers);
203 if (C4::Context->boolean_preference('marc') eq '1') {
204 $template->param(script => "MARCdetail.pl");
206 $template->param(script => "detail.pl");
210 output_html_with_http_headers $query, $cookie, $template->output;