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 (-e "opac") && ($type='opac');
33 my ($loggedinuser, $cookie, $sessionID) = checkauth($query, ($type eq 'opac') ? (1) : (0));
36 my $startfrom=$query->param('startfrom');
37 ($startfrom) || ($startfrom=0);
39 my $subject=$query->param('subject');
41 # if it's a subject we need to use the subject.tmpl
43 $template = gettemplate("catalogue/subject.tmpl",0);
45 $template = gettemplate("catalogue/searchresults.tmpl", 0);
51 # get all the search variables
52 # we assume that C4::Search will validate these values for us
53 # FIXME - This whole section, up to the &catalogsearch call, is crying
55 # foreach $search_term (qw(keyword subject author ...))
58 my $keyword=$query->param('keyword');
59 $search{'keyword'}=$keyword;
61 $search{'subject'}=$subject;
62 my $author=$query->param('author');
63 $search{'author'}=$author;
64 $search{'authoresc'}=$author;
65 #$search{'authorhtmlescaped'}=~s/ /%20/g;
66 my $illustrator=$query->param('illustrator');
67 $search{'param'}=$illustrator;
68 my $itemnumber=$query->param('itemnumber');
69 $search{'itemnumber'}=$itemnumber;
70 my $isbn=$query->param('isbn');
71 $search{'isbn'}=$isbn;
72 my $datebefore=$query->param('date-before');
73 $search{'date-before'}=$datebefore;
74 my $class=$query->param('class');
75 $search{'class'}=$class;
76 my $dewey=$query->param('dewey');
77 $search{'dewey'}=$dewey;
78 my $branch=$query->param('branch');
79 $search{'branch'}=$branch;
80 my $title=$query->param('title');
81 $search{'title'}=$title;
82 my $abstract=$query->param('abstract');
83 $search{'abstract'}=$abstract;
84 my $publisher=$query->param('publisher');
85 $search{'publisher'}=$publisher;
87 my $ttype=$query->param('ttype');
88 $search{'ttype'}=$ttype;
91 ($keyword) && (push @$forminputs, { line => "keyword=$keyword"});
92 ($subject) && (push @$forminputs, { line => "subject=$subject"});
93 ($author) && (push @$forminputs, { line => "author=$author"});
94 ($illustrator) && (push @$forminputs, { line => "illustrator=$illustrator"});
95 ($itemnumber) && (push @$forminputs, { line => "itemnumber=$itemnumber"});
96 ($isbn) && (push @$forminputs, { line => "isbn=$isbn"});
97 ($datebefore) && (push @$forminputs, { line => "date-before=$datebefore"});
98 ($class) && (push @$forminputs, { line => "class=$class"});
99 ($dewey) && (push @$forminputs, { line => "dewey=$dewey"});
100 ($branch) && (push @$forminputs, { line => "branch=$branch"});
101 ($title) && (push @$forminputs, { line => "title=$title"});
102 ($ttype) && (push @$forminputs, { line => "ttype=$ttype"});
103 ($abstract) && (push @$forminputs, { line => "abstract=$abstract"});
104 ($publisher) && (push @$forminputs, { line => "publisher=$publisher"});
105 ($forminputs) || (@$forminputs=());
106 $template->param(FORMINPUTS => $forminputs);
108 # I think it is (or was) a search from the "front" page... [st]
109 $search{'front'}=$query->param('front');
114 if (my $subject=$query->param('subjectitems')) {
116 @results=subsearch(\$blah,$subject);
119 ($count,@results)=catalogsearch($env,'',\%search,$num,$startfrom);
122 #my $resultsarray=\@results;
125 foreach my $result (@results) {
126 $result->{'authorhtmlescaped'}=$result->{'author'};
127 $result->{'authorhtmlescaped'}=~s/ /%20/g;
128 ($result->{'copyrightdate'}==0) && ($result->{'copyrightdate'}='');
129 ($type eq 'opac') ? ($result->{'opac'}=1) : ($result->{'opac'}=0);
130 push (@$resultsarray, $result);
132 ($resultsarray) || (@$resultsarray=());
136 $search=$search."&keyword=$keyword"; # FIXME - .=
137 $searchdesc.="keyword $keyword, ";
139 if (my $subjectitems=$query->param('subjectitems')){
140 $search=$search."&subjectitems=$subjectitems"; # FIXME - .=
141 $searchdesc.="subject $subjectitems, ";
144 $search=$search."&subject=$subject"; # FIXME - .=
145 $searchdesc.="subject $subject, ";
148 $search=$search."&author=$author"; # FIXME - .=
149 $searchdesc.="author $author, ";
152 $search=$search."&class=$class"; # FIXME - .=
153 $searchdesc.="class $class, ";
156 $search=$search."&title=$title"; # FIXME - .=
157 $searchdesc.="title $title, ";
160 $search=$search."&dewey=$dewey"; # FIXME - .=
161 $searchdesc.="dewey $dewey, ";
163 $search.="&ttype=$ttype";
166 $template->param(startfrom => $startfrom+1);
167 ($startfrom+$num<=$count) ? ($template->param(endat => $startfrom+$num)) : ($template->param(endat => $count));
168 $template->param(numrecords => $count);
169 my $nextstartfrom=($startfrom+$num<$count) ? ($startfrom+$num) : (-1);
170 my $prevstartfrom=($startfrom-$num>=0) ? ($startfrom-$num) : (-1);
171 $template->param(nextstartfrom => $nextstartfrom);
174 ($nextstartfrom==-1) ? ($displaynext=0) : ($displaynext=1);
175 ($prevstartfrom==-1) ? ($displayprev=0) : ($displayprev=1);
176 $template->param(displaynext => $displaynext);
177 $template->param(displayprev => $displayprev);
178 ($type eq 'opac') ? ($template->param(opac => 1)) : ($template->param(opac => 0));
179 $template->param(prevstartfrom => $prevstartfrom);
180 $template->param(search => $search);
181 $template->param(searchdesc => $searchdesc);
182 $template->param(SEARCH_RESULTS => $resultsarray);
183 #$template->param(includesdir => $includes);
184 $template->param(loggedinuser => $loggedinuser);
189 for (my $i=1; $i<$count/10+1; $i++) {
191 ($title) && (push @$forminputs, { line => "title=$title"});
193 ($startfrom==($i-1)*10) && ($highlight=1);
195 foreach (@$forminputs) {
197 $formelements.="$line&";
199 $formelements=~s/ /+/g;
200 push @$numbers, { number => $i, highlight => $highlight , FORMELEMENTS => $formelements, FORMINPUTS => $forminputs, startfrom => ($i-1)*10, opac => (($type eq 'opac') ? (1) : (0))};
205 $template->param(numbers => $numbers);
209 print $query->header(-cookie => $cookie), $template->output;