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 $sth=$dbh->prepare("insert into aqorders (biblionumber,title,basketno,
191 quantity,listprice,booksellerid,entrydate,requisitionedby,authorisedby,notes,
192 biblioitemnumber,rrp,ecost,gst,unitprice,subscription,booksellerinvoicenumber)
193 values (?,?,?,?,?,?,now(),?,?,?,?,?,?,?,?,?,?)");
194 $sth->execute($bibnum,$title,$basket,$quantity,$listprice,$supplier,
195 $who,$who,$notes,$bibitemnum,$rrp,$ecost,$gst,$cost,
198 $sth=$dbh->prepare("select * from aqorders where
199 biblionumber=? and basketno=? and ordernumber >=?");
200 $sth->execute($bibnum,$basket,$ordnum);
201 my $data=$sth->fetchrow_hashref;
203 $ordnum=$data->{'ordernumber'};
204 $sth=$dbh->prepare("insert into aqorderbreakdown (ordernumber,bookfundid) values
207 $sth->execute($ordnum,$bookfund);
213 &delorder($biblionumber, $ordernumber);
215 Cancel the order with the given order and biblio numbers. It does not
216 delete any entries in the aqorders table, it merely marks them as
219 If there are no items remaining with the given biblionumber,
220 C<&delorder> also deletes them from the marc_subfield_table and
221 marc_biblio tables of the Koha database.
226 my ($bibnum,$ordnum)=@_;
227 my $dbh = C4::Context->dbh;
228 my $query="update aqorders set datecancellationprinted=now()
229 where biblionumber='$bibnum' and
230 ordernumber='$ordnum'";
231 my $sth=$dbh->prepare($query);
235 my $count=itemcount($bibnum);
243 &modorder($title, $ordernumber, $quantity, $listprice,
244 $biblionumber, $basketno, $supplier, $who, $notes,
245 $bookfundid, $bibitemnum, $rrp, $ecost, $gst, $budget,
246 $unitprice, $booksellerinvoicenumber);
248 Modifies an existing order. Updates the order with order number
249 C<$ordernumber> and biblionumber C<$biblionumber>. All other arguments
250 update the fields with the same name in the aqorders table of the Koha
253 Entries with order number C<$ordernumber> in the aqorderbreakdown
254 table are also updated to the new book fund ID.
259 my ($title,$ordnum,$quantity,$listprice,$bibnum,$basketno,$supplier,$who,$notes,$bookfund,$bibitemnum,$rrp,$ecost,$gst,$budget,$cost,$invoice)=@_;
260 my $dbh = C4::Context->dbh;
261 my $query="update aqorders set title='$title',
262 quantity='$quantity',listprice='$listprice',basketno='$basketno',
263 rrp='$rrp',ecost='$ecost',unitprice='$cost',
264 booksellerinvoicenumber='$invoice'
266 ordernumber=$ordnum and biblionumber=$bibnum";
267 my $sth=$dbh->prepare($query);
270 $query="update aqorderbreakdown set bookfundid=? where
272 $sth=$dbh->prepare($query);
273 $sth->execute($bookfund,$ordnum);
279 $order = &newordernum();
281 Finds the next unused order number in the aqorders table of the Koha
282 database, and returns it.
286 # FIXME - Race condition
288 my $dbh = C4::Context->dbh;
289 my $query="Select max(ordernumber) from aqorders";
290 my $sth=$dbh->prepare($query);
292 my $data=$sth->fetchrow_arrayref;
293 my $ordnum=$$data[0];
301 &receiveorder($biblionumber, $ordernumber, $quantityreceived, $user,
302 $unitprice, $booksellerinvoicenumber, $biblioitemnumber,
303 $freight, $bookfund, $rrp);
305 Updates an order, to reflect the fact that it was received, at least
306 in part. All arguments not mentioned below update the fields with the
307 same name in the aqorders table of the Koha database.
309 Updates the order with bibilionumber C<$biblionumber> and ordernumber
312 Also updates the book fund ID in the aqorderbreakdown table.
317 my ($biblio,$ordnum,$quantrec,$user,$cost,$invoiceno,$bibitemno,$freight,$bookfund,$rrp)=@_;
318 my $dbh = C4::Context->dbh;
319 my $query="update aqorders set quantityreceived=?,datereceived=now(),booksellerinvoicenumber=?,
320 biblioitemnumber=?,unitprice=?,freight=?,rrp=?
321 where biblionumber=? and ordernumber=?";
322 my $sth=$dbh->prepare($query);
323 $sth->execute($quantrec,$invoiceno,$bibitemno,$cost,$freight,$rrp,$biblio,$ordnum);
325 $query="update aqorderbreakdown set bookfundid=? where
327 $sth=$dbh->prepare($query);
328 $sth->execute($bookfund,$ordnum);
334 &updaterecorder($biblionumber, $ordernumber, $user, $unitprice,
337 Updates the order with biblionumber C<$biblionumber> and order number
338 C<$ordernumber>. C<$bookfundid> is the new value for the book fund ID
339 in the aqorderbreakdown table of the Koha database. All other
340 arguments update the fields with the same name in the aqorders table.
347 my($biblio,$ordnum,$user,$cost,$bookfund,$rrp)=@_;
348 my $dbh = C4::Context->dbh;
349 my $query="update aqorders set
350 unitprice='$cost', rrp='$rrp'
351 where biblionumber=$biblio and ordernumber=$ordnum
354 my $sth=$dbh->prepare($query);
357 $query="update aqorderbreakdown set bookfundid=$bookfund where
358 ordernumber=$ordnum";
359 $sth=$dbh->prepare($query);
373 ($count, $orders) = &getorders($booksellerid);
375 Finds pending orders from the bookseller with the given ID. Ignores
376 completed and cancelled orders.
378 C<$count> is the number of elements in C<@{$orders}>.
380 C<$orders> is a reference-to-array; each element is a
381 reference-to-hash with the following fields:
387 Gives the number of orders in with this basket number.
389 =item C<authorizedby>
395 These give the value of the corresponding field in the aqorders table
396 of the Koha database.
400 Results are ordered from most to least recent.
406 my $dbh = C4::Context->dbh;
407 my $query = "Select count(*),authorisedby,entrydate,basketno from aqorders where
408 booksellerid='$supplierid' and (quantity > quantityreceived or
409 quantityreceived is NULL)
410 and (datecancellationprinted is NULL or datecancellationprinted = '0000-00-00')";
411 $query.=" group by basketno order by entrydate desc";
413 my $sth=$dbh->prepare($query);
417 while (my $data=$sth->fetchrow_hashref){
422 return ($i,\@results);
427 ($order, $ordernumber) = &getorder($biblioitemnumber, $biblionumber);
429 Looks up the order with the given biblionumber and biblioitemnumber.
431 Returns a two-element array. C<$ordernumber> is the order number.
432 C<$order> is a reference-to-hash describing the order; its keys are
433 fields from the biblio, biblioitems, aqorders, and aqorderbreakdown
434 tables of the Koha database.
438 # FIXME - This is effectively identical to &C4::Biblio::getorder.
439 # Pick one and stick with it.
442 my $dbh = C4::Context->dbh;
443 my $query="Select ordernumber from aqorders where biblionumber=? and biblioitemnumber=?";
444 my $sth=$dbh->prepare($query);
445 $sth->execute($bib,$bi);
446 # FIXME - Use fetchrow_array(), since we're only interested in the one
448 my $ordnum=$sth->fetchrow_hashref;
450 my $order=getsingleorder($ordnum->{'ordernumber'});
452 return ($order,$ordnum->{'ordernumber'});
457 $order = &getsingleorder($ordernumber);
459 Looks up an order by order number.
461 Returns a reference-to-hash describing the order. The keys of
462 C<$order> are fields from the biblio, biblioitems, aqorders, and
463 aqorderbreakdown tables of the Koha database.
467 # FIXME - This is effectively identical to
468 # &C4::Biblio::getsingleorder.
469 # Pick one and stick with it.
472 my $dbh = C4::Context->dbh;
473 my $query="Select * from biblio,biblioitems,aqorders,aqorderbreakdown
474 where aqorders.ordernumber='$ordnum'
475 and biblio.biblionumber=aqorders.biblionumber and
476 biblioitems.biblioitemnumber=aqorders.biblioitemnumber and
477 aqorders.ordernumber=aqorderbreakdown.ordernumber";
478 my $sth=$dbh->prepare($query);
480 my $data=$sth->fetchrow_hashref;
487 ($count, @results) = &getallorders($booksellerid);
489 Looks up all of the pending orders from the supplier with the given
490 bookseller ID. Ignores cancelled and completed orders.
492 C<$count> is the number of elements in C<@results>. C<@results> is an
493 array of references-to-hash. The keys of each element are fields from
494 the aqorders, biblio, and biblioitems tables of the Koha database.
496 C<@results> is sorted alphabetically by book title.
501 #gets all orders from a certain supplier, orders them alphabetically
503 my $dbh = C4::Context->dbh;
504 my $query="Select * from aqorders,biblio,biblioitems where booksellerid='$supid'
505 and (cancelledby is NULL or cancelledby = '')
506 and (quantityreceived < quantity or quantityreceived is NULL)
507 and biblio.biblionumber=aqorders.biblionumber and biblioitems.biblioitemnumber=
508 aqorders.biblioitemnumber
509 group by aqorders.biblioitemnumber
514 my $sth=$dbh->prepare($query);
516 while (my $data=$sth->fetchrow_hashref){
526 #gets all orders from a certain supplier, orders them alphabetically
528 my $dbh = C4::Context->dbh;
529 my $query="Select * from aqorders,biblio,biblioitems where booksellerid='$supid'
530 and (cancelledby is NULL or cancelledby = '')
531 and biblio.biblionumber=aqorders.biblionumber and biblioitems.biblioitemnumber=
532 aqorders.biblioitemnumber and
533 aqorders.quantityreceived>0
534 and aqorders.datereceived >=now()
535 group by aqorders.biblioitemnumber
540 my $sth=$dbh->prepare($query);
542 while (my $data=$sth->fetchrow_hashref){
552 ($count, @results) = &ordersearch($search, $biblionumber, $complete);
556 C<$search> may take one of several forms: if it is an ISBN,
557 C<&ordersearch> returns orders with that ISBN. If C<$search> is an
558 order number, C<&ordersearch> returns orders with that order number
559 and biblionumber C<$biblionumber>. Otherwise, C<$search> is considered
560 to be a space-separated list of search terms; in this case, all of the
561 terms must appear in the title (matching the beginning of title
564 If C<$complete> is C<yes>, the results will include only completed
565 orders. In any case, C<&ordersearch> ignores cancelled orders.
567 C<&ordersearch> returns an array. C<$count> is the number of elements
568 in C<@results>. C<@results> is an array of references-to-hash with the
586 my ($search,$id,$biblio,$catview) = @_;
587 my $dbh = C4::Context->dbh;
588 my $query = "Select *,biblio.title from aqorders,biblioitems,biblio
589 where aqorders.biblioitemnumber = biblioitems.biblioitemnumber
590 and aqorders.booksellerid = '$id'
591 and biblio.biblionumber=aqorders.biblionumber
592 and ((datecancellationprinted is NULL)
593 or (datecancellationprinted = '0000-00-00'))
595 my @data = split(' ',$search);
597 for (my $i = 0; $i < $count; $i++) {
598 $query .= "(biblio.title like '$data[$i]%' or biblio.title like '% $data[$i]%') and ";
601 # FIXME - Redo this properly instead of hacking off the
603 $query.=" ) or biblioitems.isbn='$search' or (aqorders.ordernumber='$search' and aqorders.biblionumber='$biblio')) ";
604 if ($catview ne 'yes'){
605 $query.=" and (quantityreceived < quantity or quantityreceived is NULL)";
607 $query.=" group by aqorders.ordernumber";
608 my $sth=$dbh->prepare($query);
612 my $sth2=$dbh->prepare("Select * from biblio where biblionumber=?");
613 my $sth3=$dbh->prepare("Select * from aqorderbreakdown where ordernumber=?");
614 while (my $data=$sth->fetchrow_hashref){
615 $sth2->execute($data->{'biblionumber'});
616 my $data2=$sth2->fetchrow_hashref;
617 $data->{'author'}=$data2->{'author'};
618 $data->{'seriestitle'}=$data2->{'seriestitle'};
619 $sth3->execute($data->{'ordernumber'});
620 my $data3=$sth3->fetchrow_hashref;
621 $data->{'branchcode'}=$data3->{'branchcode'};
622 $data->{'bookfundid'}=$data3->{'bookfundid'};
639 ($count, @results) = &invoice($booksellerinvoicenumber);
641 Looks up orders by invoice number.
643 Returns an array. C<$count> is the number of elements in C<@results>.
644 C<@results> is an array of references-to-hash; the keys of each
645 elements are fields from the aqorders, biblio, and biblioitems tables
646 of the Koha database.
652 my $dbh = C4::Context->dbh;
653 my $query="Select * from aqorders,biblio,biblioitems where
654 booksellerinvoicenumber='$invoice'
655 and biblio.biblionumber=aqorders.biblionumber and biblioitems.biblioitemnumber=
656 aqorders.biblioitemnumber group by aqorders.ordernumber,aqorders.biblioitemnumber";
659 my $sth=$dbh->prepare($query);
661 while (my $data=$sth->fetchrow_hashref){
671 ($count, @results) = &bookfunds();
673 Returns a list of all book funds.
675 C<$count> is the number of elements in C<@results>. C<@results> is an
676 array of references-to-hash, whose keys are fields from the aqbookfund
677 and aqbudget tables of the Koha database. Results are ordered
678 alphabetically by book fund name.
683 my $dbh = C4::Context->dbh;
684 my $query="Select * from aqbookfund,aqbudget where aqbookfund.bookfundid
686 group by aqbookfund.bookfundid order by bookfundname";
687 my $sth=$dbh->prepare($query);
691 while (my $data=$sth->fetchrow_hashref){
699 # FIXME - POD. I can't figure out what this function is doing. Then
700 # again, I don't think it's being used (anymore).
701 sub bookfundbreakdown {
703 my $dbh = C4::Context->dbh;
704 my $query="Select quantity,datereceived,freight,unitprice,listprice,ecost,quantityreceived,subscription
705 from aqorders,aqorderbreakdown where bookfundid='$id' and
706 aqorders.ordernumber=aqorderbreakdown.ordernumber
707 and (datecancellationprinted is NULL or
708 datecancellationprinted='0000-00-00')";
709 my $sth=$dbh->prepare($query);
713 while (my $data=$sth->fetchrow_hashref){
714 if ($data->{'subscription'} == 1){
715 $spent+=$data->{'quantity'}*$data->{'unitprice'};
717 my $leftover=$data->{'quantity'}-$data->{'quantityreceived'};
718 $comtd+=($data->{'ecost'})*$leftover;
719 $spent+=($data->{'unitprice'})*$data->{'quantityreceived'};
723 return($spent,$comtd);
728 $foreignprice = &curconvert($currency, $localprice);
730 Converts the price C<$localprice> to foreign currency C<$currency> by
731 dividing by the exchange rate, and returns the result.
733 If no exchange rate is found, C<&curconvert> assumes the rate is one
739 my ($currency,$price)=@_;
740 my $dbh = C4::Context->dbh;
741 my $query="Select rate from currency where currency='$currency'";
742 my $sth=$dbh->prepare($query);
744 my $data=$sth->fetchrow_hashref;
746 my $cur=$data->{'rate'};
750 return($price / $cur);
755 ($count, $currencies) = &getcurrencies();
757 Returns the list of all known currencies.
759 C<$count> is the number of elements in C<$currencies>. C<$currencies>
760 is a reference-to-array; its elements are references-to-hash, whose
761 keys are the fields from the currency table in the Koha database.
766 my $dbh = C4::Context->dbh;
767 my $query="Select * from currency";
768 my $sth=$dbh->prepare($query);
772 while (my $data=$sth->fetchrow_hashref){
777 return($i,\@results);
780 =item updatecurrencies
782 &updatecurrencies($currency, $newrate);
784 Sets the exchange rate for C<$currency> to be C<$newrate>.
788 sub updatecurrencies {
789 my ($currency,$rate)=@_;
790 my $dbh = C4::Context->dbh;
791 my $query="update currency set rate=$rate where currency='$currency'";
792 my $sth=$dbh->prepare($query);
797 # FIXME - This is never used
799 my($price,$rrp,$itemnum)=@_;
800 my $dbh = C4::Context->dbh;
801 my $query="update items set price='$price',replacementprice='$rrp'
802 where itemnumber=$itemnum";
803 my $sth=$dbh->prepare($query);
816 ($count, @results) = &bookseller($searchstring);
818 Looks up a book seller. C<$searchstring> may be either a book seller
819 ID, or a string to look for in the book seller's name.
821 C<$count> is the number of elements in C<@results>. C<@results> is an
822 array of references-to-hash, whose keys are the fields of of the
823 aqbooksellers table in the Koha database.
828 my ($searchstring)=@_;
829 my $dbh = C4::Context->dbh;
830 my $query="Select * from aqbooksellers where name like '$searchstring%' or
831 id = '$searchstring'";
832 my $sth=$dbh->prepare($query);
836 while (my $data=$sth->fetchrow_hashref){
846 ($count, $results) = &breakdown($ordernumber);
848 Looks up an order by order ID, and returns its breakdown.
850 C<$count> is the number of elements in C<$results>. C<$results> is a
851 reference-to-array; its elements are references-to-hash, whose keys
852 are the fields of the aqorderbreakdown table in the Koha database.
858 my $dbh = C4::Context->dbh;
859 my $query="Select * from aqorderbreakdown where ordernumber='$id'";
860 my $sth=$dbh->prepare($query);
864 while (my $data=$sth->fetchrow_hashref){
869 return($i,\@results);
874 ($count, @results) = &branches();
876 Returns a list of all library branches.
878 C<$count> is the number of elements in C<@results>. C<@results> is an
879 array of references-to-hash, whose keys are the fields of the branches
880 table of the Koha database.
885 my $dbh = C4::Context->dbh;
886 my $query = "Select * from branches order by branchname";
887 my $sth = $dbh->prepare($query);
892 while (my $data = $sth->fetchrow_hashref) {
893 $results[$i] = $data;
898 return($i, @results);
903 my ($biblionumber)=@_;
904 my $dbh = C4::Context->dbh;
905 my $query="Select * from biblioitems,items,itemtypes where
906 biblioitems.biblionumber=$biblionumber
907 and biblioitems.biblioitemnumber=items.biblioitemnumber and
908 itemtypes.itemtype=biblioitems.itemtype
909 order by items.biblioitemnumber";
910 my $sth=$dbh->prepare($query);
914 while (my $data=$sth->fetchrow_hashref){
924 my ($bibitemnum,$itemtype)=@_;
925 my $dbh = C4::Context->dbh;
926 my $query="Select * from biblioitems where biblioitemnumber=$bibitemnum
927 and itemtype='$itemtype'";
928 my $sth=$dbh->prepare($query);
931 if (my $data=$sth->fetchrow_hashref){
940 &updatesup($bookseller);
942 Updates the information for a given bookseller. C<$bookseller> is a
943 reference-to-hash whose keys are the fields of the aqbooksellers table
944 in the Koha database. It must contain entries for all of the fields.
945 The entry to modify is determined by C<$bookseller-E<gt>{id}>.
947 The easiest way to get all of the necessary fields is to look up a
948 book seller with C<&booksellers>, modify what's necessary, then call
949 C<&updatesup> with the result.
955 my $dbh = C4::Context->dbh;
956 my $query="Update aqbooksellers set
957 name=?,address1=?,address2=?,address3=?,address4=?,postal=?,
958 phone=?,fax=?,url=?,contact=?,contpos=?,contphone=?,contfax=?,contaltphone=?,
959 contemail=?,contnotes=?,active=?,
960 listprice=?, invoiceprice=?,gstreg=?, listincgst=?,
961 invoiceincgst=?, specialty=?,discount=?,invoicedisc=?,
964 my $sth=$dbh->prepare($query);
965 $sth->execute($data->{'name'},$data->{'address1'},$data->{'address2'},
966 $data->{'address3'},$data->{'address4'},$data->{'postal'},$data->{'phone'},
967 $data->{'fax'},$data->{'url'},$data->{'contact'},$data->{'contpos'},
968 $data->{'contphone'},$data->{'contfax'},$data->{'contaltphone'},
969 $data->{'contemail'},
970 $data->{'contnote'},$data->{'active'},$data->{'listprice'},
971 $data->{'invoiceprice'},$data->{'gstreg'},$data->{'listincgst'},
972 $data->{'invoiceincgst'},$data->{'specialty'},$data->{'discount'},
973 $data->{'invoicedisc'},$data->{'nocalc'},$data->{'id'});
980 $id = &insertsup($bookseller);
982 Creates a new bookseller. C<$bookseller> is a reference-to-hash whose
983 keys are the fields of the aqbooksellers table in the Koha database.
984 All fields must be present.
986 Returns the ID of the newly-created bookseller.
992 my $dbh = C4::Context->dbh;
993 my $sth=$dbh->prepare("Select max(id) from aqbooksellers");
995 my $data2=$sth->fetchrow_hashref;
997 $data2->{'max(id)'}++;
998 $sth=$dbh->prepare("Insert into aqbooksellers (id) values ($data2->{'max(id)'})");
1001 $data->{'id'}=$data2->{'max(id)'};
1003 return($data->{'id'});
1008 ($count, @results) = &websitesearch($keywordlist);
1010 Looks up biblioitems by URL.
1012 C<$keywordlist> is a space-separated list of search terms.
1013 C<&websitesearch> returns those biblioitems whose URL contains at
1014 least one of the search terms.
1016 C<$count> is the number of elements in C<@results>. C<@results> is an
1017 array of references-to-hash, whose keys are the fields of the biblio
1018 and biblioitems tables in the Koha database.
1023 my ($keywordlist) = @_;
1024 my $dbh = C4::Context->dbh;
1025 my $query = "Select distinct biblio.* from biblio, biblioitems where
1026 biblio.biblionumber = biblioitems.biblionumber and (";
1030 my @keywords = split(/ +/, $keywordlist);
1031 my $keyword = shift(@keywords);
1034 # $query .= join(" and ",
1035 # apply { url like "%$_%" } @keywords
1037 $keyword =~ s/%/\\%/g;
1038 $keyword =~ s/_/\\_/;
1039 $keyword = "%" . $keyword . "%";
1040 $keyword = $dbh->quote($keyword);
1041 $query .= " (url like $keyword)";
1043 foreach $keyword (@keywords) {
1044 $keyword =~ s/%/\\%/;
1045 $keyword =~ s/_/\\_/;
1046 $keyword = "%" . $keyword . "%";
1047 $keyword = $dbh->quote($keyword);
1048 $query .= " or (url like $keyword)";
1052 $sth = $dbh->prepare($query);
1055 while (my $data = $sth->fetchrow_hashref) {
1056 $results[$count] = $data;
1061 return($count, @results);
1062 } # sub websitesearch
1066 &addwebsite($website);
1068 Adds a new web site. C<$website> is a reference-to-hash, with the keys
1069 C<biblionumber>, C<title>, C<description>, and C<url>. All of these
1076 my $dbh = C4::Context->dbh;
1080 # for (qw( biblionumber title description url )) # and any others
1082 # $website->{$_} = $dbh->quote($_);
1084 # Perhaps extend this to building the query as well. This might allow
1085 # some of the fields to be optional.
1086 $website->{'biblionumber'} = $dbh->quote($website->{'biblionumber'});
1087 $website->{'title'} = $dbh->quote($website->{'title'});
1088 $website->{'description'} = $dbh->quote($website->{'description'});
1089 $website->{'url'} = $dbh->quote($website->{'url'});
1091 $query = "Insert into websites set
1092 biblionumber = $website->{'biblionumber'},
1093 title = $website->{'title'},
1094 description = $website->{'description'},
1095 url = $website->{'url'}";
1102 &updatewebsite($website);
1104 Updates an existing web site. C<$website> is a reference-to-hash with
1105 the keys C<websitenumber>, C<title>, C<description>, and C<url>. All
1106 of these are mandatory. C<$website-E<gt>{websitenumber}> identifies
1107 the entry to update.
1113 my $dbh = C4::Context->dbh;
1116 $website->{'title'} = $dbh->quote($website->{'title'});
1117 $website->{'description'} = $dbh->quote($website->{'description'});
1118 $website->{'url'} = $dbh->quote($website->{'url'});
1120 $query = "Update websites set
1121 title = $website->{'title'},
1122 description = $website->{'description'},
1123 url = $website->{'url'}
1124 where websitenumber = $website->{'websitenumber'}";
1127 } # sub updatewebsite
1131 &deletewebsite($websitenumber);
1133 Deletes the web site with number C<$websitenumber>.
1138 my ($websitenumber) = @_;
1139 my $dbh = C4::Context->dbh;
1140 # FIXME - $query is unneeded
1141 my $query = "Delete from websites where websitenumber = $websitenumber";
1144 } # sub deletewebsite
1146 END { } # module clean-up code here (global destructor)
1155 Koha Developement team <info@koha.org>