Fixed a few warnings.
[koha.git] / html-template / search.pl
1 #!/usr/bin/perl
2 use HTML::Template;
3 use strict;
4 require Exporter;
5 use C4::Database;
6 use CGI;
7 use C4::Search;
8 use C4::Output; # no contains picktemplate
9   
10 my $query=new CGI;
11
12
13 my $language='french';
14
15
16 my %configfile;
17 open (KC, "/etc/koha.conf");
18 while (<KC>) {
19  chomp;
20  (next) if (/^\s*#/);
21  if (/(.*)\s*=\s*(.*)/) {
22    my $variable=$1;
23    my $value=$2;
24    # Clean up white space at beginning and end
25    $variable=~s/^\s*//g;
26    $variable=~s/\s*$//g;
27    $value=~s/^\s*//g;
28    $value=~s/\s*$//g;
29    $configfile{$variable}=$value;
30  }
31 }
32 #print $query->header;
33
34 my $includes=$configfile{'includes'};
35 ($includes) || ($includes="/usr/local/www/hdl/htdocs/includes");
36 my $templatebase="catalogue/searchresults.tmpl";
37 my $startfrom=$query->param('startfrom');
38 ($startfrom) || ($startfrom=0);
39 my $theme=picktemplate($includes, $templatebase);
40
41 my $subject=$query->param('subject');
42 # if its a subject we need to use the subject.tmpl
43 $templatebase=~ s/searchresults\.tmpl/subject\.tmpl/;
44
45 my $template = HTML::Template->new(filename => "$includes/templates/$theme/$templatebase", die_on_bad_params => 0, path => [$includes]);
46
47 my $env;
48 $env->{itemcount}=1;
49
50 # get all the search variables
51 # we assume that C4::Search will validate these values for us
52 my %search;
53 my $keyword=$query->param('keyword');
54 $search{'keyword'}=$keyword;
55
56 $search{'subject'}=$subject;
57 my $author=$query->param('author');
58 $search{'author'}=$author;
59 my $illustrator=$query->param('illustrator');
60 $search{'param'}=$illustrator;
61 my $itemnumber=$query->param('itemnumber');
62 $search{'itemnumber'}=$itemnumber;
63 my $isbn=$query->param('isbn');
64 $search{'isbn'}=$isbn;
65 my $datebefore=$query->param('date-before');
66 $search{'date-before'}=$datebefore;
67 my $class=$query->param('class');
68 $search{'class'}=$class;
69 my $dewey=$query->param('dewey');
70 $search{'dewey'};
71 my $branch=$query->param('branch');
72 $search{'branch'}=$branch;
73 my $title=$query->param('title');
74 $search{'title'}=$title;
75 my $ttype=$query->param('ttype');
76 $search{'ttype'}=$ttype;
77
78 # whats this for?
79 $search{'front'}=$query->param('front');
80
81 my $num=20;
82 my ($count,@results)=catalogsearch($env,'',\%search,$num,$startfrom);
83
84 my $resultsarray=\@results;
85
86 my $search="num=20";
87 if ($keyword){
88     $search=$search."&keyword=$keyword";
89 }
90 if ($subject){
91     $search=$search."&subject=$subject";
92 }
93 if ($author){
94     $search=$search."&author=$author";
95 }
96 if ($class){
97     $search=$search."&class=$class";
98 }
99 if ($title){
100     $search=$search."&title=$title";
101 }
102 if ($dewey){
103     $search=$search."&dewey=$dewey";
104 }
105 $search.="&ttype=$ttype";
106
107 $search=~ s/ /%20/g;
108 $template->param(startfrom => $startfrom+1);
109 $template->param(endat => $startfrom+20);
110 $template->param(numrecords => $count);
111 my $nextstartfrom=($startfrom+20<$count-20) ? ($startfrom+20) : ($count-20);
112 my $prevstartfrom=($startfrom-20>0) ? ($startfrom-20) : (0);
113 $template->param(nextstartfrom => $nextstartfrom);
114 $template->param(prevstartfrom => $prevstartfrom);
115 $template->param(search => $search);
116 $template->param(SEARCH_RESULTS => $resultsarray);
117 $template->param(includesdir => $includes);
118
119
120 print "Content-Type: text/html\n\n", $template->output;
121