3 #script to provide intranet (librarian) advanced search facility
6 # Copyright 2000-2002 Katipo Communications
8 # This file is part of Koha.
10 # Koha is free software; you can redistribute it and/or modify it under the
11 # terms of the GNU General Public License as published by the Free Software
12 # Foundation; either version 2 of the License, or (at your option) any later
15 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
16 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
17 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License along with
20 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
21 # Suite 330, Boston, MA 02111-1307 USA
27 use C4::Output; # no contains picktemplate
31 my $includes = C4::Context->config('includes') ||
32 "/usr/local/www/hdl/htdocs/includes";
33 my $templatebase="catalogue/searchresults.tmpl";
34 my $startfrom=$query->param('startfrom');
35 ($startfrom) || ($startfrom=0);
36 my $theme=picktemplate($includes, $templatebase);
38 my $subject=$query->param('subject');
39 # if its a subject we need to use the subject.tmpl
41 $templatebase=~ s/searchresults\.tmpl/subject\.tmpl/;
42 $theme=picktemplate($includes, $templatebase);
45 my $template = HTML::Template->new(filename => "$includes/templates/$theme/$templatebase", die_on_bad_params => 0, path => [$includes]);
50 # get all the search variables
51 # we assume that C4::Search will validate these values for us
52 # FIXME - This whole section, up to the &catalogsearch call, is crying
54 # foreach $search_term (qw(keyword subject author ...))
57 my $keyword=$query->param('keyword');
58 $search{'keyword'}=$keyword;
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 - This should be $search{'dewey'} = $dewey, right?
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;
84 my $ttype=$query->param('ttype');
85 $search{'ttype'}=$ttype;
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);
104 # I think it is (or was) a search from the "front" page... [st]
105 $search{'front'}=$query->param('front');
108 my ($count,@results)=catalogsearch($env,'',\%search,$num,$startfrom);
110 my $resultsarray=\@results;
114 $search=$search."&keyword=$keyword";
117 $search=$search."&subject=$subject";
120 $search=$search."&author=$author";
123 $search=$search."&class=$class";
126 $search=$search."&title=$title";
129 $search=$search."&dewey=$dewey";
131 $search.="&ttype=$ttype";
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);
146 print "Content-Type: text/html\n\n", $template->output;