2 # WARNING: 4-character tab stops here
4 # Copyright 2000-2002 Katipo Communications
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along with
18 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
19 # Suite 330, Boston, MA 02111-1307 USA
25 use HTML::Template::Pro;
33 use C4::Dates qw( DHTMLcalendar );
34 use C4::Koha; # XXX subfield_is_koha_internal_p
39 # Creates a scrolling list with the associated default value.
40 # Using more than one scrolling list in a CGI assigns the same default value to all the
41 # scrolling lists on the page !?!? That's why this function was written.
44 my $type = $query->param('type');
45 my $op = $query->param('op');
46 my $batch_id = $query->param('batch_id');
47 my $dateaccessioned = $query->param('dateaccessioned');
51 my $dbh = C4::Context->dbh;
53 my $startfrom = $query->param('startfrom');
54 $startfrom = 0 if ( !defined $startfrom );
55 my ( $template, $loggedinuser, $cookie );
58 if ( $op eq "do_search" ) {
59 my @marclist = $query->param('marclist');
60 my @and_or = $query->param('and_or');
61 my @excluding = $query->param('excluding');
62 my @operator = $query->param('operator');
63 my @value = $query->param('value');
65 $resultsperpage = $query->param('resultsperpage');
66 $resultsperpage = 19 if ( !defined $resultsperpage );
67 my $orderby = $query->param('orderby');
69 # builds tag and subfield arrays
72 my ( $results, $total ) ;
73 #catalogsearch( $dbh, \@tags, \@and_or, \@excluding, \@operator, \@value,
74 # $startfrom * $resultsperpage,
75 # $resultsperpage, $orderby );
78 my $searchquery=$marclist[0];
79 my ($error, $marcresults) = SimpleSearch($searchquery);
81 my $hits = scalar @$marcresults;
86 for(my $i=0;$i<$hits;$i++) {
88 my $marcrecord = MARC::File::USMARC::decode($marcresults->[$i]);
89 my $biblio = TransformMarcToKoha(C4::Context->dbh,$marcrecord,'');
90 #build the hash for the template.
91 %resultsloop=%$biblio;
92 $resultsloop{highlight} = ($i % 2)?(1):(0);
93 #warn $resultsloop{biblionumber};
95 push @results, \%resultsloop;
99 for ( $i = 0 ; $i <= ( $hits - 1 ) ; $i++ ) {
101 my $itemnums = get_itemnumbers_of($results[$i]->{'biblionumber'});
103 my $iii = $itemnums->{$results[$i]->{'biblionumber'} } ;
106 $item_results = &GetItemInfosOf( @$iii );
108 foreach my $item (keys %$item_results) {
109 for my $bibdata (keys %{$results[$i]}) {
110 #warn Dumper($bibdata);
111 #warn Dumper($results[$i]->{$bibdata});
112 $item_results->{$item}{$bibdata} = $results[$i]->{$bibdata};
114 push @results2, $item_results->{$item};
118 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
120 template_name => "labels/result.tmpl",
123 authnotrequired => 0,
124 flagsrequired => { borrowers => 1 },
125 flagsrequired => { catalogue => 1 },
130 # multi page display gestion
132 my $displayprev = $startfrom;
133 if ( ( $total - ( ( $startfrom + 1 ) * ($resultsperpage) ) ) > 0 ) {
139 for ( my $i = 0 ; $i <= $#marclist ; $i++ ) {
140 push @field_data, { term => "marclist", val => $marclist[$i] };
141 push @field_data, { term => "and_or", val => $and_or[$i] };
142 push @field_data, { term => "excluding", val => $excluding[$i] };
143 push @field_data, { term => "operator", val => $operator[$i] };
144 push @field_data, { term => "value", val => $value[$i] };
149 if ( $total > $resultsperpage ) {
150 for ( my $i = 1 ; $i < $total / $resultsperpage + 1 ; $i++ ) {
153 ( $startfrom == ( $i - 1 ) ) && ( $highlight = 1 );
157 highlight => $highlight,
158 searchdata => \@field_data,
159 startfrom => ( $i - 1 )
165 my $from = $startfrom * $resultsperpage + 1;
168 if ( $total < ( ( $startfrom + 1 ) * $resultsperpage ) ) {
172 $to = ( ( $startfrom + 1 ) * $resultsperpage );
175 # this gets the results of the search (which are bibs)
176 # and then does a lookup on all items that exist for that bib
177 # then pushes the items onto a new array, as we really want the
178 # items attached to the bibs not thew bibs themselves
182 for ( $i = 0 ; $i <= ( $total - 1 ) ; $i++ )
183 { #total-1 coz the array starts at 0
185 #warn Dumper $results->[$i]{'bibid'};
188 &ItemInfo( 0, $results->[$i]{'biblionumber'}, $type );
190 foreach my $item (@item_results) {
193 push @results2, $item;
199 result => \@results2,
200 startfrom => $startfrom,
201 displaynext => $displaynext,
202 displayprev => $displayprev,
203 resultsperpage => $resultsperpage,
204 startfromnext => $startfrom + 1,
205 startfromprev => $startfrom - 1,
206 searchdata => \@field_data,
210 numbers => \@numbers,
211 batch_id => $batch_id,
222 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
224 template_name => "labels/search.tmpl",
227 authnotrequired => 0,
228 flagsrequired => { catalogue => 1 },
234 #using old rel2.2 getitemtypes for testing!!!!, not devweek's GetItemTypes()
236 my $itemtypes = GetItemTypes;
239 foreach my $thisitemtype (keys %$itemtypes) {
240 my %row =(value => $thisitemtype,
241 description => $itemtypes->{$thisitemtype}->{'description'},
243 push @itemtypeloop, \%row;
248 itemtypeloop =>\@itemtypeloop,
249 batch_id => $batch_id,
255 DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
257 output_html_with_http_headers $query, $cookie, $template->output;