minor fixes (to get less warning during translation)
[koha.git] / opac / opac-new.pl
1 #!/usr/bin/perl
2 use strict;
3 require Exporter;
4 use CGI;
5 use C4::Search;
6 use C4::Auth;
7 use C4::Interface::CGI::Output;
8 use HTML::Template;
9
10 my $query=new CGI;
11 my ($template, $borrowernumber, $cookie)
12     = get_template_and_user({template_name => "opac-searchresults.tmpl",
13                              query => $query,
14                              type => "opac",
15                              authnotrequired => 1,
16                              flagsrequired => {borrow => 1},
17                          });
18
19
20
21
22 my $itemtype=$query->param('itemtype');
23 my $duration =$query->param('duration');
24 my $number_of_results = 20;
25
26 my $startfrom = $query->param('startfrom');
27 ($startfrom) || ($startfrom=0);
28 my $subjectitems=$query->param('subjectitems');
29 my (@results) = newsearch($itemtype,$duration,$number_of_results,$startfrom);
30 my $count= $#results+1;
31 my $num = 1;
32 foreach my $res (@results) {
33         my @items = ItemInfo(undef, $res->{'biblionumber'}, "intra");
34         my $norequests = 1;
35         foreach my $itm (@items) {
36                 $norequests = 0 unless $itm->{'notforloan'};
37         }
38         $res->{'norequests'} = $norequests;
39         # set up the even odd elements....
40         $res->{'even'} = 1 if $num % 2 == 0;
41         $res->{'odd'} = 1 if $num % 2 == 1;
42         $num++;
43 }
44
45 my $resultsarray=\@results;
46 ($resultsarray) || (@$resultsarray=());
47
48 # sorting out which results to display.
49 $template->param(startfrom => $startfrom+1);
50 ($startfrom+$num<=$count) ? ($template->param(endat => $startfrom+$num)) : ($template->param(endat => $count));
51 $template->param(numrecords => $count);
52 my $nextstartfrom=($startfrom+$num<$count) ? ($startfrom+$num) : (-1);
53 my $prevstartfrom=($startfrom-$num>=0) ? ($startfrom-$number_of_results) : (-1);
54 my $displaynext=($nextstartfrom==-1) ? 0 : 1;
55 my $displayprev=($prevstartfrom==-1) ? 0 : 1;
56 $template->param(nextstartfrom => $nextstartfrom,
57                                 displaynext => $displaynext,
58                                 displayprev => $displayprev,
59                                 prevstartfrom => $prevstartfrom,
60                                 searchnew => 1,
61                                 itemtype => ItemType($itemtype),
62                                 duration => $duration);
63
64 $template->param(SEARCH_RESULTS => $resultsarray,
65                              LibraryName => C4::Context->preference("LibraryName"),
66 );
67
68 my $numbers;
69 @$numbers = ();
70 if ($count>$number_of_results) {
71         for (my $i=1; $i<$count/$number_of_results+1; $i++) {
72                 my $highlight=0;
73                 my $themelang = $template->param('themelang');
74                 ($startfrom==($i-1)*$number_of_results+1) && ($highlight=1);
75                 push @$numbers, { number => $i, highlight => $highlight , startfrom => ($i-1)*$number_of_results+1 };
76         }
77 }
78
79 $template->param(numbers => $numbers);
80
81 output_html_with_http_headers $query, $cookie, $template->output;