1 package C4::Search; #asummes C4/Search
3 #requires DBI.pm to be installed
13 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
15 # set the version for version checking
19 @EXPORT = qw(&CatSearch &BornameSearch &ItemInfo &KeywordSearch &subsearch
20 &itemdata &bibdata &GetItems &borrdata &itemnodata &itemcount
21 &borrdata2 &NewBorrowerNumber &bibitemdata &borrissues
22 &getboracctrecord &ItemType &itemissues &subject &subtitle
23 &addauthor &bibitems &barcodes &findguarantees &allissues &systemprefs
24 &findguarantor &getwebsites);
25 %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ],
27 # your exported package globals go here,
28 # as well as any optionally exported functions
30 @EXPORT_OK = qw($Var1 %Hashit);
33 # non-exported package globals go here
34 use vars qw(@more $stuff);
36 # initalize package globals, first exported ones
41 # then the others (which are still accessible as $Some::Module::stuff)
45 # all file-scoped lexicals must be created before
46 # the functions below that use them.
48 # file-private lexicals go here
52 # here's a file-private function as a closure,
53 # callable as &$priv_func; it cannot be prototyped.
58 # make all your functions, whether exported or not;
62 my $query="select cardnumber,borrowernumber from borrowers where
64 my $sth=$dbh->prepare($query);
68 while (my $data=$sth->fetchrow_hashref){
79 my $query="select guarantor from borrowers where
80 borrowernumber='$bornum'";
81 my $sth=$dbh->prepare($query);
83 my $data=$sth->fetchrow_hashref;
85 $query="Select * from borrowers where
86 borrowernumber='$data->{'guarantor'}'";
87 $sth=$dbh->prepare($query);
89 $data=$sth->fetchrow_hashref;
98 my $sth=$dbh->prepare("select variable,value from systempreferences");
100 while (my ($variable,$value)=$sth->fetchrow) {
101 $systemprefs{$variable}=$value;
105 return(%systemprefs);
108 sub NewBorrowerNumber {
110 my $sth=$dbh->prepare("Select max(borrowernumber) from borrowers");
112 my $data=$sth->fetchrow_hashref;
114 $data->{'max(borrowernumber)'}++;
116 return($data->{'max(borrowernumber)'});
121 my ($env,$type,$search,$num,$offset)=@_;
122 my $dbh = &C4Connect;
123 $search->{'keyword'}=~ s/ +$//;
124 $search->{'keyword'}=~ s/'/\\'/;
125 my @key=split(' ',$search->{'keyword'});
129 my $query="Select biblionumber from biblio
130 where ((title like '$key[0]%' or title like '% $key[0]%')";
132 $query=$query." and (title like '$key[$i]%' or title like '% $key[$i]%')";
135 $query.= ") or ((biblio.notes like '$key[0]%' or biblio.notes like '% $key[0]%')";
136 for ($i=1;$i<$count;$i++){
137 $query.=" and (biblio.notes like '$key[$i]%' or biblio.notes like '% $key[$i]%')";
139 $query.= ") or ((seriestitle like '$key[0]%' or seriestitle like '% $key[0]%')";
140 for ($i=1;$i<$count;$i++){
141 $query.=" and (seriestitle like '$key[$i]%' or seriestitle like '% $key[$i]%')";
145 my $sth=$dbh->prepare($query);
148 while (my @res=$sth->fetchrow_array){
149 $results[$i]=$res[0];
153 my $set1=Set::Scalar->new(@results);
154 $query="Select biblionumber from bibliosubtitle where
155 ((subtitle like '$key[0]%' or subtitle like '% $key[0]%')";
156 for ($i=1;$i<$count;$i++){
157 $query.= " and (subtitle like '$key[$i]%' or subtitle like '% $key[$i]%')";
161 $sth=$dbh->prepare($query);
164 while (my @res=$sth->fetchrow_array){
165 $results[$i]=$res[0];
169 my $set2=Set::Scalar->new(@results);
173 $query ="Select biblionumber from biblioitems where
174 ((biblioitems.notes like '$key[0]%' or biblioitems.notes like '% $key[0]%')";
175 for ($i=1;$i<$count;$i++){
176 $query.=" and (biblioitems.notes like '$key[$i]%' or biblioitems.notes like '% $key[$i]%')";
180 $sth=$dbh->prepare($query);
183 while (my @res=$sth->fetchrow_array){
184 $results[$i]=$res[0];
188 my $set3=Set::Scalar->new(@results);
192 $sth=$dbh->prepare("Select biblionumber from bibliosubject where subject
193 like '%$search->{'keyword'}%' group by biblionumber");
196 while (my @res=$sth->fetchrow_array){
197 $results[$i]=$res[0];
201 my $set4=Set::Scalar->new(@results);
210 my @res = $set1->members;
214 # print "count $count";
215 if ($search->{'class'} ne ''){
217 my $query="select * from biblio,biblioitems where
218 biblio.biblionumber='$res[$i2]' and
219 biblio.biblionumber=biblioitems.biblionumber ";
220 if ($search->{'class'} ne ''){
221 my @temp=split(/\|/,$search->{'class'});
223 $query.= "and ( itemtype='$temp[0]'";
224 for (my $i=1;$i<$count;$i++){
225 $query.=" or itemtype='$temp[$i]'";
229 my $sth=$dbh->prepare($query);
232 if (my $data2=$sth->fetchrow_hashref){
233 my $dewey= $data2->{'dewey'};
234 my $subclass=$data2->{'subclass'};
236 ($dewey == 0) && ($dewey='');
237 ($dewey) && ($dewey.=" $subclass") ;
239 my $end=$offset +$num;
244 if ($i4 <=$end && $i4 > $offset){
245 $data2->{'dewey'}=$dewey;
248 # $res2[$i3]="$data2->{'author'}\t$data2->{'title'}\t$data2->{'biblionumber'}\t$data2->{'copyrightdate'}\t$dewey";
251 # print "in here $i3<br>";
262 while ($i2 < $num && $i2 < $count){
263 my $query="select * from biblio,biblioitems where
264 biblio.biblionumber='$res[$i2+$offset]' and
265 biblio.biblionumber=biblioitems.biblionumber ";
266 if ($search->{'class'} ne ''){
267 my @temp=split(/\|/,$search->{'class'});
269 $query.= "and ( itemtype='$temp[0]'";
270 for (my $i=1;$i<$count;$i++){
271 $query.=" or itemtype='$temp[$i]'";
275 if ($search->{'dewey'} ne ''){
276 $query.= "and (dewey like '$search->{'dewey'}%') ";
279 my $sth=$dbh->prepare($query);
282 if (my $data2=$sth->fetchrow_hashref){
283 my $dewey= $data2->{'dewey'};
284 my $subclass=$data2->{'subclass'};
286 ($dewey == 0) && ($dewey='');
287 ($dewey) && ($dewey.=" $subclass") ;
289 $data2->{'dewey'}=$dewey;
291 # $res2[$i]="$data2->{'author'}\t$data2->{'title'}\t$data2->{'biblionumber'}\t$data2->{'copyrightdate'}\t$dewey";
301 return($count,@res2);
305 my ($env,$type,$search,$num,$offset)=@_;
306 my $dbh = &C4Connect;
309 $search->{'title'}=~ s/'/\\'/g;
310 $search->{'author'}=~ s/'/\\'/g;
311 $search->{'illustrator'}=~ s/'/\\'/g;
312 my $title = lc($search->{'title'});
314 if ($type eq 'loose') {
315 if ($search->{'author'} ne ''){
316 my @key=split(' ',$search->{'author'});
319 $query="select *,biblio.author,biblio.biblionumber from
321 left join additionalauthors
322 on additionalauthors.biblionumber =biblio.biblionumber
324 ((biblio.author like '$key[0]%' or biblio.author like '% $key[0]%' or
325 additionalauthors.author like '$key[0]%' or additionalauthors.author
329 $query=$query." and (
330 biblio.author like '$key[$i]%' or biblio.author like '% $key[$i]%' or
331 additionalauthors.author like '$key[$i]%' or additionalauthors.author like '% $key[$i]%'
336 if ($search->{'title'} ne ''){
337 my @key=split(' ',$search->{'title'});
340 $query.= " and (((title like '$key[0]%' or title like '% $key[0]%' or title like '% $key[0]')";
342 $query=$query." and (title like '$key[$i]%' or title like '% $key[$i]%' or title like '% $key[$i]')";
345 # $query.=") or ((subtitle like '$key[0]%' or subtitle like '% $key[0] %' or subtitle like '% $key[0]')";
346 # for ($i=1;$i<$count;$i++){
347 # $query.=" and (subtitle like '$key[$i]%' or subtitle like '% $key[$i] %' or subtitle like '% $key[$i]')";
349 $query.=") or ((seriestitle like '$key[0]%' or seriestitle like '% $key[0]%' or seriestitle like '% $key[0]')";
350 for ($i=1;$i<$count;$i++){
351 $query.=" and (seriestitle like '$key[$i]%' or seriestitle like '% $key[$i]%')";
353 $query.=") or ((unititle like '$key[0]%' or unititle like '% $key[0]%' or unititle like '% $key[0]')";
354 for ($i=1;$i<$count;$i++){
355 $query.=" and (unititle like '$key[$i]%' or unititle like '% $key[$i]%')";
358 #$query=$query. " and (title like '%$search->{'title'}%'
359 #or seriestitle like '%$search->{'title'}%')";
362 $query.=" group by biblio.biblionumber";
364 if ($search->{'title'} ne '') {
365 if ($search->{'ttype'} eq 'exact'){
366 $query="select * from biblio
368 (biblio.title='$search->{'title'}' or (biblio.unititle = '$search->{'title'}'
369 or biblio.unititle like '$search->{'title'} |%' or
370 biblio.unititle like '%| $search->{'title'} |%' or
371 biblio.unititle like '%| $search->{'title'}') or
372 (biblio.seriestitle = '$search->{'title'}' or
373 biblio.seriestitle like '$search->{'title'} |%' or
374 biblio.seriestitle like '%| $search->{'title'} |%' or
375 biblio.seriestitle like '%| $search->{'title'}')
378 my @key=split(' ',$search->{'title'});
381 $query="select * from biblio
382 left join bibliosubtitle on
383 biblio.biblionumber=bibliosubtitle.biblionumber
385 (((title like '$key[0]%' or title like '% $key[0]%' or title like '% $key[0]')";
387 $query=$query." and (title like '$key[$i]%' or title like '% $key[$i]%' or title like '% $key[$i]')";
390 $query.=") or ((subtitle like '$key[0]%' or subtitle like '% $key[0]%' or subtitle like '% $key[0]')";
391 for ($i=1;$i<$count;$i++){
392 $query.=" and (subtitle like '$key[$i]%' or subtitle like '% $key[$i]%' or subtitle like '% $key[$i]')";
394 $query.=") or ((seriestitle like '$key[0]%' or seriestitle like '% $key[0]%' or seriestitle like '% $key[0]')";
395 for ($i=1;$i<$count;$i++){
396 $query.=" and (seriestitle like '$key[$i]%' or seriestitle like '% $key[$i]%')";
398 $query.=") or ((unititle like '$key[0]%' or unititle like '% $key[0]%' or unititle like '% $key[0]')";
399 for ($i=1;$i<$count;$i++){
400 $query.=" and (unititle like '$key[$i]%' or unititle like '% $key[$i]%')";
404 } elsif ($search->{'class'} ne ''){
405 $query="select * from biblioitems,biblio where biblio.biblionumber=biblioitems.biblionumber";
406 my @temp=split(/\|/,$search->{'class'});
408 $query.= " and ( itemtype='$temp[0]'";
409 for (my $i=1;$i<$count;$i++){
410 $query.=" or itemtype='$temp[$i]'";
413 if ($search->{'illustrator'} ne ''){
414 $query.=" and illus like '%".$search->{'illustrator'}."%' ";
416 if ($search->{'dewey'} ne ''){
417 $query.=" and biblioitems.dewey like '$search->{'dewey'}%'";
419 } elsif ($search->{'dewey'} ne ''){
420 $query="select * from biblioitems,biblio
421 where biblio.biblionumber=biblioitems.biblionumber
422 and biblioitems.dewey like '$search->{'dewey'}%'";
423 } elsif ($search->{'illustrator'} ne '') {
424 if ($search->{'illustrator'} ne ''){
425 $query="select * from biblioitems,biblio
426 where biblio.biblionumber=biblioitems.biblionumber
427 and biblioitems.illus like '%".$search->{'illustrator'}."%'";
430 $query .=" group by biblio.biblionumber";
433 if ($type eq 'subject'){
434 my @key=split(' ',$search->{'subject'});
437 $query="select distinct(subject) from bibliosubject where( subject like
438 '$key[0]%' or subject like '% $key[0]%' or subject like '% $key[0]' or subject like '%($key[0])%')";
440 $query.=" and (subject like '$key[$i]%' or subject like '% $key[$i]%'
441 or subject like '% $key[$i]'
442 or subject like '%($key[$i])%')";
445 if ($search->{'subject'} eq 'NZ' || $search->{'subject'} eq 'nz'){
446 $query.= " or (subject like 'NEW ZEALAND %' or subject like '% NEW ZEALAND %'
447 or subject like '% NEW ZEALAND' or subject like '%(NEW ZEALAND)%' ) ";
448 } elsif ( $search->{'subject'} =~ /^nz /i || $search->{'subject'} =~ / nz /i || $search->{'subject'} =~ / nz$/i){
449 $query=~ s/ nz/ NEW ZEALAND/ig;
450 $query=~ s/nz /NEW ZEALAND /ig;
451 $query=~ s/\(nz\)/\(NEW ZEALAND\)/gi;
454 if ($type eq 'precise'){
455 $query="select * from items,biblio ";
456 if ($search->{'item'} ne ''){
457 my $search2=uc $search->{'item'};
458 $query=$query." where
459 items.biblionumber=biblio.biblionumber
460 and barcode='$search2'";
462 if ($search->{'isbn'} ne ''){
463 my $search2=uc $search->{'isbn'};
464 my $query1 = "select * from biblioitems where isbn='$search2'";
465 my $sth1=$dbh->prepare($query1);
469 while (my $data=$sth1->fetchrow_hashref) {
470 $query="select * from biblioitems,biblio where
471 biblio.biblionumber = $data->{'biblionumber'}
472 and biblioitems.biblionumber = biblio.biblionumber";
473 my $sth=$dbh->prepare($query);
475 my $data=$sth->fetchrow_hashref;
476 my ($dewey, $subclass) = ($data->{'dewey'}, $data->{'subclass'});
478 ($dewey == 0) && ($dewey='');
479 ($dewey) && ($dewey.=" $subclass");
480 $data->{'dewey'}=$dewey;
482 # $results[$i2]="$data->{'author'}\t$data->{'title'}\t$data->{'biblionumber'}\t$data->{'copyrightdate'}\t$dewey\t$data->{'isbn'}\t$data->{'itemtype'}";
490 if ($type ne 'precise' && $type ne 'subject'){
491 if ($search->{'author'} ne ''){
492 $query=$query." order by biblio.author,title";
494 $query=$query." order by title";
497 if ($type eq 'subject'){
498 $query=$query." order by subject";
502 my $sth=$dbh->prepare($query);
506 my $limit= $num+$offset;
507 while (my $data=$sth->fetchrow_hashref){
508 my $query="select dewey,subclass from biblioitems where biblionumber=$data->{'biblionumber'}";
509 if ($search->{'class'} ne ''){
510 my @temp=split(/\|/,$search->{'class'});
512 $query.= " and ( itemtype='$temp[0]'";
513 for (my $i=1;$i<$count;$i++){
514 $query.=" or itemtype='$temp[$i]'";
518 if ($search->{'dewey'} ne ''){
519 $query.=" and dewey='$search->{'dewey'}' ";
521 if ($search->{'illustrator'} ne ''){
522 $query.=" and illus like '%".$search->{'illustrator'}."%' ";
525 my $sti=$dbh->prepare($query);
530 if (($dewey, $subclass) = $sti->fetchrow || $type eq 'subject'){
534 ($dewey == 0) && ($dewey='');
535 ($dewey) && ($dewey.=" $subclass");
536 $data->{'dewey'}=$dewey;
539 if ($count > $offset && $count <= $limit){
540 # if ($type ne 'subject' && $type ne 'precise'){
541 # $results[$i]="$data->{'author'}\t$data->{'title'}\t$data->{'biblionumber'}\t$data->{'copyrightdate'}\t$dewey\t$data->{'illus'}";
542 # } elsif ($search->{'isbn'} ne '' || $search->{'item'} ne ''){
543 # $results[$i]="$data->{'author'}\t$data->{'title'}\t$data->{'biblionumber'}\t$data->{'copyrightdate'}\t$dewey\t$data->{'illus'}";
545 # $results[$i]="$data->{'author'}\t$data->{'subject'}\t$data->{'biblionumber'}\t$data->{'copyrightdate'}\t$dewey\t$data->{'illus'}";
554 #if ($type ne 'precise'){
558 return($count,@results);
561 sub updatesearchstats{
567 my ($env,$subject)=@_;
569 $subject=$dbh->quote($subject);
570 my $query="Select * from biblio,bibliosubject where
571 biblio.biblionumber=bibliosubject.biblionumber and
572 bibliosubject.subject=$subject group by biblio.biblionumber
573 order by biblio.title";
574 my $sth=$dbh->prepare($query);
579 while (my $data=$sth->fetchrow_hashref){
580 $results[$i]="$data->{'title'}\t$data->{'author'}\t$data->{'biblionumber'}";
590 my ($env,$biblionumber,$type)=@_;
591 my $dbh = &C4Connect;
592 my $query="Select * from items,biblio,biblioitems,branches
593 where (items.biblioitemnumber = biblioitems.biblioitemnumber)
594 and biblioitems.biblionumber=biblio.biblionumber
595 and biblio.biblionumber='$biblionumber' and branches.branchcode=
596 items.holdingbranch ";
598 if ($type ne 'intra'){
599 $query.=" and ((items.itemlost<>1 and items.itemlost <> 2)
600 or items.itemlost is NULL)
601 and (wthdrawn <> 1 or wthdrawn is NULL)";
603 $query=$query."order by items.dateaccessioned desc";
604 my $sth=$dbh->prepare($query);
609 while (my $data=$sth->fetchrow_hashref){
610 my $iquery = "Select * from issues
611 where itemnumber = '$data->{'itemnumber'}'
612 and returndate is null";
614 my $isth=$dbh->prepare($iquery);
616 if (my $idata=$isth->fetchrow_hashref){
617 my @temp=split('-',$idata->{'date_due'});
618 $datedue = "$temp[2]/$temp[1]/$temp[0]";
620 if ($data->{'itemlost'} eq '1' || $data->{'itemlost'} eq '2'){
623 if ($data->{'wthdrawn'} eq '1'){
624 $datedue="Cancelled";
627 my ($rescount,$reserves)=Findgroupreserve($data->{'biblioitemnumber'},$biblionumber);
634 my $class = $data->{'classification'};
635 my $dewey = $data->{'dewey'};
637 if ($dewey eq "000.") { $dewey = "";};
638 if ($dewey < 10){$dewey='00'.$dewey;}
639 if ($dewey < 100 && $dewey > 10){$dewey='0'.$dewey;}
644 $class = $class.$dewey;
646 $class = $class.$data->{'subclass'};
648 # $results[$i]="$data->{'title'}\t$data->{'barcode'}\t$datedue\t$data->{'branchname'}\t$data->{'dewey'}";
649 my @temp=split('-',$data->{'datelastseen'});
650 my $date="$temp[2]/$temp[1]/$temp[0]";
651 $results[$i]="$data->{'title'}\t$data->{'barcode'}\t$datedue\t$data->{'branchname'}\t$class\t$data->{'itemnumber'}\t$data->{'itemtype'}\t$date\t$data->{'biblioitemnumber'}\t$data->{'volumeddesc'}";
652 # print "$results[$i] <br>";
656 my $query2="Select * from aqorders where biblionumber=$biblionumber";
657 my $sth2=$dbh->prepare($query2);
661 if ($data=$sth2->fetchrow_hashref){
662 $ocount=$data->{'quantity'} - $data->{'quantityreceived'};
664 $results[$i]="$data->{'title'}\t$data->{'barcode'}\t$ocount\tOn Order\t\t$data->{'itemnumber'}\t$data->{'itemtype'}\t\t$data->{'biblioitemnumber'}\t$data->{'volumeddesc'}";
674 my ($env,$biblionumber)=@_;
675 #debug_msg($env,"GetItems");
676 my $dbh = &C4Connect;
677 my $query = "Select * from biblioitems where (biblionumber = $biblionumber)";
678 #debug_msg($env,$query);
679 my $sth=$dbh->prepare($query);
681 #debug_msg($env,"executed query");
684 while (my $data=$sth->fetchrow_hashref) {
685 #debug_msg($env,$data->{'biblioitemnumber'});
686 my $dewey = $data->{'dewey'};
688 my $line = $data->{'biblioitemnumber'}."\t".$data->{'itemtype'};
689 $line = $line."\t$data->{'classification'}\t$dewey";
690 $line = $line."\t$data->{'subclass'}\t$data->{isbn}";
691 $line = $line."\t$data->{'volume'}\t$data->{number}";
692 my $isth= $dbh->prepare("select * from items where biblioitemnumber = $data->{'biblioitemnumber'}");
694 while (my $idata = $isth->fetchrow_hashref) {
695 my $iline = $idata->{'barcode'}."[".$idata->{'holdingbranch'}."[";
696 if ($idata->{'notforloan'} == 1) {
697 $iline = $iline."NFL ";
699 if ($idata->{'itemlost'} == 1) {
700 $iline = $iline."LOST ";
702 $line = $line."\t$iline";
705 $results[$i] = $line;
716 my $query="Select * from items,biblioitems where barcode='$barcode'
717 and items.biblioitemnumber=biblioitems.biblioitemnumber";
719 my $sth=$dbh->prepare($query);
721 my $data=$sth->fetchrow_hashref;
728 my ($bibnum, $type)=@_;
730 my $query = "Select *, biblio.notes
731 from biblio, biblioitems
732 left join bibliosubtitle on
733 biblio.biblionumber = bibliosubtitle.biblionumber
734 where biblio.biblionumber = $bibnum
735 and biblioitems.biblionumber = $bibnum";
737 my $sth = $dbh->prepare($query);
739 my $data = $sth->fetchrow_hashref;
742 $query = "Select * from bibliosubject where biblionumber = '$bibnum'";
743 $sth=$dbh->prepare($query);
745 while (my $dat = $sth->fetchrow_hashref){
746 $data->{'subject'} .= " | $dat->{'subject'}";
758 my $query="Select *,biblioitems.notes as bnotes from biblio,biblioitems,itemtypes where biblio.biblionumber=
759 biblioitems.biblionumber and biblioitemnumber=$bibitem and
760 biblioitems.itemtype=itemtypes.itemtype";
762 my $sth=$dbh->prepare($query);
764 my $data=$sth->fetchrow_hashref;
773 my $query="Select * from bibliosubject where biblionumber=$bibnum";
774 my $sth=$dbh->prepare($query);
778 while (my $data=$sth->fetchrow_hashref){
784 return($i,\@results);
790 my $query="Select * from additionalauthors where biblionumber=$bibnum";
791 my $sth=$dbh->prepare($query);
795 while (my $data=$sth->fetchrow_hashref){
801 return($i,\@results);
807 my $query="Select * from bibliosubtitle where biblionumber=$bibnum";
808 my $sth=$dbh->prepare($query);
812 while (my $data=$sth->fetchrow_hashref){
818 return($i,\@results);
824 my ($bibitem, $biblio)=@_;
826 my $query="Select * from items where
827 items.biblioitemnumber='$bibitem'";
828 my $sth=$dbh->prepare($query) || die $dbh->errstr;
829 $sth->execute || die $sth->errstr;
832 while (my $data=$sth->fetchrow_hashref) {
833 my $query2="select * from issues,borrowers where itemnumber=$data->{'itemnumber'}
834 and returndate is NULL and issues.borrowernumber=borrowers.borrowernumber";
835 my $sth2=$dbh->prepare($query2);
837 if (my $data2=$sth2->fetchrow_hashref) {
838 $data->{'date_due'}=$data2->{'date_due'};
839 $data->{'card'}=$data2->{'cardnumber'};
841 if ($data->{'wthdrawn'} eq '1') {
842 $data->{'date_due'}='Cancelled';
844 $data->{'date_due'}='Available';
848 $query2="select * from issues,borrowers where itemnumber='$data->{'itemnumber'}'
849 and issues.borrowernumber=borrowers.borrowernumber
850 order by date_due desc";
851 my $sth2=$dbh->prepare($query2) || die $dbh->errstr;
852 $sth2->execute || die $sth2->errstr;
853 for (my $i2=0;$i2<2;$i2++){
854 if (my $data2=$sth2->fetchrow_hashref){
855 $data->{"timestamp$i2"}=$data2->{'timestamp'};
856 $data->{"card$i2"}=$data2->{'cardnumber'};
857 $data->{"borrower$i2"}=$data2->{'borrowernumber'};
870 my ($env,$dbh,$itemnumber) = @_;
872 my $query="Select * from biblio,items,biblioitems
873 where items.itemnumber = '$itemnumber'
874 and biblio.biblionumber = items.biblionumber
875 and biblioitems.biblioitemnumber = items.biblioitemnumber";
876 my $sth=$dbh->prepare($query);
879 my $data=$sth->fetchrow_hashref;
885 #used by member enquiries from the intranet
888 my ($env,$searchstring,$type)=@_;
889 my $dbh = &C4Connect;
890 $searchstring=~ s/\'/\\\'/g;
891 my @data=split(' ',$searchstring);
893 my $query="Select * from borrowers
894 where ((surname like \"$data[0]%\" or surname like \"% $data[0]%\"
895 or firstname like \"$data[0]%\" or firstname like \"% $data[0]%\"
896 or othernames like \"$data[0]%\" or othernames like \"% $data[0]%\")
898 for (my $i=1;$i<$count;$i++){
899 $query=$query." and (surname like \"$data[$i]%\" or surname like \"% $data[$i]%\"
900 or firstname like \"$data[$i]%\" or firstname like \"% $data[$i]%\"
901 or othernames like \"$data[$i]%\" or othernames like \"% $data[$i]%\")";
903 $query=$query.") or cardnumber = \"$searchstring\"
904 order by surname,firstname";
906 my $sth=$dbh->prepare($query);
910 while (my $data=$sth->fetchrow_hashref){
911 push(@results,$data);
917 return ($cnt,\@results);
921 my ($cardnumber,$bornum)=@_;
922 $cardnumber = uc $cardnumber;
926 $query="Select * from borrowers where cardnumber='$cardnumber'";
928 $query="Select * from borrowers where borrowernumber='$bornum'";
931 my $sth=$dbh->prepare($query);
933 my $data=$sth->fetchrow_hashref;
943 $query="Select * from issues,biblio,items where borrowernumber='$bornum' and
944 items.itemnumber=issues.itemnumber and
945 items.biblionumber=biblio.biblionumber and issues.returndate is NULL order
948 my $sth=$dbh->prepare($query);
952 while (my $data=$sth->fetchrow_hashref){
962 my ($bornum,$order,$limit)=@_;
965 $query="Select * from issues,biblio,items,biblioitems
966 where borrowernumber='$bornum' and
967 items.biblioitemnumber=biblioitems.biblioitemnumber and
968 items.itemnumber=issues.itemnumber and
969 items.biblionumber=biblio.biblionumber";
970 $query.=" order by $order";
972 $query.=" limit $limit";
975 my $sth=$dbh->prepare($query);
979 while (my $data=$sth->fetchrow_hashref){
989 my ($env,$bornum)=@_;
991 my $query="Select count(*) from issues where borrowernumber='$bornum' and
994 my $sth=$dbh->prepare($query);
996 my $data=$sth->fetchrow_hashref;
998 $sth=$dbh->prepare("Select count(*) from issues where
999 borrowernumber='$bornum' and date_due < now() and returndate is NULL");
1001 my $data2=$sth->fetchrow_hashref;
1003 $sth=$dbh->prepare("Select sum(amountoutstanding) from accountlines where
1004 borrowernumber='$bornum'");
1006 my $data3=$sth->fetchrow_hashref;
1010 return($data2->{'count(*)'},$data->{'count(*)'},$data3->{'sum(amountoutstanding)'});
1014 sub getboracctrecord {
1015 my ($env,$params) = @_;
1019 my $query= "Select * from accountlines where
1020 borrowernumber=$params->{'borrowernumber'} order by date desc,timestamp desc";
1021 my $sth=$dbh->prepare($query);
1025 while (my $data=$sth->fetchrow_hashref){
1026 # if ($data->{'itemnumber'} ne ''){
1027 # $query="Select * from items,biblio where items.itemnumber=
1028 # '$data->{'itemnumber'}' and biblio.biblionumber=items.biblionumber";
1029 # my $sth2=$dbh->prepare($query);
1031 # my $data2=$sth2->fetchrow_hashref;
1035 $acctlines[$numlines] = $data;
1037 $total = $total+ $data->{'amountoutstanding'};
1041 return ($numlines,\@acctlines,$total);
1045 my ($env,$bibnum,$type)=@_;
1047 my $query="Select * from items where
1048 biblionumber=$bibnum ";
1049 if ($type ne 'intra'){
1050 $query.=" and ((itemlost <>1 and itemlost <> 2) or itemlost is NULL) and
1051 (wthdrawn <> 1 or wthdrawn is NULL)";
1053 my $sth=$dbh->prepare($query);
1065 while (my $data=$sth->fetchrow_hashref){
1067 my $query2="select * from issues,items where issues.itemnumber=
1068 '$data->{'itemnumber'}' and returndate is NULL
1069 and items.itemnumber=issues.itemnumber and ((items.itemlost <>1 and
1070 items.itemlost <> 2) or items.itemlost is NULL)
1071 and (wthdrawn <> 1 or wthdrawn is NULL)";
1073 my $sth2=$dbh->prepare($query2);
1075 if (my $data2=$sth2->fetchrow_hashref){
1078 if ($data->{'holdingbranch'} eq 'C'){
1081 if ($data->{'holdingbranch'} eq 'F' || $data->{'holdingbranch'} eq 'FP'){
1084 if ($data->{'holdingbranch'} eq 'S' || $data->{'holdingbranch'} eq 'SP'){
1087 if ($data->{'itemlost'} eq '1'){
1090 if ($data->{'itemlost'} eq '2'){
1093 if ($data->{'holdingbranch'} eq 'FM'){
1096 if ($data->{'holdingbranch'} eq 'TR'){
1103 my $query2="Select * from aqorders where biblionumber=$bibnum";
1104 my $sth2=$dbh->prepare($query2);
1106 if (my $data=$sth2->fetchrow_hashref){
1107 $ocount=$data->{'quantity'} - $data->{'quantityreceived'};
1113 return ($count,$lcount,$nacount,$fcount,$scount,$lostcount,$mending,$transit,$ocount);
1119 my $query="select description from itemtypes where itemtype='$type'";
1120 my $sth=$dbh->prepare($query);
1122 my $dat=$sth->fetchrow_hashref;
1125 return ($dat->{'description'});
1131 my $query="Select * from biblioitems,itemtypes,items where
1132 biblioitems.biblionumber='$bibnum' and biblioitems.itemtype=itemtypes.itemtype and
1133 biblioitems.biblioitemnumber=items.biblioitemnumber group by
1134 items.biblioitemnumber";
1135 my $sth=$dbh->prepare($query);
1139 while (my $data=$sth->fetchrow_hashref){
1145 return($i,@results);
1149 #called from request.pl
1150 my ($biblioitemnumber)=@_;
1152 my $query="Select barcode from items where
1153 biblioitemnumber='$biblioitemnumber'
1154 and ((itemlost <> 1 and itemlost <> 2) or itemlost is NULL) and
1155 (wthdrawn <> 1 or wthdrawn is NULL)";
1157 my $sth=$dbh->prepare($query);
1161 while (my $data=$sth->fetchrow_hashref){
1162 $barcodes[$i]=$data->{'barcode'};
1173 my ($biblionumber) = @_;
1174 my $dbh = C4Connect;
1175 my $query = "Select * from websites where biblionumber = $biblionumber";
1176 my $sth = $dbh->prepare($query);
1181 while (my $data = $sth->fetchrow_hashref) {
1182 $results[$count] = $data;
1188 return($count, @results);
1192 END { } # module clean-up code here (global destructor)
1196 C4::Search - Module that provides Catalog searching for Koha
1201 my ($count,@results)=KeywordSearch($env,$type,$search,$num,$offset);
1202 my ($count,@results)=CatSearch($env,$type,$search,$num,$offset);
1206 This module provides the searching facilities for the Catalog.
1207 Here I should go through and document each function thats exported and what it does. But I havent yet.
1217 Koha Developement team <info@koha.org>