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 $sth=$dbh->prepare("Select *,biblio.title from aqorders,biblio,biblioitems
103 and biblio.biblionumber=aqorders.biblionumber and biblioitems.biblioitemnumber
104 =aqorders.biblioitemnumber
105 and (datecancellationprinted is NULL or datecancellationprinted =
107 .(($supplier ne '')?" and aqorders.booksellerid=?":"")
108 ." group by aqorders.ordernumber");
109 if ($supplier ne '') {
110 $sth->execute($basketno,$supplier);
112 $sth->execute($basketno);
115 while (my $data=$sth->fetchrow_hashref){
116 push(@results,$data);
119 return(scalar(@results),@results);
124 $basket = &newbasket();
126 Finds the next unused basket number in the aqorders table of the Koha
127 database, and returns it.
131 # FIXME - There's a race condition here:
133 # B calls &newbasket (gets the same number as A)
134 # A updates the basket
135 # B updates the basket, and clobbers A's result.
136 # A better approach might be to create a dummy order (with, say,
137 # requisitionedby == "Dummy-$$" or notes == "dummy <time> <pid>"), and
138 # see which basket number it gets. Then have a cron job periodically
139 # remove out-of-date dummy orders.
141 my $dbh = C4::Context->dbh;
142 my $sth=$dbh->prepare("Select max(basketno) from aqorders");
144 my $data=$sth->fetchrow_arrayref;
145 my $basket=$$data[0];
153 &neworder($biblionumber, $title, $ordnum, $basket, $quantity, $listprice,
154 $booksellerid, $who, $notes, $bookfund, $biblioitemnumber, $rrp,
155 $ecost, $gst, $budget, $unitprice, $subscription,
156 $booksellerinvoicenumber);
158 Adds a new order to the database. Any argument that isn't described
159 below is the new value of the field with the same name in the aqorders
160 table of the Koha database.
162 C<$ordnum> is a "minimum order number." After adding the new entry to
163 the aqorders table, C<&neworder> finds the first entry in aqorders
164 with order number greater than or equal to C<$ordnum>, and adds an
165 entry to the aqorderbreakdown table, with the order number just found,
166 and the book fund ID of the newly-added order.
168 C<$budget> is effectively ignored.
170 C<$subscription> may be either "yes", or anything else for "no".
175 my ($bibnum,$title,$ordnum,$basket,$quantity,$listprice,$supplier,$who,$notes,$bookfund,$bibitemnum,$rrp,$ecost,$gst,$budget,$cost,$sub,$invoice)=@_;
176 if ($budget eq 'now'){
179 $budget="'2001-07-01'";
186 my $dbh = C4::Context->dbh;
187 my $sth=$dbh->prepare("insert into aqorders (biblionumber,title,basketno,
188 quantity,listprice,booksellerid,entrydate,requisitionedby,authorisedby,notes,
189 biblioitemnumber,rrp,ecost,gst,unitprice,subscription,booksellerinvoicenumber)
190 values (?,?,?,?,?,?,now(),?,?,?,?,?,?,?,?,?,?)");
191 $sth->execute($bibnum,$title,$basket,$quantity,$listprice,$supplier,
192 $who,$who,$notes,$bibitemnum,$rrp,$ecost,$gst,$cost,
195 $sth=$dbh->prepare("select * from aqorders where
196 biblionumber=? and basketno=? and ordernumber >=?");
197 $sth->execute($bibnum,$basket,$ordnum);
198 my $data=$sth->fetchrow_hashref;
200 $ordnum=$data->{'ordernumber'};
201 $sth=$dbh->prepare("insert into aqorderbreakdown (ordernumber,bookfundid) values
204 $sth->execute($ordnum,$bookfund);
210 &delorder($biblionumber, $ordernumber);
212 Cancel the order with the given order and biblio numbers. It does not
213 delete any entries in the aqorders table, it merely marks them as
216 If there are no items remaining with the given biblionumber,
217 C<&delorder> also deletes them from the marc_subfield_table and
218 marc_biblio tables of the Koha database.
223 my ($bibnum,$ordnum)=@_;
224 my $dbh = C4::Context->dbh;
225 my $sth=$dbh->prepare("update aqorders set datecancellationprinted=now()
226 where biblionumber=? and ordernumber=?");
227 $sth->execute($bibnum,$ordnum);
229 my $count=itemcount($bibnum);
237 &modorder($title, $ordernumber, $quantity, $listprice,
238 $biblionumber, $basketno, $supplier, $who, $notes,
239 $bookfundid, $bibitemnum, $rrp, $ecost, $gst, $budget,
240 $unitprice, $booksellerinvoicenumber);
242 Modifies an existing order. Updates the order with order number
243 C<$ordernumber> and biblionumber C<$biblionumber>. All other arguments
244 update the fields with the same name in the aqorders table of the Koha
247 Entries with order number C<$ordernumber> in the aqorderbreakdown
248 table are also updated to the new book fund ID.
253 my ($title,$ordnum,$quantity,$listprice,$bibnum,$basketno,$supplier,$who,$notes,$bookfund,$bibitemnum,$rrp,$ecost,$gst,$budget,$cost,$invoice)=@_;
254 my $dbh = C4::Context->dbh;
255 my $sth=$dbh->prepare("update aqorders set title=?,
256 quantity=?,listprice=?,basketno=?,
257 rrp=?,ecost=?,unitprice=?,
258 booksellerinvoicenumber=?
260 ordernumber=? and biblionumber=?");
261 $sth->execute($title,$quantity,$listprice,$basketno,$rrp,$ecost,$cost,$invoice,$ordnum,$bibnum);
263 $sth=$dbh->prepare("update aqorderbreakdown set bookfundid=? where
265 $sth->execute($bookfund,$ordnum);
271 $order = &newordernum();
273 Finds the next unused order number in the aqorders table of the Koha
274 database, and returns it.
278 # FIXME - Race condition
280 my $dbh = C4::Context->dbh;
281 my $sth=$dbh->prepare("Select max(ordernumber) from aqorders");
283 my $data=$sth->fetchrow_arrayref;
284 my $ordnum=$$data[0];
292 &receiveorder($biblionumber, $ordernumber, $quantityreceived, $user,
293 $unitprice, $booksellerinvoicenumber, $biblioitemnumber,
294 $freight, $bookfund, $rrp);
296 Updates an order, to reflect the fact that it was received, at least
297 in part. All arguments not mentioned below update the fields with the
298 same name in the aqorders table of the Koha database.
300 Updates the order with bibilionumber C<$biblionumber> and ordernumber
303 Also updates the book fund ID in the aqorderbreakdown table.
308 my ($biblio,$ordnum,$quantrec,$user,$cost,$invoiceno,$bibitemno,$freight,$bookfund,$rrp)=@_;
309 my $dbh = C4::Context->dbh;
310 my $sth=$dbh->prepare("update aqorders set quantityreceived=?,datereceived=now(),booksellerinvoicenumber=?,
311 biblioitemnumber=?,unitprice=?,freight=?,rrp=?
312 where biblionumber=? and ordernumber=?");
313 $sth->execute($quantrec,$invoiceno,$bibitemno,$cost,$freight,$rrp,$biblio,$ordnum);
315 $sth=$dbh->prepare("update aqorderbreakdown set bookfundid=? where
317 $sth->execute($bookfund,$ordnum);
323 &updaterecorder($biblionumber, $ordernumber, $user, $unitprice,
326 Updates the order with biblionumber C<$biblionumber> and order number
327 C<$ordernumber>. C<$bookfundid> is the new value for the book fund ID
328 in the aqorderbreakdown table of the Koha database. All other
329 arguments update the fields with the same name in the aqorders table.
336 my($biblio,$ordnum,$user,$cost,$bookfund,$rrp)=@_;
337 my $dbh = C4::Context->dbh;
338 my $sth=$dbh->prepare("update aqorders set
340 where biblionumber=? and ordernumber=?
342 $sth->execute($cost,$rrp,$biblio,$ordnum);
344 $sth=$dbh->prepare("update aqorderbreakdown set bookfundid=? where ordernumber=?");
345 $sth->execute($bookfund,$ordnum);
357 ($count, $orders) = &getorders($booksellerid);
359 Finds pending orders from the bookseller with the given ID. Ignores
360 completed and cancelled orders.
362 C<$count> is the number of elements in C<@{$orders}>.
364 C<$orders> is a reference-to-array; each element is a
365 reference-to-hash with the following fields:
371 Gives the number of orders in with this basket number.
373 =item C<authorizedby>
379 These give the value of the corresponding field in the aqorders table
380 of the Koha database.
384 Results are ordered from most to least recent.
390 my $dbh = C4::Context->dbh;
391 my $sth=$dbh->prepare("Select count(*),authorisedby,entrydate,basketno from aqorders where
392 booksellerid=? and (quantity > quantityreceived or
393 quantityreceived is NULL)
394 and (datecancellationprinted is NULL or datecancellationprinted = '0000-00-00')
395 group by basketno order by entrydate desc");
396 $sth->execute($supplierid);
398 while (my $data=$sth->fetchrow_hashref){
399 push(@results,$data);
402 return (scalar(@results),\@results);
407 ($order, $ordernumber) = &getorder($biblioitemnumber, $biblionumber);
409 Looks up the order with the given biblionumber and biblioitemnumber.
411 Returns a two-element array. C<$ordernumber> is the order number.
412 C<$order> is a reference-to-hash describing the order; its keys are
413 fields from the biblio, biblioitems, aqorders, and aqorderbreakdown
414 tables of the Koha database.
418 # FIXME - This is effectively identical to &C4::Biblio::getorder.
419 # Pick one and stick with it.
422 my $dbh = C4::Context->dbh;
423 my $sth=$dbh->prepare("Select ordernumber from aqorders where biblionumber=? and biblioitemnumber=?");
424 $sth->execute($bib,$bi);
425 # FIXME - Use fetchrow_array(), since we're only interested in the one
427 my $ordnum=$sth->fetchrow_hashref;
429 my $order=getsingleorder($ordnum->{'ordernumber'});
430 return ($order,$ordnum->{'ordernumber'});
435 $order = &getsingleorder($ordernumber);
437 Looks up an order by order number.
439 Returns a reference-to-hash describing the order. The keys of
440 C<$order> are fields from the biblio, biblioitems, aqorders, and
441 aqorderbreakdown tables of the Koha database.
445 # FIXME - This is effectively identical to
446 # &C4::Biblio::getsingleorder.
447 # Pick one and stick with it.
450 my $dbh = C4::Context->dbh;
451 my $sth=$dbh->prepare("Select * from biblio,biblioitems,aqorders,aqorderbreakdown
452 where aqorders.ordernumber=?
453 and biblio.biblionumber=aqorders.biblionumber and
454 biblioitems.biblioitemnumber=aqorders.biblioitemnumber and
455 aqorders.ordernumber=aqorderbreakdown.ordernumber");
456 $sth->execute($ordnum);
457 my $data=$sth->fetchrow_hashref;
464 ($count, @results) = &getallorders($booksellerid);
466 Looks up all of the pending orders from the supplier with the given
467 bookseller ID. Ignores cancelled and completed orders.
469 C<$count> is the number of elements in C<@results>. C<@results> is an
470 array of references-to-hash. The keys of each element are fields from
471 the aqorders, biblio, and biblioitems tables of the Koha database.
473 C<@results> is sorted alphabetically by book title.
478 #gets all orders from a certain supplier, orders them alphabetically
480 my $dbh = C4::Context->dbh;
482 my $sth=$dbh->prepare("Select * from aqorders,biblio,biblioitems where booksellerid=?
483 and (cancelledby is NULL or cancelledby = '')
484 and (quantityreceived < quantity or quantityreceived is NULL)
485 and biblio.biblionumber=aqorders.biblionumber and biblioitems.biblioitemnumber=
486 aqorders.biblioitemnumber
487 group by aqorders.biblioitemnumber
490 $sth->execute($supid);
491 while (my $data=$sth->fetchrow_hashref){
492 push(@results,$data);
495 return(scalar(@results),@results);
500 #gets all orders from a certain supplier, orders them alphabetically
502 my $dbh = C4::Context->dbh;
504 my $sth=$dbh->prepare("Select * from aqorders,biblio,biblioitems where booksellerid=?
505 and (cancelledby is NULL or cancelledby = '')
506 and biblio.biblionumber=aqorders.biblionumber and biblioitems.biblioitemnumber=
507 aqorders.biblioitemnumber and
508 aqorders.quantityreceived>0
509 and aqorders.datereceived >=now()
510 group by aqorders.biblioitemnumber
513 $sth->execute($supid);
514 while (my $data=$sth->fetchrow_hashref){
515 push(@results,$data);
518 return(scalar(@results),@results);
523 ($count, @results) = &ordersearch($search, $biblionumber, $complete);
527 C<$search> may take one of several forms: if it is an ISBN,
528 C<&ordersearch> returns orders with that ISBN. If C<$search> is an
529 order number, C<&ordersearch> returns orders with that order number
530 and biblionumber C<$biblionumber>. Otherwise, C<$search> is considered
531 to be a space-separated list of search terms; in this case, all of the
532 terms must appear in the title (matching the beginning of title
535 If C<$complete> is C<yes>, the results will include only completed
536 orders. In any case, C<&ordersearch> ignores cancelled orders.
538 C<&ordersearch> returns an array. C<$count> is the number of elements
539 in C<@results>. C<@results> is an array of references-to-hash with the
557 my ($search,$id,$biblio,$catview) = @_;
558 my $dbh = C4::Context->dbh;
559 my @data = split(' ',$search);
560 my @searchterms = ($id);
561 map { push(@searchterms,"$_%","% $_%") } @data;
562 push(@searchterms,$search,$search,$biblio);
563 my $sth=$dbh->prepare("Select *,biblio.title from aqorders,biblioitems,biblio
564 where aqorders.biblioitemnumber = biblioitems.biblioitemnumber
565 and aqorders.booksellerid = ?
566 and biblio.biblionumber=aqorders.biblionumber
567 and ((datecancellationprinted is NULL)
568 or (datecancellationprinted = '0000-00-00'))
570 .(join(" and ",map { "(biblio.title like ? or biblio.title like ?)" } @data))
571 .") or biblioitems.isbn=? or (aqorders.ordernumber=? and aqorders.biblionumber=?)) "
572 .(($catview ne 'yes')?" and (quantityreceived < quantity or quantityreceived is NULL)":"")
573 ." group by aqorders.ordernumber");
574 $sth->execute(@searchterms);
576 my $sth2=$dbh->prepare("Select * from biblio where biblionumber=?");
577 my $sth3=$dbh->prepare("Select * from aqorderbreakdown where ordernumber=?");
578 while (my $data=$sth->fetchrow_hashref){
579 $sth2->execute($data->{'biblionumber'});
580 my $data2=$sth2->fetchrow_hashref;
581 $data->{'author'}=$data2->{'author'};
582 $data->{'seriestitle'}=$data2->{'seriestitle'};
583 $sth3->execute($data->{'ordernumber'});
584 my $data3=$sth3->fetchrow_hashref;
585 $data->{'branchcode'}=$data3->{'branchcode'};
586 $data->{'bookfundid'}=$data3->{'bookfundid'};
587 push(@results,$data);
592 return(scalar(@results),@results);
602 ($count, @results) = &invoice($booksellerinvoicenumber);
604 Looks up orders by invoice number.
606 Returns an array. C<$count> is the number of elements in C<@results>.
607 C<@results> is an array of references-to-hash; the keys of each
608 elements are fields from the aqorders, biblio, and biblioitems tables
609 of the Koha database.
615 my $dbh = C4::Context->dbh;
617 my $sth=$dbh->prepare("Select * from aqorders,biblio,biblioitems where
618 booksellerinvoicenumber=?
619 and biblio.biblionumber=aqorders.biblionumber and biblioitems.biblioitemnumber=
620 aqorders.biblioitemnumber group by aqorders.ordernumber,aqorders.biblioitemnumber");
621 $sth->execute($invoice);
622 while (my $data=$sth->fetchrow_hashref){
623 push(@results,$data);
626 return(scalar(@results),@results);
631 ($count, @results) = &bookfunds();
633 Returns a list of all book funds.
635 C<$count> is the number of elements in C<@results>. C<@results> is an
636 array of references-to-hash, whose keys are fields from the aqbookfund
637 and aqbudget tables of the Koha database. Results are ordered
638 alphabetically by book fund name.
643 my $dbh = C4::Context->dbh;
644 my $sth=$dbh->prepare("Select * from aqbookfund,aqbudget where aqbookfund.bookfundid
646 group by aqbookfund.bookfundid order by bookfundname");
649 while (my $data=$sth->fetchrow_hashref){
650 push(@results,$data);
653 return(scalar(@results),@results);
656 # FIXME - POD. I can't figure out what this function is doing. Then
657 # again, I don't think it's being used (anymore).
658 sub bookfundbreakdown {
660 my $dbh = C4::Context->dbh;
661 my $sth=$dbh->prepare("Select quantity,datereceived,freight,unitprice,listprice,ecost,quantityreceived,subscription
662 from aqorders,aqorderbreakdown where bookfundid=? and
663 aqorders.ordernumber=aqorderbreakdown.ordernumber
664 and (datecancellationprinted is NULL or
665 datecancellationprinted='0000-00-00')");
669 while (my $data=$sth->fetchrow_hashref){
670 if ($data->{'subscription'} == 1){
671 $spent+=$data->{'quantity'}*$data->{'unitprice'};
673 my $leftover=$data->{'quantity'}-$data->{'quantityreceived'};
674 $comtd+=($data->{'ecost'})*$leftover;
675 $spent+=($data->{'unitprice'})*$data->{'quantityreceived'};
679 return($spent,$comtd);
684 $foreignprice = &curconvert($currency, $localprice);
686 Converts the price C<$localprice> to foreign currency C<$currency> by
687 dividing by the exchange rate, and returns the result.
689 If no exchange rate is found, C<&curconvert> assumes the rate is one
695 my ($currency,$price)=@_;
696 my $dbh = C4::Context->dbh;
697 my $sth=$dbh->prepare("Select rate from currency where currency=?");
698 $sth->execute($currency);
699 my $cur=($sth->fetchrow_array())[0];
704 return($price / $cur);
709 ($count, $currencies) = &getcurrencies();
711 Returns the list of all known currencies.
713 C<$count> is the number of elements in C<$currencies>. C<$currencies>
714 is a reference-to-array; its elements are references-to-hash, whose
715 keys are the fields from the currency table in the Koha database.
720 my $dbh = C4::Context->dbh;
721 my $sth=$dbh->prepare("Select * from currency");
724 while (my $data=$sth->fetchrow_hashref){
725 push(@results,$data);
728 return(scalar(@results),\@results);
731 =item updatecurrencies
733 &updatecurrencies($currency, $newrate);
735 Sets the exchange rate for C<$currency> to be C<$newrate>.
739 sub updatecurrencies {
740 my ($currency,$rate)=@_;
741 my $dbh = C4::Context->dbh;
742 my $sth=$dbh->prepare("update currency set rate=? where currency=?");
743 $sth->execute($rate,$currency);
747 # FIXME - This is never used
749 my($price,$rrp,$itemnum)=@_;
750 my $dbh = C4::Context->dbh;
751 my $sth=$dbh->prepare("update items set price=?,replacementprice=? where itemnumber=?");
752 $sth->execute($price,$rrp,$itemnum);
764 ($count, @results) = &bookseller($searchstring);
766 Looks up a book seller. C<$searchstring> may be either a book seller
767 ID, or a string to look for in the book seller's name.
769 C<$count> is the number of elements in C<@results>. C<@results> is an
770 array of references-to-hash, whose keys are the fields of of the
771 aqbooksellers table in the Koha database.
776 my ($searchstring)=@_;
777 my $dbh = C4::Context->dbh;
778 my $sth=$dbh->prepare("Select * from aqbooksellers where name like ? or id = ?");
779 $sth->execute("$searchstring%",$searchstring);
781 while (my $data=$sth->fetchrow_hashref){
782 push(@results,$data);
785 return(scalar(@results),@results);
790 ($count, $results) = &breakdown($ordernumber);
792 Looks up an order by order ID, and returns its breakdown.
794 C<$count> is the number of elements in C<$results>. C<$results> is a
795 reference-to-array; its elements are references-to-hash, whose keys
796 are the fields of the aqorderbreakdown table in the Koha database.
802 my $dbh = C4::Context->dbh;
803 my $sth=$dbh->prepare("Select * from aqorderbreakdown where ordernumber=?");
806 while (my $data=$sth->fetchrow_hashref){
807 push(@results,$data);
810 return(scalar(@results),\@results);
815 ($count, @results) = &branches();
817 Returns a list of all library branches.
819 C<$count> is the number of elements in C<@results>. C<@results> is an
820 array of references-to-hash, whose keys are the fields of the branches
821 table of the Koha database.
826 my $dbh = C4::Context->dbh;
827 my $sth = $dbh->prepare("Select * from branches order by branchname");
831 while (my $data = $sth->fetchrow_hashref) {
832 push(@results,$data);
836 return(scalar(@results), @results);
841 my ($biblionumber)=@_;
842 my $dbh = C4::Context->dbh;
843 my $sth=$dbh->prepare("Select * from biblioitems,items,itemtypes where
844 biblioitems.biblionumber=?
845 and biblioitems.biblioitemnumber=items.biblioitemnumber and
846 itemtypes.itemtype=biblioitems.itemtype
847 order by items.biblioitemnumber");
848 $sth->execute($biblionumber);
850 while (my $data=$sth->fetchrow_hashref){
851 push(@results,$data);
859 my ($bibitemnum,$itemtype)=@_;
860 my $dbh = C4::Context->dbh;
861 my $sth=$dbh->prepare("Select * from biblioitems where biblioitemnumber=?
863 $sth->execute($bibitemnum,$itemtype);
865 if (my $data=$sth->fetchrow_hashref){
874 &updatesup($bookseller);
876 Updates the information for a given bookseller. C<$bookseller> is a
877 reference-to-hash whose keys are the fields of the aqbooksellers table
878 in the Koha database. It must contain entries for all of the fields.
879 The entry to modify is determined by C<$bookseller-E<gt>{id}>.
881 The easiest way to get all of the necessary fields is to look up a
882 book seller with C<&booksellers>, modify what's necessary, then call
883 C<&updatesup> with the result.
889 my $dbh = C4::Context->dbh;
890 my $sth=$dbh->prepare("Update aqbooksellers set
891 name=?,address1=?,address2=?,address3=?,address4=?,postal=?,
892 phone=?,fax=?,url=?,contact=?,contpos=?,contphone=?,contfax=?,contaltphone=?,
893 contemail=?,contnotes=?,active=?,
894 listprice=?, invoiceprice=?,gstreg=?, listincgst=?,
895 invoiceincgst=?, specialty=?,discount=?,invoicedisc=?,
898 $sth->execute($data->{'name'},$data->{'address1'},$data->{'address2'},
899 $data->{'address3'},$data->{'address4'},$data->{'postal'},$data->{'phone'},
900 $data->{'fax'},$data->{'url'},$data->{'contact'},$data->{'contpos'},
901 $data->{'contphone'},$data->{'contfax'},$data->{'contaltphone'},
902 $data->{'contemail'},
903 $data->{'contnote'},$data->{'active'},$data->{'listprice'},
904 $data->{'invoiceprice'},$data->{'gstreg'},$data->{'listincgst'},
905 $data->{'invoiceincgst'},$data->{'specialty'},$data->{'discount'},
906 $data->{'invoicedisc'},$data->{'nocalc'},$data->{'id'});
913 $id = &insertsup($bookseller);
915 Creates a new bookseller. C<$bookseller> is a reference-to-hash whose
916 keys are the fields of the aqbooksellers table in the Koha database.
917 All fields must be present.
919 Returns the ID of the newly-created bookseller.
925 my $dbh = C4::Context->dbh;
926 my $sth=$dbh->prepare("Select max(id) from aqbooksellers");
928 my $data2=$sth->fetchrow_hashref;
930 $data2->{'max(id)'}++;
931 $sth=$dbh->prepare("Insert into aqbooksellers (id) values (?)");
932 $sth->execute($data2->{'max(id)'});
934 $data->{'id'}=$data2->{'max(id)'};
936 return($data->{'id'});
941 ($count, @results) = &websitesearch($keywordlist);
943 Looks up biblioitems by URL.
945 C<$keywordlist> is a space-separated list of search terms.
946 C<&websitesearch> returns those biblioitems whose URL contains at
947 least one of the search terms.
949 C<$count> is the number of elements in C<@results>. C<@results> is an
950 array of references-to-hash, whose keys are the fields of the biblio
951 and biblioitems tables in the Koha database.
956 my ($keywordlist) = @_;
957 my $dbh = C4::Context->dbh;
960 my @keywords = split(/ +/, $keywordlist);
962 $sth = $dbh->prepare("Select distinct biblio.* from biblio, biblioitems where
963 biblio.biblionumber = biblioitems.biblionumber and ("
964 .(join(") or (",map { "url like ?" } @keywords)).")");
965 $sth->execute(map { s/([%_])/\\\1/g; "%$_%" } @keywords);
967 while (my $data = $sth->fetchrow_hashref) {
968 push(@results,$data);
972 return(scalar(@results), @results);
973 } # sub websitesearch
977 &addwebsite($website);
979 Adds a new web site. C<$website> is a reference-to-hash, with the keys
980 C<biblionumber>, C<title>, C<description>, and C<url>. All of these
987 my $dbh = C4::Context->dbh;
991 # for (qw( biblionumber title description url )) # and any others
993 # $website->{$_} = $dbh->quote($_);
995 # Perhaps extend this to building the query as well. This might allow
996 # some of the fields to be optional.
997 $website->{'biblionumber'} = $dbh->quote($website->{'biblionumber'});
998 $website->{'title'} = $dbh->quote($website->{'title'});
999 $website->{'description'} = $dbh->quote($website->{'description'});
1000 $website->{'url'} = $dbh->quote($website->{'url'});
1002 $query = "Insert into websites set
1003 biblionumber = $website->{'biblionumber'},
1004 title = $website->{'title'},
1005 description = $website->{'description'},
1006 url = $website->{'url'}";
1013 &updatewebsite($website);
1015 Updates an existing web site. C<$website> is a reference-to-hash with
1016 the keys C<websitenumber>, C<title>, C<description>, and C<url>. All
1017 of these are mandatory. C<$website-E<gt>{websitenumber}> identifies
1018 the entry to update.
1024 my $dbh = C4::Context->dbh;
1027 $website->{'title'} = $dbh->quote($website->{'title'});
1028 $website->{'description'} = $dbh->quote($website->{'description'});
1029 $website->{'url'} = $dbh->quote($website->{'url'});
1031 $query = "Update websites set
1032 title = $website->{'title'},
1033 description = $website->{'description'},
1034 url = $website->{'url'}
1035 where websitenumber = $website->{'websitenumber'}";
1038 } # sub updatewebsite
1042 &deletewebsite($websitenumber);
1044 Deletes the web site with number C<$websitenumber>.
1049 my ($websitenumber) = @_;
1050 my $dbh = C4::Context->dbh;
1051 # FIXME - $query is unneeded
1052 my $query = "Delete from websites where websitenumber = $websitenumber";
1055 } # sub deletewebsite
1057 END { } # module clean-up code here (global destructor)
1066 Koha Developement team <info@koha.org>