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 # 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');
50 my $dbh = C4::Context->dbh;
52 my $startfrom = $query->param('startfrom') || 0;
53 my ( $template, $loggedinuser, $cookie );
54 my (@marclist,@and_or,@excluding,@operator,@value,$orderby,@tags,$results,$total,$error,$marcresults);
55 # XXX should this be maxItemsInSearchResults or numSearchResults preference instead of 19?
56 my $resultsperpage = $query->param('resultsperpage') || 19;
59 if ( $op eq "do_search" ) {
60 @marclist = $query->param('marclist');
61 @and_or = $query->param('and_or');
62 @excluding = $query->param('excluding');
63 @operator = $query->param('operator');
64 @value = $query->param('value');
65 $orderby = $query->param('orderby');
66 if (scalar @marclist) {
67 #catalogsearch( $dbh, \@tags, \@and_or, \@excluding, \@operator, \@value,
68 # $startfrom * $resultsperpage,
69 # $resultsperpage, $orderby );
70 ( $error, $marcresults ) = SimpleSearch( $marclist[0], $startfrom, $resultsperpage );
72 $show_results = scalar @$marcresults;
74 warn "ERROR label-item-search: no results from SimpleSearch";
75 # leave $show_results undef
80 if ( $show_results ) {
81 my $hits = $show_results;
82 my (@results,@results2);
83 # This code needs to be refactored using these subs...
84 #my @items = &GetItemsInfo( $biblio->{biblionumber}, 'intra' );
85 #my $dat = &GetBiblioData( $biblio->{biblionumber} );
86 for(my $i=0; $i<$hits; $i++) {
87 #DEBUG Notes: Decode the MARC record from each resulting MARC record...
88 my $marcrecord = MARC::File::USMARC::decode($marcresults->[$i]);
89 #DEBUG Notes: Transform it to Koha form...
90 my $biblio = TransformMarcToKoha(C4::Context->dbh,$marcrecord,'');
91 #build the hash for the template.
92 $biblio->{highlight} = ($i % 2)?(1):(0);
93 #DEBUG Notes: Stuff it into @results... (used below to supply fields not existing in the item data)
94 push @results, $biblio;
95 my $biblionumber = $biblio->{'biblionumber'};
96 #DEBUG Notes: Grab the item numbers associated with this MARC record...
97 my $itemnums = get_itemnumbers_of($biblionumber);
98 #DEBUG Notes: Retrieve the item data for each number...
99 my $iii = $itemnums->{$biblionumber};
101 my @titem_results = GetItemsInfo( $itemnums->{$biblionumber}, 'intra' );
102 my $item_results = GetItemInfosOf( @$iii );
103 foreach my $item (keys %$item_results) {
104 for my $bibdata (keys %{$results[$i]}) {
105 if ( !$item_results->{$item}{$bibdata} ) { #Only add the data from the bibliodata if the data does not already exit in itemdata.
106 #Otherwise we just build duplicate records rather than unique records per item.
107 $item_results->{$item}{$bibdata} = $results[$i]->{$bibdata};
110 #DEBUG Notes: After merging the bib and item data, stuff the results into $results2...
111 push @results2, $item_results->{$item};
113 #warn Dumper(@results2);
117 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
119 template_name => "labels/result.tmpl",
122 authnotrequired => 0,
123 flagsrequired => { borrowers => 1 },
124 flagsrequired => { catalogue => 1 },
131 # FIXME: this relies on symmetric order of CGI params that IS NOT GUARANTEED by spec.
133 for ( my $i = 0 ; $i <= $#marclist ; $i++ ) {
134 push @field_data, { term => "marclist", val => $marclist[$i] };
135 push @field_data, { term => "and_or", val => $and_or[$i] };
136 push @field_data, { term => "excluding", val => $excluding[$i] };
137 push @field_data, { term => "operator", val => $operator[$i] };
138 push @field_data, { term => "value", val => $value[$i] };
142 if ( $total > $resultsperpage ) {
143 for ( my $i = 1 ; $i < $total / $resultsperpage + 1 ; $i++ ) {
146 ( $startfrom == ( $i - 1 ) ) && ( $highlight = 1 );
150 highlight => $highlight,
151 searchdata => \@field_data,
152 startfrom => ( $i - 1 )
158 # multi page display gestion
160 my $displayprev = $startfrom;
161 # XXX Kludge. We show the "next" link if we retrieved the max number of results. There could be 0 more.
162 if ( scalar @results2 == $resultsperpage ) {
167 result => \@results2,
168 startfrom => $startfrom,
169 displaynext => $displaynext,
170 displayprev => $displayprev,
171 resultsperpage => $resultsperpage,
172 startfromnext => $startfrom + min( $resultsperpage, scalar @results2 ),
173 startfromprev => max( $startfrom - $resultsperpage, 0 ),
174 searchdata => \@field_data,
176 from => $startfrom + 1,
177 to => $startfrom + min( $resultsperpage, scalar @results2 ),
178 numbers => \@numbers,
179 batch_id => $batch_id,
189 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
191 template_name => "labels/search.tmpl",
194 authnotrequired => 0,
195 flagsrequired => { catalogue => 1 },
200 #using old rel2.2 getitemtypes for testing!!!!, not devweek's GetItemTypes()
202 my $itemtypes = GetItemTypes;
205 foreach my $thisitemtype (keys %$itemtypes) {
206 my %row =(value => $thisitemtype,
207 description => $itemtypes->{$thisitemtype}->{'description'},
209 push @itemtypeloop, \%row;
212 itemtypeloop =>\@itemtypeloop,
213 batch_id => $batch_id,
220 DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
222 output_html_with_http_headers $query, $cookie, $template->output;