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
28 use C4::Output; # no contains picktemplate
32 my $includes = C4::Context->config('includes') ||
33 "/usr/local/www/hdl/htdocs/includes";
34 my $templatebase="catalogue/searchresults.tmpl";
35 my $startfrom=$query->param('startfrom');
36 ($startfrom) || ($startfrom=0);
37 my $theme=picktemplate($includes, $templatebase);
39 my $subject=$query->param('subject');
40 # if its a subject we need to use the subject.tmpl
42 $templatebase=~ s/searchresults\.tmpl/subject\.tmpl/;
43 $theme=picktemplate($includes, $templatebase);
46 my $template = HTML::Template->new(filename => "$includes/templates/$theme/$templatebase", die_on_bad_params => 0, path => [$includes]);
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 my $illustrator=$query->param('illustrator');
65 $search{'param'}=$illustrator;
66 my $itemnumber=$query->param('itemnumber');
67 $search{'itemnumber'}=$itemnumber;
68 my $isbn=$query->param('isbn');
69 $search{'isbn'}=$isbn;
70 my $datebefore=$query->param('date-before');
71 $search{'date-before'}=$datebefore;
72 my $class=$query->param('class');
73 $search{'class'}=$class;
74 my $dewey=$query->param('dewey');
75 $search{'dewey'}; # FIXME - This should be $search{'dewey'} = $dewey, right?
76 my $branch=$query->param('branch');
77 $search{'branch'}=$branch;
78 my $title=$query->param('title');
79 $search{'title'}=$title;
80 my $abstract=$query->param('abstract');
81 $search{'abstract'}=$abstract;
82 my $publisher=$query->param('publisher');
83 $search{'publisher'}=$publisher;
85 my $ttype=$query->param('ttype');
86 $search{'ttype'}=$ttype;
89 ($keyword) && (push @$forminputs, { line => "keyword=$keyword"});
90 ($subject) && (push @$forminputs, { line => "subject=$subject"});
91 ($author) && (push @$forminputs, { line => "author=$author"});
92 ($illustrator) && (push @$forminputs, { line => "illustrator=$illustrator"});
93 ($itemnumber) && (push @$forminputs, { line => "itemnumber=$itemnumber"});
94 ($isbn) && (push @$forminputs, { line => "isbn=$isbn"});
95 ($datebefore) && (push @$forminputs, { line => "date-before=$datebefore"});
96 ($class) && (push @$forminputs, { line => "class=$class"});
97 ($dewey) && (push @$forminputs, { line => "dewey=$dewey"});
98 ($branch) && (push @$forminputs, { line => "branch=$branch"});
99 ($title) && (push @$forminputs, { line => "title=$title"});
100 ($ttype) && (push @$forminputs, { line => "ttype=$ttype"});
101 ($abstract) && (push @$forminputs, { line => "abstract=$abstract"});
102 ($publisher) && (push @$forminputs, { line => "publisher=$publisher"});
103 $template->param(FORMINPUTS => $forminputs);
105 # I think it is (or was) a search from the "front" page... [st]
106 $search{'front'}=$query->param('front');
109 my ($count,@results)=catalogsearch($env,'',\%search,$num,$startfrom);
111 my $resultsarray=\@results;
115 $search=$search."&keyword=$keyword";
118 $search=$search."&subject=$subject";
121 $search=$search."&author=$author";
124 $search=$search."&class=$class";
127 $search=$search."&title=$title";
130 $search=$search."&dewey=$dewey";
132 $search.="&ttype=$ttype";
135 $template->param(startfrom => $startfrom+1);
136 $template->param(endat => $startfrom+$num);
137 $template->param(numrecords => $count);
138 my $nextstartfrom=($startfrom+$num<$count-$num) ? ($startfrom+$num) : ($count-$num);
139 my $prevstartfrom=($startfrom-$num>0) ? ($startfrom-$num) : (0);
140 $template->param(nextstartfrom => $nextstartfrom);
141 $template->param(prevstartfrom => $prevstartfrom);
142 $template->param(search => $search);
143 $template->param(SEARCH_RESULTS => $resultsarray);
144 $template->param(includesdir => $includes);
147 print "Content-Type: text/html\n\n", $template->output;