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
30 my $type=$query->param('type');
31 warn $type; # FIXME - What's this for?
33 #(-e "opac") && ($type='opac');
35 my ($loggedinuser, $cookie, $sessionID) = checkauth($query, ($type eq 'opac') ? (1) : (0));
36 warn $type; # FIXME - What's this for?
38 my $startfrom=$query->param('startfrom');
39 ($startfrom) || ($startfrom=0);
41 my $subject=$query->param('subject');
43 # if it's a subject we need to use the subject.tmpl
45 $template = gettemplate("catalogue/subject.tmpl",0);
47 $template = gettemplate("catalogue/searchresults.tmpl", 0);
51 # Additional parameters for &catalogsearch
53 itemcount => 1, # If set to 1, &catalogsearch enumerates
54 # the results found and returns the number
55 # of items found, where they're located,
59 # get all the search variables
60 # we assume that C4::Search will validate these values for us
61 my %search; # Search terms. If the key is "author",
62 # then $search{author} is the author the
63 # user is looking for.
65 my @forminputs; # This is used in the form template.
67 foreach my $term (qw(keyword subject author illustrator itemnumber
68 isbn date-before class dewey branch title abstract
71 my $value = $query->param($term);
73 next unless defined $value && $value ne "";
74 # Skip blank search terms
75 $search{$term} = $value;
76 push @forminputs, { line => "$term=$value" };
79 $template->param(FORMINPUTS => \@forminputs);
82 # I think it is (or was) a search from the "front" page... [st]
83 $search{'front'}=$query->param('front');
88 if (my $subject=$query->param('subjectitems')) {
90 @results=subsearch(\$blah,$subject);
93 ($count,@results)=catalogsearch(\%env,'',\%search,$num,$startfrom);
96 #my $resultsarray=\@results;
99 foreach my $result (@results) {
100 $result->{'authorhtmlescaped'}=$result->{'author'};
101 $result->{'authorhtmlescaped'}=~s/ /%20/g;
102 ($result->{'copyrightdate'}==0) && ($result->{'copyrightdate'}='');
103 ($type eq 'opac') ? ($result->{'opac'}=1) : ($result->{'opac'}=0);
104 push (@$resultsarray, $result);
106 ($resultsarray) || (@$resultsarray=());
109 if ($search{"keyword"}) {
110 $search .= "&keyword=$search{keyword}";
111 $searchdesc.="keyword $search{keyword}, ";
113 if (my $subjectitems=$query->param('subjectitems')){
114 $search .= "&subjectitems=$subjectitems";
115 $searchdesc.="subject $subjectitems, ";
118 $search .= "&subject=$subject";
119 $searchdesc.="subject $subject, ";
121 if ($search{"author"}){
122 $search .= "&author=$search{author}";
123 $searchdesc.="author $search{author}, ";
125 if ($search{"class"}){
126 $search .= "&class=$search{class}";
127 $searchdesc.="class $search{class}, ";
129 if ($search{"title"}){
130 $search .= "&title=$search{title}";
131 $searchdesc.="title $search{title}, ";
133 if ($search{"dewey"}){
134 $search .= "&dewey=$search{dewey}";
135 $searchdesc.="dewey $search{dewey}, ";
137 $search.="&ttype=$search{ttype}";
140 $template->param(startfrom => $startfrom+1);
141 ($startfrom+$num<=$count) ? ($template->param(endat => $startfrom+$num)) : ($template->param(endat => $count));
142 $template->param(numrecords => $count);
143 my $nextstartfrom=($startfrom+$num<$count) ? ($startfrom+$num) : (-1);
144 my $prevstartfrom=($startfrom-$num>=0) ? ($startfrom-$num) : (-1);
145 $template->param(nextstartfrom => $nextstartfrom);
148 ($nextstartfrom==-1) ? ($displaynext=0) : ($displaynext=1);
149 ($prevstartfrom==-1) ? ($displayprev=0) : ($displayprev=1);
150 $template->param(displaynext => $displaynext);
151 $template->param(displayprev => $displayprev);
152 ($type eq 'opac') ? ($template->param(opac => 1)) : ($template->param(opac => 0));
153 $template->param(prevstartfrom => $prevstartfrom);
154 $template->param(search => $search);
155 $template->param(searchdesc => $searchdesc);
156 $template->param(SEARCH_RESULTS => $resultsarray);
157 #$template->param(includesdir => $includes);
158 $template->param(loggedinuser => $loggedinuser);
162 for (my $i=1; $i<$count/10+1; $i++) {
164 if ($search{"title"})
166 push @forminputs, { line => "title=$search{title}"};
169 ($startfrom==($i-1)*10) && ($highlight=1);
171 foreach (@forminputs) {
173 $formelements.="$line&";
175 $formelements=~s/ /+/g;
176 push @numbers, { number => $i, highlight => $highlight , FORMELEMENTS => $formelements, FORMINPUTS => \@forminputs, startfrom => ($i-1)*10, opac => (($type eq 'opac') ? (1) : (0))};
181 $template->param(numbers => \@numbers);
182 if (C4::Context->preference('acquisitions') eq 'simple') {
183 $template->param(script => "MARCdetail.pl");
185 $template->param(script => "detail.pl");
189 print $query->header(-cookie => $cookie), $template->output;