Add biblio using C4::Acquisitions newbiblio
[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 $abstract=$query->param('abstract');
79 $search{'abstract'}=$abstract;
80 my $publisher=$query->param('publisher');
81 $search{'publisher'}=$publisher;
82
83 my $ttype=$query->param('ttype');
84 $search{'ttype'}=$ttype;
85
86 my $forminputs;
87 ($keyword) && (push @$forminputs, { line => "keyword=$keyword"});
88 ($subject) && (push @$forminputs, { line => "subject=$subject"});
89 ($author) && (push @$forminputs, { line => "author=$author"});
90 ($illustrator) && (push @$forminputs, { line => "illustrator=$illustrator"});
91 ($itemnumber) && (push @$forminputs, { line => "itemnumber=$itemnumber"});
92 ($isbn) && (push @$forminputs, { line => "isbn=$isbn"});
93 ($datebefore) && (push @$forminputs, { line => "date-before=$datebefore"});
94 ($class) && (push @$forminputs, { line => "class=$class"});
95 ($dewey) && (push @$forminputs, { line => "dewey=$dewey"});
96 ($branch) && (push @$forminputs, { line => "branch=$branch"});
97 ($title) && (push @$forminputs, { line => "title=$title"});
98 ($ttype) && (push @$forminputs, { line => "ttype=$ttype"});
99 ($abstract) && (push @$forminputs, { line => "abstract=$abstract"});
100 ($publisher) && (push @$forminputs, { line => "publisher=$publisher"});
101 $template->param(FORMINPUTS => $forminputs);
102 # whats this for?
103 # I think it is (or was) a search from the "front" page...   [st]
104 $search{'front'}=$query->param('front');
105
106 my $num=10;
107 my ($count,@results)=catalogsearch($env,'',\%search,$num,$startfrom);
108
109 my $resultsarray=\@results;
110
111 my $search="num=20";
112 if ($keyword){
113     $search=$search."&keyword=$keyword";
114 }
115 if ($subject){
116     $search=$search."&subject=$subject";
117 }
118 if ($author){
119     $search=$search."&author=$author";
120 }
121 if ($class){
122     $search=$search."&class=$class";
123 }
124 if ($title){
125     $search=$search."&title=$title";
126 }
127 if ($dewey){
128     $search=$search."&dewey=$dewey";
129 }
130 $search.="&ttype=$ttype";
131
132 $search=~ s/ /%20/g;
133 $template->param(startfrom => $startfrom+1);
134 $template->param(endat => $startfrom+$num);
135 $template->param(numrecords => $count);
136 my $nextstartfrom=($startfrom+$num<$count-$num) ? ($startfrom+$num) : ($count-$num);
137 my $prevstartfrom=($startfrom-$num>0) ? ($startfrom-$num) : (0);
138 $template->param(nextstartfrom => $nextstartfrom);
139 $template->param(prevstartfrom => $prevstartfrom);
140 $template->param(search => $search);
141 $template->param(SEARCH_RESULTS => $resultsarray);
142 $template->param(includesdir => $includes);
143
144
145 print "Content-Type: text/html\n\n", $template->output;
146