2 #origninally script to provide intranet (librarian) advanced search facility
3 #now script to do searching for acquisitions
5 # Copyright 2000-2002 Katipo Communications
7 # This file is part of Koha.
9 # Koha is free software; you can redistribute it and/or modify it under the
10 # terms of the GNU General Public License as published by the Free Software
11 # Foundation; either version 2 of the License, or (at your option) any later
14 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License along with
19 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
20 # Suite 330, Boston, MA 02111-1307 USA
30 use C4::Interface::CGI::Output;
37 #print $input->header;
39 #whether it is called from the opac of the intranet
40 my $type = $input->param('type');
49 #build hash of users input
50 my $title = $input->param('search');
51 $search{'title'} = $title;
52 my $keyword = $input->param('d');
53 $search{'keyword'} = $keyword;
54 my $author = $input->param('author');
55 $search{'author'} = $author;
58 my $offset = $input->param('offset');
59 if ( $offset eq '' ) {
62 my $num = $input->param('num');
67 my $booksellerid = $input->param('booksellerid');
68 if ( $booksellerid == 72 ) {
71 my $basketno = $input->param('basketno');
72 my $sub = $input->param('sub');
75 my ( $count, @booksellers ) = bookseller($booksellerid);
76 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
78 template_name => "acqui/newbasket2.tmpl",
82 flagsrequired => { order => 1 },
87 #my $template = gettemplate("acqui/newbasket2.tmpl");
89 #print startmenu('acquisitions');
92 if ( $keyword ne '' ) {
93 ( $count, @results ) =
94 KeywordSearch( undef, 'intra', \%search, $num, $offset );
96 elsif ( $search{'front'} ne '' ) {
97 ( $count, @results ) =
98 FrontSearch( undef, 'intra', \%search, $num, $offset );
100 elsif ( $search{'author'} || $search{'title'} ) {
101 ( $count, @results ) = CatSearch( undef, 'loose', \%search, $num, $offset );
109 while ( my ( $key, $value ) = each %search ) {
110 if ( $value ne '' ) {
113 $linesearch{key} = $key;
114 $linesearch{value} = $value;
115 push( @loopsearch, \%linesearch );
119 my $offset2 = $num + $offset;
120 my $dispnum = $offset + 1;
121 if ( $offset2 > $count ) {
125 my $count2 = @results;
126 if ( $keyword ne '' && $offset > 0 ) {
127 $count2 = $count - $offset;
128 if ( $count2 > 10 ) {
137 while ( $i < $count2 ) {
141 my $result = $results[$i];
142 $result->{'title'} =~ s/\`/\\\'/g;
143 my $title2 = $result->{'title'};
144 my $author2 = $result->{'author'};
145 $author2 =~ s/ /%20/g;
146 $title2 =~ s/ /%20/g;
147 $title2 =~ s/\#/\&\#x23;/g;
148 $title2 =~ s/\"/\"\;/g;
152 my $location_only = '';
153 my $word = $result->{'author'};
154 $word =~ s/([a-z]) +([a-z])/$1%20$2/ig;
157 $word =~ s/\,/\,%20/g;
159 $lineres{word} = $word;
160 $lineres{type} = $type;
162 my ( $counts, $branchcounts ) =
163 C4::Search::itemcount( $env, $result->{'biblionumber'}, $type );
165 if ( $counts->{'nacount'} > 0 ) {
166 $location .= "On Loan";
167 if ( $counts->{'nacount'} > 1 ) {
168 $location .= "=($counts->{'nacount'})";
171 $lineres{'on-loan-p'} = 1;
173 foreach my $key ( keys %$branchcounts ) {
174 if ( $branchcounts->{$key} > 0 ) {
176 $location_only .= $key;
178 if ( $branchcounts->{$key} > 1 ) {
179 $location .= "=$branchcounts->{$key}";
180 $location_only .= "=$branchcounts->{$key}";
183 $location_only .= " ";
186 if ( $counts->{'lostcount'} > 0 ) {
188 if ( $counts->{'lostcount'} > 1 ) {
189 $location .= "=($counts->{'lostcount'})";
192 $lineres{'lost-p'} = 1;
194 if ( $counts->{'mending'} > 0 ) {
195 $location .= "Mending";
196 if ( $counts->{'mending'} > 1 ) {
197 $location .= "=($counts->{'mending'})";
200 $lineres{'mending-p'} = 1;
202 if ( $counts->{'transit'} > 0 ) {
203 $location .= "In Transit";
204 if ( $counts->{'transit'} > 1 ) {
205 $location .= "=($counts->{'transit'})";
208 $lineres{'in-transit-p'} = 1;
210 if ( $colour eq 0 ) {
218 $lineres{author2} = $author2;
219 $lineres{title2} = $title2;
220 $lineres{copyright} = $result->{'copyrightdate'};
221 $lineres{booksellerid} = $booksellerid;
222 $lineres{basketno} = $basketno;
223 $lineres{sub} = $sub;
224 $lineres{biblionumber} = $result->{biblionumber};
225 $lineres{title} = $result->{title};
226 $lineres{author} = $result->{author};
227 $lineres{toggle} = $toggle;
228 $lineres{itemcount} = $counts->{'count'};
229 $lineres{location} = $location;
230 $lineres{'location-only'} = $location_only;
232 # lets get a list on existing orders for all bibitems.
233 ( my $count1, my @bibitems ) =
234 getbiblioitembybiblionumber( $result->{biblionumber} );
236 my $order, my $ordernumber;
241 foreach my $bibitem (@bibitems) {
243 ( $order, $ordernumber ) =
244 &getorder( $bibitem->{biblioitemnumber}, $result->{biblionumber} );
246 #only show order if its current;
248 $order{'number'} = $ordernumber;
249 if ( ( !$order->{cancelledby} )
250 && ( $order->{quantityreceived} < $order->{quantity} ) )
252 push @ordernumbers, \%order;
255 $lineres{existingorder} = \@ordernumbers;
256 push( @loopresult, \%lineres );
260 my $prevoffset = $offset - $num;
262 if ( $prevoffset < 0 ) {
266 $offset = $num + $offset;
270 for ( my $i = 0 ; $i < ( $count / $num ) ; $i++ ) {
272 my $numberoffset = $i * $num;
273 if ( ( $numberoffset + $num ) == $offset ) { $highlight = 1 }
275 # warn "I $i | N $num | O $offset | NO $numberoffset | H $highlight";
278 number => ( $i + 1 ),
279 highlight => $highlight,
280 numberoffset => $numberoffset
286 bookselname => $booksellers[0]->{'name'},
287 booksellerid => $booksellerid,
288 basketno => $basketno,
293 offsetover => ( $offset < $count ),
295 offset => $prevoffset,
296 offsetprev => $offsetprev,
300 donation => $donation,
301 loopsearch => \@loopsearch,
302 loopresult => \@loopresult,
303 numbers => \@numbers,
304 invalidsearch => $invalidsearch,
305 'use-location-flags-p' => 1
308 output_html_with_http_headers $input, $cookie, $template->output;