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.31 2003/05/11 07:31:37 rangi
23 # Removing duplicate use C4::Auth
34 use C4::Interface::CGI::Output;
37 my $type=$query->param('type');
39 #(-e "opac") && ($type='opac');
41 my ($loggedinuser, $cookie, $sessionID) = checkauth($query, ($type eq 'opac') ? (1) : (0));
43 my $startfrom=$query->param('startfrom');
44 ($startfrom) || ($startfrom=0);
46 my $subject=$query->param('subject');
47 # if it's a subject we need to use the subject.tmpl
48 my ($template, $loggedinuser, $cookie);
50 ($template, $loggedinuser, $cookie)
51 = get_template_and_user({template_name => "catalogue/subject.tmpl",
55 flagsrequired => {catalogue => 1},
59 ($template, $loggedinuser, $cookie)
60 = get_template_and_user({template_name => "catalogue/searchresults.tmpl",
64 flagsrequired => {catalogue => 1},
70 # Additional parameters for &catalogsearch
72 itemcount => 1, # If set to 1, &catalogsearch enumerates
73 # the results found and returns the number
74 # of items found, where they're located,
78 # get all the search variables
79 # we assume that C4::Search will validate these values for us
80 my %search; # Search terms. If the key is "author",
81 # then $search{author} is the author the
82 # user is looking for.
84 my @forminputs; # This is used in the form template.
86 foreach my $term (qw(keyword subject author illustrator itemnumber
87 isbn date-before class dewey branch title abstract
90 my $value = $query->param($term);
91 next unless defined $value && $value ne "";
92 # Skip blank search terms
93 $search{$term} = $value;
94 push @forminputs, { term => $term,
98 $template->param(FORMINPUTS => \@forminputs);
101 # I think it is (or was) a search from the "front" page... [st]
102 $search{'front'}=$query->param('front');
107 if (my $subject=$query->param('subjectitems')) {
109 @results=subsearch(\$blah,$subject);
112 ($count,@results)=catalogsearch(\%env,'',\%search,$num,$startfrom);
115 #my $resultsarray=\@results;
118 foreach my $result (@results) {
119 $result->{'authorhtmlescaped'}=$result->{'author'};
120 $result->{'authorhtmlescaped'}=~s/ /%20/g;
121 ($result->{'copyrightdate'}==0) && ($result->{'copyrightdate'}='');
122 ($type eq 'opac') ? ($result->{'opac'}=1) : ($result->{'opac'}=0);
123 push (@$resultsarray, $result);
125 ($resultsarray) || (@$resultsarray=());
128 if ($search{"keyword"}) {
129 $search .= "&keyword=$search{keyword}";
130 $searchdesc.="keyword $search{keyword}, ";
132 if (my $subjectitems=$query->param('subjectitems')){
133 $search .= "&subjectitems=$subjectitems";
134 $searchdesc.="subject $subjectitems, ";
137 $search .= "&subject=$subject";
138 $searchdesc.="subject $subject, ";
140 if ($search{"author"}){
141 $search .= "&author=$search{author}";
142 $searchdesc.="author $search{author}, ";
144 if ($search{"class"}){
145 $search .= "&class=$search{class}";
146 $searchdesc.="class $search{class}, ";
148 if ($search{"title"}){
149 $search .= "&title=$search{title}";
150 $searchdesc.="title $search{title}, ";
152 if ($search{"dewey"}){
153 $search .= "&dewey=$search{dewey}";
154 $searchdesc.="dewey $search{dewey}, ";
156 $search.="&ttype=$search{ttype}";
159 $template->param(startfrom => $startfrom+1);
160 ($startfrom+$num<=$count) ? ($template->param(endat => $startfrom+$num)) : ($template->param(endat => $count));
161 $template->param(numrecords => $count);
162 my $nextstartfrom=($startfrom+$num<$count) ? ($startfrom+$num) : (-1);
163 my $prevstartfrom=($startfrom-$num>=0) ? ($startfrom-$num) : (-1);
164 $template->param(nextstartfrom => $nextstartfrom);
167 ($nextstartfrom==-1) ? ($displaynext=0) : ($displaynext=1);
168 ($prevstartfrom==-1) ? ($displayprev=0) : ($displayprev=1);
169 $template->param(displaynext => $displaynext);
170 $template->param(displayprev => $displayprev);
171 ($type eq 'opac') ? ($template->param(opac => 1)) : ($template->param(opac => 0));
172 $template->param(prevstartfrom => $prevstartfrom);
173 $template->param(search => $search);
174 $template->param(searchdesc => $searchdesc);
175 $template->param(SEARCH_RESULTS => $resultsarray);
176 #$template->param(includesdir => $includes);
180 for (my $i=1; $i<$count/10+1; $i++) {
182 if ($search{"title"})
184 push @forminputs, { line => "title=$search{title}"};
187 ($startfrom==($i-1)*10) && ($highlight=1);
189 foreach (@forminputs) {
191 $formelements.="$line&";
193 $formelements=~s/ /+/g;
194 push @numbers, { number => $i, highlight => $highlight , FORMELEMENTS => $formelements, FORMINPUTS => \@forminputs, startfrom => ($i-1)*10, opac => (($type eq 'opac') ? (1) : (0))};
199 $template->param(numbers => \@numbers);
200 if (C4::Context->preference('marc') eq 'on') {
201 $template->param(script => "MARCdetail.pl");
203 $template->param(script => "detail.pl");
207 output_html_with_http_headers $query, $cookie, $template->output;