Translating to Spanish. First round.
[koha.git] / opac / opac-searchresults.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::Output; # now contains gettemplate
8
9 my $query=new CGI;
10
11 my $flagsrequired;
12 $flagsrequired->{borrow}=1;
13
14 my ($loggedinuser, $cookie, $sessionID) = checkauth($query, 1, $flagsrequired);
15
16
17 my $template = gettemplate ("opac-searchresults.tmpl", "opac");
18
19
20
21 my $subject=$query->param('subject');
22
23
24 if ($subject) {
25     $template->param(subjectsearch => $subject);
26 }
27
28 # get all the search variables
29 # we assume that C4::Search will validate these values for us
30 my @fields = ('keyword', 'subject', 'author', 'illustrator', 'itemnumber', 'isbn', 'date-before', 'date-after', 'class', 'dewey', 'branch', 'title', 'abstract', 'publisher');
31
32
33
34 # collect all the fields ...
35 my %search;
36 my $forminputs;
37 my $searchdesc = '';
38 foreach my $field (@fields) {
39     $search{$field} = $query->param($field);
40     if ($search{$field}) {
41         push @$forminputs, {field => $field, value => $search{$field}};
42         $searchdesc .= "$field = $search{$field}, ";
43     }
44 }
45 $search{'ttype'} = $query->param('ttype');
46 push @$forminputs, {field => 'ttype', value => $search{'ttype'}};
47
48 if (my $subjectitems=$query->param('subjectitems')){
49     $search{'subject'} = $subjectitems;
50     $searchdesc.="subject = $subjectitems, ";
51 }
52
53 @$forminputs=() unless $forminputs;
54 $template->param(FORMINPUTS => $forminputs);
55
56 # do the searchs ....
57 my $env;
58 $env->{itemcount}=1;
59 my $num=10;
60 my @results;
61 my $count;
62 my $startfrom = $query->param('startfrom');
63 my $subjectitems=$query->param('subjectitems');
64 if ($subjectitems) {
65     @results = subsearch($env,$subjectitems, $num, $startfrom);
66     $count = $#results+1;
67 } else {
68     ($count, @results) = catalogsearch($env,'',\%search,$num,$startfrom);
69 }
70
71 foreach my $res (@results) {
72     my @items = ItemInfo(undef, $res->{'biblionumber'}, "intra");
73     my $norequests = 1;
74     foreach my $itm (@items) {
75         $norequests = 0 unless $itm->{'notforloan'};
76     }
77     $res->{'norequests'} = $norequests;
78 }
79
80
81 my $startfrom=$query->param('startfrom');
82 ($startfrom) || ($startfrom=0);
83
84 my $resultsarray=\@results;
85 ($resultsarray) || (@$resultsarray=());
86
87
88 # sorting out which results to display.
89 $template->param(startfrom => $startfrom+1);
90 ($startfrom+$num<=$count) ? ($template->param(endat => $startfrom+$num)) : ($template->param(endat => $count));
91 $template->param(numrecords => $count);
92 my $nextstartfrom=($startfrom+$num<$count) ? ($startfrom+$num) : (-1);
93 my $prevstartfrom=($startfrom-$num>=0) ? ($startfrom-$num) : (-1);
94 $template->param(nextstartfrom => $nextstartfrom);
95 my $displaynext=1;
96 my $displayprev=0;
97 ($nextstartfrom==-1) ? ($displaynext=0) : ($displaynext=1);
98 ($prevstartfrom==-1) ? ($displayprev=0) : ($displayprev=1);
99 $template->param(displaynext => $displaynext);
100 $template->param(displayprev => $displayprev);
101 $template->param(prevstartfrom => $prevstartfrom);
102
103 $template->param(searchdesc => $searchdesc);
104 $template->param(SEARCH_RESULTS => $resultsarray);
105 $template->param(loggedinuser => $loggedinuser);
106
107 my $numbers;
108 @$numbers = ();
109 if ($count>10) {
110     for (my $i=1; $i<$count/10+1; $i++) {
111         my $highlight=0;
112         my $themelang = $template->param('themelang');
113         ($startfrom==($i-1)*10) && ($highlight=1);
114         push @$numbers, { number => $i, highlight => $highlight , startfrom => ($i-1)*10 };
115     }
116 }
117
118 $template->param(numbers => $numbers);
119
120 $template->param(loggedinuser => $loggedinuser);
121
122 print $query->header(-cookie => $cookie), $template->output;
123