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 );
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 my $hits = $show_results;
90 my (@results, @items);
91 # This code needs to be refactored using these subs...
92 #my @items = &GetItemsInfo( $biblio->{biblionumber}, 'intra' );
93 #my $dat = &GetBiblioData( $biblio->{biblionumber} );
94 for(my $i=0; $i<$hits; $i++) {
95 #DEBUG Notes: Decode the MARC record from each resulting MARC record...
96 my $marcrecord = MARC
::File
::USMARC
::decode
($marcresults->[$i]);
97 #DEBUG Notes: Transform it to Koha form...
98 my $biblio = TransformMarcToKoha
(C4
::Context
->dbh,$marcrecord,'');
99 # Begin building the hash for the template...
100 # I don't think we need this with the current template design, but I'm leaving it in place. -fbcit
101 #$biblio->{highlight} = ($i % 2)?(1):(0);
102 #DEBUG Notes: Stuff the bib into @results...
103 push @results, $biblio;
104 my $biblionumber = $biblio->{'biblionumber'};
105 #DEBUG Notes: Grab the item numbers associated with this MARC record...
106 my $itemnums = get_itemnumbers_of
($biblionumber);
107 #DEBUG Notes: Retrieve the item data for each number...
108 my $iii = $itemnums->{$biblionumber};
110 my $item_results = GetItemInfosOf
( @
$iii );
111 foreach my $item (keys %$item_results) {
112 #DEBUG Notes: Build an array element 'item' of the correct bib (results) hash which contains item-specific data...
113 if ($item_results->{$item}->{'biblionumber'} eq $results[$i]->{'biblionumber'}) {
114 # NOTE: The order of the elements in this array must be preserved or the table dependent on it will be incorrectly rendered.
115 # This is a real hack, but I can't think of a better way right now. -fbcit
116 # It is conceivable that itemcallnumber and/or barcode fields might be empty so the trinaries cover this possibility.
117 push @
{$results[$i]->{'item'}}, { i_itemnumber1
=> $item_results->{$item}->{'itemnumber'} };
118 push @
{$results[$i]->{'item'}}, { i_itemcallnumber
=> ($item_results->{$item}->{'itemcallnumber'} ?
$item_results->{$item}->{'itemcallnumber'} : 'NA') };
119 push @
{$results[$i]->{'item'}}, { i_dateaccessioned
=> $item_results->{$item}->{'dateaccessioned'} };
120 push @
{$results[$i]->{'item'}}, { i_barcode
=> ($item_results->{$item}->{'barcode'} ?
$item_results->{$item}->{'barcode'} : 'NA')};
121 push @
{$results[$i]->{'item'}}, { i_itemnumber2
=> $item_results->{$item}->{'itemnumber'} };
126 $debug and warn "**********\@results**********\n";
127 $debug and warn Dumper
(@results);
129 ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
131 template_name
=> "labels/result.tmpl",
134 authnotrequired
=> 0,
135 flagsrequired
=> { borrowers
=> 1 },
136 flagsrequired
=> { catalogue
=> 1 },
143 # FIXME: this relies on symmetric order of CGI params that IS NOT GUARANTEED by spec.
145 for ( my $i = 0 ; $i <= $#marclist ; $i++ ) {
146 push @field_data, { term
=> "marclist", val
=> $marclist[$i] };
147 push @field_data, { term
=> "and_or", val
=> $and_or[$i] };
148 push @field_data, { term
=> "excluding", val
=> $excluding[$i] };
149 push @field_data, { term
=> "operator", val
=> $operator[$i] };
150 push @field_data, { term
=> "value", val
=> $value[$i] };
154 $total = $total_hits;
155 if ( $total > $resultsperpage ) {
156 for ( my $i = 1 ; $i < $total / $resultsperpage + 1 ; $i++ ) {
159 ( $startfrom == ( $i - 1 ) ) && ( $highlight = 1 );
163 highlight
=> $highlight,
164 searchdata
=> \
@field_data,
165 startfrom
=> ( $i - 1 )
171 # multi page display gestion
173 my $displayprev = $startfrom;
174 # XXX Kludge. We show the "next" link if we retrieved the max number of results. There could be 0 more.
175 if ( scalar @results == $resultsperpage ) {
181 startfrom
=> $startfrom,
182 displaynext
=> $displaynext,
183 displayprev
=> $displayprev,
184 resultsperpage
=> $resultsperpage,
185 startfromnext
=> $startfrom + min
( $resultsperpage, scalar @results ),
186 startfromprev
=> max
( $startfrom - $resultsperpage, 0 ),
187 searchdata
=> \
@field_data,
188 total
=> $total_hits,
189 from
=> $startfrom + 1,
190 to
=> $startfrom + min
( $resultsperpage, scalar @results ),
191 numbers
=> \
@numbers,
192 batch_id
=> $batch_id,
202 ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
204 template_name
=> "labels/search.tmpl",
207 authnotrequired
=> 0,
208 flagsrequired
=> { catalogue
=> 1 },
213 #using old rel2.2 getitemtypes for testing!!!!, not devweek's GetItemTypes()
215 my $itemtypes = GetItemTypes
;
218 foreach my $thisitemtype (keys %$itemtypes) {
219 my %row =(value
=> $thisitemtype,
220 description
=> $itemtypes->{$thisitemtype}->{'description'},
222 push @itemtypeloop, \
%row;
225 itemtypeloop
=>\
@itemtypeloop,
226 batch_id
=> $batch_id,
233 DHTMLcalendar_dateformat
=> C4
::Dates
->DHTMLcalendar(),
235 output_html_with_http_headers
$query, $cookie, $template->output;