Added copyright statement to all .pl and .pm files
[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 use HTML::Template;
21 use strict;
22 require Exporter;
23 use C4::Database;
24 use CGI;
25 use C4::Search;
26 use C4::Output; # no contains picktemplate
27   
28 my $query=new CGI;
29
30
31 my $language='french';
32
33
34 my %configfile;
35 open (KC, "/etc/koha.conf");
36 while (<KC>) {
37  chomp;
38  (next) if (/^\s*#/);
39  if (/(.*)\s*=\s*(.*)/) {
40    my $variable=$1;
41    my $value=$2;
42    # Clean up white space at beginning and end
43    $variable=~s/^\s*//g;
44    $variable=~s/\s*$//g;
45    $value=~s/^\s*//g;
46    $value=~s/\s*$//g;
47    $configfile{$variable}=$value;
48  }
49 }
50 #print $query->header;
51
52 my $includes=$configfile{'includes'};
53 ($includes) || ($includes="/usr/local/www/hdl/htdocs/includes");
54 my $templatebase="catalogue/searchresults.tmpl";
55 my $startfrom=$query->param('startfrom');
56 ($startfrom) || ($startfrom=0);
57 my $theme=picktemplate($includes, $templatebase);
58
59 my $subject=$query->param('subject');
60 # if its a subject we need to use the subject.tmpl
61 if ($subject) {
62     $templatebase=~ s/searchresults\.tmpl/subject\.tmpl/;
63     $theme=picktemplate($includes, $templatebase);
64 }
65
66 my $template = HTML::Template->new(filename => "$includes/templates/$theme/$templatebase", die_on_bad_params => 0, path => [$includes]);
67
68 my $env;
69 $env->{itemcount}=1;
70
71 # get all the search variables
72 # we assume that C4::Search will validate these values for us
73 my %search;
74 my $keyword=$query->param('keyword');
75 $search{'keyword'}=$keyword;
76
77 $search{'subject'}=$subject;
78 my $author=$query->param('author');
79 $search{'author'}=$author;
80 my $illustrator=$query->param('illustrator');
81 $search{'param'}=$illustrator;
82 my $itemnumber=$query->param('itemnumber');
83 $search{'itemnumber'}=$itemnumber;
84 my $isbn=$query->param('isbn');
85 $search{'isbn'}=$isbn;
86 my $datebefore=$query->param('date-before');
87 $search{'date-before'}=$datebefore;
88 my $class=$query->param('class');
89 $search{'class'}=$class;
90 my $dewey=$query->param('dewey');
91 $search{'dewey'};
92 my $branch=$query->param('branch');
93 $search{'branch'}=$branch;
94 my $title=$query->param('title');
95 $search{'title'}=$title;
96 my $abstract=$query->param('abstract');
97 $search{'abstract'}=$abstract;
98 my $publisher=$query->param('publisher');
99 $search{'publisher'}=$publisher;
100
101 my $ttype=$query->param('ttype');
102 $search{'ttype'}=$ttype;
103
104 my $forminputs;
105 ($keyword) && (push @$forminputs, { line => "keyword=$keyword"});
106 ($subject) && (push @$forminputs, { line => "subject=$subject"});
107 ($author) && (push @$forminputs, { line => "author=$author"});
108 ($illustrator) && (push @$forminputs, { line => "illustrator=$illustrator"});
109 ($itemnumber) && (push @$forminputs, { line => "itemnumber=$itemnumber"});
110 ($isbn) && (push @$forminputs, { line => "isbn=$isbn"});
111 ($datebefore) && (push @$forminputs, { line => "date-before=$datebefore"});
112 ($class) && (push @$forminputs, { line => "class=$class"});
113 ($dewey) && (push @$forminputs, { line => "dewey=$dewey"});
114 ($branch) && (push @$forminputs, { line => "branch=$branch"});
115 ($title) && (push @$forminputs, { line => "title=$title"});
116 ($ttype) && (push @$forminputs, { line => "ttype=$ttype"});
117 ($abstract) && (push @$forminputs, { line => "abstract=$abstract"});
118 ($publisher) && (push @$forminputs, { line => "publisher=$publisher"});
119 $template->param(FORMINPUTS => $forminputs);
120 # whats this for?
121 # I think it is (or was) a search from the "front" page...   [st]
122 $search{'front'}=$query->param('front');
123
124 my $num=10;
125 my ($count,@results)=catalogsearch($env,'',\%search,$num,$startfrom);
126
127 my $resultsarray=\@results;
128
129 my $search="num=20";
130 if ($keyword){
131     $search=$search."&keyword=$keyword";
132 }
133 if ($subject){
134     $search=$search."&subject=$subject";
135 }
136 if ($author){
137     $search=$search."&author=$author";
138 }
139 if ($class){
140     $search=$search."&class=$class";
141 }
142 if ($title){
143     $search=$search."&title=$title";
144 }
145 if ($dewey){
146     $search=$search."&dewey=$dewey";
147 }
148 $search.="&ttype=$ttype";
149
150 $search=~ s/ /%20/g;
151 $template->param(startfrom => $startfrom+1);
152 $template->param(endat => $startfrom+$num);
153 $template->param(numrecords => $count);
154 my $nextstartfrom=($startfrom+$num<$count-$num) ? ($startfrom+$num) : ($count-$num);
155 my $prevstartfrom=($startfrom-$num>0) ? ($startfrom-$num) : (0);
156 $template->param(nextstartfrom => $nextstartfrom);
157 $template->param(prevstartfrom => $prevstartfrom);
158 $template->param(search => $search);
159 $template->param(SEARCH_RESULTS => $resultsarray);
160 $template->param(includesdir => $includes);
161
162
163 print "Content-Type: text/html\n\n", $template->output;
164