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, { line => "$term=$value" };
92 $template->param(FORMINPUTS => \@forminputs);
95 # I think it is (or was) a search from the "front" page... [st]
96 $search{'front'}=$query->param('front');
101 if (my $subject=$query->param('subjectitems')) {
103 @results=subsearch(\$blah,$subject);
106 ($count,@results)=catalogsearch(\%env,'',\%search,$num,$startfrom);
109 #my $resultsarray=\@results;
112 foreach my $result (@results) {
113 $result->{'authorhtmlescaped'}=$result->{'author'};
114 $result->{'authorhtmlescaped'}=~s/ /%20/g;
115 ($result->{'copyrightdate'}==0) && ($result->{'copyrightdate'}='');
116 ($type eq 'opac') ? ($result->{'opac'}=1) : ($result->{'opac'}=0);
117 push (@$resultsarray, $result);
119 ($resultsarray) || (@$resultsarray=());
122 if ($search{"keyword"}) {
123 $search .= "&keyword=$search{keyword}";
124 $searchdesc.="keyword $search{keyword}, ";
126 if (my $subjectitems=$query->param('subjectitems')){
127 $search .= "&subjectitems=$subjectitems";
128 $searchdesc.="subject $subjectitems, ";
131 $search .= "&subject=$subject";
132 $searchdesc.="subject $subject, ";
134 if ($search{"author"}){
135 $search .= "&author=$search{author}";
136 $searchdesc.="author $search{author}, ";
138 if ($search{"class"}){
139 $search .= "&class=$search{class}";
140 $searchdesc.="class $search{class}, ";
142 if ($search{"title"}){
143 $search .= "&title=$search{title}";
144 $searchdesc.="title $search{title}, ";
146 if ($search{"dewey"}){
147 $search .= "&dewey=$search{dewey}";
148 $searchdesc.="dewey $search{dewey}, ";
150 $search.="&ttype=$search{ttype}";
153 $template->param(startfrom => $startfrom+1);
154 ($startfrom+$num<=$count) ? ($template->param(endat => $startfrom+$num)) : ($template->param(endat => $count));
155 $template->param(numrecords => $count);
156 my $nextstartfrom=($startfrom+$num<$count) ? ($startfrom+$num) : (-1);
157 my $prevstartfrom=($startfrom-$num>=0) ? ($startfrom-$num) : (-1);
158 $template->param(nextstartfrom => $nextstartfrom);
161 ($nextstartfrom==-1) ? ($displaynext=0) : ($displaynext=1);
162 ($prevstartfrom==-1) ? ($displayprev=0) : ($displayprev=1);
163 $template->param(displaynext => $displaynext);
164 $template->param(displayprev => $displayprev);
165 ($type eq 'opac') ? ($template->param(opac => 1)) : ($template->param(opac => 0));
166 $template->param(prevstartfrom => $prevstartfrom);
167 $template->param(search => $search);
168 $template->param(searchdesc => $searchdesc);
169 $template->param(SEARCH_RESULTS => $resultsarray);
170 #$template->param(includesdir => $includes);
171 $template->param(loggedinuser => $loggedinuser);
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;