Fixed some bogosity.
[koha.git] / html-template / search.pl
1 #!/usr/bin/perl
2
3 # Copyright 2000-2002 Katipo Communications
4 #
5 # This file is part of Koha.
6 #
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
10 # version.
11 #
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.
15 #
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
19
20 # FIXME - This file is nearly identical to "../search.pl". One of them
21 # should be nuked.
22
23 use HTML::Template;
24 use strict;
25 require Exporter;       # FIXME - Is this really needed?
26 use C4::Context;
27 use CGI;
28 use C4::Search;
29 use C4::Output; # no contains picktemplate
30   
31 my $query=new CGI;
32
33 my $includes = C4::Context->config('includes') ||
34         "/usr/local/www/hdl/htdocs/includes";
35 my $templatebase="catalogue/searchresults.tmpl";
36 my $startfrom=$query->param('startfrom') || 0;
37 my $theme=picktemplate($includes, $templatebase);
38
39 my $subject=$query->param('subject');
40 # if its a subject we need to use the subject.tmpl
41 if ($subject) {
42     $templatebase=~ s/searchresults\.tmpl/subject\.tmpl/;
43     $theme=picktemplate($includes, $templatebase);
44 }
45
46 my $template = HTML::Template->new(filename => "$includes/templates/$theme/$templatebase", die_on_bad_params => 0, path => [$includes]);
47
48 my $env;
49 $env->{itemcount}=1;
50
51 # get all the search variables
52 # we assume that C4::Search will validate these values for us
53 # FIXME - This looks like it could go inside a
54 #       foreach my $term (qw(keyword subject author ...))
55 # loop.
56 my %search;
57 my $keyword=$query->param('keyword');
58 $search{'keyword'}=$keyword;
59
60 $search{'subject'}=$subject;
61 my $author=$query->param('author');
62 $search{'author'}=$author;
63 my $illustrator=$query->param('illustrator');
64 $search{'param'}=$illustrator;
65 my $itemnumber=$query->param('itemnumber');
66 $search{'itemnumber'}=$itemnumber;
67 my $isbn=$query->param('isbn');
68 $search{'isbn'}=$isbn;
69 my $datebefore=$query->param('date-before');
70 $search{'date-before'}=$datebefore;
71 my $class=$query->param('class');
72 $search{'class'}=$class;
73 my $dewey=$query->param('dewey');
74 $search{'dewey'};       # FIXME - Was this supposed to be $search{'dewey'} = $dewey ?
75 my $branch=$query->param('branch');
76 $search{'branch'}=$branch;
77 my $title=$query->param('title');
78 $search{'title'}=$title;
79 my $abstract=$query->param('abstract');
80 $search{'abstract'}=$abstract;
81 my $publisher=$query->param('publisher');
82 $search{'publisher'}=$publisher;
83
84 my $ttype=$query->param('ttype');
85 $search{'ttype'}=$ttype;
86
87 my $forminputs;
88 ($keyword) && (push @$forminputs, { line => "keyword=$keyword"});
89 ($subject) && (push @$forminputs, { line => "subject=$subject"});
90 ($author) && (push @$forminputs, { line => "author=$author"});
91 ($illustrator) && (push @$forminputs, { line => "illustrator=$illustrator"});
92 ($itemnumber) && (push @$forminputs, { line => "itemnumber=$itemnumber"});
93 ($isbn) && (push @$forminputs, { line => "isbn=$isbn"});
94 ($datebefore) && (push @$forminputs, { line => "date-before=$datebefore"});
95 ($class) && (push @$forminputs, { line => "class=$class"});
96 ($dewey) && (push @$forminputs, { line => "dewey=$dewey"});
97 ($branch) && (push @$forminputs, { line => "branch=$branch"});
98 ($title) && (push @$forminputs, { line => "title=$title"});
99 ($ttype) && (push @$forminputs, { line => "ttype=$ttype"});
100 ($abstract) && (push @$forminputs, { line => "abstract=$abstract"});
101 ($publisher) && (push @$forminputs, { line => "publisher=$publisher"});
102 $template->param(FORMINPUTS => $forminputs);
103 # whats this for?
104 # I think it is (or was) a search from the "front" page...   [st]
105 $search{'front'}=$query->param('front');
106
107 my $num=10;
108 my ($count,@results)=catalogsearch($env,'',\%search,$num,$startfrom);
109
110 my $resultsarray=\@results;
111
112 my $search="num=20";
113 if ($keyword){
114     $search=$search."&keyword=$keyword";
115 }
116 if ($subject){
117     $search=$search."&subject=$subject";
118 }
119 if ($author){
120     $search=$search."&author=$author";
121 }
122 if ($class){
123     $search=$search."&class=$class";
124 }
125 if ($title){
126     $search=$search."&title=$title";
127 }
128 if ($dewey){
129     $search=$search."&dewey=$dewey";
130 }
131 $search.="&ttype=$ttype";
132
133 $search=~ s/ /%20/g;
134 $template->param(startfrom => $startfrom+1);
135 $template->param(endat => $startfrom+$num);
136 $template->param(numrecords => $count);
137 my $nextstartfrom=($startfrom+$num<$count-$num) ? ($startfrom+$num) : ($count-$num);
138 my $prevstartfrom=($startfrom-$num>0) ? ($startfrom-$num) : (0);
139 $template->param(nextstartfrom => $nextstartfrom);
140 $template->param(prevstartfrom => $prevstartfrom);
141 $template->param(search => $search);
142 $template->param(SEARCH_RESULTS => $resultsarray);
143 $template->param(includesdir => $includes);
144
145
146 print "Content-Type: text/html\n\n", $template->output;
147