1 package C4::Search; #asummes C4/Search
3 #requires DBI.pm to be installed
12 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
14 # set the version for version checking
18 @EXPORT = qw(&CatSearch &BornameSearch &ItemInfo &KeywordSearch &subsearch
19 &itemdata &bibdata &GetItems &borrdata &getacctlist &itemnodata &itemcount
20 &OpacSearch &borrdata2 &NewBorrowerNumber &bibitemdata &borrissues
21 &getboracctrecord &ItemType &itemissues &FrontSearch &subject &subtitle
22 &addauthor &bibitems &barcodes &findguarantees &allissues &systemprefs);
23 %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ],
25 # your exported package globals go here,
26 # as well as any optionally exported functions
28 @EXPORT_OK = qw($Var1 %Hashit);
31 # non-exported package globals go here
32 use vars qw(@more $stuff);
34 # initalize package globals, first exported ones
39 # then the others (which are still accessible as $Some::Module::stuff)
43 # all file-scoped lexicals must be created before
44 # the functions below that use them.
46 # file-private lexicals go here
50 # here's a file-private function as a closure,
51 # callable as &$priv_func; it cannot be prototyped.
56 # make all your functions, whether exported or not;
60 my $query="select cardnumber,borrowernumber from borrowers where
62 my $sth=$dbh->prepare($query);
66 while (my $data=$sth->fetchrow_hashref){
79 my $sth=$dbh->prepare("select variable,value from systempreferences");
81 while (my ($variable,$value)=$sth->fetchrow) {
82 $systemprefs{$variable}=$value;
89 sub NewBorrowerNumber {
91 my $sth=$dbh->prepare("Select max(borrowernumber) from borrowers");
93 my $data=$sth->fetchrow_hashref;
95 $data->{'max(borrowernumber)'}++;
97 return($data->{'max(borrowernumber)'});
101 my ($env,$type,$search,$num,$offset)=@_;
102 my $dbh = &C4Connect;
103 $search->{'keyword'}=~ s/'/\\'/g;
104 my @key=split(' ',$search->{'keyword'});
108 my $query ="Select count(*) from biblio where
109 ((title like '$key[0]%' or title like '% $key[0]%')";
111 $query=$query." and (title like '$key[$i]%' or title like '% $key[$i]%')";
114 $query=$query.") or ((author like '$key[0]%' or author like '% $key[0]%')";
117 $query=$query." and (author like '$key[$i]%' or author like '% $key[$i]%')";
120 $query.=") or ((seriestitle like '$key[0]%' or seriestitle like '% $key[0]%')";
121 for ($i=1;$i<$count;$i++){
122 $query.=" and (seriestitle like '$key[$i]%' or seriestitle like '% $key[$i]%')";
124 $query.= ") or ((notes like '$key[0]%' or notes like '% $key[0]%')";
125 for ($i=1;$i<$count;$i++){
126 $query.=" and (notes like '$key[$i]%' or notes like '% $key[$i]%')";
128 $query=$query.") order by title";
129 my $sth=$dbh->prepare($query);
131 my $data=$sth->fetchrow_hashref;
132 my $count=$data->{'count(*)'};
134 $query=~ s/count\(\*\)/\*/;
135 $query= $query." limit $offset,$num";
136 $sth=$dbh->prepare($query);
140 while (my $data=$sth->fetchrow_hashref){
141 my $sti=$dbh->prepare("select dewey,subclass from biblioitems where biblionumber=$data->{'biblionumber'}");
143 my ($dewey, $subclass) = $sti->fetchrow;
145 ($dewey == 0) && ($dewey='');
146 ($dewey) && ($dewey.=" $subclass");
148 $results[$i]="$data->{'author'}\t$data->{'title'}\t$data->{'biblionumber'}\t$dewey";
153 return($count,@results);
159 my ($env,$type,$search,$num,$offset)=@_;
160 my $dbh = &C4Connect;
161 $search->{'front'}=~ s/ +$//;
162 $search->{'front'}=~ s/'/\\'/;
163 my @key=split(' ',$search->{'front'});
167 my $query ="Select * from biblio,bibliosubtitle where
168 biblio.biblionumber=bibliosubtitle.biblionumber and
169 ((title like '$key[0]%' or title like '% $key[0]%'
170 or subtitle like '$key[0]%' or subtitle like '% $key[0]%'
171 or author like '$key[0]%' or author like '% $key[0]%')";
173 $query=$query." and (title like '%$key[$i]%' or subtitle like '%$key[$i]%')";
176 $query=$query.") group by biblio.biblionumber order by author,title";
178 my $sth=$dbh->prepare($query);
181 while (my $data=$sth->fetchrow_hashref){
182 my $sti=$dbh->prepare("select dewey,subclass from biblioitems where biblionumber=$data->{'biblionumber'}");
184 my ($dewey, $subclass) = $sti->fetchrow;
186 ($dewey == 0) && ($dewey='');
187 ($dewey) && ($dewey.=" $subclass");
189 $results[$i]="$data->{'author'}\t$data->{'title'}\t$data->{'biblionumber'}\t$data->{'copyrightdate'}\t$dewey";
190 # print $results[$i];
194 $sth=$dbh->prepare("Select biblionumber from bibliosubject where subject
195 like '%$search->{'keyword'}%'");
197 while (my $data=$sth->fetchrow_hashref){
198 my $sth2=$dbh->prepare("Select * from biblio where
199 biblionumber=$data->{'biblionumber'}");
201 while (my $data2=$sth2->fetchrow_hashref){
203 $results[$i]="$data2->{'author'}\t$data2->{'title'}\t$data2->{'biblionumber'}\t$data->{'copyrightdate'}";
204 # print $results[$i];
210 @results=sort @results;
215 while ($i2 < $count){
216 if ($results[$i2] ne $res[$i-1]){
217 $res[$i]=$results[$i2];
225 while ($i2 < $num && $i2 < $count){
226 $res2[$i2]=$res[$i2+$offset];
237 my ($env,$type,$search,$num,$offset)=@_;
238 my $dbh = &C4Connect;
239 $search->{'keyword'}=~ s/ +$//;
240 $search->{'keyword'}=~ s/'/\\'/;
241 my @key=split(' ',$search->{'keyword'});
245 my $query ="Select * from biblio,bibliosubtitle,biblioitems where
246 biblio.biblionumber=bibliosubtitle.biblionumber and
247 biblioitems.biblionumber=biblio.biblionumber and
248 (((title like '$key[0]%' or title like '% $key[0]%')";
250 $query=$query." and (title like '$key[$i]%' or title like '% $key[$i]%')";
253 $query.= ") or ((subtitle like '$key[0]%' or subtitle like '% $key[0]%')";
254 for ($i=1;$i<$count;$i++){
255 $query.= " and (subtitle like '$key[$i]%' or subtitle like '% $key[$i]%')";
257 $query.= ") or ((seriestitle like '$key[0]%' or seriestitle like '% $key[0]%')";
258 for ($i=1;$i<$count;$i++){
259 $query.=" and (seriestitle like '$key[$i]%' or seriestitle like '% $key[$i]%')";
261 $query.= ") or ((biblio.notes like '$key[0]%' or biblio.notes like '% $key[0]%')";
262 for ($i=1;$i<$count;$i++){
263 $query.=" and (biblio.notes like '$key[$i]%' or biblio.notes like '% $key[$i]%')";
265 $query.= ") or ((biblioitems.notes like '$key[0]%' or biblioitems.notes like '% $key[0]%')";
266 for ($i=1;$i<$count;$i++){
267 $query.=" and (biblioitems.notes like '$key[$i]%' or biblioitems.notes like '% $key[$i]%')";
269 if ($search->{'keyword'} =~ /new zealand/i){
270 $query.= "or (title like 'nz%' or title like '% nz %' or title like '% nz' or subtitle like 'nz%'
271 or subtitle like '% nz %' or subtitle like '% nz' or author like 'nz %'
272 or author like '% nz %' or author like '% nz')"
274 if ($search->{'keyword'} eq 'nz' || $search->{'keyword'} eq 'NZ' ||
275 $search->{'keyword'} =~ /nz /i || $search->{'keyword'} =~ / nz /i ||
276 $search->{'keyword'} =~ / nz/i){
277 $query.= "or (title like 'new zealand%' or title like '% new zealand %'
278 or title like '% new zealand' or subtitle like 'new zealand%' or
279 subtitle like '% new zealand %'
280 or subtitle like '% new zealand' or author like 'new zealand%'
281 or author like '% new zealand %' or author like '% new zealand' or
282 seriestitle like 'new zealand%' or seriestitle like '% new zealand %'
283 or seriestitle like '% new zealand')"
286 if ($search->{'class'} ne ''){
287 my @temp=split(/\|/,$search->{'class'});
289 $query.= "and ( itemtype='$temp[0]'";
290 for (my $i=1;$i<$count;$i++){
291 $query.=" or itemtype='$temp[$i]'";
295 $query.="group by biblio.biblionumber order by author,title";
297 my $sth=$dbh->prepare($query);
300 while (my $data=$sth->fetchrow_hashref){
301 my $sti=$dbh->prepare("select dewey,subclass from biblioitems where biblionumber=$data->{'biblionumber'}");
303 my ($dewey, $subclass) = $sti->fetchrow;
305 ($dewey == 0) && ($dewey='');
306 ($dewey) && ($dewey.=" $subclass");
308 $results[$i]="$data->{'author'}\t$data->{'title'}\t$data->{'biblionumber'}\t$data->{'copyrightdate'}\t$dewey";
309 # print $results[$i];
313 $sth=$dbh->prepare("Select biblionumber from bibliosubject where subject
314 like '%$search->{'keyword'}%'");
316 while (my $data=$sth->fetchrow_hashref){
317 $query="Select * from biblio,biblioitems where
318 biblio.biblionumber=$data->{'biblionumber'} and biblio.biblionumber=biblioitems.biblionumber";
319 if ($search->{'class'} ne ''){
320 my @temp=split(/\|/,$search->{'class'});
322 $query.= " and ( itemtype='$temp[0]'";
323 for (my $i=1;$i<$count;$i++){
324 $query.=" or itemtype='$temp[$i]'";
328 my $sth2=$dbh->prepare($query);
331 while (my $data2=$sth2->fetchrow_hashref){
332 $results[$i]="$data2->{'author'}\t$data2->{'title'}\t$data2->{'biblionumber'}\t$data2->{'copyrightdate'}";
333 # print $results[$i];
339 @results=sort @results;
346 while ($i2 < $count){
347 if ($results[$i2] ne $res[$i-1]){
348 $res[$i]=$results[$i2];
356 while ($i2 < $num && $i2 < $count){
357 $res2[$i2]=$res[$i2+$offset];
368 my ($env,$type,$search,$num,$offset)=@_;
369 my $dbh = &C4Connect;
372 $search->{'title'}=~ s/'/\\'/g;
373 $search->{'author'}=~ s/'/\\'/g;
374 $search->{'illustrator'}=~ s/'/\\'/g;
375 my $title = lc($search->{'title'});
377 if ($type eq 'loose') {
378 if ($search->{'author'} ne ''){
379 my @key=split(' ',$search->{'author'});
382 $query="select *,biblio.author,biblio.biblionumber from
384 left join additionalauthors
385 on additionalauthors.biblionumber =biblio.biblionumber
386 where biblioitems.biblionumber=biblio.biblionumber
388 ((biblio.author like '$key[0]%' or biblio.author like '% $key[0]%' or
389 additionalauthors.author like '$key[0]%' or additionalauthors.author
393 $query=$query." and (
394 biblio.author like '$key[$i]%' or biblio.author like '% $key[$i]%' or
395 additionalauthors.author like '$key[$i]%' or additionalauthors.author like '% $key[$i]%'
400 if ($search->{'title'} ne ''){
401 $query=$query. " and title like '%$search->{'title'}%'";
403 if ($search->{'class'} ne ''){
404 my @temp=split(/\|/,$search->{'class'});
406 $query.= "and ( itemtype='$temp[0]'";
407 for (my $i=1;$i<$count;$i++){
408 $query.=" or itemtype='$temp[$i]'";
412 if ($search->{'dewey'} ne ''){
413 $query.=" and dewey='$search->{'dewey'}' ";
415 if ($search->{'illustrator'} ne ''){
416 $query.=" and illus like '%".$search->{'illustrator'}."%' ";
419 $query.=" group by biblio.biblionumber";
421 if ($search->{'title'} ne '') {
422 if ($search->{'ttype'} eq 'exact'){
423 $query="select * from biblio
425 (biblio.title='$search->{'title'}' or (biblio.unititle = '$search->{'title'}'
426 or biblio.unititle like '$search->{'title'} |%' or
427 biblio.unititle like '%| $search->{'title'} |%' or
428 biblio.unititle like '%| $search->{'title'}') or
429 (biblio.seriestitle = '$search->{'title'}' or
430 biblio.seriestitle like '$search->{'title'} |%' or
431 biblio.seriestitle like '%| $search->{'title'} |%' or
432 biblio.seriestitle like '%| $search->{'title'}')
435 my @key=split(' ',$search->{'title'});
438 $query="select * from biblio,bibliosubtitle,biblioitems
440 (biblio.biblionumber=bibliosubtitle.biblionumber and
441 biblioitems.biblionumber=biblio.biblionumber) and
442 (((title like '$key[0]%' or title like '% $key[0]%' or title like '% $key[0]')";
444 $query=$query." and (title like '$key[$i]%' or title like '% $key[$i]%' or title like '% $key[$i]')";
447 $query.=") or ((subtitle like '$key[0]%' or subtitle like '% $key[0] %' or subtitle like '% $key[0]')";
448 for ($i=1;$i<$count;$i++){
449 $query.=" and (subtitle like '$key[$i]%' or subtitle like '% $key[$i] %' or subtitle like '% $key[$i]')";
451 $query.=") or ((seriestitle like '$key[0]%' or seriestitle like '% $key[0] %' or seriestitle like '% $key[0]')";
452 for ($i=1;$i<$count;$i++){
453 $query.=" and (seriestitle like '$key[$i]%' or seriestitle like '% $key[$i] %')";
455 $query.=") or ((unititle like '$key[0]%' or unititle like '% $key[0] %' or unititle like '% $key[0]')";
456 for ($i=1;$i<$count;$i++){
457 $query.=" and (unititle like '$key[$i]%' or unititle like '% $key[$i] %')";
460 if ($search->{'class'} ne ''){
461 my @temp=split(/\|/,$search->{'class'});
463 $query.= " and ( itemtype='$temp[0]'";
464 for (my $i=1;$i<$count;$i++){
465 $query.=" or itemtype='$temp[$i]'";
469 if ($search->{'dewey'} ne ''){
470 $query.=" and dewey='$search->{'dewey'}' ";
472 if ($search->{'illustrator'} ne ''){
473 $query.=" and illus like '%".$search->{'illustrator'}."%' ";
476 } elsif ($search->{'class'} ne ''){
477 $query="select * from biblioitems,biblio where biblio.biblionumber=biblioitems.biblionumber";
478 my @temp=split(/\|/,$search->{'class'});
480 $query.= " and ( itemtype='$temp[0]'";
481 for (my $i=1;$i<$count;$i++){
482 $query.=" or itemtype='$temp[$i]'";
485 if ($search->{'illustrator'} ne ''){
486 $query.=" and illus like '%".$search->{'illustrator'}."%' ";
488 } elsif ($search->{'dewey'} ne ''){
489 $query="select * from biblioitems,biblio
490 where biblio.biblionumber=biblioitems.biblionumber
491 and biblioitems.dewey like '$search->{'dewey'}%'";
492 } elsif ($search->{'illustrator'} ne '') {
493 if ($search->{'illustrator'} ne ''){
494 $query="select * from biblioitems,biblio
495 where biblio.biblionumber=biblioitems.biblionumber
496 and biblioitems.illus like '%".$search->{'illustrator'}."%'";
499 $query .=" group by biblio.biblionumber";
502 if ($type eq 'subject'){
503 my @key=split(' ',$search->{'subject'});
506 $query="select distinct(subject) from bibliosubject where( subject like
507 '$key[0]%' or subject like '% $key[0]%' or subject like '% $key[0]' or subject like '%($key[0])%')";
509 $query.=" and (subject like '$key[$i]%' or subject like '% $key[$i]%'
510 or subject like '% $key[$i]'
511 or subject like '%($key[$i])%')";
514 if ($search->{'subject'} eq 'NZ' || $search->{'subject'} eq 'nz'){
515 $query.= " or (subject like 'NEW ZEALAND %' or subject like '% NEW ZEALAND %'
516 or subject like '% NEW ZEALAND' or subject like '%(NEW ZEALAND)%' ) ";
517 } elsif ( $search->{'subject'} =~ /^nz /i || $search->{'subject'} =~ / nz /i || $search->{'subject'} =~ / nz$/i){
518 $query=~ s/ nz/ NEW ZEALAND/ig;
519 $query=~ s/nz /NEW ZEALAND /ig;
520 $query=~ s/\(nz\)/\(NEW ZEALAND\)/gi;
523 if ($type eq 'precise'){
524 $query="select * from items,biblio ";
525 if ($search->{'item'} ne ''){
526 my $search2=uc $search->{'item'};
527 $query=$query." where
528 items.biblionumber=biblio.biblionumber
529 and barcode='$search2'";
531 if ($search->{'isbn'} ne ''){
532 my $search2=uc $search->{'isbn'};
533 my $query1 = "select * from biblioitems where isbn='$search2'";
534 my $sth1=$dbh->prepare($query1);
538 while (my $data=$sth1->fetchrow_hashref) {
539 $query="select * from biblioitems,biblio where
540 biblio.biblionumber = $data->{'biblionumber'}
541 and biblioitems.biblionumber = biblio.biblionumber";
542 my $sth=$dbh->prepare($query);
544 my $data=$sth->fetchrow_hashref;
545 my ($dewey, $subclass) = ($data->{'dewey'}, $data->{'subclass'});
547 ($dewey == 0) && ($dewey='');
548 ($dewey) && ($dewey.=" $subclass");
549 $results[$i2]="$data->{'author'}\t$data->{'title'}\t$data->{'biblionumber'}\t$data->{'copyrightdate'}\t$dewey\t$data->{'isbn'}\t$data->{'itemtype'}";
557 if ($type ne 'precise' && $type ne 'subject'){
558 if ($search->{'author'} ne ''){
559 $query=$query." order by biblio.author,title";
561 $query=$query." order by title";
564 if ($type eq 'subject'){
565 $query=$query." order by subject";
568 my $sth=$dbh->prepare($query);
572 my $limit= $num+$offset;
573 while (my $data=$sth->fetchrow_hashref){
574 my $sti=$dbh->prepare("select dewey,subclass from biblioitems where biblionumber=$data->{'biblionumber'}");
576 my ($dewey, $subclass) = $sti->fetchrow;
578 ($dewey == 0) && ($dewey='');
579 ($dewey) && ($dewey.=" $subclass");
581 if ($count > $offset && $count <= $limit){
582 if ($type ne 'subject' && $type ne 'precise'){
583 $results[$i]="$data->{'author'}\t$data->{'title'}\t$data->{'biblionumber'}\t$data->{'copyrightdate'}\t$dewey\t$data->{'illus'}";
584 } elsif ($search->{'isbn'} ne '' || $search->{'item'} ne ''){
585 $results[$i]="$data->{'author'}\t$data->{'title'}\t$data->{'biblionumber'}\t$data->{'copyrightdate'}\t$dewey\t$data->{'illus'}";
587 $results[$i]="$data->{'author'}\t$data->{'subject'}\t$data->{'biblionumber'}\t$data->{'copyrightdate'}\t$dewey\t$data->{'illus'}";
594 #if ($type ne 'precise'){
598 return($count,@results);
601 sub updatesearchstats{
607 my ($env,$subject)=@_;
609 my $query="Select * from biblio,bibliosubject where
610 biblio.biblionumber=bibliosubject.biblionumber and
611 bibliosubject.subject='$subject' group by biblio.biblionumber
612 order by biblio.title";
613 my $sth=$dbh->prepare($query);
618 while (my $data=$sth->fetchrow_hashref){
619 $results[$i]="$data->{'title'}\t$data->{'author'}\t$data->{'biblionumber'}";
629 my ($env,$biblionumber,$type)=@_;
630 my $dbh = &C4Connect;
631 my $query="Select * from items,biblio,biblioitems,branches
632 where (items.biblioitemnumber = biblioitems.biblioitemnumber)
633 and biblioitems.biblionumber=biblio.biblionumber
634 and biblio.biblionumber='$biblionumber' and branches.branchcode=
635 items.holdingbranch ";
637 if ($type ne 'intra'){
638 $query.=" and (items.itemlost<>1 or items.itemlost is NULL)
639 and (wthdrawn <> 1 or wthdrawn is NULL)";
641 $query=$query."order by items.dateaccessioned desc";
642 my $sth=$dbh->prepare($query);
647 while (my $data=$sth->fetchrow_hashref){
648 my $iquery = "Select * from issues
649 where itemnumber = '$data->{'itemnumber'}'
650 and returndate is null";
652 my $isth=$dbh->prepare($iquery);
654 if (my $idata=$isth->fetchrow_hashref){
655 my @temp=split('-',$idata->{'date_due'});
656 $datedue = "$temp[2]/$temp[1]/$temp[0]";
658 if ($data->{'itemlost'} eq '1'){
661 if ($data->{'wthdrawn'} eq '1'){
662 $datedue="Cancelled";
665 my ($rescount,$reserves)=FindReserves($biblionumber,'');
671 my $class = $data->{'classification'};
672 my $dewey = $data->{'dewey'};
674 if ($dewey eq "000.") { $dewey = "";};
675 if ($dewey < 10){$dewey='00'.$dewey;}
676 if ($dewey < 100 && $dewey > 10){$dewey='0'.$dewey;}
681 $class = $class.$dewey;
682 $class = $class.$data->{'subclass'};
683 # $results[$i]="$data->{'title'}\t$data->{'barcode'}\t$datedue\t$data->{'branchname'}\t$data->{'dewey'}";
684 my @temp=split('-',$data->{'datelastseen'});
685 my $date="$temp[2]/$temp[1]/$temp[0]";
686 $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'}";
687 # print "$results[$i] <br>";
696 my ($env,$biblionumber)=@_;
697 #debug_msg($env,"GetItems");
698 my $dbh = &C4Connect;
699 my $query = "Select * from biblioitems where (biblionumber = $biblionumber)";
700 #debug_msg($env,$query);
701 my $sth=$dbh->prepare($query);
703 #debug_msg($env,"executed query");
706 while (my $data=$sth->fetchrow_hashref) {
707 #debug_msg($env,$data->{'biblioitemnumber'});
708 my $dewey = $data->{'dewey'};
710 my $line = $data->{'biblioitemnumber'}."\t".$data->{'itemtype'};
711 $line = $line."\t$data->{'classification'}\t$dewey";
712 $line = $line."\t$data->{'subclass'}\t$data->{isbn}";
713 $line = $line."\t$data->{'volume'}\t$data->{number}";
714 my $isth= $dbh->prepare("select * from items where biblioitemnumber = $data->{'biblioitemnumber'}");
716 while (my $idata = $isth->fetchrow_hashref) {
717 my $iline = $idata->{'barcode'}."[".$idata->{'holdingbranch'}."[";
718 if ($idata->{'notforloan'} == 1) {
719 $iline = $iline."NFL ";
721 if ($idata->{'itemlost'} == 1) {
722 $iline = $iline."LOST ";
724 $line = $line."\t$iline";
727 $results[$i] = $line;
738 my $query="Select * from items,biblioitems where barcode='$barcode'
739 and items.biblioitemnumber=biblioitems.biblioitemnumber";
741 my $sth=$dbh->prepare($query);
743 my $data=$sth->fetchrow_hashref;
750 my ($bibnum,$type)=@_;
752 my $query="Select *,biblio.notes from biblio,biblioitems,bibliosubtitle where biblio.biblionumber=$bibnum
753 and biblioitems.biblionumber=$bibnum and
754 (bibliosubtitle.biblionumber=$bibnum)";
756 my $sth=$dbh->prepare($query);
758 my $data=$sth->fetchrow_hashref;
760 $query="Select * from bibliosubject where biblionumber='$bibnum'";
761 $sth=$dbh->prepare($query);
763 while (my $dat=$sth->fetchrow_hashref){
764 $data->{'subject'}.=" | $dat->{'subject'}";
776 my $query="Select * from biblio,biblioitems,itemtypes where biblio.biblionumber=
777 biblioitems.biblionumber and biblioitemnumber=$bibitem and
778 biblioitems.itemtype=itemtypes.itemtype";
780 my $sth=$dbh->prepare($query);
782 my $data=$sth->fetchrow_hashref;
791 my $query="Select * from bibliosubject where biblionumber=$bibnum";
792 my $sth=$dbh->prepare($query);
796 while (my $data=$sth->fetchrow_hashref){
802 return($i,\@results);
808 my $query="Select * from additionalauthors where biblionumber=$bibnum";
809 my $sth=$dbh->prepare($query);
813 while (my $data=$sth->fetchrow_hashref){
819 return($i,\@results);
825 my $query="Select * from bibliosubtitle where biblionumber=$bibnum";
826 my $sth=$dbh->prepare($query);
830 while (my $data=$sth->fetchrow_hashref){
836 return($i,\@results);
842 my ($bibitem,$biblio)=@_;
844 my $query="Select * from items where
845 items.biblioitemnumber='$bibitem'";
846 my $sth=$dbh->prepare($query) || die $dbh->errstr;
847 $sth->execute || die $sth->errstr;
850 while (my $data=$sth->fetchrow_hashref) {
851 my $query2="select * from issues,borrowers where itemnumber=$data->{'itemnumber'}
852 and returndate is NULL and issues.borrowernumber=borrowers.borrowernumber";
853 my $sth2=$dbh->prepare($query2);
855 if (my $data2=$sth2->fetchrow_hashref) {
856 $data->{'date_due'}=$data2->{'date_due'};
857 $data->{'card'}=$data2->{'cardnumber'};
859 if ($data->{'wthdrawn'} eq '1') {
860 $data->{'date_due'}='Cancelled';
862 $data->{'date_due'}='Available';
866 $query2="select * from issues,borrowers where itemnumber='$data->{'itemnumber'}'
867 and issues.borrowernumber=borrowers.borrowernumber
868 order by date_due desc";
869 my $sth2=$dbh->prepare($query2) || die $dbh->errstr;
870 $sth2->execute || die $sth2->errstr;
871 for (my $i2=0;$i2<2;$i2++){
872 if (my $data2=$sth2->fetchrow_hashref){
873 $data->{"timestamp$i2"}=$data2->{'timestamp'};
874 $data->{"card$i2"}=$data2->{'cardnumber'};
875 $data->{"borrower$i2"}=$data2->{'borrowernumber'};
888 my ($env,$dbh,$itemnumber) = @_;
890 my $query="Select * from biblio,items,biblioitems
891 where items.itemnumber = '$itemnumber'
892 and biblio.biblionumber = items.biblionumber
893 and biblioitems.biblioitemnumber = items.biblioitemnumber";
894 my $sth=$dbh->prepare($query);
897 my $data=$sth->fetchrow_hashref;
903 #used by member enquiries from the intranet
906 my ($env,$searchstring,$type)=@_;
907 my $dbh = &C4Connect;
908 $searchstring=~ s/\'/\\\'/g;
909 my @data=split(' ',$searchstring);
911 my $query="Select * from borrowers
912 where ((surname like \"$data[0]%\" or surname like \"% $data[0]%\"
913 or firstname like \"$data[0]%\" or firstname like \"% $data[0]%\"
914 or othernames like \"$data[0]%\" or othernames like \"% $data[0]%\")
916 for (my $i=1;$i<$count;$i++){
917 $query=$query." and (surname like \"$data[$i]%\" or surname like \"% $data[$i]%\"
918 or firstname like \"$data[$i]%\" or firstname like \"% $data[$i]%\"
919 or othernames like \"$data[$i]%\" or othernames like \"% $data[$i]%\")";
921 $query=$query.") or cardnumber = \"$searchstring\"
922 order by surname,firstname";
924 my $sth=$dbh->prepare($query);
928 while (my $data=$sth->fetchrow_hashref){
929 push(@results,$data);
935 return ($cnt,\@results);
939 my ($cardnumber,$bornum)=@_;
940 $cardnumber = uc $cardnumber;
944 $query="Select * from borrowers where cardnumber='$cardnumber'";
946 $query="Select * from borrowers where borrowernumber='$bornum'";
949 my $sth=$dbh->prepare($query);
951 my $data=$sth->fetchrow_hashref;
961 $query="Select * from issues,biblio,items where borrowernumber='$bornum' and
962 items.itemnumber=issues.itemnumber and
963 items.biblionumber=biblio.biblionumber and issues.returndate is NULL order
966 my $sth=$dbh->prepare($query);
970 while (my $data=$sth->fetchrow_hashref){
983 $query="Select * from issues,biblio,items where borrowernumber='$bornum' and
984 items.itemnumber=issues.itemnumber and
985 items.biblionumber=biblio.biblionumber order
988 my $sth=$dbh->prepare($query);
992 while (my $data=$sth->fetchrow_hashref){
1004 my ($env,$bornum)=@_;
1006 my $query="Select count(*) from issues where borrowernumber='$bornum' and
1007 returndate is NULL";
1009 my $sth=$dbh->prepare($query);
1011 my $data=$sth->fetchrow_hashref;
1013 $sth=$dbh->prepare("Select count(*) from issues where
1014 borrowernumber='$bornum' and date_due < now() and returndate is NULL");
1016 my $data2=$sth->fetchrow_hashref;
1018 $sth=$dbh->prepare("Select sum(amountoutstanding) from accountlines where
1019 borrowernumber='$bornum'");
1021 my $data3=$sth->fetchrow_hashref;
1025 return($data2->{'count(*)'},$data->{'count(*)'},$data3->{'sum(amountoutstanding)'});
1029 my ($env,$params) = @_;
1033 my $query = "Select borrowernumber, accountno, date, amount, description,
1034 dispute, accounttype, amountoutstanding, barcode, title
1035 from accountlines,items,biblio
1036 where borrowernumber = $params->{'borrowernumber'} ";
1037 if ($params->{'acctno'} ne "") {
1038 my $query = $query." and accountlines.accountno = $params->{'acctno'} ";
1040 my $query = $query." and accountlines.itemnumber = items.itemnumber
1041 and items.biblionumber = biblio.biblionumber
1042 and accountlines.amountoutstanding<>0 order by date";
1043 my $sth=$dbh->prepare($query);
1047 while (my $data=$sth->fetchrow_hashref){
1048 $acctlines[$numlines] = $data;
1050 $total = $total+ $data->{'amountoutstanding'};
1052 return ($numlines,\@acctlines,$total);
1057 sub getboracctrecord {
1058 my ($env,$params) = @_;
1062 my $query= "Select * from accountlines where
1063 borrowernumber=$params->{'borrowernumber'} order by date desc,timestamp desc";
1064 my $sth=$dbh->prepare($query);
1068 while (my $data=$sth->fetchrow_hashref){
1069 # if ($data->{'itemnumber'} ne ''){
1070 # $query="Select * from items,biblio where items.itemnumber=
1071 # '$data->{'itemnumber'}' and biblio.biblionumber=items.biblionumber";
1072 # my $sth2=$dbh->prepare($query);
1074 # my $data2=$sth2->fetchrow_hashref;
1078 $acctlines[$numlines] = $data;
1080 $total = $total+ $data->{'amountoutstanding'};
1084 return ($numlines,\@acctlines,$total);
1088 my ($env,$bibnum,$type)=@_;
1090 my $query="Select * from items where
1091 biblionumber=$bibnum ";
1092 if ($type ne 'intra'){
1093 $query.=" and (itemlost <>1 or itemlost is NULL) and
1094 (wthdrawn <> 1 or wthdrawn is NULL)";
1096 my $sth=$dbh->prepare($query);
1108 while (my $data=$sth->fetchrow_hashref){
1110 my $query2="select * from issues,items where issues.itemnumber=
1111 '$data->{'itemnumber'}' and returndate is NULL
1112 and items.itemnumber=issues.itemnumber and (items.itemlost <>1 or
1113 items.itemlost is NULL)";
1114 my $sth2=$dbh->prepare($query2);
1116 if (my $data2=$sth2->fetchrow_hashref){
1119 if ($data->{'holdingbranch'} eq 'C'){
1122 if ($data->{'holdingbranch'} eq 'F' || $data->{'holdingbranch'} eq 'FP'){
1125 if ($data->{'holdingbranch'} eq 'S' || $data->{'holdingbranch'} eq 'SP'){
1128 if ($data->{'itemlost'} eq '1'){
1131 if ($data->{'holdingbranch'} eq 'FM'){
1134 if ($data->{'holdingbranch'} eq 'TR'){
1141 my $query2="Select * from aqorders where biblionumber=$bibnum";
1142 my $sth2=$dbh->prepare($query2);
1144 if (my $data=$sth2->fetchrow_hashref){
1145 $ocount=$data->{'quantity'} - $data->{'quantityreceived'};
1151 return ($count,$lcount,$nacount,$fcount,$scount,$lostcount,$mending,$transit,$ocount);
1157 my $query="select description from itemtypes where itemtype='$type'";
1158 my $sth=$dbh->prepare($query);
1160 my $dat=$sth->fetchrow_hashref;
1163 return ($dat->{'description'});
1169 my $query="Select * from biblioitems,itemtypes,items where
1170 biblioitems.biblionumber='$bibnum' and biblioitems.itemtype=itemtypes.itemtype and
1171 biblioitems.biblioitemnumber=items.biblioitemnumber group by
1172 items.biblioitemnumber";
1173 my $sth=$dbh->prepare($query);
1177 while (my $data=$sth->fetchrow_hashref){
1183 return($i,@results);
1187 my ($biblioitemnumber)=@_;
1189 my $query="Select barcode from items where
1190 biblioitemnumber='$biblioitemnumber'";
1191 my $sth=$dbh->prepare($query);
1195 while (my $data=$sth->fetchrow_hashref){
1196 $barcodes[$i]=$data->{'barcode'};
1204 END { } # module clean-up code here (global destructor)