7 # Copyright 2000-2002 Katipo Communications
9 # This file is part of Koha.
11 # Koha is free software; you can redistribute it and/or modify it under the
12 # terms of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
16 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
17 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
18 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License along with
21 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
22 # Suite 330, Boston, MA 02111-1307 USA
34 my $type=$query->param('type');
35 (-e "opac") && ($type='opac');
37 my ($loggedinuser, $cookie, $sessionID) = checkauth($query, ($type eq 'opac') ? (1) : (0));
40 my $startfrom=$query->param('startfrom');
41 ($startfrom) || ($startfrom=0);
43 my $subject=$query->param('subject');
45 # if it's a subject we need to use the subject.tmpl
47 $template = gettemplate("catalogue/subject.tmpl",0);
49 $template = gettemplate("catalogue/searchresults.tmpl", 0);
55 # get all the search variables
56 # we assume that C4::Search will validate these values for us
57 # FIXME - This whole section, up to the &catalogsearch call, is crying
59 # foreach $search_term (qw(keyword subject author ...))
62 my $keyword=$query->param('keyword');
63 $search{'keyword'}=$keyword;
65 $search{'subject'}=$subject;
66 my $author=$query->param('author');
67 $search{'author'}=$author;
68 $search{'authoresc'}=$author;
69 #$search{'authorhtmlescaped'}=~s/ /%20/g;
70 my $illustrator=$query->param('illustrator');
71 $search{'param'}=$illustrator;
72 my $itemnumber=$query->param('itemnumber');
73 $search{'itemnumber'}=$itemnumber;
74 my $isbn=$query->param('isbn');
75 $search{'isbn'}=$isbn;
76 my $datebefore=$query->param('date-before');
77 $search{'date-before'}=$datebefore;
78 my $class=$query->param('class');
79 $search{'class'}=$class;
80 my $dewey=$query->param('dewey');
81 $search{'dewey'}=$dewey;
82 my $branch=$query->param('branch');
83 $search{'branch'}=$branch;
84 my $title=$query->param('title');
85 $search{'title'}=$title;
86 my $abstract=$query->param('abstract');
87 $search{'abstract'}=$abstract;
88 my $publisher=$query->param('publisher');
89 $search{'publisher'}=$publisher;
91 my $ttype=$query->param('ttype');
92 $search{'ttype'}=$ttype;
95 ($keyword) && (push @$forminputs, { line => "keyword=$keyword"});
96 ($subject) && (push @$forminputs, { line => "subject=$subject"});
97 ($author) && (push @$forminputs, { line => "author=$author"});
98 ($illustrator) && (push @$forminputs, { line => "illustrator=$illustrator"});
99 ($itemnumber) && (push @$forminputs, { line => "itemnumber=$itemnumber"});
100 ($isbn) && (push @$forminputs, { line => "isbn=$isbn"});
101 ($datebefore) && (push @$forminputs, { line => "date-before=$datebefore"});
102 ($class) && (push @$forminputs, { line => "class=$class"});
103 ($dewey) && (push @$forminputs, { line => "dewey=$dewey"});
104 ($branch) && (push @$forminputs, { line => "branch=$branch"});
105 ($title) && (push @$forminputs, { line => "title=$title"});
106 ($ttype) && (push @$forminputs, { line => "ttype=$ttype"});
107 ($abstract) && (push @$forminputs, { line => "abstract=$abstract"});
108 ($publisher) && (push @$forminputs, { line => "publisher=$publisher"});
109 ($forminputs) || (@$forminputs=());
110 $template->param(FORMINPUTS => $forminputs);
112 # I think it is (or was) a search from the "front" page... [st]
113 $search{'front'}=$query->param('front');
118 if (my $subject=$query->param('subjectitems')) {
120 @results=subsearch(\$blah,$subject);
123 ($count,@results)=catalogsearch($env,'',\%search,$num,$startfrom);
126 #my $resultsarray=\@results;
129 foreach my $result (@results) {
130 $result->{'authorhtmlescaped'}=$result->{'author'};
131 $result->{'authorhtmlescaped'}=~s/ /%20/g;
132 ($result->{'copyrightdate'}==0) && ($result->{'copyrightdate'}='');
133 ($type eq 'opac') ? ($result->{'opac'}=1) : ($result->{'opac'}=0);
134 push (@$resultsarray, $result);
136 ($resultsarray) || (@$resultsarray=());
140 $search=$search."&keyword=$keyword";
141 $searchdesc.="keyword $keyword, ";
143 if (my $subjectitems=$query->param('subjectitems')){
144 $search=$search."&subjectitems=$subjectitems";
145 $searchdesc.="subject $subjectitems, ";
148 $search=$search."&subject=$subject";
149 $searchdesc.="subject $subject, ";
152 $search=$search."&author=$author";
153 $searchdesc.="author $author, ";
156 $search=$search."&class=$class";
157 $searchdesc.="class $class, ";
160 $search=$search."&title=$title";
161 $searchdesc.="title $title, ";
164 $search=$search."&dewey=$dewey";
165 $searchdesc.="dewey $dewey, ";
167 $search.="&ttype=$ttype";
170 $template->param(startfrom => $startfrom+1);
171 ($startfrom+$num<=$count) ? ($template->param(endat => $startfrom+$num)) : ($template->param(endat => $count));
172 $template->param(numrecords => $count);
173 my $nextstartfrom=($startfrom+$num<$count) ? ($startfrom+$num) : (-1);
174 my $prevstartfrom=($startfrom-$num>=0) ? ($startfrom-$num) : (-1);
175 $template->param(nextstartfrom => $nextstartfrom);
178 ($nextstartfrom==-1) ? ($displaynext=0) : ($displaynext=1);
179 ($prevstartfrom==-1) ? ($displayprev=0) : ($displayprev=1);
180 $template->param(displaynext => $displaynext);
181 $template->param(displayprev => $displayprev);
182 ($type eq 'opac') ? ($template->param(opac => 1)) : ($template->param(opac => 0));
183 $template->param(prevstartfrom => $prevstartfrom);
184 $template->param(search => $search);
185 $template->param(searchdesc => $searchdesc);
186 $template->param(SEARCH_RESULTS => $resultsarray);
187 #$template->param(includesdir => $includes);
188 $template->param(loggedinuser => $loggedinuser);
193 for (my $i=1; $i<$count/10+1; $i++) {
195 ($title) && (push @$forminputs, { line => "title=$title"});
197 ($startfrom==($i-1)*10) && ($highlight=1);
199 foreach (@$forminputs) {
201 $formelements.="$line&";
203 $formelements=~s/ /+/g;
204 push @$numbers, { number => $i, highlight => $highlight , FORMELEMENTS => $formelements, FORMINPUTS => $forminputs, startfrom => ($i-1)*10, opac => (($type eq 'opac') ? (1) : (0))};
209 $template->param(numbers => $numbers);
213 print $query->header(-cookie => $cookie), $template->output;