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,$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 biblio.biblionumber=aqorders.biblionumber
598 and ((datecancellationprinted is NULL)
599 or (datecancellationprinted = '0000-00-00'))
601 my @data = split(' ',$search);
603 for (my $i = 0; $i < $count; $i++) {
604 $query .= "(biblio.title like '$data[$i]%' or biblio.title like '% $data[$i]%') and ";
607 # FIXME - Redo this properly instead of hacking off the
609 $query.=" ) or biblioitems.isbn='$search' or (aqorders.ordernumber='$search' and aqorders.biblionumber='$biblio')) ";
610 if ($catview ne 'yes'){
611 $query.=" and (quantityreceived < quantity or quantityreceived is NULL)";
613 $query.=" group by aqorders.ordernumber";
614 my $sth=$dbh->prepare($query);
618 while (my $data=$sth->fetchrow_hashref){
619 my $sth2=$dbh->prepare("Select * from biblio where biblionumber=?");
620 $sth2->execute($data->{'biblionumber'});
621 my $data2=$sth2->fetchrow_hashref;
623 $data->{'author'}=$data2->{'author'};
624 $data->{'seriestitle'}=$data2->{'seriestitle'};
625 $sth2=$dbh->prepare("Select * from aqorderbreakdown where ordernumber=?");
626 $sth2->execute($data->{'ordernumber'});
627 $data2=$sth2->fetchrow_hashref;
629 $data->{'branchcode'}=$data2->{'branchcode'};
630 $data->{'bookfundid'}=$data2->{'bookfundid'};
645 ($count, @results) = &invoice($booksellerinvoicenumber);
647 Looks up orders by invoice number.
649 Returns an array. C<$count> is the number of elements in C<@results>.
650 C<@results> is an array of references-to-hash; the keys of each
651 elements are fields from the aqorders, biblio, and biblioitems tables
652 of the Koha database.
658 my $dbh = C4::Context->dbh;
659 my $query="Select * from aqorders,biblio,biblioitems where
660 booksellerinvoicenumber='$invoice'
661 and biblio.biblionumber=aqorders.biblionumber and biblioitems.biblioitemnumber=
662 aqorders.biblioitemnumber group by aqorders.ordernumber,aqorders.biblioitemnumber";
665 my $sth=$dbh->prepare($query);
667 while (my $data=$sth->fetchrow_hashref){
677 ($count, @results) = &bookfunds();
679 Returns a list of all book funds.
681 C<$count> is the number of elements in C<@results>. C<@results> is an
682 array of references-to-hash, whose keys are fields from the aqbookfund
683 and aqbudget tables of the Koha database. Results are ordered
684 alphabetically by book fund name.
689 my $dbh = C4::Context->dbh;
690 my $query="Select * from aqbookfund,aqbudget where aqbookfund.bookfundid
692 group by aqbookfund.bookfundid order by bookfundname";
693 my $sth=$dbh->prepare($query);
697 while (my $data=$sth->fetchrow_hashref){
705 # FIXME - POD. I can't figure out what this function is doing. Then
706 # again, I don't think it's being used (anymore).
707 sub bookfundbreakdown {
709 my $dbh = C4::Context->dbh;
710 my $query="Select quantity,datereceived,freight,unitprice,listprice,ecost,quantityreceived,subscription
711 from aqorders,aqorderbreakdown where bookfundid='$id' and
712 aqorders.ordernumber=aqorderbreakdown.ordernumber
713 and (datecancellationprinted is NULL or
714 datecancellationprinted='0000-00-00')";
715 my $sth=$dbh->prepare($query);
719 while (my $data=$sth->fetchrow_hashref){
720 if ($data->{'subscription'} == 1){
721 $spent+=$data->{'quantity'}*$data->{'unitprice'};
723 my $leftover=$data->{'quantity'}-$data->{'quantityreceived'};
724 $comtd+=($data->{'ecost'})*$leftover;
725 $spent+=($data->{'unitprice'})*$data->{'quantityreceived'};
729 return($spent,$comtd);
734 $foreignprice = &curconvert($currency, $localprice);
736 Converts the price C<$localprice> to foreign currency C<$currency> by
737 dividing by the exchange rate, and returns the result.
739 If no exchange rate is found, C<&curconvert> assumes the rate is one
745 my ($currency,$price)=@_;
746 my $dbh = C4::Context->dbh;
747 my $query="Select rate from currency where currency='$currency'";
748 my $sth=$dbh->prepare($query);
750 my $data=$sth->fetchrow_hashref;
752 my $cur=$data->{'rate'};
756 return($price / $cur);
761 ($count, $currencies) = &getcurrencies();
763 Returns the list of all known currencies.
765 C<$count> is the number of elements in C<$currencies>. C<$currencies>
766 is a reference-to-array; its elements are references-to-hash, whose
767 keys are the fields from the currency table in the Koha database.
772 my $dbh = C4::Context->dbh;
773 my $query="Select * from currency";
774 my $sth=$dbh->prepare($query);
778 while (my $data=$sth->fetchrow_hashref){
783 return($i,\@results);
786 =item updatecurrencies
788 &updatecurrencies($currency, $newrate);
790 Sets the exchange rate for C<$currency> to be C<$newrate>.
794 sub updatecurrencies {
795 my ($currency,$rate)=@_;
796 my $dbh = C4::Context->dbh;
797 my $query="update currency set rate=$rate where currency='$currency'";
798 my $sth=$dbh->prepare($query);
803 # FIXME - This is never used
805 my($price,$rrp,$itemnum)=@_;
806 my $dbh = C4::Context->dbh;
807 my $query="update items set price='$price',replacementprice='$rrp'
808 where itemnumber=$itemnum";
809 my $sth=$dbh->prepare($query);
822 ($count, @results) = &bookseller($searchstring);
824 Looks up a book seller. C<$searchstring> may be either a book seller
825 ID, or a string to look for in the book seller's name.
827 C<$count> is the number of elements in C<@results>. C<@results> is an
828 array of references-to-hash, whose keys are the fields of of the
829 aqbooksellers table in the Koha database.
834 my ($searchstring)=@_;
835 my $dbh = C4::Context->dbh;
836 my $query="Select * from aqbooksellers where name like '%$searchstring%' or
837 id = '$searchstring'";
838 my $sth=$dbh->prepare($query);
842 while (my $data=$sth->fetchrow_hashref){
852 ($count, $results) = &breakdown($ordernumber);
854 Looks up an order by order ID, and returns its breakdown.
856 C<$count> is the number of elements in C<$results>. C<$results> is a
857 reference-to-array; its elements are references-to-hash, whose keys
858 are the fields of the aqorderbreakdown table in the Koha database.
864 my $dbh = C4::Context->dbh;
865 my $query="Select * from aqorderbreakdown where ordernumber='$id'";
866 my $sth=$dbh->prepare($query);
870 while (my $data=$sth->fetchrow_hashref){
875 return($i,\@results);
880 ($count, @results) = &branches();
882 Returns a list of all library branches.
884 C<$count> is the number of elements in C<@results>. C<@results> is an
885 array of references-to-hash, whose keys are the fields of the branches
886 table of the Koha database.
891 my $dbh = C4::Context->dbh;
892 my $query = "Select * from branches";
893 my $sth = $dbh->prepare($query);
898 while (my $data = $sth->fetchrow_hashref) {
899 $results[$i] = $data;
904 return($i, @results);
909 my ($biblionumber)=@_;
910 my $dbh = C4::Context->dbh;
911 my $query="Select * from biblioitems,items,itemtypes where
912 biblioitems.biblionumber=$biblionumber
913 and biblioitems.biblioitemnumber=items.biblioitemnumber and
914 itemtypes.itemtype=biblioitems.itemtype
915 order by items.biblioitemnumber";
916 my $sth=$dbh->prepare($query);
920 while (my $data=$sth->fetchrow_hashref){
930 my ($bibitemnum,$itemtype)=@_;
931 my $dbh = C4::Context->dbh;
932 my $query="Select * from biblioitems where biblioitemnumber=$bibitemnum
933 and itemtype='$itemtype'";
934 my $sth=$dbh->prepare($query);
937 if (my $data=$sth->fetchrow_hashref){
946 &updatesup($bookseller);
948 Updates the information for a given bookseller. C<$bookseller> is a
949 reference-to-hash whose keys are the fields of the aqbooksellers table
950 in the Koha database. It must contain entries for all of the fields.
951 The entry to modify is determined by C<$bookseller-E<gt>{id}>.
953 The easiest way to get all of the necessary fields is to look up a
954 book seller with C<&booksellers>, modify what's necessary, then call
955 C<&updatesup> with the result.
961 my $dbh = C4::Context->dbh;
962 my $query="Update aqbooksellers set
963 name='$data->{'name'}',address1='$data->{'address1'}',address2='$data->{'address2'}',
964 address3='$data->{'address3'}',address4='$data->{'address4'}',postal='$data->{'postal'}',
965 phone='$data->{'phone'}',fax='$data->{'fax'}',url='$data->{'url'}',
966 contact='$data->{'contact'}',contpos='$data->{'contpos'}',
967 contphone='$data->{'contphone'}', contfax='$data->{'contfax'}', contaltphone=
968 '$data->{'contaltphone'}', contemail='$data->{'contemail'}', contnotes=
969 '$data->{'contnotes'}', active=$data->{'active'},
970 listprice='$data->{'listprice'}', invoiceprice='$data->{'invoiceprice'}',
971 gstreg=$data->{'gstreg'}, listincgst=$data->{'listincgst'},
972 invoiceincgst=$data->{'invoiceincgst'}, specialty='$data->{'specialty'}',
973 discount='$data->{'discount'}',invoicedisc='$data->{'invoicedisc'}',
974 nocalc='$data->{'nocalc'}'
975 where id='$data->{'id'}'";
976 my $sth=$dbh->prepare($query);
984 $id = &insertsup($bookseller);
986 Creates a new bookseller. C<$bookseller> is a reference-to-hash whose
987 keys are the fields of the aqbooksellers table in the Koha database.
988 All fields must be present.
990 Returns the ID of the newly-created bookseller.
996 my $dbh = C4::Context->dbh;
997 my $sth=$dbh->prepare("Select max(id) from aqbooksellers");
999 my $data2=$sth->fetchrow_hashref;
1001 $data2->{'max(id)'}++;
1002 $sth=$dbh->prepare("Insert into aqbooksellers (id) values ($data2->{'max(id)'})");
1005 $data->{'id'}=$data2->{'max(id)'};
1007 return($data->{'id'});
1012 ($count, @results) = &websitesearch($keywordlist);
1014 Looks up biblioitems by URL.
1016 C<$keywordlist> is a space-separated list of search terms.
1017 C<&websitesearch> returns those biblioitems whose URL contains at
1018 least one of the search terms.
1020 C<$count> is the number of elements in C<@results>. C<@results> is an
1021 array of references-to-hash, whose keys are the fields of the biblio
1022 and biblioitems tables in the Koha database.
1027 my ($keywordlist) = @_;
1028 my $dbh = C4::Context->dbh;
1029 my $query = "Select distinct biblio.* from biblio, biblioitems where
1030 biblio.biblionumber = biblioitems.biblionumber and (";
1034 my @keywords = split(/ +/, $keywordlist);
1035 my $keyword = shift(@keywords);
1038 # $query .= join(" and ",
1039 # apply { url like "%$_%" } @keywords
1041 $keyword =~ s/%/\\%/g;
1042 $keyword =~ s/_/\\_/;
1043 $keyword = "%" . $keyword . "%";
1044 $keyword = $dbh->quote($keyword);
1045 $query .= " (url like $keyword)";
1047 foreach $keyword (@keywords) {
1048 $keyword =~ s/%/\\%/;
1049 $keyword =~ s/_/\\_/;
1050 $keyword = "%" . $keyword . "%";
1051 $keyword = $dbh->quote($keyword);
1052 $query .= " or (url like $keyword)";
1056 $sth = $dbh->prepare($query);
1059 while (my $data = $sth->fetchrow_hashref) {
1060 $results[$count] = $data;
1065 return($count, @results);
1066 } # sub websitesearch
1070 &addwebsite($website);
1072 Adds a new web site. C<$website> is a reference-to-hash, with the keys
1073 C<biblionumber>, C<title>, C<description>, and C<url>. All of these
1080 my $dbh = C4::Context->dbh;
1084 # for (qw( biblionumber title description url )) # and any others
1086 # $website->{$_} = $dbh->quote($_);
1088 # Perhaps extend this to building the query as well. This might allow
1089 # some of the fields to be optional.
1090 $website->{'biblionumber'} = $dbh->quote($website->{'biblionumber'});
1091 $website->{'title'} = $dbh->quote($website->{'title'});
1092 $website->{'description'} = $dbh->quote($website->{'description'});
1093 $website->{'url'} = $dbh->quote($website->{'url'});
1095 $query = "Insert into websites set
1096 biblionumber = $website->{'biblionumber'},
1097 title = $website->{'title'},
1098 description = $website->{'description'},
1099 url = $website->{'url'}";
1106 &updatewebsite($website);
1108 Updates an existing web site. C<$website> is a reference-to-hash with
1109 the keys C<websitenumber>, C<title>, C<description>, and C<url>. All
1110 of these are mandatory. C<$website-E<gt>{websitenumber}> identifies
1111 the entry to update.
1117 my $dbh = C4::Context->dbh;
1120 $website->{'title'} = $dbh->quote($website->{'title'});
1121 $website->{'description'} = $dbh->quote($website->{'description'});
1122 $website->{'url'} = $dbh->quote($website->{'url'});
1124 $query = "Update websites set
1125 title = $website->{'title'},
1126 description = $website->{'description'},
1127 url = $website->{'url'}
1128 where websitenumber = $website->{'websitenumber'}";
1131 } # sub updatewebsite
1135 &deletewebsite($websitenumber);
1137 Deletes the web site with number C<$websitenumber>.
1142 my ($websitenumber) = @_;
1143 my $dbh = C4::Context->dbh;
1144 # FIXME - $query is unneeded
1145 my $query = "Delete from websites where websitenumber = $websitenumber";
1148 } # sub deletewebsite
1150 END { } # module clean-up code here (global destructor)
1159 Koha Developement team <info@koha.org>