3 # Copyright 2000-2002 Katipo Communications
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
25 use HTML
::Template
::Pro
;
35 use C4
::Koha
; # XXX subfield_is_koha_internal_p
37 use List
::Util
qw( max min );
44 $debug = $debug || $cgi_debug;
47 import Data
::Dumper
qw(Dumper);
51 # Creates a scrolling list with the associated default value.
52 # Using more than one scrolling list in a CGI assigns the same default value to all the
53 # scrolling lists on the page !?!? That's why this function was written.
57 my $type = $query->param('type');
58 my $op = $query->param('op') || '';
59 my $batch_id = $query->param('batch_id');
60 my $ccl_query = $query->param('ccl_query');
62 my $dbh = C4
::Context
->dbh;
64 my $startfrom = $query->param('startfrom') || 1;
65 my ( $template, $loggedinuser, $cookie );
67 $total_hits, $orderby, $results, $total, $error,
68 $marcresults, $idx, $datefrom, $dateto, $ccl_textbox
71 my $resultsperpage = C4
::Context
->preference('numSearchResults') || '20';
75 if ( $op eq "do_search" ) {
76 $idx = $query->param('idx');
77 $ccl_textbox = $query->param('ccl_textbox');
78 if ( $ccl_textbox && $idx ) {
79 $ccl_query = "$idx=$ccl_textbox";
82 $datefrom = $query->param('datefrom');
83 $dateto = $query->param('dateto');
86 $datefrom = C4
::Dates
->new($datefrom);
87 $ccl_query .= ' and ' if $ccl_textbox;
89 "acqdate,st-date-normalized,ge=" . $datefrom->output("iso");
93 $dateto = C4
::Dates
->new($dateto);
94 $ccl_query .= ' and ' if ( $ccl_textbox || $datefrom );
95 $ccl_query .= "acqdate,st-date-normalized,le=" . $dateto->output("iso");
98 my $offset = $startfrom > 1 ?
$startfrom - 1 : 0;
99 ( $error, $marcresults, $total_hits ) =
100 SimpleSearch
( $ccl_query, $offset, $resultsperpage );
103 $show_results = scalar @
$marcresults;
106 $debug and warn "ERROR label-item-search: no results from SimpleSearch";
108 # leave $show_results undef
113 my $hits = $show_results;
114 my ( @results, @items );
116 # This code needs to be refactored using these subs...
117 #my @items = &GetItemsInfo( $biblio->{biblionumber}, 'intra' );
118 #my $dat = &GetBiblioData( $biblio->{biblionumber} );
119 for ( my $i = 0 ; $i < $hits ; $i++ ) {
121 #DEBUG Notes: Decode the MARC record from each resulting MARC record...
122 my $marcrecord = MARC
::File
::USMARC
::decode
( $marcresults->[$i] );
124 #DEBUG Notes: Transform it to Koha form...
125 my $biblio = TransformMarcToKoha
( C4
::Context
->dbh, $marcrecord, '' );
127 # Begin building the hash for the template...
128 # I don't think we need this with the current template design, but I'm leaving it in place. -fbcit
129 #$biblio->{highlight} = ($i % 2)?(1):(0);
130 #DEBUG Notes: Stuff the bib into @results...
131 push @results, $biblio;
132 my $biblionumber = $biblio->{'biblionumber'};
134 #DEBUG Notes: Grab the item numbers associated with this MARC record...
135 my $itemnums = get_itemnumbers_of
($biblionumber);
137 #DEBUG Notes: Retrieve the item data for each number...
138 my $iii = $itemnums->{$biblionumber};
140 my $item_results = GetItemInfosOf
(@
$iii);
141 foreach my $item ( keys %$item_results ) {
143 #DEBUG Notes: Build an array element 'item' of the correct bib (results) hash which contains item-specific data...
144 if ( $item_results->{$item}->{'biblionumber'} eq
145 $results[$i]->{'biblionumber'} )
148 # NOTE: The order of the elements in this array must be preserved or the table dependent on it will be incorrectly rendered.
149 # This is a real hack, but I can't think of a better way right now. -fbcit
150 # It is conceivable that itemcallnumber and/or barcode fields might be empty so the trinaries cover this possibility.
151 push @
{ $results[$i]->{'item'} }, { i_itemnumber1
=>
152 $item_results->{$item}->{'itemnumber'} };
153 push @
{ $results[$i]->{'item'} },
155 i_itemcallnumber
=> (
156 $item_results->{$item}->{'itemcallnumber'}
157 ?
$item_results->{$item}->{'itemcallnumber'}
161 push @
{ $results[$i]->{'item'} }, { i_dateaccessioned
=>
162 $item_results->{$item}->{'dateaccessioned'} };
163 push @
{ $results[$i]->{'item'} },
166 $item_results->{$item}->{'barcode'}
167 ?
$item_results->{$item}->{'barcode'}
171 push @
{ $results[$i]->{'item'} }, { i_itemnumber2
=>
172 $item_results->{$item}->{'itemnumber'} };
177 $debug and warn "**********\@results**********\n";
178 $debug and warn Dumper
(@results);
180 ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
182 template_name
=> "labels/result.tmpl",
185 authnotrequired
=> 0,
186 flagsrequired
=> { borrowers
=> 1 },
187 flagsrequired
=> { catalogue
=> 1 },
192 # build page nav stuff.
193 my ( @field_data, @numbers );
194 $total = $total_hits;
196 my ( $from, $to, $startfromnext, $startfromprev, $displaynext,
199 if ( $total > $resultsperpage ) {
200 my $num_of_pages = ceil
( $total / $resultsperpage + 1 );
201 for ( my $page = 1 ; $page < $num_of_pages ; $page++ ) {
202 my $startfrm = ( ( $page - 1 ) * $resultsperpage ) + 1;
206 startfrom
=> $startfrm
211 $startfromprev = $startfrom - $resultsperpage;
212 $startfromnext = $startfrom + $resultsperpage;
215 $startfrom + $resultsperpage > $total
217 : $startfrom + $resultsperpage - 1;
221 $displayprev = $startfrom > 1 ?
$startfrom : 0;
223 $displaynext = 1 if $to < $total_hits;
232 total
=> $total_hits,
235 startfromnext
=> $startfromnext,
236 startfromprev
=> $startfromprev,
237 startfrom
=> $startfrom,
238 displaynext
=> $displaynext,
239 displayprev
=> $displayprev,
240 resultsperpage
=> $resultsperpage,
241 numbers
=> \
@numbers,
246 batch_id
=> $batch_id,
249 ccl_query
=> $ccl_query,
258 ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
260 template_name
=> "labels/search.tmpl",
263 authnotrequired
=> 0,
264 flagsrequired
=> { catalogue
=> 1 },
268 my $itemtypes = GetItemTypes
;
270 foreach my $thisitemtype ( keys %$itemtypes ) {
272 value
=> $thisitemtype,
273 description
=> $itemtypes->{$thisitemtype}->{'description'},
275 push @itemtypeloop, \
%row;
278 itemtypeloop
=> \
@itemtypeloop,
279 batch_id
=> $batch_id,
286 $template->param( DHTMLcalendar_dateformat
=> C4
::Dates
->DHTMLcalendar(), );
287 output_html_with_http_headers
$query, $cookie, $template->output;