Added a couple of comments.
[koha.git] / search.pl
1 #!/usr/bin/perl
2 use HTML::Template;
3 #script to provide intranet (librarian) advanced search facility
4
5
6 # Copyright 2000-2002 Katipo Communications
7 #
8 # This file is part of Koha.
9 #
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
13 # version.
14 #
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.
18 #
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
22
23 use strict;
24 require Exporter;
25 use CGI;
26 use C4::Context;
27 use C4::Search;
28 use C4::Output;
29
30 my $query=new CGI;
31
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);
38
39 my $subject=$query->param('subject');
40 # if its a subject we need to use the subject.tmpl
41 my $template;
42 if ($subject) {
43         $template = gettemplate("catalogue/subject.tmpl")
44 #    $templatebase=~ s/searchresults\.tmpl/subject\.tmpl/;
45 #    $theme=picktemplate($includes, $templatebase);
46 } else {
47         $template = gettemplate("catalogue/searchresults.tmpl")
48 }
49
50 #my $template = HTML::Template->new(filename => "$includes/templates/$theme/$templatebase", die_on_bad_params => 0, path => [$includes]);
51
52 my $env;
53 $env->{itemcount}=1;
54
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
58 # out for
59 #       foreach $search_term (qw(keyword subject author ...))
60 #       { ... }
61 my %search;
62 my $keyword=$query->param('keyword');
63 $search{'keyword'}=$keyword;
64
65 $search{'subject'}=$subject;
66 my $author=$query->param('author');
67 $search{'author'}=$author;
68 my $illustrator=$query->param('illustrator');
69 $search{'param'}=$illustrator;
70 my $itemnumber=$query->param('itemnumber');
71 $search{'itemnumber'}=$itemnumber;
72 my $isbn=$query->param('isbn');
73 $search{'isbn'}=$isbn;
74 my $datebefore=$query->param('date-before');
75 $search{'date-before'}=$datebefore;
76 my $class=$query->param('class');
77 $search{'class'}=$class;
78 my $dewey=$query->param('dewey');
79 $search{'dewey'};               # FIXME - This should be $search{'dewey'} = $dewey, right?
80 my $branch=$query->param('branch');
81 $search{'branch'}=$branch;
82 my $title=$query->param('title');
83 $search{'title'}=$title;
84 my $abstract=$query->param('abstract');
85 $search{'abstract'}=$abstract;
86 my $publisher=$query->param('publisher');
87 $search{'publisher'}=$publisher;
88
89 my $ttype=$query->param('ttype');
90 $search{'ttype'}=$ttype;
91
92 my $forminputs;
93 ($keyword) && (push @$forminputs, { line => "keyword=$keyword"});
94 ($subject) && (push @$forminputs, { line => "subject=$subject"});
95 ($author) && (push @$forminputs, { line => "author=$author"});
96 ($illustrator) && (push @$forminputs, { line => "illustrator=$illustrator"});
97 ($itemnumber) && (push @$forminputs, { line => "itemnumber=$itemnumber"});
98 ($isbn) && (push @$forminputs, { line => "isbn=$isbn"});
99 ($datebefore) && (push @$forminputs, { line => "date-before=$datebefore"});
100 ($class) && (push @$forminputs, { line => "class=$class"});
101 ($dewey) && (push @$forminputs, { line => "dewey=$dewey"});
102 ($branch) && (push @$forminputs, { line => "branch=$branch"});
103 ($title) && (push @$forminputs, { line => "title=$title"});
104 ($ttype) && (push @$forminputs, { line => "ttype=$ttype"});
105 ($abstract) && (push @$forminputs, { line => "abstract=$abstract"});
106 ($publisher) && (push @$forminputs, { line => "publisher=$publisher"});
107 $template->param(FORMINPUTS => $forminputs);
108 # whats this for?
109 # I think it is (or was) a search from the "front" page...   [st]
110 $search{'front'}=$query->param('front');
111
112 my $num=10;
113 my ($count,@results)=catalogsearch($env,'',\%search,$num,$startfrom);
114
115 my $resultsarray=\@results;
116
117 my $search="num=20";
118 if ($keyword){
119     $search=$search."&keyword=$keyword";
120 }
121 if ($subject){
122     $search=$search."&subject=$subject";
123 }
124 if ($author){
125     $search=$search."&author=$author";
126 }
127 if ($class){
128     $search=$search."&class=$class";
129 }
130 if ($title){
131     $search=$search."&title=$title";
132 }
133 if ($dewey){
134     $search=$search."&dewey=$dewey";
135 }
136 $search.="&ttype=$ttype";
137
138 $search=~ s/ /%20/g;
139 $template->param(startfrom => $startfrom+1);
140 $template->param(endat => $startfrom+$num);
141 $template->param(numrecords => $count);
142 my $nextstartfrom=($startfrom+$num<$count-$num) ? ($startfrom+$num) : ($count-$num);
143 my $prevstartfrom=($startfrom-$num>0) ? ($startfrom-$num) : (0);
144 $template->param(nextstartfrom => $nextstartfrom);
145 $template->param(prevstartfrom => $prevstartfrom);
146 $template->param(search => $search);
147 $template->param(SEARCH_RESULTS => $resultsarray);
148 $template->param(includesdir => $includes);
149
150
151 print "Content-Type: text/html\n\n", $template->output;
152