3 # Copyright 2000-2002 Katipo Communications
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
29 use C4::Interface::CGI::Output;
32 my $type=$query->param('type');
34 #(-e "opac") && ($type='opac');
36 my ($loggedinuser, $cookie, $sessionID) = checkauth($query, ($type eq 'opac') ? (1) : (0));
38 my $startfrom=$query->param('startfrom');
39 ($startfrom) || ($startfrom=0);
41 my $subject=$query->param('subject');
42 # if it's a subject we need to use the subject.tmpl
43 my ($template, $loggedinuser, $cookie);
45 ($template, $loggedinuser, $cookie)
46 = get_template_and_user({template_name => "catalogue/subject.tmpl",
50 flagsrequired => {catalogue => 1},
54 ($template, $loggedinuser, $cookie)
55 = get_template_and_user({template_name => "catalogue/searchresults.tmpl",
59 flagsrequired => {catalogue => 1},
65 # Additional parameters for &catalogsearch
67 itemcount => 1, # If set to 1, &catalogsearch enumerates
68 # the results found and returns the number
69 # of items found, where they're located,
73 # get all the search variables
74 # we assume that C4::Search will validate these values for us
75 my %search; # Search terms. If the key is "author",
76 # then $search{author} is the author the
77 # user is looking for.
79 my @forminputs; # This is used in the form template.
81 foreach my $term (qw(keyword subject author illustrator itemnumber
82 isbn date-before class dewey branch title abstract
85 my $value = $query->param($term);
86 next unless defined $value && $value ne "";
87 # Skip blank search terms
88 $search{$term} = $value;
89 push @forminputs, { term => $term,
93 $template->param(FORMINPUTS => \@forminputs);
96 # I think it is (or was) a search from the "front" page... [st]
97 $search{'front'}=$query->param('front');
102 if (my $subject=$query->param('subjectitems')) {
104 @results=subsearch(\$blah,$subject);
107 ($count,@results)=catalogsearch(\%env,'',\%search,$num,$startfrom);
110 #my $resultsarray=\@results;
113 foreach my $result (@results) {
114 $result->{'authorhtmlescaped'}=$result->{'author'};
115 $result->{'authorhtmlescaped'}=~s/ /%20/g;
116 ($result->{'copyrightdate'}==0) && ($result->{'copyrightdate'}='');
117 ($type eq 'opac') ? ($result->{'opac'}=1) : ($result->{'opac'}=0);
118 push (@$resultsarray, $result);
120 ($resultsarray) || (@$resultsarray=());
123 if ($search{"keyword"}) {
124 $search .= "&keyword=$search{keyword}";
125 $searchdesc.="keyword $search{keyword}, ";
127 if (my $subjectitems=$query->param('subjectitems')){
128 $search .= "&subjectitems=$subjectitems";
129 $searchdesc.="subject $subjectitems, ";
132 $search .= "&subject=$subject";
133 $searchdesc.="subject $subject, ";
135 if ($search{"author"}){
136 $search .= "&author=$search{author}";
137 $searchdesc.="author $search{author}, ";
139 if ($search{"class"}){
140 $search .= "&class=$search{class}";
141 $searchdesc.="class $search{class}, ";
143 if ($search{"title"}){
144 $search .= "&title=$search{title}";
145 $searchdesc.="title $search{title}, ";
147 if ($search{"dewey"}){
148 $search .= "&dewey=$search{dewey}";
149 $searchdesc.="dewey $search{dewey}, ";
151 $search.="&ttype=$search{ttype}";
154 $template->param(startfrom => $startfrom+1);
155 ($startfrom+$num<=$count) ? ($template->param(endat => $startfrom+$num)) : ($template->param(endat => $count));
156 $template->param(numrecords => $count);
157 my $nextstartfrom=($startfrom+$num<$count) ? ($startfrom+$num) : (-1);
158 my $prevstartfrom=($startfrom-$num>=0) ? ($startfrom-$num) : (-1);
159 $template->param(nextstartfrom => $nextstartfrom);
162 ($nextstartfrom==-1) ? ($displaynext=0) : ($displaynext=1);
163 ($prevstartfrom==-1) ? ($displayprev=0) : ($displayprev=1);
164 $template->param(displaynext => $displaynext);
165 $template->param(displayprev => $displayprev);
166 ($type eq 'opac') ? ($template->param(opac => 1)) : ($template->param(opac => 0));
167 $template->param(prevstartfrom => $prevstartfrom);
168 $template->param(search => $search);
169 $template->param(searchdesc => $searchdesc);
170 $template->param(SEARCH_RESULTS => $resultsarray);
171 #$template->param(includesdir => $includes);
175 for (my $i=1; $i<$count/10+1; $i++) {
177 if ($search{"title"})
179 push @forminputs, { line => "title=$search{title}"};
182 ($startfrom==($i-1)*10) && ($highlight=1);
184 foreach (@forminputs) {
186 $formelements.="$line&";
188 $formelements=~s/ /+/g;
189 push @numbers, { number => $i, highlight => $highlight , FORMELEMENTS => $formelements, FORMINPUTS => \@forminputs, startfrom => ($i-1)*10, opac => (($type eq 'opac') ? (1) : (0))};
194 $template->param(numbers => \@numbers);
195 if (C4::Context->preference('acquisitions') eq 'simple') {
196 $template->param(script => "MARCdetail.pl");
198 $template->param(script => "detail.pl");
202 output_html_with_http_headers $query, $cookie, $template->output;