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;
34 use C4::Dates qw( DHTMLcalendar );
35 use C4::Koha; # XXX subfield_is_koha_internal_p
40 # Creates a scrolling list with the associated default value.
41 # Using more than one scrolling list in a CGI assigns the same default value to all the
42 # scrolling lists on the page !?!? That's why this function was written.
45 my $type = $query->param('type');
46 my $op = $query->param('op');
47 my $batch_id = $query->param('batch_id');
48 my $dateaccessioned = $query->param('dateaccessioned');
52 my $dbh = C4::Context->dbh;
54 my $startfrom = $query->param('startfrom');
55 $startfrom = 0 if ( !defined $startfrom );
56 my ( $template, $loggedinuser, $cookie );
59 if ( $op eq "do_search" ) {
60 my @marclist = $query->param('marclist');
61 my @and_or = $query->param('and_or');
62 my @excluding = $query->param('excluding');
63 my @operator = $query->param('operator');
64 my @value = $query->param('value');
66 $resultsperpage = $query->param('resultsperpage');
67 $resultsperpage = 19 if ( !defined $resultsperpage );
68 my $orderby = $query->param('orderby');
70 # builds tag and subfield arrays
73 my ( $results, $total ) ;
74 #catalogsearch( $dbh, \@tags, \@and_or, \@excluding, \@operator, \@value,
75 # $startfrom * $resultsperpage,
76 # $resultsperpage, $orderby );
79 my $searchquery=$marclist[0];
80 my ($error, $marcresults) = SimpleSearch($searchquery);
81 my $hits = scalar @$marcresults;
84 for(my $i=0;$i<$hits;$i++) {
86 my $marcrecord = MARC::File::USMARC::decode($marcresults->[$i]);
87 my $biblio = TransformMarcToKoha(C4::Context->dbh,$marcrecord,'');
88 #build the hash for the template.
89 %resultsloop=%$biblio;
90 $resultsloop{highlight} = ($i % 2)?(1):(0);
91 #warn $resultsloop{biblionumber};
92 push @results, \%resultsloop;
96 for ( $i = 0 ; $i <= ( $hits - 1 ) ; $i++ ) {
97 my $itemnums = get_itemnumbers_of($results[$i]->{'biblionumber'});
99 my $iii = $itemnums->{$results[$i]->{'biblionumber'} } ;
102 $item_results = &GetItemInfosOf( @$iii );
104 foreach my $item (keys %$item_results) {
105 for my $bibdata (keys %{$results[$i]}) {
106 #warn Dumper($bibdata);
107 #warn Dumper($results[$i]->{$bibdata});
108 $item_results->{$item}{$bibdata} = $results[$i]->{$bibdata} unless exists $item_results->{$item}{$bibdata};
110 push @results2, $item_results->{$item};
114 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
116 template_name => "labels/result.tmpl",
119 authnotrequired => 0,
120 flagsrequired => { borrowers => 1 },
121 flagsrequired => { catalogue => 1 },
126 # multi page display gestion
128 my $displayprev = $startfrom;
129 if ( ( $total - ( ( $startfrom + 1 ) * ($resultsperpage) ) ) > 0 ) {
135 for ( my $i = 0 ; $i <= $#marclist ; $i++ ) {
136 push @field_data, { term => "marclist", val => $marclist[$i] };
137 push @field_data, { term => "and_or", val => $and_or[$i] };
138 push @field_data, { term => "excluding", val => $excluding[$i] };
139 push @field_data, { term => "operator", val => $operator[$i] };
140 push @field_data, { term => "value", val => $value[$i] };
145 if ( $total > $resultsperpage ) {
146 for ( my $i = 1 ; $i < $total / $resultsperpage + 1 ; $i++ ) {
149 ( $startfrom == ( $i - 1 ) ) && ( $highlight = 1 );
153 highlight => $highlight,
154 searchdata => \@field_data,
155 startfrom => ( $i - 1 )
161 my $from = $startfrom * $resultsperpage + 1;
164 if ( $total < ( ( $startfrom + 1 ) * $resultsperpage ) ) {
168 $to = ( ( $startfrom + 1 ) * $resultsperpage );
171 # this gets the results of the search (which are bibs)
172 # and then does a lookup on all items that exist for that bib
173 # then pushes the items onto a new array, as we really want the
174 # items attached to the bibs not thew bibs themselves
177 for (my $i = 0 ; $i <= ( $total - 1 ) ; $i++ )
178 { #total-1 coz the array starts at 0
180 #warn Dumper $results->[$i]{'bibid'};
183 &ItemInfo( 0, $results->[$i]{'biblionumber'}, $type );
185 foreach my $item (@item_results) {
187 push @results2, $item;
193 result => \@results2,
194 startfrom => $startfrom,
195 displaynext => $displaynext,
196 displayprev => $displayprev,
197 resultsperpage => $resultsperpage,
198 startfromnext => $startfrom + 1,
199 startfromprev => $startfrom - 1,
200 searchdata => \@field_data,
204 numbers => \@numbers,
205 batch_id => $batch_id,
216 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
218 template_name => "labels/search.tmpl",
221 authnotrequired => 0,
222 flagsrequired => { catalogue => 1 },
228 #using old rel2.2 getitemtypes for testing!!!!, not devweek's GetItemTypes()
230 my $itemtypes = GetItemTypes;
233 foreach my $thisitemtype (keys %$itemtypes) {
234 my %row =(value => $thisitemtype,
235 description => $itemtypes->{$thisitemtype}->{'description'},
237 push @itemtypeloop, \%row;
242 itemtypeloop =>\@itemtypeloop,
243 batch_id => $batch_id,
249 DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
251 output_html_with_http_headers $query, $cookie, $template->output;