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 );
43 $debug = $debug || $cgi_debug;
46 import Data::Dumper qw(Dumper);
50 # Creates a scrolling list with the associated default value.
51 # Using more than one scrolling list in a CGI assigns the same default value to all the
52 # scrolling lists on the page !?!? That's why this function was written.
56 my $type = $query->param('type');
57 my $op = $query->param('op');
58 my $batch_id = $query->param('batch_id');
59 my $ccl_query = $query->param('ccl_query');
61 my $dbh = C4::Context->dbh;
63 my $startfrom = $query->param('startfrom') || 1;
64 my ( $template, $loggedinuser, $cookie );
65 my ($total_hits, $orderby, $results, $total, $error, $marcresults, $idx, $datefrom, $dateto, $ccl_textbox);
67 my $resultsperpage = C4::Context->preference('numSearchResults') || '20';
71 if ($op eq "do_search") {
72 $idx = $query->param('idx');
73 $ccl_textbox = $query->param('ccl_textbox');
74 if ($ccl_textbox && $idx) {
75 $ccl_query = "$idx=$ccl_textbox" ;
78 $datefrom = $query->param('datefrom');
79 $dateto = $query->param('dateto');
82 $datefrom = C4::Dates->new($datefrom);
83 $ccl_query .= ' and ' if $ccl_textbox;
84 $ccl_query .= "acqdate,st-date-normalized,ge=" . $datefrom->output("iso");
88 $dateto = C4::Dates->new($dateto);
89 $ccl_query .= ' and ' if ($ccl_textbox || $datefrom) ;
90 $ccl_query .= "acqdate,st-date-normalized,le=". $dateto->output("iso");
93 my $offset = $startfrom > 1 ? $startfrom - 1 : 0;
94 ($error, $marcresults, $total_hits) =
95 SimpleSearch($ccl_query, $offset, $resultsperpage);
98 $show_results = scalar @$marcresults;
100 warn "ERROR label-item-search: no results from SimpleSearch";
102 # leave $show_results undef
107 my $hits = $show_results;
108 my (@results, @items);
110 # This code needs to be refactored using these subs...
111 #my @items = &GetItemsInfo( $biblio->{biblionumber}, 'intra' );
112 #my $dat = &GetBiblioData( $biblio->{biblionumber} );
113 for (my $i = 0 ; $i < $hits ; $i++) {
115 #DEBUG Notes: Decode the MARC record from each resulting MARC record...
116 my $marcrecord = MARC::File::USMARC::decode($marcresults->[$i]);
118 #DEBUG Notes: Transform it to Koha form...
119 my $biblio = TransformMarcToKoha(C4::Context->dbh, $marcrecord, '');
121 # Begin building the hash for the template...
122 # I don't think we need this with the current template design, but I'm leaving it in place. -fbcit
123 #$biblio->{highlight} = ($i % 2)?(1):(0);
124 #DEBUG Notes: Stuff the bib into @results...
125 push @results, $biblio;
126 my $biblionumber = $biblio->{'biblionumber'};
128 #DEBUG Notes: Grab the item numbers associated with this MARC record...
129 my $itemnums = get_itemnumbers_of($biblionumber);
131 #DEBUG Notes: Retrieve the item data for each number...
132 my $iii = $itemnums->{$biblionumber};
134 my $item_results = GetItemInfosOf(@$iii);
135 foreach my $item (keys %$item_results) {
137 #DEBUG Notes: Build an array element 'item' of the correct bib (results) hash which contains item-specific data...
138 if ($item_results->{$item}->{'biblionumber'} eq
139 $results[$i]->{'biblionumber'}) {
141 # NOTE: The order of the elements in this array must be preserved or the table dependent on it will be incorrectly rendered.
142 # This is a real hack, but I can't think of a better way right now. -fbcit
143 # It is conceivable that itemcallnumber and/or barcode fields might be empty so the trinaries cover this possibility.
144 push @{ $results[$i]->{'item'} }, { i_itemnumber1 =>
145 $item_results->{$item}->{'itemnumber'} };
146 push @{ $results[$i]->{'item'} },
147 { i_itemcallnumber => (
148 $item_results->{$item}->{'itemcallnumber'}
149 ? $item_results->{$item}->{'itemcallnumber'} : 'NA'
152 push @{ $results[$i]->{'item'} }, { i_dateaccessioned =>
153 $item_results->{$item}->{'dateaccessioned'} };
154 push @{ $results[$i]->{'item'} },
156 $item_results->{$item}->{'barcode'}
157 ? $item_results->{$item}->{'barcode'} : 'NA'
160 push @{ $results[$i]->{'item'} }, { i_itemnumber2 =>
161 $item_results->{$item}->{'itemnumber'} };
166 $debug and warn "**********\@results**********\n";
167 $debug and warn Dumper(@results);
169 ($template, $loggedinuser, $cookie) = get_template_and_user(
170 { template_name => "labels/result.tmpl",
173 authnotrequired => 0,
174 flagsrequired => { borrowers => 1 },
175 flagsrequired => { catalogue => 1 },
180 # build page nav stuff.
181 my (@field_data, @numbers);
182 $total = $total_hits;
184 my ($from, $to, $startfromnext, $startfromprev, $displaynext, $displayprev);
186 if ($total > $resultsperpage) {
187 my $num_of_pages = ceil($total / $resultsperpage + 1);
188 for (my $page = 1 ; $page < $num_of_pages ; $page++) {
189 my $startfrm = (($page - 1) * $resultsperpage) + 1;
192 startfrom => $startfrm
197 $startfromprev = $startfrom - $resultsperpage;
198 $startfromnext = $startfrom + $resultsperpage;
201 $startfrom + $resultsperpage > $total
203 : $startfrom + $resultsperpage - 1;
207 my $displayprev = $startfrom;
209 $displaynext = 1 if (scalar @results == $resultsperpage);
213 total => $total_hits,
216 startfromnext => $startfromnext,
217 startfromprev => $startfromprev,
218 startfrom => $startfrom,
219 displaynext => $displaynext,
220 displayprev => $displayprev,
221 resultsperpage => $resultsperpage,
222 numbers => \@numbers,
229 batch_id => $batch_id,
232 ccl_query => $ccl_query,
241 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
243 template_name => "labels/search.tmpl",
246 authnotrequired => 0,
247 flagsrequired => { catalogue => 1 },
251 my $itemtypes = GetItemTypes;
253 foreach my $thisitemtype (keys %$itemtypes) {
254 my %row =(value => $thisitemtype,
255 description => $itemtypes->{$thisitemtype}->{'description'},
257 push @itemtypeloop, \%row;
260 itemtypeloop =>\@itemtypeloop,
261 batch_id => $batch_id,
268 DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
270 output_html_with_http_headers $query, $cookie, $template->output;