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;
33 use C4::Dates qw( DHTMLcalendar );
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 );
61 my (@marclist,@and_or,@excluding,@operator,@value,$orderby,@tags,$results,$total,$error,$marcresults);
62 # XXX should this be maxItemsInSearchResults or numSearchResults preference instead of 19?
63 my $resultsperpage = $query->param('resultsperpage') || 19;
66 if ( $op eq "do_search" ) {
67 @marclist = $query->param('marclist');
68 @and_or = $query->param('and_or');
69 @excluding = $query->param('excluding');
70 @operator = $query->param('operator');
71 @value = $query->param('value');
72 $orderby = $query->param('orderby');
73 if (scalar @marclist) {
74 #catalogsearch( $dbh, \@tags, \@and_or, \@excluding, \@operator, \@value,
75 # $startfrom * $resultsperpage,
76 # $resultsperpage, $orderby );
77 ( $error, $marcresults ) = SimpleSearch( $marclist[0], $startfrom, $resultsperpage );
79 $show_results = scalar @$marcresults;
81 warn "ERROR label-item-search: no results from SimpleSearch";
82 # leave $show_results undef
87 if ( $show_results ) {
88 my $hits = $show_results;
89 my (@results, @items);
90 # This code needs to be refactored using these subs...
91 #my @items = &GetItemsInfo( $biblio->{biblionumber}, 'intra' );
92 #my $dat = &GetBiblioData( $biblio->{biblionumber} );
93 for(my $i=0; $i<$hits; $i++) {
94 #DEBUG Notes: Decode the MARC record from each resulting MARC record...
95 my $marcrecord = MARC::File::USMARC::decode($marcresults->[$i]);
96 #DEBUG Notes: Transform it to Koha form...
97 my $biblio = TransformMarcToKoha(C4::Context->dbh,$marcrecord,'');
98 # Begin building the hash for the template...
99 # I don't think we need this with the current template design, but I'm leaving it in place. -fbcit
100 #$biblio->{highlight} = ($i % 2)?(1):(0);
101 #DEBUG Notes: Stuff the bib into @results...
102 push @results, $biblio;
103 my $biblionumber = $biblio->{'biblionumber'};
104 #DEBUG Notes: Grab the item numbers associated with this MARC record...
105 my $itemnums = get_itemnumbers_of($biblionumber);
106 #DEBUG Notes: Retrieve the item data for each number...
107 my $iii = $itemnums->{$biblionumber};
109 my $item_results = GetItemInfosOf( @$iii );
110 foreach my $item (keys %$item_results) {
111 #DEBUG Notes: Build an array element 'item' of the correct bib (results) hash which contains item-specific data...
112 if ($item_results->{$item}->{'biblionumber'} eq $results[$i]->{'biblionumber'}) {
113 # NOTE: The order of the elements in this array must be preserved or the table dependent on it will be incorrectly rendered.
114 # This is a real hack, but I can't think of a better way right now. -fbcit
115 push @{$results[$i]->{'item'}}, { i_itemnumber1 => $item_results->{$item}->{'itemnumber'} };
116 push @{$results[$i]->{'item'}}, { i_itemcallnumber => $item_results->{$item}->{'itemcallnumber'} };
117 push @{$results[$i]->{'item'}}, { i_dateaccessioned => $item_results->{$item}->{'dateaccessioned'} };
118 push @{$results[$i]->{'item'}}, { i_barcode => $item_results->{$item}->{'barcode'} };
119 push @{$results[$i]->{'item'}}, { i_itemnumber2 => $item_results->{$item}->{'itemnumber'} };
124 $debug and warn "**********\@results**********\n";
125 $debug and warn Dumper(@results);
127 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
129 template_name => "labels/result.tmpl",
132 authnotrequired => 0,
133 flagsrequired => { borrowers => 1 },
134 flagsrequired => { catalogue => 1 },
141 # FIXME: this relies on symmetric order of CGI params that IS NOT GUARANTEED by spec.
143 for ( my $i = 0 ; $i <= $#marclist ; $i++ ) {
144 push @field_data, { term => "marclist", val => $marclist[$i] };
145 push @field_data, { term => "and_or", val => $and_or[$i] };
146 push @field_data, { term => "excluding", val => $excluding[$i] };
147 push @field_data, { term => "operator", val => $operator[$i] };
148 push @field_data, { term => "value", val => $value[$i] };
152 if ( $total > $resultsperpage ) {
153 for ( my $i = 1 ; $i < $total / $resultsperpage + 1 ; $i++ ) {
156 ( $startfrom == ( $i - 1 ) ) && ( $highlight = 1 );
160 highlight => $highlight,
161 searchdata => \@field_data,
162 startfrom => ( $i - 1 )
168 # multi page display gestion
170 my $displayprev = $startfrom;
171 # XXX Kludge. We show the "next" link if we retrieved the max number of results. There could be 0 more.
172 if ( scalar @results == $resultsperpage ) {
178 startfrom => $startfrom,
179 displaynext => $displaynext,
180 displayprev => $displayprev,
181 resultsperpage => $resultsperpage,
182 startfromnext => $startfrom + min( $resultsperpage, scalar @results ),
183 startfromprev => max( $startfrom - $resultsperpage, 0 ),
184 searchdata => \@field_data,
185 total => (scalar @results),
186 from => $startfrom + 1,
187 to => $startfrom + min( $resultsperpage, scalar @results ),
188 numbers => \@numbers,
189 batch_id => $batch_id,
199 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
201 template_name => "labels/search.tmpl",
204 authnotrequired => 0,
205 flagsrequired => { catalogue => 1 },
210 #using old rel2.2 getitemtypes for testing!!!!, not devweek's GetItemTypes()
212 my $itemtypes = GetItemTypes;
215 foreach my $thisitemtype (keys %$itemtypes) {
216 my %row =(value => $thisitemtype,
217 description => $itemtypes->{$thisitemtype}->{'description'},
219 push @itemtypeloop, \%row;
222 itemtypeloop =>\@itemtypeloop,
223 batch_id => $batch_id,
230 DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
232 output_html_with_http_headers $query, $cookie, $template->output;