1 package C4::Acquisitions; #assumes C4/Acquisitions.pm
7 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
9 # set the version for version checking
13 @EXPORT = qw(&getorders &bookseller &breakdown &basket &newbasket &bookfunds
14 &ordersearch &newbiblio &newbiblioitem &newsubject &newsubtitle &neworder
15 &newordernum &modbiblio &modorder &getsingleorder &invoice &receiveorder
16 &bookfundbreakdown &curconvert &updatesup &insertsup &newitems &modbibitem
17 &getcurrencies &modsubtitle &modsubject &modaddauthor &moditem &countitems
18 &findall &needsmod &delitem &delbibitem &delbiblio &delorder &branches
19 &getallorders &getrecorders &updatecurrencies &getorder &getcurrency &updaterecorder
20 &updatecost &checkitems &modnote &getitemtypes &getbiblio
21 &getbiblioitem &getitemsbybiblioitem &isbnsearch &keywordsearch
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
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;
63 my $query = "Select count(*),authorisedby,entrydate,basketno from aqorders where
64 booksellerid='$supplierid' and (quantity > quantityreceived or
65 quantityreceived is NULL)
66 and (datecancellationprinted is NULL or datecancellationprinted = '0000-00-00')";
67 $query.=" group by basketno order by entrydate desc";
69 my $sth=$dbh->prepare($query);
73 while (my $data=$sth->fetchrow_hashref){
79 return ($i,\@results);
85 my $query="Select count(*) from items where biblionumber=$biblio";
87 my $sth=$dbh->prepare($query);
89 my $data=$sth->fetchrow_hashref;
92 return($data->{'count(*)'});
98 my $query="Select ordernumber
100 where biblionumber=? and biblioitemnumber=?";
101 my $sth=$dbh->prepare($query);
102 $sth->execute($bib,$bi);
103 my $ordnum=$sth->fetchrow_hashref;
105 my $order=getsingleorder($ordnum->{'ordernumber'});
108 return ($order,$ordnum->{'ordernumber'});
114 my $query="Select * from biblio,biblioitems,aqorders,aqorderbreakdown
115 where aqorders.ordernumber=?
116 and biblio.biblionumber=aqorders.biblionumber and
117 biblioitems.biblioitemnumber=aqorders.biblioitemnumber and
118 aqorders.ordernumber=aqorderbreakdown.ordernumber";
119 my $sth=$dbh->prepare($query);
120 $sth->execute($ordnum);
121 my $data=$sth->fetchrow_hashref;
130 my $query="Select * from aqorders,biblio,biblioitems where
131 booksellerinvoicenumber='$invoice'
132 and biblio.biblionumber=aqorders.biblionumber and biblioitems.biblioitemnumber=
133 aqorders.biblioitemnumber group by aqorders.ordernumber,aqorders.biblioitemnumber";
136 my $sth=$dbh->prepare($query);
138 while (my $data=$sth->fetchrow_hashref){
148 #gets all orders from a certain supplier, orders them alphabetically
151 my $query="Select * from aqorders,biblio,biblioitems where booksellerid='$supid'
152 and (cancelledby is NULL or cancelledby = '')
153 and biblio.biblionumber=aqorders.biblionumber and biblioitems.biblioitemnumber=
154 aqorders.biblioitemnumber
155 group by aqorders.biblioitemnumber
160 my $sth=$dbh->prepare($query);
162 while (my $data=$sth->fetchrow_hashref){
172 #gets all orders from a certain supplier, orders them alphabetically
175 my $query="Select * from aqorders,biblio,biblioitems where booksellerid='$supid'
176 and (cancelledby is NULL or cancelledby = '')
177 and biblio.biblionumber=aqorders.biblionumber and biblioitems.biblioitemnumber=
178 aqorders.biblioitemnumber and
179 aqorders.quantityreceived>0
180 and aqorders.datereceived >=now()
181 group by aqorders.biblioitemnumber
186 my $sth=$dbh->prepare($query);
188 while (my $data=$sth->fetchrow_hashref){
198 my ($search,$biblio,$catview)=@_;
200 my $query="Select *,biblio.title from aqorders,biblioitems,biblio
201 where aqorders.biblioitemnumber = biblioitems.biblioitemnumber
202 and biblio.biblionumber=aqorders.biblionumber
203 and ((datecancellationprinted is NULL)
204 or (datecancellationprinted = '0000-00-00')
206 my @data=split(' ',$search);
208 for (my $i=0;$i<$count;$i++){
209 $query.= "(biblio.title like '$data[$i]%' or biblio.title like '% $data[$i]%') and ";
212 $query.=" ) or biblioitems.isbn='$search'
213 or (aqorders.ordernumber='$search' and aqorders.biblionumber='$biblio')) ";
214 if ($catview ne 'yes'){
215 $query.=" and (quantityreceived < quantity or quantityreceived is NULL)";
217 $query.=" group by aqorders.ordernumber";
218 my $sth=$dbh->prepare($query);
223 while (my $data=$sth->fetchrow_hashref){
224 my $sth2=$dbh->prepare("Select * from biblio where
225 biblionumber='$data->{'biblionumber'}'");
227 my $data2=$sth2->fetchrow_hashref;
229 $data->{'author'}=$data2->{'author'};
230 $data->{'seriestitle'}=$data2->{'seriestitle'};
231 $sth2=$dbh->prepare("Select * from aqorderbreakdown where
232 ordernumber=$data->{'ordernumber'}");
234 $data2=$sth2->fetchrow_hashref;
236 $data->{'branchcode'}=$data2->{'branchcode'};
237 $data->{'bookfundid'}=$data2->{'bookfundid'};
248 my ($searchstring)=@_;
250 my $query="Select * from aqbooksellers where name like '%$searchstring%' or
251 id = '$searchstring'";
252 my $sth=$dbh->prepare($query);
256 while (my $data=$sth->fetchrow_hashref){
268 my $query="Select * from aqorderbreakdown where ordernumber='$id'";
269 my $sth=$dbh->prepare($query);
273 while (my $data=$sth->fetchrow_hashref){
279 return($i,\@results);
283 my ($basketno,$supplier)=@_;
285 my $query="Select *,biblio.title from aqorders,biblio,biblioitems
286 where basketno='$basketno'
287 and biblio.biblionumber=aqorders.biblionumber and biblioitems.biblioitemnumber
288 =aqorders.biblioitemnumber
289 and (datecancellationprinted is NULL or datecancellationprinted =
291 if ($supplier ne ''){
292 $query.=" and aqorders.booksellerid='$supplier'";
294 $query.=" group by aqorders.ordernumber";
295 my $sth=$dbh->prepare($query);
300 while (my $data=$sth->fetchrow_hashref){
311 my $query="Select max(basketno) from aqorders";
312 my $sth=$dbh->prepare($query);
314 my $data=$sth->fetchrow_arrayref;
315 my $basket=$$data[0];
324 my $query="Select * from aqbookfund,aqbudget where aqbookfund.bookfundid
326 and aqbudget.startdate='2001=07-01'
327 group by aqbookfund.bookfundid order by bookfundname";
328 my $sth=$dbh->prepare($query);
332 while (my $data=$sth->fetchrow_hashref){
343 my $query="Select * from branches";
344 my $sth=$dbh->prepare($query);
349 while (my $data=$sth->fetchrow_hashref){
359 sub bookfundbreakdown {
362 my $query="Select quantity,datereceived,freight,unitprice,listprice,ecost,quantityreceived,subscription
363 from aqorders,aqorderbreakdown where bookfundid='$id' and
364 aqorders.ordernumber=aqorderbreakdown.ordernumber and ((budgetdate >=
365 '2001-07-01' and budgetdate <'2002-07-01') or
366 (datereceived >= '2001-07-01' and datereceived < '2002-07-01'))
367 and (datecancellationprinted is NULL or
368 datecancellationprinted='0000-00-00')";
369 my $sth=$dbh->prepare($query);
373 while (my $data=$sth->fetchrow_hashref){
374 if ($data->{'subscription'} == 1){
375 $spent+=$data->{'quantity'}*$data->{'unitprice'};
377 my $leftover=$data->{'quantity'}-$data->{'quantityreceived'};
378 $comtd+=($data->{'ecost'})*$leftover;
379 $spent+=($data->{'unitprice'})*$data->{'quantityreceived'};
384 return($spent,$comtd);
390 my $dbh = &C4Connect;
391 my $query = "Select max(biblionumber) from biblio";
392 my $sth = $dbh->prepare($query);
394 my $data = $sth->fetchrow_arrayref;
395 my $bibnum = $$data[0] + 1;
398 if ($biblio->{'seriestitle'}) { $series = 1 } else { $series = 0 };
401 $query = "insert into biblio set
411 $sth = $dbh->prepare($query);
416 $biblio->{'copyright'},
418 $biblio->{'seriestitle'} ,
428 my ($bibnum,$title,$author,$copyright,$seriestitle,$serial,$unititle,$notes)=@_;
430 my $query = "Update biblio set
433 copyrightdate = '$copyright',
434 seriestitle = '$seriestitle',
436 unititle = '$unititle',
438 where biblionumber = $bibnum";
439 my $sth=$dbh->prepare($query);
449 my ($bibnum,$subtitle)=@_;
451 my $query="update bibliosubtitle set subtitle='$subtitle' where biblionumber=$bibnum";
452 my $sth=$dbh->prepare($query);
459 my ($bibnum,$author)=@_;
461 my $query="Delete from additionalauthors where biblionumber=$bibnum";
462 my $sth=$dbh->prepare($query);
468 $query = "Insert into additionalauthors set
470 biblionumber = '$bibnum'";
471 $sth=$dbh->prepare($query);
483 my ($bibnum,$force,@subject)=@_;
487 for (my $i=0;$i<$count;$i++){
488 $subject[$i]=~ s/^ //g;
489 $subject[$i]=~ s/ $//g;
490 my $query = "select * from catalogueentry
491 where entrytype = 's'
492 and catalogueentry = '$subject[$i]'";
493 my $sth=$dbh->prepare($query);
496 if (my $data = $sth->fetchrow_hashref) {
498 if ($force eq $subject[$i]){
500 #subject not in aut, chosen to force anway
501 #so insert into cataloguentry so its in auth file
502 $query = "Insert into catalogueentry
503 (entrytype,catalogueentry)
504 values ('s','$subject[$i]')";
505 my $sth2=$dbh->prepare($query);
512 $error="$subject[$i]\n does not exist in the subject authority file";
513 $query = "Select * from catalogueentry
514 where entrytype = 's'
515 and (catalogueentry like '$subject[$i] %'
516 or catalogueentry like '% $subject[$i] %'
517 or catalogueentry like '% $subject[$i]')";
518 my $sth2=$dbh->prepare($query);
521 while (my $data=$sth2->fetchrow_hashref){
522 $error=$error."<br>$data->{'catalogueentry'}";
531 my $query="Delete from bibliosubject where biblionumber=$bibnum";
532 my $sth=$dbh->prepare($query);
537 for (my $i=0;$i<$count;$i++){
538 $sth = $dbh->prepare("Insert into bibliosubject
539 values ('$subject[$i]', $bibnum)");
551 my ($bibitemnum,$itemtype,$isbn,$publishercode,$publicationdate,$classification,$dewey,$subclass,$illus,$pages,$volumeddesc,$notes,$size,$place)=@_;
553 my $query="update biblioitems set itemtype='$itemtype',
554 isbn='$isbn',publishercode='$publishercode',publicationyear='$publicationdate',
555 classification='$classification',dewey='$dewey',subclass='$subclass',illus='$illus',
556 pages='$pages',volumeddesc='$volumeddesc',notes='$notes',size='$size',place='$place'
558 biblioitemnumber=$bibitemnum";
559 my $sth=$dbh->prepare($query);
567 my ($bibitemnum,$note)=@_;
569 my $query="update biblioitems set notes='$note' where
570 biblioitemnumber='$bibitemnum'";
571 my $sth=$dbh->prepare($query);
578 my ($biblioitem) = @_;
580 my $query = "Select max(biblioitemnumber) from biblioitems";
581 my $sth = $dbh->prepare($query);
585 $biblioitem->{'volume'} = $dbh->quote($biblioitem->{'volume'});
586 $biblioitem->{'number'} = $dbh->quote($biblioitem->{'number'});
587 $biblioitem->{'classification'} = $dbh->quote($biblioitem->{'classification'});
588 $biblioitem->{'itemtype'} = $dbh->quote($biblioitem->{'itemtype'});
589 $biblioitem->{'url'} = $dbh->quote($biblioitem->{'url'});
590 $biblioitem->{'isbn'} = $dbh->quote($biblioitem->{'isbn'});
591 $biblioitem->{'issn'} = $dbh->quote($biblioitem->{'issn'});
592 $biblioitem->{'dewey'} = $dbh->quote($biblioitem->{'dewey'});
593 $biblioitem->{'subclass'} = $dbh->quote($biblioitem->{'subclass'});
594 $biblioitem->{'publicationyear'} = $dbh->quote($biblioitem->{'publicationyear'});
595 $biblioitem->{'publishercode'} = $dbh->quote($biblioitem->{'publishercode'});
596 $biblioitem->{'volumedate'} = $dbh->quote($biblioitem->{'volumedate'});
597 $biblioitem->{'volumeddesc'} = $dbh->quote($biblioitem->{'volumeddesc'}); $biblioitem->{'illus'} = $dbh->quote($biblioitem->{'illus'});
598 $biblioitem->{'pages'} = $dbh->quote($biblioitem->{'pages'});
599 $biblioitem->{'notes'} = $dbh->quote($biblioitem->{'notes'});
600 $biblioitem->{'size'} = $dbh->quote($biblioitem->{'size'});
601 $biblioitem->{'place'} = $dbh->quote($biblioitem->{'place'});
604 $data = $sth->fetchrow_arrayref;
605 $bibitemnum = $$data[0] + 1;
609 $query = "insert into biblioitems set
610 biblioitemnumber = $bibitemnum,
611 biblionumber = $biblioitem->{'biblionumber'},
612 volume = $biblioitem->{'volume'},
613 number = $biblioitem->{'number'},
614 classification = $biblioitem->{'classification'},
615 itemtype = $biblioitem->{'itemtype'},
616 url = $biblioitem->{'url'},
617 isbn = $biblioitem->{'isbn'},
618 issn = $biblioitem->{'issn'},
619 dewey = $biblioitem->{'dewey'},
620 subclass = $biblioitem->{'subclass'},
621 publicationyear = $biblioitem->{'publicationyear'},
622 publishercode = $biblioitem->{'publishercode'},
623 volumedate = $biblioitem->{'volumedate'},
624 volumeddesc = $biblioitem->{'volumeddesc'},
625 illus = $biblioitem->{'illus'},
626 pages = $biblioitem->{'pages'},
627 notes = $biblioitem->{'notes'},
628 size = $biblioitem->{'size'},
629 place = $biblioitem->{'place'}";
631 $sth = $dbh->prepare($query);
642 my $query="insert into bibliosubject (biblionumber) values
644 my $sth=$dbh->prepare($query);
652 my ($bibnum, $subtitle) = @_;
654 $subtitle = $dbh->quote($subtitle);
655 my $query = "insert into bibliosubtitle set
656 biblionumber = $bibnum,
657 subtitle = $subtitle";
658 my $sth = $dbh->prepare($query);
667 my ($bibnum,$title,$ordnum,$basket,$quantity,$listprice,$supplier,$who,$notes,$bookfund,$bibitemnum,$rrp,$ecost,$gst,$budget,$cost,$sub,$invoice)=@_;
668 if ($budget eq 'now'){
671 $budget="'2001-07-01'";
679 my $query="insert into aqorders (biblionumber,title,basketno,
680 quantity,listprice,booksellerid,entrydate,requisitionedby,authorisedby,notes,
681 biblioitemnumber,rrp,ecost,gst,budgetdate,unitprice,subscription,booksellerinvoicenumber)
684 ($bibnum,'$title',$basket,$quantity,$listprice,'$supplier',now(),
685 '$who','$who','$notes',$bibitemnum,'$rrp','$ecost','$gst',$budget,'$cost',
687 my $sth=$dbh->prepare($query);
691 $query="select * from aqorders where
692 biblionumber=$bibnum and basketno=$basket and ordernumber >=$ordnum";
693 $sth=$dbh->prepare($query);
695 my $data=$sth->fetchrow_hashref;
697 $ordnum=$data->{'ordernumber'};
698 $query="insert into aqorderbreakdown (ordernumber,bookfundid) values
699 ($ordnum,'$bookfund')";
700 $sth=$dbh->prepare($query);
708 my ($bibnum,$ordnum)=@_;
710 my $query="update aqorders set datecancellationprinted=now()
711 where biblionumber='$bibnum' and
712 ordernumber='$ordnum'";
713 my $sth=$dbh->prepare($query);
717 my $count=itemcount($bibnum);
725 my ($title,$ordnum,$quantity,$listprice,$bibnum,$basketno,$supplier,$who,$notes,$bookfund,$bibitemnum,$rrp,$ecost,$gst,$budget,$cost,$invoice)=@_;
727 my $query="update aqorders set title='$title',
728 quantity='$quantity',listprice='$listprice',basketno='$basketno',
729 rrp='$rrp',ecost='$ecost',unitprice='$cost',
730 booksellerinvoicenumber='$invoice'
732 ordernumber=$ordnum and biblionumber=$bibnum";
733 my $sth=$dbh->prepare($query);
737 $query="update aqorderbreakdown set bookfundid=$bookfund where
738 ordernumber=$ordnum";
739 $sth=$dbh->prepare($query);
748 my $query="Select max(ordernumber) from aqorders";
749 my $sth=$dbh->prepare($query);
751 my $data=$sth->fetchrow_arrayref;
752 my $ordnum=$$data[0];
760 my ($biblio,$ordnum,$quantrec,$user,$cost,$invoiceno,$bibitemno,$freight,$bookfund,$rrp)=@_;
762 my $query="update aqorders set quantityreceived='$quantrec',
763 datereceived=now(),booksellerinvoicenumber='$invoiceno',
764 biblioitemnumber=$bibitemno,unitprice='$cost',freight='$freight',
766 where biblionumber=$biblio and ordernumber=$ordnum
769 my $sth=$dbh->prepare($query);
772 $query="update aqorderbreakdown set bookfundid=$bookfund where
773 ordernumber=$ordnum";
774 $sth=$dbh->prepare($query);
781 my($biblio,$ordnum,$user,$cost,$bookfund,$rrp)=@_;
783 my $query="update aqorders set
784 unitprice='$cost', rrp='$rrp'
785 where biblionumber=$biblio and ordernumber=$ordnum
788 my $sth=$dbh->prepare($query);
791 $query="update aqorderbreakdown set bookfundid=$bookfund where
792 ordernumber=$ordnum";
793 $sth=$dbh->prepare($query);
801 my ($currency,$price)=@_;
804 my $query="Select rate from currency where currency='$currency'";
805 my $sth=$dbh->prepare($query);
807 my $data=$sth->fetchrow_hashref;
810 my $cur=$data->{'rate'};
814 $convertedprice=$price / $cur;
815 return($convertedprice);
820 my $query="Select * from currency";
821 my $sth=$dbh->prepare($query);
825 while (my $data=$sth->fetchrow_hashref){
831 return($i,\@results);
837 my $query="Select * from currency where currency='$cur'";
838 my $sth=$dbh->prepare($query);
841 my $data=$sth->fetchrow_hashref;
847 sub updatecurrencies {
848 my ($currency,$rate)=@_;
850 my $query="update currency set rate=$rate where currency='$currency'";
851 my $sth=$dbh->prepare($query);
860 my $query="Update aqbooksellers set
861 name='$data->{'name'}',address1='$data->{'address1'}',address2='$data->{'address2'}',
862 address3='$data->{'address3'}',address4='$data->{'address4'}',postal='$data->{'postal'}',
863 phone='$data->{'phone'}',fax='$data->{'fax'}',url='$data->{'url'}',
864 contact='$data->{'contact'}',contpos='$data->{'contpos'}',
865 contphone='$data->{'contphone'}', contfax='$data->{'contfax'}', contaltphone=
866 '$data->{'contaltphone'}', contemail='$data->{'contemail'}', contnotes=
867 '$data->{'contnotes'}', active=$data->{'active'},
868 listprice='$data->{'listprice'}', invoiceprice='$data->{'invoiceprice'}',
869 gstreg=$data->{'gstreg'}, listincgst=$data->{'listincgst'},
870 invoiceincgst=$data->{'invoiceincgst'}, specialty='$data->{'specialty'}',
871 discount='$data->{'discount'}',invoicedisc='$data->{'invoicedisc'}',
872 nocalc='$data->{'nocalc'}'
873 where id='$data->{'id'}'";
874 my $sth=$dbh->prepare($query);
884 my $sth=$dbh->prepare("Select max(id) from aqbooksellers");
886 my $data2=$sth->fetchrow_hashref;
888 $data2->{'max(id)'}++;
889 $sth=$dbh->prepare("Insert into aqbooksellers (id) values ($data2->{'max(id)'})");
892 $data->{'id'}=$data2->{'max(id)'};
895 return($data->{'id'});
900 my ($item, @barcodes) = @_;
902 my $query = "Select max(itemnumber) from items";
903 my $sth = $dbh->prepare($query);
909 $data = $sth->fetchrow_hashref;
910 $itemnumber = $data->{'max(itemnumber)'} + 1;
913 $item->{'booksellerid'} = $dbh->quote($item->{'bookselletid'});
914 $item->{'homebranch'} = $dbh->quote($item->{'homebranch'});
915 $item->{'price'} = $dbh->quote($item->{'price'});
916 $item->{'replacementprice'} = $dbh->quote($item->{'replacementprice'});
917 $item->{'itemnotes'} = $dbh->quote($item->{'itemnotes'});
919 foreach my $barcode (@barcodes) {
920 $barcode = uc($barcode);
921 $query = "Insert into items set
922 itemnumber = $itemnumber,
923 biblionumber = $item->{'biblionumber'},
924 biblioitemnumber = $item->{'biblioitemnumber'},
926 booksellerid = $item->{'booksellerid'},
927 dateaccessioned = NOW(),
928 homebranch = $item->{'homebranch'},
929 holdingbranch = $item->{'homebranch'},
930 price = $item->{'price'},
931 replacementprice = $item->{'replacementprice'},
932 replacementpricedate = NOW(),
933 itemnotes = $item->{'itemnotes'}";
935 if ($item->{'loan'}) {
937 notforloan = $item->{'loan'}";
940 $sth = $dbh->prepare($query);
943 $error.=$sth->errstr;
954 my ($count,@barcodes)=@_;
957 for (my $i=0;$i<$count;$i++){
958 $barcodes[$i]=uc $barcodes[$i];
959 my $query="Select * from items where barcode='$barcodes[$i]'";
960 my $sth=$dbh->prepare($query);
962 if (my $data=$sth->fetchrow_hashref){
963 $error.=" Duplicate Barcode: $barcodes[$i]";
972 my ($loan,$itemnum,$bibitemnum,$barcode,$notes,$homebranch,$lost,$wthdrawn,$replacement)=@_;
974 my $query="update items set biblioitemnumber=$bibitemnum,
975 barcode='$barcode',itemnotes='$notes'
976 where itemnumber=$itemnum";
978 $query="update items set biblioitemnumber=$bibitemnum,notforloan=$loan where itemnumber=$itemnum";
981 $query="update items set biblioitemnumber=$bibitemnum,
982 barcode='$barcode',itemnotes='$notes',homebranch='$homebranch',
983 itemlost='$lost',wthdrawn='$wthdrawn' where itemnumber=$itemnum";
985 if ($replacement ne ''){
986 $query=~ s/ where/,replacementprice='$replacement' where/;
989 my $sth=$dbh->prepare($query);
996 my($price,$rrp,$itemnum)=@_;
998 my $query="update items set price='$price',replacementprice='$rrp'
999 where itemnumber=$itemnum";
1000 my $sth=$dbh->prepare($query);
1006 my ($bibitemnum)=@_;
1008 my $query="Select count(*) from items where biblioitemnumber='$bibitemnum'";
1009 my $sth=$dbh->prepare($query);
1011 my $data=$sth->fetchrow_hashref;
1014 return($data->{'count(*)'});
1018 my ($biblionumber)=@_;
1020 my $query="Select * from biblioitems,items,itemtypes where
1021 biblioitems.biblionumber=$biblionumber
1022 and biblioitems.biblioitemnumber=items.biblioitemnumber and
1023 itemtypes.itemtype=biblioitems.itemtype
1024 order by items.biblioitemnumber";
1025 my $sth=$dbh->prepare($query);
1029 while (my $data=$sth->fetchrow_hashref){
1039 my ($bibitemnum,$itemtype)=@_;
1041 my $query="Select * from biblioitems where biblioitemnumber=$bibitemnum
1042 and itemtype='$itemtype'";
1043 my $sth=$dbh->prepare($query);
1046 if (my $data=$sth->fetchrow_hashref){
1057 my $query="select * from items where itemnumber=$itemnum";
1058 my $sth=$dbh->prepare($query);
1060 my @data=$sth->fetchrow_array;
1062 $query="Insert into deleteditems values (";
1063 foreach my $temp (@data){
1064 $query=$query."'$temp',";
1068 $sth=$dbh->prepare($query);
1071 $query = "Delete from items where itemnumber=$itemnum";
1072 $sth=$dbh->prepare($query);
1081 my $query="select * from biblioitems where biblioitemnumber=$itemnum";
1082 my $sth=$dbh->prepare($query);
1084 if (my @data=$sth->fetchrow_array){
1086 $query="Insert into deletedbiblioitems values (";
1087 foreach my $temp (@data){
1088 $temp=~ s/\'/\\\'/g;
1089 $query=$query."'$temp',";
1093 $sth=$dbh->prepare($query);
1096 $query = "Delete from biblioitems where biblioitemnumber=$itemnum";
1097 $sth=$dbh->prepare($query);
1108 my $query="select * from biblio where biblionumber=$biblio";
1109 my $sth=$dbh->prepare($query);
1111 if (my @data=$sth->fetchrow_array){
1113 $query="Insert into deletedbiblio values (";
1114 foreach my $temp (@data){
1115 $temp=~ s/\'/\\\'/g;
1116 $query=$query."'$temp',";
1120 $sth=$dbh->prepare($query);
1123 $query = "Delete from biblio where biblionumber=$biblio";
1124 $sth=$dbh->prepare($query);
1134 my $dbh = C4Connect;
1135 my $query = "select * from itemtypes";
1136 my $sth = $dbh->prepare($query);
1137 # || die "Cannot prepare $query" . $dbh->errstr;
1142 # || die "Cannot execute $query\n" . $sth->errstr;
1143 while (my $data = $sth->fetchrow_hashref) {
1144 $results[$count] = $data;
1150 return($count, @results);
1151 } # sub getitemtypes
1155 my ($biblionumber) = @_;
1156 my $dbh = C4Connect;
1157 my $query = "Select * from biblio where biblionumber = $biblionumber";
1158 my $sth = $dbh->prepare($query);
1159 # || die "Cannot prepare $query\n" . $dbh->errstr;
1164 # || die "Cannot execute $query\n" . $sth->errstr;
1165 while (my $data = $sth->fetchrow_hashref) {
1166 $results[$count] = $data;
1172 return($count, @results);
1177 my ($biblioitemnum) = @_;
1178 my $dbh = C4Connect;
1179 my $query = "Select * from biblioitems where
1180 biblioitemnumber = $biblioitemnum";
1181 my $sth = $dbh->prepare($query);
1187 while (my $data = $sth->fetchrow_hashref) {
1188 $results[$count] = $data;
1194 return($count, @results);
1195 } # sub getbiblioitem
1198 sub getitemsbybiblioitem {
1199 my ($biblioitemnum) = @_;
1200 my $dbh = C4Connect;
1201 my $query = "Select * from items, biblio where
1202 biblio.biblionumber = items.biblionumber and biblioitemnumber
1204 my $sth = $dbh->prepare($query);
1205 # || die "Cannot prepare $query\n" . $dbh->errstr;
1210 # || die "Cannot execute $query\n" . $sth->errstr;
1211 while (my $data = $sth->fetchrow_hashref) {
1212 $results[$count] = $data;
1218 return($count, @results);
1219 } # sub getitemsbybiblioitem
1224 my $dbh = C4Connect;
1230 $isbn = $dbh->quote($isbn);
1231 $query = "Select * from biblioitems where isbn = $isbn";
1232 $sth = $dbh->prepare($query);
1235 while (my $data = $sth->fetchrow_hashref) {
1236 $results[$count] = $data;
1242 return($count, @results);
1247 my ($keywordlist) = @_;
1248 my $dbh = C4Connect;
1249 my $query = "Select * from biblio where";
1253 my @keywords = split(/ +/, $keywordlist);
1254 my $keyword = shift(@keywords);
1256 $keyword =~ s/%/\\%/g;
1257 $keyword =~ s/_/\\_/;
1258 $keyword = "%" . $keyword . "%";
1259 $keyword = $dbh->quote($keyword);
1260 $query .= " (author like $keyword) or
1261 (title like $keyword) or (unititle like $keyword) or
1262 (notes like $keyword) or (seriestitle like $keyword) or
1263 (abstract like $keyword)";
1265 foreach $keyword (@keywords) {
1266 $keyword =~ s/%/\\%/;
1267 $keyword =~ s/_/\\_/;
1268 $keyword = "%" . $keyword . "%";
1269 $keyword = $dbh->quote($keyword);
1270 $query .= " or (author like $keyword) or
1271 (title like $keyword) or (unititle like $keyword) or
1272 (notes like $keyword) or (seriestitle like $keyword) or
1273 (abstract like $keyword)";
1276 $sth = $dbh->prepare($query);
1279 while (my $data = $sth->fetchrow_hashref) {
1280 $results[$count] = $data;
1286 return($count, @results);
1287 } # sub keywordsearch
1291 my ($keywordlist) = @_;
1292 my $dbh = C4Connect;
1293 my $query = "Select distinct biblio.* from biblio, biblioitems where
1294 biblio.biblionumber = biblioitems.biblionumber and (";
1298 my @keywords = split(/ +/, $keywordlist);
1299 my $keyword = shift(@keywords);
1301 $keyword =~ s/%/\\%/g;
1302 $keyword =~ s/_/\\_/;
1303 $keyword = "%" . $keyword . "%";
1304 $keyword = $dbh->quote($keyword);
1305 $query .= " (url like $keyword)";
1307 foreach $keyword (@keywords) {
1308 $keyword =~ s/%/\\%/;
1309 $keyword =~ s/_/\\_/;
1310 $keyword = "%" . $keyword . "%";
1311 $keyword = $dbh->quote($keyword);
1312 $query .= " or (url like $keyword)";
1316 $sth = $dbh->prepare($query);
1319 while (my $data = $sth->fetchrow_hashref) {
1320 $results[$count] = $data;
1326 return($count, @results);
1327 } # sub websitesearch
1330 END { } # module clean-up code here (global destructor)