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 &getwebbiblioitems);
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'
596 and branches.branchcode = 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 .= " 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;
729 my ($bibnum, $type) = @_;
731 my $query = "Select *, biblio.notes
732 from biblio, biblioitems
733 left join bibliosubtitle on
734 biblio.biblionumber = bibliosubtitle.biblionumber
735 where biblio.biblionumber = $bibnum
736 and biblioitems.biblionumber = $bibnum";
737 my $sth = $dbh->prepare($query);
741 $data = $sth->fetchrow_hashref;
744 $query = "Select * from bibliosubject where biblionumber = '$bibnum'";
745 $sth = $dbh->prepare($query);
747 while (my $dat = $sth->fetchrow_hashref){
748 $data->{'subject'} .= " | $dat->{'subject'}";
760 my $query = "Select *,biblioitems.notes as bnotes from biblio, biblioitems,itemtypes
761 where biblio.biblionumber = biblioitems.biblionumber
762 and biblioitemnumber = $bibitem
763 and biblioitems.itemtype = itemtypes.itemtype";
764 my $sth = $dbh->prepare($query);
769 $data = $sth->fetchrow_hashref;
780 my $query="Select * from bibliosubject where biblionumber=$bibnum";
781 my $sth=$dbh->prepare($query);
785 while (my $data=$sth->fetchrow_hashref){
791 return($i,\@results);
797 my $query="Select * from additionalauthors where biblionumber=$bibnum";
798 my $sth=$dbh->prepare($query);
802 while (my $data=$sth->fetchrow_hashref){
808 return($i,\@results);
814 my $query="Select * from bibliosubtitle where biblionumber=$bibnum";
815 my $sth=$dbh->prepare($query);
819 while (my $data=$sth->fetchrow_hashref){
825 return($i,\@results);
831 my ($bibitem, $biblio)=@_;
833 my $query = "Select * from items where
834 items.biblioitemnumber = '$bibitem'";
835 my $sth = $dbh->prepare($query)
843 while (my $data = $sth->fetchrow_hashref) {
844 my $query2 = "select * from issues,borrowers
845 where itemnumber = $data->{'itemnumber'}
846 and returndate is NULL
847 and issues.borrowernumber = borrowers.borrowernumber";
848 my $sth2 = $dbh->prepare($query2);
851 if (my $data2 = $sth2->fetchrow_hashref) {
852 $data->{'date_due'} = $data2->{'date_due'};
853 $data->{'card'} = $data2->{'cardnumber'};
855 if ($data->{'wthdrawn'} eq '1') {
856 $data->{'date_due'} = 'Cancelled';
858 $data->{'date_due'} = 'Available';
863 $query2 = "select * from issues, borrowers
864 where itemnumber = '$data->{'itemnumber'}'
865 and issues.borrowernumber = borrowers.borrowernumber
866 order by date_due desc";
867 $sth2 = $dbh->prepare($query2)
870 || die $sth2->errstr;
872 for (my $i2 = 0; $i2 < 2; $i2++) {
873 if (my $data2 = $sth2->fetchrow_hashref) {
874 $data->{"timestamp$i2"} = $data2->{'timestamp'};
875 $data->{"card$i2"} = $data2->{'cardnumber'};
876 $data->{"borrower$i2"} = $data2->{'borrowernumber'};
881 $results[$i] = $data;
892 my ($env,$dbh,$itemnumber) = @_;
894 my $query="Select * from biblio,items,biblioitems
895 where items.itemnumber = '$itemnumber'
896 and biblio.biblionumber = items.biblionumber
897 and biblioitems.biblioitemnumber = items.biblioitemnumber";
898 my $sth=$dbh->prepare($query);
901 my $data=$sth->fetchrow_hashref;
907 #used by member enquiries from the intranet
910 my ($env,$searchstring,$type)=@_;
911 my $dbh = &C4Connect;
912 $searchstring=~ s/\'/\\\'/g;
913 my @data=split(' ',$searchstring);
915 my $query="Select * from borrowers
916 where ((surname like \"$data[0]%\" or surname like \"% $data[0]%\"
917 or firstname like \"$data[0]%\" or firstname like \"% $data[0]%\"
918 or othernames like \"$data[0]%\" or othernames like \"% $data[0]%\")
920 for (my $i=1;$i<$count;$i++){
921 $query=$query." and (surname like \"$data[$i]%\" or surname like \"% $data[$i]%\"
922 or firstname like \"$data[$i]%\" or firstname like \"% $data[$i]%\"
923 or othernames like \"$data[$i]%\" or othernames like \"% $data[$i]%\")";
925 $query=$query.") or cardnumber = \"$searchstring\"
926 order by surname,firstname";
928 my $sth=$dbh->prepare($query);
932 while (my $data=$sth->fetchrow_hashref){
933 push(@results,$data);
939 return ($cnt,\@results);
943 my ($cardnumber,$bornum)=@_;
944 $cardnumber = uc $cardnumber;
948 $query="Select * from borrowers where cardnumber='$cardnumber'";
950 $query="Select * from borrowers where borrowernumber='$bornum'";
953 my $sth=$dbh->prepare($query);
955 my $data=$sth->fetchrow_hashref;
965 $query="Select * from issues,biblio,items where borrowernumber='$bornum' and
966 items.itemnumber=issues.itemnumber and
967 items.biblionumber=biblio.biblionumber and issues.returndate is NULL order
970 my $sth=$dbh->prepare($query);
974 while (my $data=$sth->fetchrow_hashref){
984 my ($bornum,$order,$limit)=@_;
987 $query="Select * from issues,biblio,items,biblioitems
988 where borrowernumber='$bornum' and
989 items.biblioitemnumber=biblioitems.biblioitemnumber and
990 items.itemnumber=issues.itemnumber and
991 items.biblionumber=biblio.biblionumber";
992 $query.=" order by $order";
994 $query.=" limit $limit";
997 my $sth=$dbh->prepare($query);
1001 while (my $data=$sth->fetchrow_hashref){
1007 return($i,\@result);
1011 my ($env,$bornum)=@_;
1013 my $query="Select count(*) from issues where borrowernumber='$bornum' and
1014 returndate is NULL";
1016 my $sth=$dbh->prepare($query);
1018 my $data=$sth->fetchrow_hashref;
1020 $sth=$dbh->prepare("Select count(*) from issues where
1021 borrowernumber='$bornum' and date_due < now() and returndate is NULL");
1023 my $data2=$sth->fetchrow_hashref;
1025 $sth=$dbh->prepare("Select sum(amountoutstanding) from accountlines where
1026 borrowernumber='$bornum'");
1028 my $data3=$sth->fetchrow_hashref;
1032 return($data2->{'count(*)'},$data->{'count(*)'},$data3->{'sum(amountoutstanding)'});
1036 sub getboracctrecord {
1037 my ($env,$params) = @_;
1041 my $query= "Select * from accountlines where
1042 borrowernumber=$params->{'borrowernumber'} order by date desc,timestamp desc";
1043 my $sth=$dbh->prepare($query);
1047 while (my $data=$sth->fetchrow_hashref){
1048 # if ($data->{'itemnumber'} ne ''){
1049 # $query="Select * from items,biblio where items.itemnumber=
1050 # '$data->{'itemnumber'}' and biblio.biblionumber=items.biblionumber";
1051 # my $sth2=$dbh->prepare($query);
1053 # my $data2=$sth2->fetchrow_hashref;
1057 $acctlines[$numlines] = $data;
1059 $total = $total+ $data->{'amountoutstanding'};
1063 return ($numlines,\@acctlines,$total);
1067 my ($env,$bibnum,$type)=@_;
1069 my $query="Select * from items where
1070 biblionumber=$bibnum ";
1071 if ($type ne 'intra'){
1072 $query.=" and ((itemlost <>1 and itemlost <> 2) or itemlost is NULL) and
1073 (wthdrawn <> 1 or wthdrawn is NULL)";
1075 my $sth=$dbh->prepare($query);
1087 while (my $data=$sth->fetchrow_hashref){
1089 my $query2="select * from issues,items where issues.itemnumber=
1090 '$data->{'itemnumber'}' and returndate is NULL
1091 and items.itemnumber=issues.itemnumber and ((items.itemlost <>1 and
1092 items.itemlost <> 2) or items.itemlost is NULL)
1093 and (wthdrawn <> 1 or wthdrawn is NULL)";
1095 my $sth2=$dbh->prepare($query2);
1097 if (my $data2=$sth2->fetchrow_hashref){
1100 if ($data->{'holdingbranch'} eq 'C'){
1103 if ($data->{'holdingbranch'} eq 'F' || $data->{'holdingbranch'} eq 'FP'){
1106 if ($data->{'holdingbranch'} eq 'S' || $data->{'holdingbranch'} eq 'SP'){
1109 if ($data->{'itemlost'} eq '1'){
1112 if ($data->{'itemlost'} eq '2'){
1115 if ($data->{'holdingbranch'} eq 'FM'){
1118 if ($data->{'holdingbranch'} eq 'TR'){
1125 my $query2="Select * from aqorders where biblionumber=$bibnum";
1126 my $sth2=$dbh->prepare($query2);
1128 if (my $data=$sth2->fetchrow_hashref){
1129 $ocount=$data->{'quantity'} - $data->{'quantityreceived'};
1135 return ($count,$lcount,$nacount,$fcount,$scount,$lostcount,$mending,$transit,$ocount);
1141 my $query="select description from itemtypes where itemtype='$type'";
1142 my $sth=$dbh->prepare($query);
1144 my $dat=$sth->fetchrow_hashref;
1147 return ($dat->{'description'});
1153 my $dbh = C4Connect;
1154 my $query = "Select * from biblioitems, itemtypes, items
1155 where biblioitems.biblionumber = '$bibnum'
1156 and biblioitems.itemtype = itemtypes.itemtype
1157 and biblioitems.biblioitemnumber = items.biblioitemnumber
1158 group by items.biblioitemnumber";
1159 my $sth = $dbh->prepare($query);
1165 while (my $data = $sth->fetchrow_hashref) {
1166 $results[$count] = $data;
1172 return($count, @results);
1177 #called from request.pl
1178 my ($biblioitemnumber)=@_;
1180 my $query="Select barcode from items where
1181 biblioitemnumber='$biblioitemnumber'
1182 and ((itemlost <> 1 and itemlost <> 2) or itemlost is NULL) and
1183 (wthdrawn <> 1 or wthdrawn is NULL)";
1185 my $sth=$dbh->prepare($query);
1189 while (my $data=$sth->fetchrow_hashref){
1190 $barcodes[$i]=$data->{'barcode'};
1201 my ($biblionumber) = @_;
1202 my $dbh = C4Connect;
1203 my $query = "Select * from websites where biblionumber = $biblionumber";
1204 my $sth = $dbh->prepare($query);
1209 while (my $data = $sth->fetchrow_hashref) {
1210 $results[$count] = $data;
1216 return($count, @results);
1220 sub getwebbiblioitems {
1221 my ($biblionumber) = @_;
1222 my $dbh = C4Connect;
1223 my $query = "Select * from biblioitems where biblionumber = $biblionumber
1224 and itemtype = 'WEB'";
1225 my $sth = $dbh->prepare($query);
1230 while (my $data = $sth->fetchrow_hashref) {
1231 $results[$count] = $data;
1237 return($count, @results);
1238 } # sub getwebbiblioitems
1241 END { } # module clean-up code here (global destructor)
1245 C4::Search - Module that provides Catalog searching for Koha
1250 my ($count,@results)=KeywordSearch($env,$type,$search,$num,$offset);
1251 my ($count,@results)=CatSearch($env,$type,$search,$num,$offset);
1255 This module provides the searching facilities for the Catalog.
1256 Here I should go through and document each function thats exported and what it does. But I havent yet.
1266 Koha Developement team <info@koha.org>