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=$bib and
444 biblioitemnumber='$bi'";
445 my $sth=$dbh->prepare($query);
447 # FIXME - Use fetchrow_array(), since we're only interested in the one
449 my $ordnum=$sth->fetchrow_hashref;
451 my $order=getsingleorder($ordnum->{'ordernumber'});
453 return ($order,$ordnum->{'ordernumber'});
458 $order = &getsingleorder($ordernumber);
460 Looks up an order by order number.
462 Returns a reference-to-hash describing the order. The keys of
463 C<$order> are fields from the biblio, biblioitems, aqorders, and
464 aqorderbreakdown tables of the Koha database.
468 # FIXME - This is effectively identical to
469 # &C4::Biblio::getsingleorder.
470 # Pick one and stick with it.
473 my $dbh = C4::Context->dbh;
474 my $query="Select * from biblio,biblioitems,aqorders,aqorderbreakdown
475 where aqorders.ordernumber='$ordnum'
476 and biblio.biblionumber=aqorders.biblionumber and
477 biblioitems.biblioitemnumber=aqorders.biblioitemnumber and
478 aqorders.ordernumber=aqorderbreakdown.ordernumber";
479 my $sth=$dbh->prepare($query);
481 my $data=$sth->fetchrow_hashref;
488 ($count, @results) = &getallorders($booksellerid);
490 Looks up all of the pending orders from the supplier with the given
491 bookseller ID. Ignores cancelled and completed orders.
493 C<$count> is the number of elements in C<@results>. C<@results> is an
494 array of references-to-hash. The keys of each element are fields from
495 the aqorders, biblio, and biblioitems tables of the Koha database.
497 C<@results> is sorted alphabetically by book title.
502 #gets all orders from a certain supplier, orders them alphabetically
504 my $dbh = C4::Context->dbh;
505 my $query="Select * from aqorders,biblio,biblioitems where booksellerid='$supid'
506 and (cancelledby is NULL or cancelledby = '')
507 and (quantityreceived < quantity or quantityreceived is NULL)
508 and biblio.biblionumber=aqorders.biblionumber and biblioitems.biblioitemnumber=
509 aqorders.biblioitemnumber
510 group by aqorders.biblioitemnumber
515 my $sth=$dbh->prepare($query);
517 while (my $data=$sth->fetchrow_hashref){
527 #gets all orders from a certain supplier, orders them alphabetically
529 my $dbh = C4::Context->dbh;
530 my $query="Select * from aqorders,biblio,biblioitems where booksellerid='$supid'
531 and (cancelledby is NULL or cancelledby = '')
532 and biblio.biblionumber=aqorders.biblionumber and biblioitems.biblioitemnumber=
533 aqorders.biblioitemnumber and
534 aqorders.quantityreceived>0
535 and aqorders.datereceived >=now()
536 group by aqorders.biblioitemnumber
541 my $sth=$dbh->prepare($query);
543 while (my $data=$sth->fetchrow_hashref){
553 ($count, @results) = &ordersearch($search, $biblionumber, $complete);
557 C<$search> may take one of several forms: if it is an ISBN,
558 C<&ordersearch> returns orders with that ISBN. If C<$search> is an
559 order number, C<&ordersearch> returns orders with that order number
560 and biblionumber C<$biblionumber>. Otherwise, C<$search> is considered
561 to be a space-separated list of search terms; in this case, all of the
562 terms must appear in the title (matching the beginning of title
565 If C<$complete> is C<yes>, the results will include only completed
566 orders. In any case, C<&ordersearch> ignores cancelled orders.
568 C<&ordersearch> returns an array. C<$count> is the number of elements
569 in C<@results>. C<@results> is an array of references-to-hash with the
587 my ($search,$id,$biblio,$catview) = @_;
588 my $dbh = C4::Context->dbh;
589 my $query = "Select *,biblio.title from aqorders,biblioitems,biblio
590 where aqorders.biblioitemnumber = biblioitems.biblioitemnumber
591 and aqorders.booksellerid = '$id'
592 and biblio.biblionumber=aqorders.biblionumber
593 and ((datecancellationprinted is NULL)
594 or (datecancellationprinted = '0000-00-00'))
596 my @data = split(' ',$search);
598 for (my $i = 0; $i < $count; $i++) {
599 $query .= "(biblio.title like '$data[$i]%' or biblio.title like '% $data[$i]%') and ";
602 # FIXME - Redo this properly instead of hacking off the
604 $query.=" ) or biblioitems.isbn='$search' or (aqorders.ordernumber='$search' and aqorders.biblionumber='$biblio')) ";
605 if ($catview ne 'yes'){
606 $query.=" and (quantityreceived < quantity or quantityreceived is NULL)";
608 $query.=" group by aqorders.ordernumber";
609 my $sth=$dbh->prepare($query);
613 my $sth2=$dbh->prepare("Select * from biblio where biblionumber=?");
614 my $sth3=$dbh->prepare("Select * from aqorderbreakdown where ordernumber=?");
615 while (my $data=$sth->fetchrow_hashref){
616 $sth2->execute($data->{'biblionumber'});
617 my $data2=$sth2->fetchrow_hashref;
618 $data->{'author'}=$data2->{'author'};
619 $data->{'seriestitle'}=$data2->{'seriestitle'};
620 $sth3->execute($data->{'ordernumber'});
621 my $data3=$sth3->fetchrow_hashref;
622 $data->{'branchcode'}=$data3->{'branchcode'};
623 $data->{'bookfundid'}=$data3->{'bookfundid'};
640 ($count, @results) = &invoice($booksellerinvoicenumber);
642 Looks up orders by invoice number.
644 Returns an array. C<$count> is the number of elements in C<@results>.
645 C<@results> is an array of references-to-hash; the keys of each
646 elements are fields from the aqorders, biblio, and biblioitems tables
647 of the Koha database.
653 my $dbh = C4::Context->dbh;
654 my $query="Select * from aqorders,biblio,biblioitems where
655 booksellerinvoicenumber='$invoice'
656 and biblio.biblionumber=aqorders.biblionumber and biblioitems.biblioitemnumber=
657 aqorders.biblioitemnumber group by aqorders.ordernumber,aqorders.biblioitemnumber";
660 my $sth=$dbh->prepare($query);
662 while (my $data=$sth->fetchrow_hashref){
672 ($count, @results) = &bookfunds();
674 Returns a list of all book funds.
676 C<$count> is the number of elements in C<@results>. C<@results> is an
677 array of references-to-hash, whose keys are fields from the aqbookfund
678 and aqbudget tables of the Koha database. Results are ordered
679 alphabetically by book fund name.
684 my $dbh = C4::Context->dbh;
685 my $query="Select * from aqbookfund,aqbudget where aqbookfund.bookfundid
687 group by aqbookfund.bookfundid order by bookfundname";
688 my $sth=$dbh->prepare($query);
692 while (my $data=$sth->fetchrow_hashref){
700 # FIXME - POD. I can't figure out what this function is doing. Then
701 # again, I don't think it's being used (anymore).
702 sub bookfundbreakdown {
704 my $dbh = C4::Context->dbh;
705 my $query="Select quantity,datereceived,freight,unitprice,listprice,ecost,quantityreceived,subscription
706 from aqorders,aqorderbreakdown where bookfundid='$id' and
707 aqorders.ordernumber=aqorderbreakdown.ordernumber
708 and (datecancellationprinted is NULL or
709 datecancellationprinted='0000-00-00')";
710 my $sth=$dbh->prepare($query);
714 while (my $data=$sth->fetchrow_hashref){
715 if ($data->{'subscription'} == 1){
716 $spent+=$data->{'quantity'}*$data->{'unitprice'};
718 my $leftover=$data->{'quantity'}-$data->{'quantityreceived'};
719 $comtd+=($data->{'ecost'})*$leftover;
720 $spent+=($data->{'unitprice'})*$data->{'quantityreceived'};
724 return($spent,$comtd);
729 $foreignprice = &curconvert($currency, $localprice);
731 Converts the price C<$localprice> to foreign currency C<$currency> by
732 dividing by the exchange rate, and returns the result.
734 If no exchange rate is found, C<&curconvert> assumes the rate is one
740 my ($currency,$price)=@_;
741 my $dbh = C4::Context->dbh;
742 my $query="Select rate from currency where currency='$currency'";
743 my $sth=$dbh->prepare($query);
745 my $data=$sth->fetchrow_hashref;
747 my $cur=$data->{'rate'};
751 return($price / $cur);
756 ($count, $currencies) = &getcurrencies();
758 Returns the list of all known currencies.
760 C<$count> is the number of elements in C<$currencies>. C<$currencies>
761 is a reference-to-array; its elements are references-to-hash, whose
762 keys are the fields from the currency table in the Koha database.
767 my $dbh = C4::Context->dbh;
768 my $query="Select * from currency";
769 my $sth=$dbh->prepare($query);
773 while (my $data=$sth->fetchrow_hashref){
778 return($i,\@results);
781 =item updatecurrencies
783 &updatecurrencies($currency, $newrate);
785 Sets the exchange rate for C<$currency> to be C<$newrate>.
789 sub updatecurrencies {
790 my ($currency,$rate)=@_;
791 my $dbh = C4::Context->dbh;
792 my $query="update currency set rate=$rate where currency='$currency'";
793 my $sth=$dbh->prepare($query);
798 # FIXME - This is never used
800 my($price,$rrp,$itemnum)=@_;
801 my $dbh = C4::Context->dbh;
802 my $query="update items set price='$price',replacementprice='$rrp'
803 where itemnumber=$itemnum";
804 my $sth=$dbh->prepare($query);
817 ($count, @results) = &bookseller($searchstring);
819 Looks up a book seller. C<$searchstring> may be either a book seller
820 ID, or a string to look for in the book seller's name.
822 C<$count> is the number of elements in C<@results>. C<@results> is an
823 array of references-to-hash, whose keys are the fields of of the
824 aqbooksellers table in the Koha database.
829 my ($searchstring)=@_;
830 my $dbh = C4::Context->dbh;
831 my $query="Select * from aqbooksellers where name like '$searchstring%' or
832 id = '$searchstring'";
833 my $sth=$dbh->prepare($query);
837 while (my $data=$sth->fetchrow_hashref){
847 ($count, $results) = &breakdown($ordernumber);
849 Looks up an order by order ID, and returns its breakdown.
851 C<$count> is the number of elements in C<$results>. C<$results> is a
852 reference-to-array; its elements are references-to-hash, whose keys
853 are the fields of the aqorderbreakdown table in the Koha database.
859 my $dbh = C4::Context->dbh;
860 my $query="Select * from aqorderbreakdown where ordernumber='$id'";
861 my $sth=$dbh->prepare($query);
865 while (my $data=$sth->fetchrow_hashref){
870 return($i,\@results);
875 ($count, @results) = &branches();
877 Returns a list of all library branches.
879 C<$count> is the number of elements in C<@results>. C<@results> is an
880 array of references-to-hash, whose keys are the fields of the branches
881 table of the Koha database.
886 my $dbh = C4::Context->dbh;
887 my $query = "Select * from branches order by branchname";
888 my $sth = $dbh->prepare($query);
893 while (my $data = $sth->fetchrow_hashref) {
894 $results[$i] = $data;
899 return($i, @results);
904 my ($biblionumber)=@_;
905 my $dbh = C4::Context->dbh;
906 my $query="Select * from biblioitems,items,itemtypes where
907 biblioitems.biblionumber=$biblionumber
908 and biblioitems.biblioitemnumber=items.biblioitemnumber and
909 itemtypes.itemtype=biblioitems.itemtype
910 order by items.biblioitemnumber";
911 my $sth=$dbh->prepare($query);
915 while (my $data=$sth->fetchrow_hashref){
925 my ($bibitemnum,$itemtype)=@_;
926 my $dbh = C4::Context->dbh;
927 my $query="Select * from biblioitems where biblioitemnumber=$bibitemnum
928 and itemtype='$itemtype'";
929 my $sth=$dbh->prepare($query);
932 if (my $data=$sth->fetchrow_hashref){
941 &updatesup($bookseller);
943 Updates the information for a given bookseller. C<$bookseller> is a
944 reference-to-hash whose keys are the fields of the aqbooksellers table
945 in the Koha database. It must contain entries for all of the fields.
946 The entry to modify is determined by C<$bookseller-E<gt>{id}>.
948 The easiest way to get all of the necessary fields is to look up a
949 book seller with C<&booksellers>, modify what's necessary, then call
950 C<&updatesup> with the result.
956 my $dbh = C4::Context->dbh;
957 my $query="Update aqbooksellers set
958 name=?,address1=?,address2=?,address3=?,address4=?,postal=?,
959 phone=?,fax=?,url=?,contact=?,contpos=?,contphone=?,contfax=?,contaltphone=?,
960 contemail=?,contnotes=?,active=?,
961 listprice=?, invoiceprice=?,gstreg=?, listincgst=?,
962 invoiceincgst=?, specialty=?,discount=?,invoicedisc=?,
965 my $sth=$dbh->prepare($query);
966 $sth->execute($data->{'name'},$data->{'address1'},$data->{'address2'},
967 $data->{'address3'},$data->{'address4'},$data->{'postal'},$data->{'phone'},
968 $data->{'fax'},$data->{'url'},$data->{'contact'},$data->{'contpos'},
969 $data->{'contphone'},$data->{'contfax'},$data->{'contaltphone'},
970 $data->{'contemail'},
971 $data->{'contnote'},$data->{'active'},$data->{'listprice'},
972 $data->{'invoiceprice'},$data->{'gstreg'},$data->{'listincgst'},
973 $data->{'invoiceincgst'},$data->{'specialty'},$data->{'discount'},
974 $data->{'invoicedisc'},$data->{'nocalc'},$data->{'id'});
981 $id = &insertsup($bookseller);
983 Creates a new bookseller. C<$bookseller> is a reference-to-hash whose
984 keys are the fields of the aqbooksellers table in the Koha database.
985 All fields must be present.
987 Returns the ID of the newly-created bookseller.
993 my $dbh = C4::Context->dbh;
994 my $sth=$dbh->prepare("Select max(id) from aqbooksellers");
996 my $data2=$sth->fetchrow_hashref;
998 $data2->{'max(id)'}++;
999 $sth=$dbh->prepare("Insert into aqbooksellers (id) values ($data2->{'max(id)'})");
1002 $data->{'id'}=$data2->{'max(id)'};
1004 return($data->{'id'});
1009 ($count, @results) = &websitesearch($keywordlist);
1011 Looks up biblioitems by URL.
1013 C<$keywordlist> is a space-separated list of search terms.
1014 C<&websitesearch> returns those biblioitems whose URL contains at
1015 least one of the search terms.
1017 C<$count> is the number of elements in C<@results>. C<@results> is an
1018 array of references-to-hash, whose keys are the fields of the biblio
1019 and biblioitems tables in the Koha database.
1024 my ($keywordlist) = @_;
1025 my $dbh = C4::Context->dbh;
1026 my $query = "Select distinct biblio.* from biblio, biblioitems where
1027 biblio.biblionumber = biblioitems.biblionumber and (";
1031 my @keywords = split(/ +/, $keywordlist);
1032 my $keyword = shift(@keywords);
1035 # $query .= join(" and ",
1036 # apply { url like "%$_%" } @keywords
1038 $keyword =~ s/%/\\%/g;
1039 $keyword =~ s/_/\\_/;
1040 $keyword = "%" . $keyword . "%";
1041 $keyword = $dbh->quote($keyword);
1042 $query .= " (url like $keyword)";
1044 foreach $keyword (@keywords) {
1045 $keyword =~ s/%/\\%/;
1046 $keyword =~ s/_/\\_/;
1047 $keyword = "%" . $keyword . "%";
1048 $keyword = $dbh->quote($keyword);
1049 $query .= " or (url like $keyword)";
1053 $sth = $dbh->prepare($query);
1056 while (my $data = $sth->fetchrow_hashref) {
1057 $results[$count] = $data;
1062 return($count, @results);
1063 } # sub websitesearch
1067 &addwebsite($website);
1069 Adds a new web site. C<$website> is a reference-to-hash, with the keys
1070 C<biblionumber>, C<title>, C<description>, and C<url>. All of these
1077 my $dbh = C4::Context->dbh;
1081 # for (qw( biblionumber title description url )) # and any others
1083 # $website->{$_} = $dbh->quote($_);
1085 # Perhaps extend this to building the query as well. This might allow
1086 # some of the fields to be optional.
1087 $website->{'biblionumber'} = $dbh->quote($website->{'biblionumber'});
1088 $website->{'title'} = $dbh->quote($website->{'title'});
1089 $website->{'description'} = $dbh->quote($website->{'description'});
1090 $website->{'url'} = $dbh->quote($website->{'url'});
1092 $query = "Insert into websites set
1093 biblionumber = $website->{'biblionumber'},
1094 title = $website->{'title'},
1095 description = $website->{'description'},
1096 url = $website->{'url'}";
1103 &updatewebsite($website);
1105 Updates an existing web site. C<$website> is a reference-to-hash with
1106 the keys C<websitenumber>, C<title>, C<description>, and C<url>. All
1107 of these are mandatory. C<$website-E<gt>{websitenumber}> identifies
1108 the entry to update.
1114 my $dbh = C4::Context->dbh;
1117 $website->{'title'} = $dbh->quote($website->{'title'});
1118 $website->{'description'} = $dbh->quote($website->{'description'});
1119 $website->{'url'} = $dbh->quote($website->{'url'});
1121 $query = "Update websites set
1122 title = $website->{'title'},
1123 description = $website->{'description'},
1124 url = $website->{'url'}
1125 where websitenumber = $website->{'websitenumber'}";
1128 } # sub updatewebsite
1132 &deletewebsite($websitenumber);
1134 Deletes the web site with number C<$websitenumber>.
1139 my ($websitenumber) = @_;
1140 my $dbh = C4::Context->dbh;
1141 # FIXME - $query is unneeded
1142 my $query = "Delete from websites where websitenumber = $websitenumber";
1145 } # sub deletewebsite
1147 END { } # module clean-up code here (global destructor)
1156 Koha Developement team <info@koha.org>