Darn. Committed over old search.pl... really going to have to learn how to
[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 if ($subject) {
44     $templatebase=~ s/searchresults\.tmpl/subject\.tmpl/;
45     $theme=picktemplate($includes, $templatebase);
46 }
47
48 my $template = HTML::Template->new(filename => "$includes/templates/$theme/$templatebase", die_on_bad_params => 0, path => [$includes]);
49
50 my $env;
51 $env->{itemcount}=1;
52
53 # get all the search variables
54 # we assume that C4::Search will validate these values for us
55 my %search;
56 my $keyword=$query->param('keyword');
57 $search{'keyword'}=$keyword;
58
59 $search{'subject'}=$subject;
60 my $author=$query->param('author');
61 $search{'author'}=$author;
62 my $illustrator=$query->param('illustrator');
63 $search{'param'}=$illustrator;
64 my $itemnumber=$query->param('itemnumber');
65 $search{'itemnumber'}=$itemnumber;
66 my $isbn=$query->param('isbn');
67 $search{'isbn'}=$isbn;
68 my $datebefore=$query->param('date-before');
69 $search{'date-before'}=$datebefore;
70 my $class=$query->param('class');
71 $search{'class'}=$class;
72 my $dewey=$query->param('dewey');
73 $search{'dewey'};
74 my $branch=$query->param('branch');
75 $search{'branch'}=$branch;
76 my $title=$query->param('title');
77 $search{'title'}=$title;
78 my $ttype=$query->param('ttype');
79 $search{'ttype'}=$ttype;
80
81 my $forminputs;
82 ($keyword) && (push @$forminputs, { line => "keyword=$keyword"});
83 ($subject) && (push @$forminputs, { line => "subject=$subject"});
84 ($author) && (push @$forminputs, { line => "author=$author"});
85 ($illustrator) && (push @$forminputs, { line => "illustrator=$illustrator"});
86 ($itemnumber) && (push @$forminputs, { line => "itemnumber=$itemnumber"});
87 ($isbn) && (push @$forminputs, { line => "isbn=$isbn"});
88 ($datebefore) && (push @$forminputs, { line => "date-before=$datebefore"});
89 ($class) && (push @$forminputs, { line => "class=$class"});
90 ($dewey) && (push @$forminputs, { line => "dewey=$dewey"});
91 ($branch) && (push @$forminputs, { line => "branch=$branch"});
92 ($title) && (push @$forminputs, { line => "title=$title"});
93 ($ttype) && (push @$forminputs, { line => "ttype=$ttype"});
94 $template->param(FORMINPUTS => $forminputs);
95 # whats this for?
96 # I think it is (or was) a search from the "front" page...   [st]
97 $search{'front'}=$query->param('front');
98
99 my $num=20;
100 my ($count,@results)=catalogsearch($env,'',\%search,$num,$startfrom);
101
102 my $resultsarray=\@results;
103
104 my $search="num=20";
105 if ($keyword){
106     $search=$search."&keyword=$keyword";
107 }
108 if ($subject){
109     $search=$search."&subject=$subject";
110 }
111 if ($author){
112     $search=$search."&author=$author";
113 }
114 if ($class){
115     $search=$search."&class=$class";
116 }
117 if ($title){
118     $search=$search."&title=$title";
119 }
120 if ($dewey){
121     $search=$search."&dewey=$dewey";
122 }
123 $search.="&ttype=$ttype";
124
125 $search=~ s/ /%20/g;
126 $template->param(startfrom => $startfrom+1);
127 $template->param(endat => $startfrom+20);
128 $template->param(numrecords => $count);
129 my $nextstartfrom=($startfrom+20<$count-20) ? ($startfrom+20) : ($count-20);
130 my $prevstartfrom=($startfrom-20>0) ? ($startfrom-20) : (0);
131 $template->param(nextstartfrom => $nextstartfrom);
132 $template->param(prevstartfrom => $prevstartfrom);
133 $template->param(search => $search);
134 $template->param(SEARCH_RESULTS => $resultsarray);
135 $template->param(includesdir => $includes);
136
137
138 print "Content-Type: text/html\n\n", $template->output;
139