3 #origninally script to provide intranet (librarian) advanced search facility
4 #now script to do searching for acquisitions
6 # Copyright 2000-2002 Katipo Communications
8 # This file is part of Koha.
10 # Koha is free software; you can redistribute it and/or modify it under the
11 # terms of the GNU General Public License as published by the Free Software
12 # Foundation; either version 2 of the License, or (at your option) any later
15 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
16 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
17 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License along with
20 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
21 # Suite 330, Boston, MA 02111-1307 USA
28 this script allows to perform a new order from an existing record.
35 the title the librarian has typed to search an existing record.
38 To know if this script is called from intranet or from the opac.
41 the keyword the librarian has typed to search an existing record.
44 the author of the new record.
51 the id of the bookseller this script has to add an order.
54 the basket number to know on which basket this script have to add a new order.
57 FIXME : is this param still used ?
72 use C4::Interface::CGI::Output;
80 #print $input->header;
82 #whether it is called from the opac of the intranet
83 my $type = $input->param('type');
92 #build hash of users input
93 my $title = $input->param('search');
94 $search{'title'} = $title;
95 my $keyword = $input->param('d');
96 $search{'keyword'} = $keyword;
97 my $author = $input->param('author');
98 $search{'author'} = $author;
101 my $offset = $input->param('offset');
103 #default value for offset
104 my $offset = 0 unless $offset;
106 my $num = $input->param('num');
108 #default value for num
109 my $num = 10 unless $num;
112 my $booksellerid = $input->param('booksellerid');
113 if ( $booksellerid == 72 ) {
116 my $basketno = $input->param('basketno');
117 my $sub = $input->param('sub');
120 my @booksellers = GetBookSeller($booksellerid);
121 my $count = scalar @booksellers;
123 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
125 template_name => "acqui/newbasket2.tmpl",
128 authnotrequired => 0,
129 flagsrequired => { order => 1 },
134 #my $template = gettemplate("acqui/newbasket2.tmpl");
136 #print startmenu('acquisitions');
139 if ( $keyword ne '' ) {
140 ( $count, @results ) =
141 KeywordSearch( undef, 'intra', \%search, $num, $offset );
143 elsif ( $search{'front'} ne '' ) {
144 ( $count, @results ) =
145 FrontSearch( undef, 'intra', \%search, $num, $offset );
147 elsif ( $search{'author'} || $search{'title'} ) {
148 ( $count, @results ) = CatSearch( undef, 'loose', \%search, $num, $offset );
156 while ( my ( $key, $value ) = each %search ) {
157 if ( $value ne '' ) {
160 $linesearch{key} = $key;
161 $linesearch{value} = $value;
162 push( @loopsearch, \%linesearch );
166 my $offset2 = $num + $offset;
167 my $dispnum = $offset + 1;
168 if ( $offset2 > $count ) {
172 my $count2 = @results;
173 if ( $keyword ne '' && $offset > 0 ) {
174 $count2 = $count - $offset;
175 if ( $count2 > 10 ) {
184 while ( $i < $count2 ) {
188 my $result = $results[$i];
189 $result->{'title'} =~ s/\`/\\\'/g;
190 my $title2 = $result->{'title'};
191 my $author2 = $result->{'author'};
192 $author2 =~ s/ /%20/g;
193 $title2 =~ s/ /%20/g;
194 $title2 =~ s/\#/\&\#x23;/g;
195 $title2 =~ s/\"/\"\;/g;
199 my $location_only = '';
200 my $word = $result->{'author'};
201 $word =~ s/([a-z]) +([a-z])/$1%20$2/ig;
204 $word =~ s/\,/\,%20/g;
206 $lineres{word} = $word;
207 $lineres{type} = $type;
209 my ( $counts, $branchcounts ) =
210 C4::Search::itemcount( $env, $result->{'biblionumber'}, $type );
212 if ( $counts->{'nacount'} > 0 ) {
213 $location .= "On Loan";
214 if ( $counts->{'nacount'} > 1 ) {
215 $location .= "=($counts->{'nacount'})";
218 $lineres{'on-loan-p'} = 1;
220 foreach my $key ( keys %$branchcounts ) {
221 if ( $branchcounts->{$key} > 0 ) {
223 $location_only .= $key;
225 if ( $branchcounts->{$key} > 1 ) {
226 $location .= "=$branchcounts->{$key}";
227 $location_only .= "=$branchcounts->{$key}";
230 $location_only .= " ";
233 if ( $counts->{'lostcount'} > 0 ) {
235 if ( $counts->{'lostcount'} > 1 ) {
236 $location .= "=($counts->{'lostcount'})";
239 $lineres{'lost-p'} = 1;
241 if ( $counts->{'mending'} > 0 ) {
242 $location .= "Mending";
243 if ( $counts->{'mending'} > 1 ) {
244 $location .= "=($counts->{'mending'})";
247 $lineres{'mending-p'} = 1;
249 if ( $counts->{'transit'} > 0 ) {
250 $location .= "In Transit";
251 if ( $counts->{'transit'} > 1 ) {
252 $location .= "=($counts->{'transit'})";
255 $lineres{'in-transit-p'} = 1;
257 if ( $colour eq 0 ) {
265 $lineres{author2} = $author2;
266 $lineres{title2} = $title2;
267 $lineres{copyright} = $result->{'copyrightdate'};
268 $lineres{booksellerid} = $booksellerid;
269 $lineres{basketno} = $basketno;
270 $lineres{sub} = $sub;
271 $lineres{biblionumber} = $result->{biblionumber};
272 $lineres{title} = $result->{title};
273 $lineres{author} = $result->{author};
274 $lineres{toggle} = $toggle;
275 $lineres{itemcount} = $counts->{'count'};
276 $lineres{location} = $location;
277 $lineres{'location-only'} = $location_only;
279 # lets get a list on existing orders for all bibitems.
280 my @bibitems = GetBiblioItemByBiblioNumber( $result->{biblionumber} );
281 my $count1 = scalar @bibitems;
282 my $order, my $ordernumber;
287 foreach my $bibitem (@bibitems) {
288 my $ordernumber = GetOrderNumber($result->{biblionumber},$bibitem->{biblioitemnumber});
289 $order = &GetOrder($ordernumber);
291 #only show order if its current;
293 $order{'number'} = $ordernumber;
294 if ( ( !$order->{cancelledby} )
295 && ( $order->{quantityreceived} < $order->{quantity} ) )
297 push @ordernumbers, \%order;
300 $lineres{existingorder} = \@ordernumbers;
301 push( @loopresult, \%lineres );
305 my $prevoffset = $offset - $num;
307 if ( $prevoffset < 0 ) {
311 $offset = $num + $offset;
315 for ( my $i = 0 ; $i < ( $count / $num ) ; $i++ ) {
317 my $numberoffset = $i * $num;
318 if ( ( $numberoffset + $num ) == $offset ) { $highlight = 1 }
320 # warn "I $i | N $num | O $offset | NO $numberoffset | H $highlight";
323 number => ( $i + 1 ),
324 highlight => $highlight,
325 numberoffset => $numberoffset
331 bookselname => $booksellers[0]->{'name'},
332 booksellerid => $booksellerid,
333 basketno => $basketno,
338 offsetover => ( $offset < $count ),
340 offset => $prevoffset,
341 offsetprev => $offsetprev,
345 donation => $donation,
346 loopsearch => \@loopsearch,
347 loopresult => \@loopresult,
348 numbers => \@numbers,
349 invalidsearch => $invalidsearch,
350 'use-location-flags-p' => 1
353 output_html_with_http_headers $input, $cookie, $template->output;