1 package C4::Acquisitions; #assumes C4/Acquisitions.pm
7 use vars qw($VERSION @ISA @EXPORT);
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);
348 while (my $data=$sth->fetchrow_hashref){
357 sub bookfundbreakdown {
360 my $query="Select quantity,datereceived,freight,unitprice,listprice,ecost,quantityreceived,subscription
361 from aqorders,aqorderbreakdown where bookfundid='$id' and
362 aqorders.ordernumber=aqorderbreakdown.ordernumber and ((budgetdate >=
363 '2001-07-01' and budgetdate <'2002-07-01') or
364 (datereceived >= '2001-07-01' and datereceived < '2002-07-01'))
365 and (datecancellationprinted is NULL or
366 datecancellationprinted='0000-00-00')";
367 my $sth=$dbh->prepare($query);
371 while (my $data=$sth->fetchrow_hashref){
372 if ($data->{'subscription'} == 1){
373 $spent+=$data->{'quantity'}*$data->{'unitprice'};
375 my $leftover=$data->{'quantity'}-$data->{'quantityreceived'};
376 $comtd+=($data->{'ecost'})*$leftover;
377 $spent+=($data->{'unitprice'})*$data->{'quantityreceived'};
382 return($spent,$comtd);
388 my $dbh = &C4Connect;
389 my $query = "Select max(biblionumber) from biblio";
390 my $sth = $dbh->prepare($query);
392 my $data = $sth->fetchrow_arrayref;
393 my $bibnum = $$data[0] + 1;
396 if ($biblio->{'seriestitle'}) { $series = 1 } else { $series = 0 };
399 $query = "insert into biblio set
409 $sth = $dbh->prepare($query);
414 $biblio->{'copyright'},
416 $biblio->{'seriestitle'} ,
426 my ($bibnum,$title,$author,$copyright,$seriestitle,$serial,$unititle,$notes)=@_;
428 my $query = "Update biblio set
431 copyrightdate = '$copyright',
432 seriestitle = '$seriestitle',
434 unititle = '$unititle',
436 where biblionumber = $bibnum";
437 my $sth=$dbh->prepare($query);
447 my ($bibnum,$subtitle)=@_;
449 my $query="update bibliosubtitle set subtitle='$subtitle' where biblionumber=$bibnum";
450 my $sth=$dbh->prepare($query);
457 my ($bibnum,$author)=@_;
459 my $query="Delete from additionalauthors where biblionumber=$bibnum";
460 my $sth=$dbh->prepare($query);
466 $query = "Insert into additionalauthors set
468 biblionumber = '$bibnum'";
469 $sth=$dbh->prepare($query);
481 my ($bibnum,$force,@subject)=@_;
485 for (my $i=0;$i<$count;$i++){
486 $subject[$i]=~ s/^ //g;
487 $subject[$i]=~ s/ $//g;
488 my $query="select * from catalogueentry where entrytype='s' and
489 catalogueentry='$subject[$i]'";
490 my $sth=$dbh->prepare($query);
492 if (my $data=$sth->fetchrow_hashref){
495 if ($force eq $subject[$i]){
496 #subject not in aut, chosen to force anway
497 #so insert into cataloguentry so its in auth file
498 $query="Insert into catalogueentry (entrytype,catalogueentry)
499 values ('s','$subject[$i]')";
500 my $sth2=$dbh->prepare($query);
505 $error="$subject[$i]\n does not exist in the subject authority file";
506 $query= "Select * from catalogueentry where
507 entrytype='s' and (catalogueentry like '$subject[$i] %' or
508 catalogueentry like '% $subject[$i] %' or catalogueentry like
510 my $sth2=$dbh->prepare($query);
513 while (my $data=$sth2->fetchrow_hashref){
514 $error=$error."<br>$data->{'catalogueentry'}";
517 # $error=$error."<br>$query";
523 my $query="Delete from bibliosubject where biblionumber=$bibnum";
525 my $sth=$dbh->prepare($query);
529 for (my $i=0;$i<$count;$i++){
530 $sth=$dbh->prepare("Insert into bibliosubject values ('$subject[$i]',$bibnum)");
531 # print $subject[$i];
541 my ($bibitemnum,$itemtype,$isbn,$publishercode,$publicationdate,$classification,$dewey,$subclass,$illus,$pages,$volumeddesc,$notes,$size,$place)=@_;
543 my $query="update biblioitems set itemtype='$itemtype',
544 isbn='$isbn',publishercode='$publishercode',publicationyear='$publicationdate',
545 classification='$classification',dewey='$dewey',subclass='$subclass',illus='$illus',
546 pages='$pages',volumeddesc='$volumeddesc',notes='$notes',size='$size',place='$place'
548 biblioitemnumber=$bibitemnum";
549 my $sth=$dbh->prepare($query);
557 my ($bibitemnum,$note)=@_;
559 my $query="update biblioitems set notes='$note' where
560 biblioitemnumber='$bibitemnum'";
561 my $sth=$dbh->prepare($query);
568 my ($biblioitem) = @_;
570 my $query = "Select max(biblioitemnumber) from biblioitems";
571 my $sth = $dbh->prepare($query);
575 $biblioitem->{'volume'} = $dbh->quote($biblioitem->{'volume'});
576 $biblioitem->{'number'} = $dbh->quote($biblioitem->{'number'});
577 $biblioitem->{'classification'} = $dbh->quote($biblioitem->{'classification'});
578 $biblioitem->{'itemtype'} = $dbh->quote($biblioitem->{'itemtype'});
579 $biblioitem->{'url'} = $dbh->quote($biblioitem->{'url'});
580 $biblioitem->{'isbn'} = $dbh->quote($biblioitem->{'isbn'});
581 $biblioitem->{'issn'} = $dbh->quote($biblioitem->{'issn'});
582 $biblioitem->{'dewey'} = $dbh->quote($biblioitem->{'dewey'});
583 $biblioitem->{'subclass'} = $dbh->quote($biblioitem->{'subclass'});
584 $biblioitem->{'publicationyear'} = $dbh->quote($biblioitem->{'publicationyear'});
585 $biblioitem->{'publishercode'} = $dbh->quote($biblioitem->{'publishercode'});
586 $biblioitem->{'volumedate'} = $dbh->quote($biblioitem->{'volumedate'});
587 $biblioitem->{'volumeddesc'} = $dbh->quote($biblioitem->{'volumeddesc'}); $biblioitem->{'illus'} = $dbh->quote($biblioitem->{'illus'});
588 $biblioitem->{'pages'} = $dbh->quote($biblioitem->{'pages'});
589 $biblioitem->{'notes'} = $dbh->quote($biblioitem->{'notes'});
590 $biblioitem->{'size'} = $dbh->quote($biblioitem->{'size'});
591 $biblioitem->{'place'} = $dbh->quote($biblioitem->{'place'});
594 $data = $sth->fetchrow_arrayref;
595 $bibitemnum = $$data[0] + 1;
599 $query = "insert into biblioitems set
600 biblioitemnumber = $bibitemnum,
601 biblionumber = $biblioitem->{'biblionumber'},
602 volume = $biblioitem->{'volume'},
603 number = $biblioitem->{'number'},
604 classification = $biblioitem->{'classification'},
605 itemtype = $biblioitem->{'itemtype'},
606 url = $biblioitem->{'url'},
607 isbn = $biblioitem->{'isbn'},
608 issn = $biblioitem->{'issn'},
609 dewey = $biblioitem->{'dewey'},
610 subclass = $biblioitem->{'subclass'},
611 publicationyear = $biblioitem->{'publicationyear'},
612 publishercode = $biblioitem->{'publishercode'},
613 volumedate = $biblioitem->{'volumedate'},
614 volumeddesc = $biblioitem->{'volumeddesc'},
615 illus = $biblioitem->{'illus'},
616 pages = $biblioitem->{'pages'},
617 notes = $biblioitem->{'notes'},
618 size = $biblioitem->{'size'},
619 place = $biblioitem->{'place'}";
621 $sth = $dbh->prepare($query);
632 my $query="insert into bibliosubject (biblionumber) values
634 my $sth=$dbh->prepare($query);
642 my ($bibnum, $subtitle) = @_;
644 $subtitle = $dbh->quote($subtitle);
645 my $query = "insert into bibliosubtitle set
646 biblionumber = $bibnum,
647 subtitle = $subtitle";
648 my $sth = $dbh->prepare($query);
657 my ($bibnum,$title,$ordnum,$basket,$quantity,$listprice,$supplier,$who,$notes,$bookfund,$bibitemnum,$rrp,$ecost,$gst,$budget,$cost,$sub,$invoice)=@_;
658 if ($budget eq 'now'){
661 $budget="'2001-07-01'";
669 my $query="insert into aqorders (biblionumber,title,basketno,
670 quantity,listprice,booksellerid,entrydate,requisitionedby,authorisedby,notes,
671 biblioitemnumber,rrp,ecost,gst,budgetdate,unitprice,subscription,booksellerinvoicenumber)
674 ($bibnum,'$title',$basket,$quantity,$listprice,'$supplier',now(),
675 '$who','$who','$notes',$bibitemnum,'$rrp','$ecost','$gst',$budget,'$cost',
677 my $sth=$dbh->prepare($query);
681 $query="select * from aqorders where
682 biblionumber=$bibnum and basketno=$basket and ordernumber >=$ordnum";
683 $sth=$dbh->prepare($query);
685 my $data=$sth->fetchrow_hashref;
687 $ordnum=$data->{'ordernumber'};
688 $query="insert into aqorderbreakdown (ordernumber,bookfundid) values
689 ($ordnum,'$bookfund')";
690 $sth=$dbh->prepare($query);
698 my ($bibnum,$ordnum)=@_;
700 my $query="update aqorders set datecancellationprinted=now()
701 where biblionumber='$bibnum' and
702 ordernumber='$ordnum'";
703 my $sth=$dbh->prepare($query);
707 my $count=itemcount($bibnum);
715 my ($title,$ordnum,$quantity,$listprice,$bibnum,$basketno,$supplier,$who,$notes,$bookfund,$bibitemnum,$rrp,$ecost,$gst,$budget,$cost,$invoice)=@_;
717 my $query="update aqorders set title='$title',
718 quantity='$quantity',listprice='$listprice',basketno='$basketno',
719 rrp='$rrp',ecost='$ecost',unitprice='$cost',
720 booksellerinvoicenumber='$invoice'
722 ordernumber=$ordnum and biblionumber=$bibnum";
723 my $sth=$dbh->prepare($query);
727 $query="update aqorderbreakdown set bookfundid=$bookfund where
728 ordernumber=$ordnum";
729 $sth=$dbh->prepare($query);
738 my $query="Select max(ordernumber) from aqorders";
739 my $sth=$dbh->prepare($query);
741 my $data=$sth->fetchrow_arrayref;
742 my $ordnum=$$data[0];
750 my ($biblio,$ordnum,$quantrec,$user,$cost,$invoiceno,$bibitemno,$freight,$bookfund,$rrp)=@_;
752 my $query="update aqorders set quantityreceived='$quantrec',
753 datereceived=now(),booksellerinvoicenumber='$invoiceno',
754 biblioitemnumber=$bibitemno,unitprice='$cost',freight='$freight',
756 where biblionumber=$biblio and ordernumber=$ordnum
759 my $sth=$dbh->prepare($query);
762 $query="update aqorderbreakdown set bookfundid=$bookfund where
763 ordernumber=$ordnum";
764 $sth=$dbh->prepare($query);
771 my($biblio,$ordnum,$user,$cost,$bookfund,$rrp)=@_;
773 my $query="update aqorders set
774 unitprice='$cost', rrp='$rrp'
775 where biblionumber=$biblio and ordernumber=$ordnum
778 my $sth=$dbh->prepare($query);
781 $query="update aqorderbreakdown set bookfundid=$bookfund where
782 ordernumber=$ordnum";
783 $sth=$dbh->prepare($query);
791 my ($currency,$price)=@_;
793 my $query="Select rate from currency where currency='$currency'";
794 my $sth=$dbh->prepare($query);
796 my $data=$sth->fetchrow_hashref;
799 my $cur=$data->{'rate'};
803 my $price=$price / $cur;
809 my $query="Select * from currency";
810 my $sth=$dbh->prepare($query);
814 while (my $data=$sth->fetchrow_hashref){
820 return($i,\@results);
826 my $query="Select * from currency where currency='$cur'";
827 my $sth=$dbh->prepare($query);
830 my $data=$sth->fetchrow_hashref;
836 sub updatecurrencies {
837 my ($currency,$rate)=@_;
839 my $query="update currency set rate=$rate where currency='$currency'";
840 my $sth=$dbh->prepare($query);
849 my $query="Update aqbooksellers set
850 name='$data->{'name'}',address1='$data->{'address1'}',address2='$data->{'address2'}',
851 address3='$data->{'address3'}',address4='$data->{'address4'}',postal='$data->{'postal'}',
852 phone='$data->{'phone'}',fax='$data->{'fax'}',url='$data->{'url'}',
853 contact='$data->{'contact'}',contpos='$data->{'contpos'}',
854 contphone='$data->{'contphone'}', contfax='$data->{'contfax'}', contaltphone=
855 '$data->{'contaltphone'}', contemail='$data->{'contemail'}', contnotes=
856 '$data->{'contnotes'}', active=$data->{'active'},
857 listprice='$data->{'listprice'}', invoiceprice='$data->{'invoiceprice'}',
858 gstreg=$data->{'gstreg'}, listincgst=$data->{'listincgst'},
859 invoiceincgst=$data->{'invoiceincgst'}, specialty='$data->{'specialty'}',
860 discount='$data->{'discount'}',invoicedisc='$data->{'invoicedisc'}',
861 nocalc='$data->{'nocalc'}'
862 where id='$data->{'id'}'";
863 my $sth=$dbh->prepare($query);
873 my $sth=$dbh->prepare("Select max(id) from aqbooksellers");
875 my $data2=$sth->fetchrow_hashref;
877 $data2->{'max(id)'}++;
878 $sth=$dbh->prepare("Insert into aqbooksellers (id) values ($data2->{'max(id)'})");
881 $data->{'id'}=$data2->{'max(id)'};
884 return($data->{'id'});
889 my ($item, @barcodes) = @_;
891 my $query = "Select max(itemnumber) from items";
892 my $sth = $dbh->prepare($query);
898 $data = $sth->fetchrow_hashref;
899 $itemnumber = $data->{'max(itemnumber)'} + 1;
902 $item->{'booksellerid'} = $dbh->quote($item->{'bookselletid'});
903 $item->{'homebranch'} = $dbh->quote($item->{'homebranch'});
904 $item->{'price'} = $dbh->quote($item->{'price'});
905 $item->{'replacementprice'} = $dbh->quote($item->{'replacementprice'});
906 $item->{'itemnotes'} = $dbh->quote($item->{'itemnotes'});
908 foreach my $barcode (@barcodes) {
909 $barcode = uc($barcode);
910 $query = "Insert into items set
911 itemnumber = $itemnumber,
912 biblionumber = $item->{'biblionumber'},
913 biblioitemnumber = $item->{'biblioitemnumber'},
915 booksellerid = $item->{'booksellerid'},
916 dateaccessioned = NOW(),
917 homebranch = $item->{'branch'},
918 holdingbranch = $item->{'branch'},
919 price = $item->{'price'},
920 replacementprice = $item->{'replacementprice'},
921 replacementpricedate = NOW(),
922 notforloan = $item->{'loan'},
923 itemnotes = $item->{'itemnotes'}";
925 $sth = $dbh->prepare($query);
928 $error.=$sth->errstr;
939 my ($count,@barcodes)=@_;
942 for (my $i=0;$i<$count;$i++){
943 $barcodes[$i]=uc $barcodes[$i];
944 my $query="Select * from items where barcode='$barcodes[$i]'";
945 my $sth=$dbh->prepare($query);
947 if (my $data=$sth->fetchrow_hashref){
948 $error.=" Duplicate Barcode: $barcodes[$i]";
957 my ($loan,$itemnum,$bibitemnum,$barcode,$notes,$homebranch,$lost,$wthdrawn,$replacement)=@_;
959 my $query="update items set biblioitemnumber=$bibitemnum,
960 barcode='$barcode',itemnotes='$notes'
961 where itemnumber=$itemnum";
963 $query="update items set biblioitemnumber=$bibitemnum,notforloan=$loan where itemnumber=$itemnum";
966 $query="update items set biblioitemnumber=$bibitemnum,
967 barcode='$barcode',itemnotes='$notes',homebranch='$homebranch',
968 itemlost='$lost',wthdrawn='$wthdrawn' where itemnumber=$itemnum";
970 if ($replacement ne ''){
971 $query=~ s/ where/,replacementprice='$replacement' where/;
974 my $sth=$dbh->prepare($query);
981 my($price,$rrp,$itemnum)=@_;
983 my $query="update items set price='$price',replacementprice='$rrp'
984 where itemnumber=$itemnum";
985 my $sth=$dbh->prepare($query);
993 my $query="Select count(*) from items where biblioitemnumber='$bibitemnum'";
994 my $sth=$dbh->prepare($query);
996 my $data=$sth->fetchrow_hashref;
999 return($data->{'count(*)'});
1003 my ($biblionumber)=@_;
1005 my $query="Select * from biblioitems,items,itemtypes where
1006 biblioitems.biblionumber=$biblionumber
1007 and biblioitems.biblioitemnumber=items.biblioitemnumber and
1008 itemtypes.itemtype=biblioitems.itemtype
1009 order by items.biblioitemnumber";
1010 my $sth=$dbh->prepare($query);
1014 while (my $data=$sth->fetchrow_hashref){
1024 my ($bibitemnum,$itemtype)=@_;
1026 my $query="Select * from biblioitems where biblioitemnumber=$bibitemnum
1027 and itemtype='$itemtype'";
1028 my $sth=$dbh->prepare($query);
1031 if (my $data=$sth->fetchrow_hashref){
1042 my $query="select * from items where itemnumber=$itemnum";
1043 my $sth=$dbh->prepare($query);
1045 my @data=$sth->fetchrow_array;
1047 $query="Insert into deleteditems values (";
1048 foreach my $temp (@data){
1049 $query=$query."'$temp',";
1053 $sth=$dbh->prepare($query);
1056 $query = "Delete from items where itemnumber=$itemnum";
1057 $sth=$dbh->prepare($query);
1066 my $query="select * from biblioitems where biblioitemnumber=$itemnum";
1067 my $sth=$dbh->prepare($query);
1069 if (my @data=$sth->fetchrow_array){
1071 $query="Insert into deletedbiblioitems values (";
1072 foreach my $temp (@data){
1073 $temp=~ s/\'/\\\'/g;
1074 $query=$query."'$temp',";
1078 $sth=$dbh->prepare($query);
1081 $query = "Delete from biblioitems where biblioitemnumber=$itemnum";
1082 $sth=$dbh->prepare($query);
1093 my $query="select * from biblio where biblionumber=$biblio";
1094 my $sth=$dbh->prepare($query);
1096 if (my @data=$sth->fetchrow_array){
1098 $query="Insert into deletedbiblio values (";
1099 foreach my $temp (@data){
1100 $temp=~ s/\'/\\\'/g;
1101 $query=$query."'$temp',";
1105 $sth=$dbh->prepare($query);
1108 $query = "Delete from biblio where biblionumber=$biblio";
1109 $sth=$dbh->prepare($query);
1119 my $dbh = C4Connect;
1120 my $query = "select * from itemtypes";
1121 my $sth = $dbh->prepare($query);
1122 # || die "Cannot prepare $query" . $dbh->errstr;
1127 # || die "Cannot execute $query\n" . $sth->errstr;
1128 while (my $data = $sth->fetchrow_hashref) {
1129 @results[$count] = $data;
1135 return($count, @results);
1136 } # sub getitemtypes
1140 my ($biblionumber) = @_;
1141 my $dbh = C4Connect;
1142 my $query = "Select * from biblio where biblionumber = $biblionumber";
1143 my $sth = $dbh->prepare($query);
1144 # || die "Cannot prepare $query\n" . $dbh->errstr;
1149 # || die "Cannot execute $query\n" . $sth->errstr;
1150 while (my $data = $sth->fetchrow_hashref) {
1151 $results[$count] = $data;
1157 return($count, @results);
1162 my ($biblioitemnum) = @_;
1163 my $dbh = C4Connect;
1164 my $query = "Select * from biblioitems where
1165 biblioitemnumber = $biblioitemnum";
1166 my $sth = $dbh->prepare($query);
1172 while (my $data = $sth->fetchrow_hashref) {
1173 $results[$count] = $data;
1179 return($count, @results);
1180 } # sub getbiblioitem
1183 sub getitemsbybiblioitem {
1184 my ($biblioitemnum) = @_;
1185 my $dbh = C4Connect;
1186 my $query = "Select * from items, biblio where
1187 biblio.biblionumber = items.biblionumber and biblioitemnumber
1189 my $sth = $dbh->prepare($query);
1190 # || die "Cannot prepare $query\n" . $dbh->errstr;
1195 # || die "Cannot execute $query\n" . $sth->errstr;
1196 while (my $data = $sth->fetchrow_hashref) {
1197 $results[$count] = $data;
1203 return($count, @results);
1204 } # sub getitemsbybiblioitem
1209 my $dbh = C4Connect;
1215 $isbn = $dbh->quote($isbn);
1216 $query = "Select * from biblioitems where isbn = $isbn";
1217 $sth = $dbh->prepare($query);
1220 while (my $data = $sth->fetchrow_hashref) {
1221 $results[$count] = $data;
1227 return($count, @results);
1232 my ($keywordlist) = @_;
1233 my $dbh = C4Connect;
1234 my $query = "Select * from biblio where";
1238 my @keywords = split(/ +/, $keywordlist);
1239 my $keyword = shift(@keywords);
1241 $keyword =~ s/%/\\%/g;
1242 $keyword =~ s/_/\\_/;
1243 $keyword = "%" . $keyword . "%";
1244 $keyword = $dbh->quote($keyword);
1245 $query .= " (author like $keyword) or
1246 (title like $keyword) or (unititle like $keyword) or
1247 (notes like $keyword) or (seriestitle like $keyword) or
1248 (abstract like $keyword)";
1250 foreach $keyword (@keywords) {
1251 $keyword =~ s/%/\\%/;
1252 $keyword =~ s/_/\\_/;
1253 $keyword = "%" . $keyword . "%";
1254 $keyword = $dbh->quote($keyword);
1255 $query .= " or (author like $keyword) or
1256 (title like $keyword) or (unititle like $keyword) or
1257 (notes like $keyword) or (seriestitle like $keyword) or
1258 (abstract like $keyword)";
1261 $sth = $dbh->prepare($query);
1264 while (my $data = $sth->fetchrow_hashref) {
1265 $results[$count] = $data;
1271 return($count, @results);
1272 } # sub keywordsearch
1276 my ($keywordlist) = @_;
1277 my $dbh = C4Connect;
1278 my $query = "Select distinct biblio.* from biblio, biblioitems where
1279 biblio.biblionumber = biblioitems.biblionumber and (";
1283 my @keywords = split(/ +/, $keywordlist);
1284 my $keyword = shift(@keywords);
1286 $keyword =~ s/%/\\%/g;
1287 $keyword =~ s/_/\\_/;
1288 $keyword = "%" . $keyword . "%";
1289 $keyword = $dbh->quote($keyword);
1290 $query .= " (url like $keyword)";
1292 foreach $keyword (@keywords) {
1293 $keyword =~ s/%/\\%/;
1294 $keyword =~ s/_/\\_/;
1295 $keyword = "%" . $keyword . "%";
1296 $keyword = $dbh->quote($keyword);
1297 $query .= " or (url like $keyword)";
1301 $sth = $dbh->prepare($query);
1304 while (my $data = $sth->fetchrow_hashref) {
1305 $results[$count] = $data;
1311 return($count, @results);
1312 } # sub websitesearch
1315 END { } # module clean-up code here (global destructor)