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
24 use HTML::Template::Pro;
34 use C4::Koha; # XXX subfield_is_koha_internal_p
36 use List::Util qw( max min );
40 $debug = $debug || $cgi_debug;
43 import Data::Dumper qw(Dumper);
47 # Creates a scrolling list with the associated default value.
48 # Using more than one scrolling list in a CGI assigns the same default value to all the
49 # scrolling lists on the page !?!? That's why this function was written.
52 my $type = $query->param('type');
53 my $op = $query->param('op');
54 my $batch_id = $query->param('batch_id');
55 my $dateaccessioned = $query->param('dateaccessioned');
57 my $dbh = C4::Context->dbh;
59 my $startfrom = $query->param('startfrom') || 0;
60 my ( $template, $loggedinuser, $cookie );
62 my (@marclist,@and_or,@excluding,@operator,@value,$orderby,@tags,$results,$total,$error,$marcresults);
63 # XXX should this be maxItemsInSearchResults or numSearchResults preference instead of 19?
64 my $resultsperpage = $query->param('resultsperpage') || 19;
67 if ( $op eq "do_search" ) {
68 @marclist = $query->param('marclist');
69 @and_or = $query->param('and_or');
70 @excluding = $query->param('excluding');
71 @operator = $query->param('operator');
72 @value = $query->param('value');
73 $orderby = $query->param('orderby');
74 if (scalar @marclist) {
75 #catalogsearch( $dbh, \@tags, \@and_or, \@excluding, \@operator, \@value,
76 # $startfrom * $resultsperpage,
77 # $resultsperpage, $orderby );
78 ( $error, $marcresults, $total_hits ) = SimpleSearch( $marclist[0], $startfrom, $resultsperpage );
80 $show_results = scalar @$marcresults;
82 warn "ERROR label-item-search: no results from SimpleSearch";
83 # leave $show_results undef
88 if ( $show_results ) {
89 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
91 template_name => "labels/result.tmpl",
95 flagsrequired => { catalogue => 1 },
100 my $hits = $show_results;
101 my (@results, @items);
102 # This code needs to be refactored using these subs...
103 #my @items = &GetItemsInfo( $biblio->{biblionumber}, 'intra' );
104 #my $dat = &GetBiblioData( $biblio->{biblionumber} );
105 for(my $i=0; $i<$hits; $i++) {
106 #DEBUG Notes: Decode the MARC record from each resulting MARC record...
107 my $marcrecord = MARC::File::USMARC::decode($marcresults->[$i]);
108 #DEBUG Notes: Transform it to Koha form...
109 my $biblio = TransformMarcToKoha(C4::Context->dbh,$marcrecord,'');
110 # Begin building the hash for the template...
111 # I don't think we need this with the current template design, but I'm leaving it in place. -fbcit
112 #$biblio->{highlight} = ($i % 2)?(1):(0);
113 #DEBUG Notes: Stuff the bib into @results...
114 push @results, $biblio;
115 my $biblionumber = $biblio->{'biblionumber'};
116 #DEBUG Notes: Grab the item numbers associated with this MARC record...
117 my $itemnums = get_itemnumbers_of($biblionumber);
118 #DEBUG Notes: Retrieve the item data for each number...
119 my $iii = $itemnums->{$biblionumber};
121 my $item_results = GetItemInfosOf( @$iii );
122 foreach my $item (keys %$item_results) {
123 #DEBUG Notes: Build an array element 'item' of the correct bib (results) hash which contains item-specific data...
124 if ($item_results->{$item}->{'biblionumber'} eq $results[$i]->{'biblionumber'}) {
125 # NOTE: The order of the elements in this array must be preserved or the table dependent on it will be incorrectly rendered.
126 # This is a real hack, but I can't think of a better way right now. -fbcit
127 # It is conceivable that itemcallnumber and/or barcode fields might be empty so the trinaries cover this possibility.
128 push @{$results[$i]->{'item'}}, { i_itemnumber1 => $item_results->{$item}->{'itemnumber'} };
129 push @{$results[$i]->{'item'}}, { i_itemcallnumber => ($item_results->{$item}->{'itemcallnumber'} ? $item_results->{$item}->{'itemcallnumber'} : 'NA') };
130 push @{$results[$i]->{'item'}}, { i_dateaccessioned => $item_results->{$item}->{'dateaccessioned'} };
131 push @{$results[$i]->{'item'}}, { i_barcode => ($item_results->{$item}->{'barcode'} ? $item_results->{$item}->{'barcode'} : 'NA')};
132 push @{$results[$i]->{'item'}}, { i_itemnumber2 => $item_results->{$item}->{'itemnumber'} };
137 $debug and warn "**********\@results**********\n";
138 $debug and warn Dumper(@results);
142 # FIXME: this relies on symmetric order of CGI params that IS NOT GUARANTEED by spec.
144 for ( my $i = 0 ; $i <= $#marclist ; $i++ ) {
145 push @field_data, { term => "marclist", val => $marclist[$i] };
146 push @field_data, { term => "and_or", val => $and_or[$i] };
147 push @field_data, { term => "excluding", val => $excluding[$i] };
148 push @field_data, { term => "operator", val => $operator[$i] };
149 push @field_data, { term => "value", val => $value[$i] };
153 $total = $total_hits;
154 if ( $total > $resultsperpage ) {
155 for ( my $i = 1 ; $i < $total / $resultsperpage + 1 ; $i++ ) {
158 ( $startfrom == ( $i - 1 ) ) && ( $highlight = 1 );
162 highlight => $highlight,
163 searchdata => \@field_data,
164 startfrom => ( $i - 1 )
170 # multi page display gestion
172 my $displayprev = $startfrom;
173 # XXX Kludge. We show the "next" link if we retrieved the max number of results. There could be 0 more.
174 if ( scalar @results == $resultsperpage ) {
180 startfrom => $startfrom,
181 displaynext => $displaynext,
182 displayprev => $displayprev,
183 resultsperpage => $resultsperpage,
184 startfromnext => $startfrom + min( $resultsperpage, scalar @results ),
185 startfromprev => max( $startfrom - $resultsperpage, 0 ),
186 searchdata => \@field_data,
187 total => $total_hits,
188 from => $startfrom + 1,
189 to => $startfrom + min( $resultsperpage, scalar @results ),
190 numbers => \@numbers,
191 batch_id => $batch_id,
201 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
203 template_name => "labels/search.tmpl",
206 authnotrequired => 0,
207 flagsrequired => { catalogue => 1 },
211 my $itemtypes = GetItemTypes;
213 foreach my $thisitemtype (keys %$itemtypes) {
214 my %row =(value => $thisitemtype,
215 description => $itemtypes->{$thisitemtype}->{'description'},
217 push @itemtypeloop, \%row;
220 itemtypeloop =>\@itemtypeloop,
221 batch_id => $batch_id,
228 DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
230 output_html_with_http_headers $query, $cookie, $template->output;