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');
84 my $acq_search = $input->param('acq_search');
93 #build hash of users input
94 my $title = $input->param('search');
95 $search{'title'} = $title;
96 my $keyword = $input->param('d');
97 $search{'keyword'} = $keyword;
98 my $author = $input->param('author');
99 $search{'author'} = $author;
102 my $offset = $input->param('offset');
104 #default value for offset
105 my $offset = 0 unless $offset;
107 my $num = $input->param('num');
109 #default value for num
110 my $num = 10 unless $num;
113 my $booksellerid = $input->param('booksellerid');
114 if ( $booksellerid == 72 ) {
117 my $basketno = $input->param('basketno');
118 my $sub = $input->param('sub');
121 my @booksellers = GetBookSeller($booksellerid);
122 my $count = scalar @booksellers;
124 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
126 template_name => "acqui/neworderbiblio.tmpl",
129 authnotrequired => 0,
130 flagsrequired => { order => 1 },
135 #my $template = gettemplate("acqui/neworderbiblio.tmpl");
137 #print startmenu('acquisitions');
140 if ( $keyword ne '' ) {
141 ( $count, @results ) =
142 KeywordSearch( undef, 'intra', \%search, $num, $offset );
144 elsif ( $search{'front'} ne '' ) {
145 ( $count, @results ) =
146 FrontSearch( undef, 'intra', \%search, $num, $offset );
148 elsif ( $search{'author'} || $search{'title'} ) {
149 if($acq_search == 1){
150 ( $count, @results ) = CatSearch( undef, 'loose_acq', \%search, $num, $offset );
152 ( $count, @results ) = CatSearch( undef, 'loose', \%search, $num, $offset );
161 while ( my ( $key, $value ) = each %search ) {
162 if ( $value ne '' ) {
165 $linesearch{key} = $key;
166 $linesearch{value} = $value;
167 push( @loopsearch, \%linesearch );
171 my $offset2 = $num + $offset;
172 my $dispnum = $offset + 1;
173 if ( $offset2 > $count ) {
177 my $count2 = @results;
178 if ( $keyword ne '' && $offset > 0 ) {
179 $count2 = $count - $offset;
180 if ( $count2 > 10 ) {
189 while ( $i < $count2 ) {
193 my $result = $results[$i];
194 $result->{'title'} =~ s/\`/\\\'/g;
195 my $title2 = $result->{'title'};
196 my $author2 = $result->{'author'};
197 $author2 =~ s/ /%20/g;
198 $title2 =~ s/ /%20/g;
199 $title2 =~ s/\#/\&\#x23;/g;
200 $title2 =~ s/\"/\"\;/g;
204 my $location_only = '';
205 my $word = $result->{'author'};
206 $word =~ s/([a-z]) +([a-z])/$1%20$2/ig;
209 $word =~ s/\,/\,%20/g;
211 $lineres{word} = $word;
212 $lineres{type} = $type;
214 my ( $counts, $branchcounts ) =
215 C4::Search::itemcount( $env, $result->{'biblionumber'}, $type );
217 if ( $counts->{'nacount'} > 0 ) {
218 $location .= "On Loan";
219 if ( $counts->{'nacount'} > 1 ) {
220 $location .= "=($counts->{'nacount'})";
223 $lineres{'on-loan-p'} = 1;
225 foreach my $key ( keys %$branchcounts ) {
226 if ( $branchcounts->{$key} > 0 ) {
228 $location_only .= $key;
230 if ( $branchcounts->{$key} > 1 ) {
231 $location .= "=$branchcounts->{$key}";
232 $location_only .= "=$branchcounts->{$key}";
235 $location_only .= " ";
238 if ( $counts->{'lostcount'} > 0 ) {
240 if ( $counts->{'lostcount'} > 1 ) {
241 $location .= "=($counts->{'lostcount'})";
244 $lineres{'lost-p'} = 1;
246 if ( $counts->{'mending'} > 0 ) {
247 $location .= "Mending";
248 if ( $counts->{'mending'} > 1 ) {
249 $location .= "=($counts->{'mending'})";
252 $lineres{'mending-p'} = 1;
254 if ( $counts->{'transit'} > 0 ) {
255 $location .= "In Transit";
256 if ( $counts->{'transit'} > 1 ) {
257 $location .= "=($counts->{'transit'})";
260 $lineres{'in-transit-p'} = 1;
262 if ( $colour eq 0 ) {
270 $lineres{author2} = $author2;
271 $lineres{title2} = $title2;
272 $lineres{copyright} = $result->{'copyrightdate'};
273 $lineres{booksellerid} = $booksellerid;
274 $lineres{basketno} = $basketno;
275 $lineres{sub} = $sub;
276 $lineres{biblionumber} = $result->{biblionumber};
277 $lineres{title} = $result->{title};
278 $lineres{author} = $result->{author};
279 $lineres{toggle} = $toggle;
280 $lineres{itemcount} = $counts->{'count'};
281 $lineres{location} = $location;
282 $lineres{'location-only'} = $location_only;
284 # lets get a list on existing orders for all bibitems.
285 my @bibitems = GetBiblioItemByBiblioNumber( $result->{biblionumber} );
286 my $count1 = scalar @bibitems;
287 my $order, my $ordernumber;
292 foreach my $bibitem (@bibitems) {
293 my $ordernumber = GetOrderNumber($result->{biblionumber},$bibitem->{biblioitemnumber});
294 $order = &GetOrder($ordernumber);
296 #only show order if its current;
298 $order{'number'} = $ordernumber;
299 if ( ( !$order->{cancelledby} )
300 && ( $order->{quantityreceived} < $order->{quantity} ) )
302 push @ordernumbers, \%order;
305 $lineres{existingorder} = \@ordernumbers;
306 push( @loopresult, \%lineres );
310 my $prevoffset = $offset - $num;
312 if ( $prevoffset < 0 ) {
316 $offset = $num + $offset;
320 for ( my $i = 0 ; $i < ( $count / $num ) ; $i++ ) {
322 my $numberoffset = $i * $num;
323 if ( ( $numberoffset + $num ) == $offset ) { $highlight = 1 }
325 # warn "I $i | N $num | O $offset | NO $numberoffset | H $highlight";
328 number => ( $i + 1 ),
329 highlight => $highlight,
330 numberoffset => $numberoffset
336 bookselname => $booksellers[0]->{'name'},
337 booksellerid => $booksellerid,
338 basketno => $basketno,
343 offsetover => ( $offset < $count ),
345 offset => $prevoffset,
346 offsetprev => $offsetprev,
350 donation => $donation,
351 loopsearch => \@loopsearch,
352 loopresult => \@loopresult,
353 numbers => \@numbers,
354 invalidsearch => $invalidsearch,
355 'use-location-flags-p' => 1
358 output_html_with_http_headers $input, $cookie, $template->output;