3 # Continue working on updateItem!!!!!!
5 # updateItem is looking not bad. Need to add addSubfield and deleteSubfield
8 # Trying to track down $dbh's that aren't disconnected....
11 # Copyright 2000-2002 Katipo Communications
13 # This file is part of Koha.
15 # Koha is free software; you can redistribute it and/or modify it under the
16 # terms of the GNU General Public License as published by the Free Software
17 # Foundation; either version 2 of the License, or (at your option) any later
20 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
21 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
22 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
24 # You should have received a copy of the GNU General Public License along with
25 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
26 # Suite 330, Boston, MA 02111-1307 USA
34 use vars qw($VERSION @ISA @EXPORT);
36 # set the version for version checking
41 C4::Catalogue - Koha functions for dealing with orders and acquisitions
49 The functions in this module deal with acquisitions, managing book
50 orders, converting money to different currencies, and so forth.
62 &getorders &getallorders &getrecorders
63 &getorder &neworder &delorder
65 &modorder &getsingleorder &invoice &receiveorder
66 &updaterecorder &newordernum
68 &bookfunds &bookfundbreakdown &updatecost
69 &curconvert &getcurrencies &updatecurrencies &getcurrency
71 &findall &needsmod &branches &updatesup &insertsup
72 &bookseller &breakdown &checkitems
73 &websitesearch &addwebsite &updatewebsite &deletewebsite
85 ($count, @orders) = &basket($basketnumber, $booksellerID);
87 Looks up the pending (non-cancelled) orders with the given basket
88 number. If C<$booksellerID> is non-empty, only orders from that seller
91 C<&basket> returns a two-element array. C<@orders> is an array of
92 references-to-hash, whose keys are the fields from the aqorders,
93 biblio, and biblioitems tables in the Koha database. C<$count> is the
94 number of elements in C<@orders>.
99 my ($basketno,$supplier)=@_;
100 my $dbh = C4::Context->dbh;
101 my $query="Select *,biblio.title from aqorders,biblio,biblioitems
102 where basketno='$basketno'
103 and biblio.biblionumber=aqorders.biblionumber and biblioitems.biblioitemnumber
104 =aqorders.biblioitemnumber
105 and (datecancellationprinted is NULL or datecancellationprinted =
107 if ($supplier ne ''){
108 $query.=" and aqorders.booksellerid='$supplier'";
110 $query.=" group by aqorders.ordernumber";
111 my $sth=$dbh->prepare($query);
116 while (my $data=$sth->fetchrow_hashref){
126 $basket = &newbasket();
128 Finds the next unused basket number in the aqorders table of the Koha
129 database, and returns it.
133 # FIXME - There's a race condition here:
135 # B calls &newbasket (gets the same number as A)
136 # A updates the basket
137 # B updates the basket, and clobbers A's result.
138 # A better approach might be to create a dummy order (with, say,
139 # requisitionedby == "Dummy-$$" or notes == "dummy <time> <pid>"), and
140 # see which basket number it gets. Then have a cron job periodically
141 # remove out-of-date dummy orders.
143 my $dbh = C4::Context->dbh;
144 my $query="Select max(basketno) from aqorders";
145 my $sth=$dbh->prepare($query);
147 my $data=$sth->fetchrow_arrayref;
148 my $basket=$$data[0];
156 &neworder($biblionumber, $title, $ordnum, $basket, $quantity, $listprice,
157 $booksellerid, $who, $notes, $bookfund, $biblioitemnumber, $rrp,
158 $ecost, $gst, $budget, $unitprice, $subscription,
159 $booksellerinvoicenumber);
161 Adds a new order to the database. Any argument that isn't described
162 below is the new value of the field with the same name in the aqorders
163 table of the Koha database.
165 C<$ordnum> is a "minimum order number." After adding the new entry to
166 the aqorders table, C<&neworder> finds the first entry in aqorders
167 with order number greater than or equal to C<$ordnum>, and adds an
168 entry to the aqorderbreakdown table, with the order number just found,
169 and the book fund ID of the newly-added order.
171 C<$budget> is effectively ignored.
173 C<$subscription> may be either "yes", or anything else for "no".
178 my ($bibnum,$title,$ordnum,$basket,$quantity,$listprice,$supplier,$who,$notes,$bookfund,$bibitemnum,$rrp,$ecost,$gst,$budget,$cost,$sub,$invoice)=@_;
179 if ($budget eq 'now'){
182 $budget="'2001-07-01'";
189 my $dbh = C4::Context->dbh;
190 my $query="insert into aqorders (biblionumber,title,basketno,
191 quantity,listprice,booksellerid,entrydate,requisitionedby,authorisedby,notes,
192 biblioitemnumber,rrp,ecost,gst,unitprice,subscription,booksellerinvoicenumber)
195 ($bibnum,'$title',$basket,$quantity,$listprice,'$supplier',now(),
196 '$who','$who','$notes',$bibitemnum,'$rrp','$ecost','$gst','$cost',
198 my $sth=$dbh->prepare($query);
202 $query="select * from aqorders where
203 biblionumber=$bibnum and basketno=$basket and ordernumber >=$ordnum";
204 $sth=$dbh->prepare($query);
206 my $data=$sth->fetchrow_hashref;
208 $ordnum=$data->{'ordernumber'};
209 $query="insert into aqorderbreakdown (ordernumber,bookfundid) values
210 ($ordnum,'$bookfund')";
211 $sth=$dbh->prepare($query);
219 &delorder($biblionumber, $ordernumber);
221 Cancel the order with the given order and biblio numbers. It does not
222 delete any entries in the aqorders table, it merely marks them as
225 If there are no items remaining with the given biblionumber,
226 C<&delorder> also deletes them from the marc_subfield_table and
227 marc_biblio tables of the Koha database.
232 my ($bibnum,$ordnum)=@_;
233 my $dbh = C4::Context->dbh;
234 my $query="update aqorders set datecancellationprinted=now()
235 where biblionumber='$bibnum' and
236 ordernumber='$ordnum'";
237 my $sth=$dbh->prepare($query);
241 my $count=itemcount($bibnum);
249 &modorder($title, $ordernumber, $quantity, $listprice,
250 $biblionumber, $basketno, $supplier, $who, $notes,
251 $bookfundid, $bibitemnum, $rrp, $ecost, $gst, $budget,
252 $unitprice, $booksellerinvoicenumber);
254 Modifies an existing order. Updates the order with order number
255 C<$ordernumber> and biblionumber C<$biblionumber>. All other arguments
256 update the fields with the same name in the aqorders table of the Koha
259 Entries with order number C<$ordernumber> in the aqorderbreakdown
260 table are also updated to the new book fund ID.
265 my ($title,$ordnum,$quantity,$listprice,$bibnum,$basketno,$supplier,$who,$notes,$bookfund,$bibitemnum,$rrp,$ecost,$gst,$budget,$cost,$invoice)=@_;
266 my $dbh = C4::Context->dbh;
267 my $query="update aqorders set title='$title',
268 quantity='$quantity',listprice='$listprice',basketno='$basketno',
269 rrp='$rrp',ecost='$ecost',unitprice='$cost',
270 booksellerinvoicenumber='$invoice'
272 ordernumber=$ordnum and biblionumber=$bibnum";
273 my $sth=$dbh->prepare($query);
276 $query="update aqorderbreakdown set bookfundid=? where
278 $sth=$dbh->prepare($query);
279 $sth->execute($bookfund,$ordnum);
285 $order = &newordernum();
287 Finds the next unused order number in the aqorders table of the Koha
288 database, and returns it.
292 # FIXME - Race condition
294 my $dbh = C4::Context->dbh;
295 my $query="Select max(ordernumber) from aqorders";
296 my $sth=$dbh->prepare($query);
298 my $data=$sth->fetchrow_arrayref;
299 my $ordnum=$$data[0];
307 &receiveorder($biblionumber, $ordernumber, $quantityreceived, $user,
308 $unitprice, $booksellerinvoicenumber, $biblioitemnumber,
309 $freight, $bookfund, $rrp);
311 Updates an order, to reflect the fact that it was received, at least
312 in part. All arguments not mentioned below update the fields with the
313 same name in the aqorders table of the Koha database.
315 Updates the order with bibilionumber C<$biblionumber> and ordernumber
318 Also updates the book fund ID in the aqorderbreakdown table.
323 my ($biblio,$ordnum,$quantrec,$user,$cost,$invoiceno,$bibitemno,$freight,$bookfund,$rrp)=@_;
324 my $dbh = C4::Context->dbh;
325 my $query="update aqorders set quantityreceived=?,datereceived=now(),booksellerinvoicenumber=?,
326 biblioitemnumber=?,unitprice=?,freight=?,rrp=?
327 where biblionumber=? and ordernumber=?";
328 my $sth=$dbh->prepare($query);
329 $sth->execute($quantrec,$invoiceno,$bibitemno,$cost,$freight,$rrp,$biblio,$ordnum);
331 $query="update aqorderbreakdown set bookfundid=? where
333 $sth=$dbh->prepare($query);
334 $sth->execute($bookfund,$ordnum);
340 &updaterecorder($biblionumber, $ordernumber, $user, $unitprice,
343 Updates the order with biblionumber C<$biblionumber> and order number
344 C<$ordernumber>. C<$bookfundid> is the new value for the book fund ID
345 in the aqorderbreakdown table of the Koha database. All other
346 arguments update the fields with the same name in the aqorders table.
353 my($biblio,$ordnum,$user,$cost,$bookfund,$rrp)=@_;
354 my $dbh = C4::Context->dbh;
355 my $query="update aqorders set
356 unitprice='$cost', rrp='$rrp'
357 where biblionumber=$biblio and ordernumber=$ordnum
360 my $sth=$dbh->prepare($query);
363 $query="update aqorderbreakdown set bookfundid=$bookfund where
364 ordernumber=$ordnum";
365 $sth=$dbh->prepare($query);
379 ($count, $orders) = &getorders($booksellerid);
381 Finds pending orders from the bookseller with the given ID. Ignores
382 completed and cancelled orders.
384 C<$count> is the number of elements in C<@{$orders}>.
386 C<$orders> is a reference-to-array; each element is a
387 reference-to-hash with the following fields:
393 Gives the number of orders in with this basket number.
395 =item C<authorizedby>
401 These give the value of the corresponding field in the aqorders table
402 of the Koha database.
406 Results are ordered from most to least recent.
412 my $dbh = C4::Context->dbh;
413 my $query = "Select count(*),authorisedby,entrydate,basketno from aqorders where
414 booksellerid='$supplierid' and (quantity > quantityreceived or
415 quantityreceived is NULL)
416 and (datecancellationprinted is NULL or datecancellationprinted = '0000-00-00')";
417 $query.=" group by basketno order by entrydate desc";
419 my $sth=$dbh->prepare($query);
423 while (my $data=$sth->fetchrow_hashref){
428 return ($i,\@results);
433 ($order, $ordernumber) = &getorder($biblioitemnumber, $biblionumber);
435 Looks up the order with the given biblionumber and biblioitemnumber.
437 Returns a two-element array. C<$ordernumber> is the order number.
438 C<$order> is a reference-to-hash describing the order; its keys are
439 fields from the biblio, biblioitems, aqorders, and aqorderbreakdown
440 tables of the Koha database.
444 # FIXME - This is effectively identical to &C4::Biblio::getorder.
445 # Pick one and stick with it.
448 my $dbh = C4::Context->dbh;
449 my $query="Select ordernumber from aqorders where biblionumber=$bib and
450 biblioitemnumber='$bi'";
451 my $sth=$dbh->prepare($query);
453 # FIXME - Use fetchrow_array(), since we're only interested in the one
455 my $ordnum=$sth->fetchrow_hashref;
457 my $order=getsingleorder($ordnum->{'ordernumber'});
459 return ($order,$ordnum->{'ordernumber'});
464 $order = &getsingleorder($ordernumber);
466 Looks up an order by order number.
468 Returns a reference-to-hash describing the order. The keys of
469 C<$order> are fields from the biblio, biblioitems, aqorders, and
470 aqorderbreakdown tables of the Koha database.
474 # FIXME - This is effectively identical to
475 # &C4::Biblio::getsingleorder.
476 # Pick one and stick with it.
479 my $dbh = C4::Context->dbh;
480 my $query="Select * from biblio,biblioitems,aqorders,aqorderbreakdown
481 where aqorders.ordernumber='$ordnum'
482 and biblio.biblionumber=aqorders.biblionumber and
483 biblioitems.biblioitemnumber=aqorders.biblioitemnumber and
484 aqorders.ordernumber=aqorderbreakdown.ordernumber";
485 my $sth=$dbh->prepare($query);
487 my $data=$sth->fetchrow_hashref;
494 ($count, @results) = &getallorders($booksellerid);
496 Looks up all of the pending orders from the supplier with the given
497 bookseller ID. Ignores cancelled and completed orders.
499 C<$count> is the number of elements in C<@results>. C<@results> is an
500 array of references-to-hash. The keys of each element are fields from
501 the aqorders, biblio, and biblioitems tables of the Koha database.
503 C<@results> is sorted alphabetically by book title.
508 #gets all orders from a certain supplier, orders them alphabetically
510 my $dbh = C4::Context->dbh;
511 my $query="Select * from aqorders,biblio,biblioitems where booksellerid='$supid'
512 and (cancelledby is NULL or cancelledby = '')
513 and (quantityreceived < quantity or quantityreceived is NULL)
514 and biblio.biblionumber=aqorders.biblionumber and biblioitems.biblioitemnumber=
515 aqorders.biblioitemnumber
516 group by aqorders.biblioitemnumber
521 my $sth=$dbh->prepare($query);
523 while (my $data=$sth->fetchrow_hashref){
533 #gets all orders from a certain supplier, orders them alphabetically
535 my $dbh = C4::Context->dbh;
536 my $query="Select * from aqorders,biblio,biblioitems where booksellerid='$supid'
537 and (cancelledby is NULL or cancelledby = '')
538 and biblio.biblionumber=aqorders.biblionumber and biblioitems.biblioitemnumber=
539 aqorders.biblioitemnumber and
540 aqorders.quantityreceived>0
541 and aqorders.datereceived >=now()
542 group by aqorders.biblioitemnumber
547 my $sth=$dbh->prepare($query);
549 while (my $data=$sth->fetchrow_hashref){
559 ($count, @results) = &ordersearch($search, $biblionumber, $complete);
563 C<$search> may take one of several forms: if it is an ISBN,
564 C<&ordersearch> returns orders with that ISBN. If C<$search> is an
565 order number, C<&ordersearch> returns orders with that order number
566 and biblionumber C<$biblionumber>. Otherwise, C<$search> is considered
567 to be a space-separated list of search terms; in this case, all of the
568 terms must appear in the title (matching the beginning of title
571 If C<$complete> is C<yes>, the results will include only completed
572 orders. In any case, C<&ordersearch> ignores cancelled orders.
574 C<&ordersearch> returns an array. C<$count> is the number of elements
575 in C<@results>. C<@results> is an array of references-to-hash with the
593 my ($search,$id,$biblio,$catview) = @_;
594 my $dbh = C4::Context->dbh;
595 my $query = "Select *,biblio.title from aqorders,biblioitems,biblio
596 where aqorders.biblioitemnumber = biblioitems.biblioitemnumber
597 and aqorders.booksellerid = '$id'
598 and biblio.biblionumber=aqorders.biblionumber
599 and ((datecancellationprinted is NULL)
600 or (datecancellationprinted = '0000-00-00'))
602 my @data = split(' ',$search);
604 for (my $i = 0; $i < $count; $i++) {
605 $query .= "(biblio.title like '$data[$i]%' or biblio.title like '% $data[$i]%') and ";
608 # FIXME - Redo this properly instead of hacking off the
610 $query.=" ) or biblioitems.isbn='$search' or (aqorders.ordernumber='$search' and aqorders.biblionumber='$biblio')) ";
611 if ($catview ne 'yes'){
612 $query.=" and (quantityreceived < quantity or quantityreceived is NULL)";
614 $query.=" group by aqorders.ordernumber";
615 my $sth=$dbh->prepare($query);
619 my $sth2=$dbh->prepare("Select * from biblio where biblionumber=?");
620 my $sth3=$dbh->prepare("Select * from aqorderbreakdown where ordernumber=?");
621 while (my $data=$sth->fetchrow_hashref){
622 $sth2->execute($data->{'biblionumber'});
623 my $data2=$sth2->fetchrow_hashref;
624 $data->{'author'}=$data2->{'author'};
625 $data->{'seriestitle'}=$data2->{'seriestitle'};
626 $sth3->execute($data->{'ordernumber'});
627 my $data3=$sth3->fetchrow_hashref;
628 $data->{'branchcode'}=$data3->{'branchcode'};
629 $data->{'bookfundid'}=$data3->{'bookfundid'};
646 ($count, @results) = &invoice($booksellerinvoicenumber);
648 Looks up orders by invoice number.
650 Returns an array. C<$count> is the number of elements in C<@results>.
651 C<@results> is an array of references-to-hash; the keys of each
652 elements are fields from the aqorders, biblio, and biblioitems tables
653 of the Koha database.
659 my $dbh = C4::Context->dbh;
660 my $query="Select * from aqorders,biblio,biblioitems where
661 booksellerinvoicenumber='$invoice'
662 and biblio.biblionumber=aqorders.biblionumber and biblioitems.biblioitemnumber=
663 aqorders.biblioitemnumber group by aqorders.ordernumber,aqorders.biblioitemnumber";
666 my $sth=$dbh->prepare($query);
668 while (my $data=$sth->fetchrow_hashref){
678 ($count, @results) = &bookfunds();
680 Returns a list of all book funds.
682 C<$count> is the number of elements in C<@results>. C<@results> is an
683 array of references-to-hash, whose keys are fields from the aqbookfund
684 and aqbudget tables of the Koha database. Results are ordered
685 alphabetically by book fund name.
690 my $dbh = C4::Context->dbh;
691 my $query="Select * from aqbookfund,aqbudget where aqbookfund.bookfundid
693 group by aqbookfund.bookfundid order by bookfundname";
694 my $sth=$dbh->prepare($query);
698 while (my $data=$sth->fetchrow_hashref){
706 # FIXME - POD. I can't figure out what this function is doing. Then
707 # again, I don't think it's being used (anymore).
708 sub bookfundbreakdown {
710 my $dbh = C4::Context->dbh;
711 my $query="Select quantity,datereceived,freight,unitprice,listprice,ecost,quantityreceived,subscription
712 from aqorders,aqorderbreakdown where bookfundid='$id' and
713 aqorders.ordernumber=aqorderbreakdown.ordernumber
714 and (datecancellationprinted is NULL or
715 datecancellationprinted='0000-00-00')";
716 my $sth=$dbh->prepare($query);
720 while (my $data=$sth->fetchrow_hashref){
721 if ($data->{'subscription'} == 1){
722 $spent+=$data->{'quantity'}*$data->{'unitprice'};
724 my $leftover=$data->{'quantity'}-$data->{'quantityreceived'};
725 $comtd+=($data->{'ecost'})*$leftover;
726 $spent+=($data->{'unitprice'})*$data->{'quantityreceived'};
730 return($spent,$comtd);
735 $foreignprice = &curconvert($currency, $localprice);
737 Converts the price C<$localprice> to foreign currency C<$currency> by
738 dividing by the exchange rate, and returns the result.
740 If no exchange rate is found, C<&curconvert> assumes the rate is one
746 my ($currency,$price)=@_;
747 my $dbh = C4::Context->dbh;
748 my $query="Select rate from currency where currency='$currency'";
749 my $sth=$dbh->prepare($query);
751 my $data=$sth->fetchrow_hashref;
753 my $cur=$data->{'rate'};
757 return($price / $cur);
762 ($count, $currencies) = &getcurrencies();
764 Returns the list of all known currencies.
766 C<$count> is the number of elements in C<$currencies>. C<$currencies>
767 is a reference-to-array; its elements are references-to-hash, whose
768 keys are the fields from the currency table in the Koha database.
773 my $dbh = C4::Context->dbh;
774 my $query="Select * from currency";
775 my $sth=$dbh->prepare($query);
779 while (my $data=$sth->fetchrow_hashref){
784 return($i,\@results);
787 =item updatecurrencies
789 &updatecurrencies($currency, $newrate);
791 Sets the exchange rate for C<$currency> to be C<$newrate>.
795 sub updatecurrencies {
796 my ($currency,$rate)=@_;
797 my $dbh = C4::Context->dbh;
798 my $query="update currency set rate=$rate where currency='$currency'";
799 my $sth=$dbh->prepare($query);
804 # FIXME - This is never used
806 my($price,$rrp,$itemnum)=@_;
807 my $dbh = C4::Context->dbh;
808 my $query="update items set price='$price',replacementprice='$rrp'
809 where itemnumber=$itemnum";
810 my $sth=$dbh->prepare($query);
823 ($count, @results) = &bookseller($searchstring);
825 Looks up a book seller. C<$searchstring> may be either a book seller
826 ID, or a string to look for in the book seller's name.
828 C<$count> is the number of elements in C<@results>. C<@results> is an
829 array of references-to-hash, whose keys are the fields of of the
830 aqbooksellers table in the Koha database.
835 my ($searchstring)=@_;
836 my $dbh = C4::Context->dbh;
837 my $query="Select * from aqbooksellers where name like '$searchstring%' or
838 id = '$searchstring'";
839 my $sth=$dbh->prepare($query);
843 while (my $data=$sth->fetchrow_hashref){
853 ($count, $results) = &breakdown($ordernumber);
855 Looks up an order by order ID, and returns its breakdown.
857 C<$count> is the number of elements in C<$results>. C<$results> is a
858 reference-to-array; its elements are references-to-hash, whose keys
859 are the fields of the aqorderbreakdown table in the Koha database.
865 my $dbh = C4::Context->dbh;
866 my $query="Select * from aqorderbreakdown where ordernumber='$id'";
867 my $sth=$dbh->prepare($query);
871 while (my $data=$sth->fetchrow_hashref){
876 return($i,\@results);
881 ($count, @results) = &branches();
883 Returns a list of all library branches.
885 C<$count> is the number of elements in C<@results>. C<@results> is an
886 array of references-to-hash, whose keys are the fields of the branches
887 table of the Koha database.
892 my $dbh = C4::Context->dbh;
893 my $query = "Select * from branches";
894 my $sth = $dbh->prepare($query);
899 while (my $data = $sth->fetchrow_hashref) {
900 $results[$i] = $data;
905 return($i, @results);
910 my ($biblionumber)=@_;
911 my $dbh = C4::Context->dbh;
912 my $query="Select * from biblioitems,items,itemtypes where
913 biblioitems.biblionumber=$biblionumber
914 and biblioitems.biblioitemnumber=items.biblioitemnumber and
915 itemtypes.itemtype=biblioitems.itemtype
916 order by items.biblioitemnumber";
917 my $sth=$dbh->prepare($query);
921 while (my $data=$sth->fetchrow_hashref){
931 my ($bibitemnum,$itemtype)=@_;
932 my $dbh = C4::Context->dbh;
933 my $query="Select * from biblioitems where biblioitemnumber=$bibitemnum
934 and itemtype='$itemtype'";
935 my $sth=$dbh->prepare($query);
938 if (my $data=$sth->fetchrow_hashref){
947 &updatesup($bookseller);
949 Updates the information for a given bookseller. C<$bookseller> is a
950 reference-to-hash whose keys are the fields of the aqbooksellers table
951 in the Koha database. It must contain entries for all of the fields.
952 The entry to modify is determined by C<$bookseller-E<gt>{id}>.
954 The easiest way to get all of the necessary fields is to look up a
955 book seller with C<&booksellers>, modify what's necessary, then call
956 C<&updatesup> with the result.
962 my $dbh = C4::Context->dbh;
963 my $query="Update aqbooksellers set
964 name=?,address1=?,address2=?,address3=?,address4=?,postal=?,
965 phone=?,fax=?,url=?,contact=?,contpos=?,contphone=?,contfax=?,contaltphone=?,
966 contemail=?,contnotes=?,active=?,
967 listprice=?, invoiceprice=?,gstreg=?, listincgst=?,
968 invoiceincgst=?, specialty=?,discount=?,invoicedisc=?,
971 my $sth=$dbh->prepare($query);
972 $sth->execute($data->{'name'},$data->{'address1'},$data->{'address2'},
973 $data->{'address3'},$data->{'address4'},$data->{'postal'},$data->{'phone'},
974 $data->{'fax'},$data->{'url'},$data->{'contact'},$data->{'contpos'},
975 $data->{'contphone'},$data->{'contfax'},$data->{'contaltphone'},
976 $data->{'contemail'},
977 $data->{'contnote'},$data->{'active'},$data->{'listprice'},
978 $data->{'invoiceprice'},$data->{'gstreg'},$data->{'listincgst'},
979 $data->{'invoiceincgst'},$data->{'specialty'},$data->{'discount'},
980 $data->{'invoicedisc'},$data->{'nocalc'},$data->{'id'});
987 $id = &insertsup($bookseller);
989 Creates a new bookseller. C<$bookseller> is a reference-to-hash whose
990 keys are the fields of the aqbooksellers table in the Koha database.
991 All fields must be present.
993 Returns the ID of the newly-created bookseller.
999 my $dbh = C4::Context->dbh;
1000 my $sth=$dbh->prepare("Select max(id) from aqbooksellers");
1002 my $data2=$sth->fetchrow_hashref;
1004 $data2->{'max(id)'}++;
1005 $sth=$dbh->prepare("Insert into aqbooksellers (id) values ($data2->{'max(id)'})");
1008 $data->{'id'}=$data2->{'max(id)'};
1010 return($data->{'id'});
1015 ($count, @results) = &websitesearch($keywordlist);
1017 Looks up biblioitems by URL.
1019 C<$keywordlist> is a space-separated list of search terms.
1020 C<&websitesearch> returns those biblioitems whose URL contains at
1021 least one of the search terms.
1023 C<$count> is the number of elements in C<@results>. C<@results> is an
1024 array of references-to-hash, whose keys are the fields of the biblio
1025 and biblioitems tables in the Koha database.
1030 my ($keywordlist) = @_;
1031 my $dbh = C4::Context->dbh;
1032 my $query = "Select distinct biblio.* from biblio, biblioitems where
1033 biblio.biblionumber = biblioitems.biblionumber and (";
1037 my @keywords = split(/ +/, $keywordlist);
1038 my $keyword = shift(@keywords);
1041 # $query .= join(" and ",
1042 # apply { url like "%$_%" } @keywords
1044 $keyword =~ s/%/\\%/g;
1045 $keyword =~ s/_/\\_/;
1046 $keyword = "%" . $keyword . "%";
1047 $keyword = $dbh->quote($keyword);
1048 $query .= " (url like $keyword)";
1050 foreach $keyword (@keywords) {
1051 $keyword =~ s/%/\\%/;
1052 $keyword =~ s/_/\\_/;
1053 $keyword = "%" . $keyword . "%";
1054 $keyword = $dbh->quote($keyword);
1055 $query .= " or (url like $keyword)";
1059 $sth = $dbh->prepare($query);
1062 while (my $data = $sth->fetchrow_hashref) {
1063 $results[$count] = $data;
1068 return($count, @results);
1069 } # sub websitesearch
1073 &addwebsite($website);
1075 Adds a new web site. C<$website> is a reference-to-hash, with the keys
1076 C<biblionumber>, C<title>, C<description>, and C<url>. All of these
1083 my $dbh = C4::Context->dbh;
1087 # for (qw( biblionumber title description url )) # and any others
1089 # $website->{$_} = $dbh->quote($_);
1091 # Perhaps extend this to building the query as well. This might allow
1092 # some of the fields to be optional.
1093 $website->{'biblionumber'} = $dbh->quote($website->{'biblionumber'});
1094 $website->{'title'} = $dbh->quote($website->{'title'});
1095 $website->{'description'} = $dbh->quote($website->{'description'});
1096 $website->{'url'} = $dbh->quote($website->{'url'});
1098 $query = "Insert into websites set
1099 biblionumber = $website->{'biblionumber'},
1100 title = $website->{'title'},
1101 description = $website->{'description'},
1102 url = $website->{'url'}";
1109 &updatewebsite($website);
1111 Updates an existing web site. C<$website> is a reference-to-hash with
1112 the keys C<websitenumber>, C<title>, C<description>, and C<url>. All
1113 of these are mandatory. C<$website-E<gt>{websitenumber}> identifies
1114 the entry to update.
1120 my $dbh = C4::Context->dbh;
1123 $website->{'title'} = $dbh->quote($website->{'title'});
1124 $website->{'description'} = $dbh->quote($website->{'description'});
1125 $website->{'url'} = $dbh->quote($website->{'url'});
1127 $query = "Update websites set
1128 title = $website->{'title'},
1129 description = $website->{'description'},
1130 url = $website->{'url'}
1131 where websitenumber = $website->{'websitenumber'}";
1134 } # sub updatewebsite
1138 &deletewebsite($websitenumber);
1140 Deletes the web site with number C<$websitenumber>.
1145 my ($websitenumber) = @_;
1146 my $dbh = C4::Context->dbh;
1147 # FIXME - $query is unneeded
1148 my $query = "Delete from websites where websitenumber = $websitenumber";
1151 } # sub deletewebsite
1153 END { } # module clean-up code here (global destructor)
1162 Koha Developement team <info@koha.org>