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);
277 $query="update aqorderbreakdown set bookfundid=$bookfund where
278 ordernumber=$ordnum";
279 $sth=$dbh->prepare($query);
287 $order = &newordernum();
289 Finds the next unused order number in the aqorders table of the Koha
290 database, and returns it.
294 # FIXME - Race condition
296 my $dbh = C4::Context->dbh;
297 my $query="Select max(ordernumber) from aqorders";
298 my $sth=$dbh->prepare($query);
300 my $data=$sth->fetchrow_arrayref;
301 my $ordnum=$$data[0];
309 &receiveorder($biblionumber, $ordernumber, $quantityreceived, $user,
310 $unitprice, $booksellerinvoicenumber, $biblioitemnumber,
311 $freight, $bookfund, $rrp);
313 Updates an order, to reflect the fact that it was received, at least
314 in part. All arguments not mentioned below update the fields with the
315 same name in the aqorders table of the Koha database.
317 Updates the order with bibilionumber C<$biblionumber> and ordernumber
320 Also updates the book fund ID in the aqorderbreakdown table.
325 my ($biblio,$ordnum,$quantrec,$user,$cost,$invoiceno,$bibitemno,$freight,$bookfund,$rrp)=@_;
326 my $dbh = C4::Context->dbh;
327 my $query="update aqorders set quantityreceived='$quantrec',
328 datereceived=now(),booksellerinvoicenumber='$invoiceno',
329 biblioitemnumber=$bibitemno,unitprice='$cost',freight='$freight',
331 where biblionumber=$biblio and ordernumber=$ordnum
334 my $sth=$dbh->prepare($query);
337 $query="update aqorderbreakdown set bookfundid=$bookfund where
338 ordernumber=$ordnum";
339 $sth=$dbh->prepare($query);
347 &updaterecorder($biblionumber, $ordernumber, $user, $unitprice,
350 Updates the order with biblionumber C<$biblionumber> and order number
351 C<$ordernumber>. C<$bookfundid> is the new value for the book fund ID
352 in the aqorderbreakdown table of the Koha database. All other
353 arguments update the fields with the same name in the aqorders table.
360 my($biblio,$ordnum,$user,$cost,$bookfund,$rrp)=@_;
361 my $dbh = C4::Context->dbh;
362 my $query="update aqorders set
363 unitprice='$cost', rrp='$rrp'
364 where biblionumber=$biblio and ordernumber=$ordnum
367 my $sth=$dbh->prepare($query);
370 $query="update aqorderbreakdown set bookfundid=$bookfund where
371 ordernumber=$ordnum";
372 $sth=$dbh->prepare($query);
386 ($count, $orders) = &getorders($booksellerid);
388 Finds pending orders from the bookseller with the given ID. Ignores
389 completed and cancelled orders.
391 C<$count> is the number of elements in C<@{$orders}>.
393 C<$orders> is a reference-to-array; each element is a
394 reference-to-hash with the following fields:
400 Gives the number of orders in with this basket number.
402 =item C<authorizedby>
408 These give the value of the corresponding field in the aqorders table
409 of the Koha database.
413 Results are ordered from most to least recent.
419 my $dbh = C4::Context->dbh;
420 my $query = "Select count(*),authorisedby,entrydate,basketno from aqorders where
421 booksellerid='$supplierid' and (quantity > quantityreceived or
422 quantityreceived is NULL)
423 and (datecancellationprinted is NULL or datecancellationprinted = '0000-00-00')";
424 $query.=" group by basketno order by entrydate desc";
426 my $sth=$dbh->prepare($query);
430 while (my $data=$sth->fetchrow_hashref){
435 return ($i,\@results);
440 ($order, $ordernumber) = &getorder($biblioitemnumber, $biblionumber);
442 Looks up the order with the given biblionumber and biblioitemnumber.
444 Returns a two-element array. C<$ordernumber> is the order number.
445 C<$order> is a reference-to-hash describing the order; its keys are
446 fields from the biblio, biblioitems, aqorders, and aqorderbreakdown
447 tables of the Koha database.
451 # FIXME - This is effectively identical to &C4::Biblio::getorder.
452 # Pick one and stick with it.
455 my $dbh = C4::Context->dbh;
456 my $query="Select ordernumber from aqorders where biblionumber=$bib and
457 biblioitemnumber='$bi'";
458 my $sth=$dbh->prepare($query);
460 # FIXME - Use fetchrow_array(), since we're only interested in the one
462 my $ordnum=$sth->fetchrow_hashref;
464 my $order=getsingleorder($ordnum->{'ordernumber'});
466 return ($order,$ordnum->{'ordernumber'});
471 $order = &getsingleorder($ordernumber);
473 Looks up an order by order number.
475 Returns a reference-to-hash describing the order. The keys of
476 C<$order> are fields from the biblio, biblioitems, aqorders, and
477 aqorderbreakdown tables of the Koha database.
481 # FIXME - This is effectively identical to
482 # &C4::Biblio::getsingleorder.
483 # Pick one and stick with it.
486 my $dbh = C4::Context->dbh;
487 my $query="Select * from biblio,biblioitems,aqorders,aqorderbreakdown
488 where aqorders.ordernumber='$ordnum'
489 and biblio.biblionumber=aqorders.biblionumber and
490 biblioitems.biblioitemnumber=aqorders.biblioitemnumber and
491 aqorders.ordernumber=aqorderbreakdown.ordernumber";
492 my $sth=$dbh->prepare($query);
494 my $data=$sth->fetchrow_hashref;
501 ($count, @results) = &getallorders($booksellerid);
503 Looks up all of the pending orders from the supplier with the given
504 bookseller ID. Ignores cancelled and completed orders.
506 C<$count> is the number of elements in C<@results>. C<@results> is an
507 array of references-to-hash. The keys of each element are fields from
508 the aqorders, biblio, and biblioitems tables of the Koha database.
510 C<@results> is sorted alphabetically by book title.
515 #gets all orders from a certain supplier, orders them alphabetically
517 my $dbh = C4::Context->dbh;
518 my $query="Select * from aqorders,biblio,biblioitems where booksellerid='$supid'
519 and (cancelledby is NULL or cancelledby = '')
520 and (quantityreceived < quantity or quantityreceived is NULL)
521 and biblio.biblionumber=aqorders.biblionumber and biblioitems.biblioitemnumber=
522 aqorders.biblioitemnumber
523 group by aqorders.biblioitemnumber
528 my $sth=$dbh->prepare($query);
530 while (my $data=$sth->fetchrow_hashref){
540 #gets all orders from a certain supplier, orders them alphabetically
542 my $dbh = C4::Context->dbh;
543 my $query="Select * from aqorders,biblio,biblioitems where booksellerid='$supid'
544 and (cancelledby is NULL or cancelledby = '')
545 and biblio.biblionumber=aqorders.biblionumber and biblioitems.biblioitemnumber=
546 aqorders.biblioitemnumber and
547 aqorders.quantityreceived>0
548 and aqorders.datereceived >=now()
549 group by aqorders.biblioitemnumber
554 my $sth=$dbh->prepare($query);
556 while (my $data=$sth->fetchrow_hashref){
566 ($count, @results) = &ordersearch($search, $biblionumber, $complete);
570 C<$search> may take one of several forms: if it is an ISBN,
571 C<&ordersearch> returns orders with that ISBN. If C<$search> is an
572 order number, C<&ordersearch> returns orders with that order number
573 and biblionumber C<$biblionumber>. Otherwise, C<$search> is considered
574 to be a space-separated list of search terms; in this case, all of the
575 terms must appear in the title (matching the beginning of title
578 If C<$complete> is C<yes>, the results will include only completed
579 orders. In any case, C<&ordersearch> ignores cancelled orders.
581 C<&ordersearch> returns an array. C<$count> is the number of elements
582 in C<@results>. C<@results> is an array of references-to-hash with the
600 my ($search,$biblio,$catview) = @_;
601 my $dbh = C4::Context->dbh;
602 my $query = "Select *,biblio.title from aqorders,biblioitems,biblio
603 where aqorders.biblioitemnumber = biblioitems.biblioitemnumber
604 and biblio.biblionumber=aqorders.biblionumber
605 and ((datecancellationprinted is NULL)
606 or (datecancellationprinted = '0000-00-00'))
608 my @data = split(' ',$search);
610 for (my $i = 0; $i < $count; $i++) {
611 $query .= "(biblio.title like '$data[$i]%' or biblio.title like '% $data[$i]%') and ";
614 # FIXME - Redo this properly instead of hacking off the
616 $query.=" ) or biblioitems.isbn='$search'
617 or (aqorders.ordernumber='$search' and aqorders.biblionumber='$biblio')) ";
618 if ($catview ne 'yes'){
619 $query.=" and (quantityreceived < quantity or quantityreceived is NULL)";
621 $query.=" group by aqorders.ordernumber";
622 my $sth=$dbh->prepare($query);
626 while (my $data=$sth->fetchrow_hashref){
627 my $sth2=$dbh->prepare("Select * from biblio where
628 biblionumber='$data->{'biblionumber'}'");
630 my $data2=$sth2->fetchrow_hashref;
632 $data->{'author'}=$data2->{'author'};
633 $data->{'seriestitle'}=$data2->{'seriestitle'};
634 $sth2=$dbh->prepare("Select * from aqorderbreakdown where
635 ordernumber=$data->{'ordernumber'}");
637 $data2=$sth2->fetchrow_hashref;
639 $data->{'branchcode'}=$data2->{'branchcode'};
640 $data->{'bookfundid'}=$data2->{'bookfundid'};
655 ($count, @results) = &invoice($booksellerinvoicenumber);
657 Looks up orders by invoice number.
659 Returns an array. C<$count> is the number of elements in C<@results>.
660 C<@results> is an array of references-to-hash; the keys of each
661 elements are fields from the aqorders, biblio, and biblioitems tables
662 of the Koha database.
668 my $dbh = C4::Context->dbh;
669 my $query="Select * from aqorders,biblio,biblioitems where
670 booksellerinvoicenumber='$invoice'
671 and biblio.biblionumber=aqorders.biblionumber and biblioitems.biblioitemnumber=
672 aqorders.biblioitemnumber group by aqorders.ordernumber,aqorders.biblioitemnumber";
675 my $sth=$dbh->prepare($query);
677 while (my $data=$sth->fetchrow_hashref){
687 ($count, @results) = &bookfunds();
689 Returns a list of all book funds.
691 C<$count> is the number of elements in C<@results>. C<@results> is an
692 array of references-to-hash, whose keys are fields from the aqbookfund
693 and aqbudget tables of the Koha database. Results are ordered
694 alphabetically by book fund name.
699 my $dbh = C4::Context->dbh;
700 my $query="Select * from aqbookfund,aqbudget where aqbookfund.bookfundid
702 group by aqbookfund.bookfundid order by bookfundname";
703 my $sth=$dbh->prepare($query);
707 while (my $data=$sth->fetchrow_hashref){
715 # FIXME - POD. I can't figure out what this function is doing. Then
716 # again, I don't think it's being used (anymore).
717 sub bookfundbreakdown {
719 my $dbh = C4::Context->dbh;
720 my $query="Select quantity,datereceived,freight,unitprice,listprice,ecost,quantityreceived,subscription
721 from aqorders,aqorderbreakdown where bookfundid='$id' and
722 aqorders.ordernumber=aqorderbreakdown.ordernumber
723 and (datecancellationprinted is NULL or
724 datecancellationprinted='0000-00-00')";
725 my $sth=$dbh->prepare($query);
729 while (my $data=$sth->fetchrow_hashref){
730 if ($data->{'subscription'} == 1){
731 $spent+=$data->{'quantity'}*$data->{'unitprice'};
733 my $leftover=$data->{'quantity'}-$data->{'quantityreceived'};
734 $comtd+=($data->{'ecost'})*$leftover;
735 $spent+=($data->{'unitprice'})*$data->{'quantityreceived'};
739 return($spent,$comtd);
744 $foreignprice = &curconvert($currency, $localprice);
746 Converts the price C<$localprice> to foreign currency C<$currency> by
747 dividing by the exchange rate, and returns the result.
749 If no exchange rate is found, C<&curconvert> assumes the rate is one
755 my ($currency,$price)=@_;
756 my $dbh = C4::Context->dbh;
757 my $query="Select rate from currency where currency='$currency'";
758 my $sth=$dbh->prepare($query);
760 my $data=$sth->fetchrow_hashref;
762 my $cur=$data->{'rate'};
766 return($price / $cur);
771 ($count, $currencies) = &getcurrencies();
773 Returns the list of all known currencies.
775 C<$count> is the number of elements in C<$currencies>. C<$currencies>
776 is a reference-to-array; its elements are references-to-hash, whose
777 keys are the fields from the currency table in the Koha database.
782 my $dbh = C4::Context->dbh;
783 my $query="Select * from currency";
784 my $sth=$dbh->prepare($query);
788 while (my $data=$sth->fetchrow_hashref){
793 return($i,\@results);
799 my $dbh = C4::Context->dbh;
800 my $query="Select * from currency where currency='$cur'";
801 my $sth=$dbh->prepare($query);
804 my $data=$sth->fetchrow_hashref;
809 =item updatecurrencies
811 &updatecurrencies($currency, $newrate);
813 Sets the exchange rate for C<$currency> to be C<$newrate>.
817 sub updatecurrencies {
818 my ($currency,$rate)=@_;
819 my $dbh = C4::Context->dbh;
820 my $query="update currency set rate=$rate where currency='$currency'";
821 my $sth=$dbh->prepare($query);
826 # FIXME - This is never used
828 my($price,$rrp,$itemnum)=@_;
829 my $dbh = C4::Context->dbh;
830 my $query="update items set price='$price',replacementprice='$rrp'
831 where itemnumber=$itemnum";
832 my $sth=$dbh->prepare($query);
845 ($count, @results) = &bookseller($searchstring);
847 Looks up a book seller. C<$searchstring> may be either a book seller
848 ID, or a string to look for in the book seller's name.
850 C<$count> is the number of elements in C<@results>. C<@results> is an
851 array of references-to-hash, whose keys are the fields of of the
852 aqbooksellers table in the Koha database.
857 my ($searchstring)=@_;
858 my $dbh = C4::Context->dbh;
859 my $query="Select * from aqbooksellers where name like '%$searchstring%' or
860 id = '$searchstring'";
861 my $sth=$dbh->prepare($query);
865 while (my $data=$sth->fetchrow_hashref){
875 ($count, $results) = &breakdown($ordernumber);
877 Looks up an order by order ID, and returns its breakdown.
879 C<$count> is the number of elements in C<$results>. C<$results> is a
880 reference-to-array; its elements are references-to-hash, whose keys
881 are the fields of the aqorderbreakdown table in the Koha database.
887 my $dbh = C4::Context->dbh;
888 my $query="Select * from aqorderbreakdown where ordernumber='$id'";
889 my $sth=$dbh->prepare($query);
893 while (my $data=$sth->fetchrow_hashref){
898 return($i,\@results);
903 ($count, @results) = &branches();
905 Returns a list of all library branches.
907 C<$count> is the number of elements in C<@results>. C<@results> is an
908 array of references-to-hash, whose keys are the fields of the branches
909 table of the Koha database.
914 my $dbh = C4::Context->dbh;
915 my $query = "Select * from branches";
916 my $sth = $dbh->prepare($query);
921 while (my $data = $sth->fetchrow_hashref) {
922 $results[$i] = $data;
927 return($i, @results);
932 my ($biblionumber)=@_;
933 my $dbh = C4::Context->dbh;
934 my $query="Select * from biblioitems,items,itemtypes where
935 biblioitems.biblionumber=$biblionumber
936 and biblioitems.biblioitemnumber=items.biblioitemnumber and
937 itemtypes.itemtype=biblioitems.itemtype
938 order by items.biblioitemnumber";
939 my $sth=$dbh->prepare($query);
943 while (my $data=$sth->fetchrow_hashref){
953 my ($bibitemnum,$itemtype)=@_;
954 my $dbh = C4::Context->dbh;
955 my $query="Select * from biblioitems where biblioitemnumber=$bibitemnum
956 and itemtype='$itemtype'";
957 my $sth=$dbh->prepare($query);
960 if (my $data=$sth->fetchrow_hashref){
969 &updatesup($bookseller);
971 Updates the information for a given bookseller. C<$bookseller> is a
972 reference-to-hash whose keys are the fields of the aqbooksellers table
973 in the Koha database. It must contain entries for all of the fields.
974 The entry to modify is determined by C<$bookseller-E<gt>{id}>.
976 The easiest way to get all of the necessary fields is to look up a
977 book seller with C<&booksellers>, modify what's necessary, then call
978 C<&updatesup> with the result.
984 my $dbh = C4::Context->dbh;
985 my $query="Update aqbooksellers set
986 name='$data->{'name'}',address1='$data->{'address1'}',address2='$data->{'address2'}',
987 address3='$data->{'address3'}',address4='$data->{'address4'}',postal='$data->{'postal'}',
988 phone='$data->{'phone'}',fax='$data->{'fax'}',url='$data->{'url'}',
989 contact='$data->{'contact'}',contpos='$data->{'contpos'}',
990 contphone='$data->{'contphone'}', contfax='$data->{'contfax'}', contaltphone=
991 '$data->{'contaltphone'}', contemail='$data->{'contemail'}', contnotes=
992 '$data->{'contnotes'}', active=$data->{'active'},
993 listprice='$data->{'listprice'}', invoiceprice='$data->{'invoiceprice'}',
994 gstreg=$data->{'gstreg'}, listincgst=$data->{'listincgst'},
995 invoiceincgst=$data->{'invoiceincgst'}, specialty='$data->{'specialty'}',
996 discount='$data->{'discount'}',invoicedisc='$data->{'invoicedisc'}',
997 nocalc='$data->{'nocalc'}'
998 where id='$data->{'id'}'";
999 my $sth=$dbh->prepare($query);
1007 $id = &insertsup($bookseller);
1009 Creates a new bookseller. C<$bookseller> is a reference-to-hash whose
1010 keys are the fields of the aqbooksellers table in the Koha database.
1011 All fields must be present.
1013 Returns the ID of the newly-created bookseller.
1019 my $dbh = C4::Context->dbh;
1020 my $sth=$dbh->prepare("Select max(id) from aqbooksellers");
1022 my $data2=$sth->fetchrow_hashref;
1024 $data2->{'max(id)'}++;
1025 $sth=$dbh->prepare("Insert into aqbooksellers (id) values ($data2->{'max(id)'})");
1028 $data->{'id'}=$data2->{'max(id)'};
1030 return($data->{'id'});
1035 ($count, @results) = &websitesearch($keywordlist);
1037 Looks up biblioitems by URL.
1039 C<$keywordlist> is a space-separated list of search terms.
1040 C<&websitesearch> returns those biblioitems whose URL contains at
1041 least one of the search terms.
1043 C<$count> is the number of elements in C<@results>. C<@results> is an
1044 array of references-to-hash, whose keys are the fields of the biblio
1045 and biblioitems tables in the Koha database.
1050 my ($keywordlist) = @_;
1051 my $dbh = C4::Context->dbh;
1052 my $query = "Select distinct biblio.* from biblio, biblioitems where
1053 biblio.biblionumber = biblioitems.biblionumber and (";
1057 my @keywords = split(/ +/, $keywordlist);
1058 my $keyword = shift(@keywords);
1061 # $query .= join(" and ",
1062 # apply { url like "%$_%" } @keywords
1064 $keyword =~ s/%/\\%/g;
1065 $keyword =~ s/_/\\_/;
1066 $keyword = "%" . $keyword . "%";
1067 $keyword = $dbh->quote($keyword);
1068 $query .= " (url like $keyword)";
1070 foreach $keyword (@keywords) {
1071 $keyword =~ s/%/\\%/;
1072 $keyword =~ s/_/\\_/;
1073 $keyword = "%" . $keyword . "%";
1074 $keyword = $dbh->quote($keyword);
1075 $query .= " or (url like $keyword)";
1079 $sth = $dbh->prepare($query);
1082 while (my $data = $sth->fetchrow_hashref) {
1083 $results[$count] = $data;
1088 return($count, @results);
1089 } # sub websitesearch
1093 &addwebsite($website);
1095 Adds a new web site. C<$website> is a reference-to-hash, with the keys
1096 C<biblionumber>, C<title>, C<description>, and C<url>. All of these
1103 my $dbh = C4::Context->dbh;
1107 # for (qw( biblionumber title description url )) # and any others
1109 # $website->{$_} = $dbh->quote($_);
1111 # Perhaps extend this to building the query as well. This might allow
1112 # some of the fields to be optional.
1113 $website->{'biblionumber'} = $dbh->quote($website->{'biblionumber'});
1114 $website->{'title'} = $dbh->quote($website->{'title'});
1115 $website->{'description'} = $dbh->quote($website->{'description'});
1116 $website->{'url'} = $dbh->quote($website->{'url'});
1118 $query = "Insert into websites set
1119 biblionumber = $website->{'biblionumber'},
1120 title = $website->{'title'},
1121 description = $website->{'description'},
1122 url = $website->{'url'}";
1129 &updatewebsite($website);
1131 Updates an existing web site. C<$website> is a reference-to-hash with
1132 the keys C<websitenumber>, C<title>, C<description>, and C<url>. All
1133 of these are mandatory. C<$website-E<gt>{websitenumber}> identifies
1134 the entry to update.
1140 my $dbh = C4::Context->dbh;
1143 $website->{'title'} = $dbh->quote($website->{'title'});
1144 $website->{'description'} = $dbh->quote($website->{'description'});
1145 $website->{'url'} = $dbh->quote($website->{'url'});
1147 $query = "Update websites set
1148 title = $website->{'title'},
1149 description = $website->{'description'},
1150 url = $website->{'url'}
1151 where websitenumber = $website->{'websitenumber'}";
1154 } # sub updatewebsite
1158 &deletewebsite($websitenumber);
1160 Deletes the web site with number C<$websitenumber>.
1165 my ($websitenumber) = @_;
1166 my $dbh = C4::Context->dbh;
1167 # FIXME - $query is unneeded
1168 my $query = "Delete from websites where websitenumber = $websitenumber";
1171 } # sub deletewebsite
1173 END { } # module clean-up code here (global destructor)
1182 Koha Developement team <info@koha.org>