1 package C4::Acquisitions; #assumes C4/Acquisitions.pm
4 # Copyright 2000-2002 Katipo Communications
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along with
18 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
19 # Suite 330, Boston, MA 02111-1307 USA
22 # NOTE: This module is deprecated in Koha 1.3.x, and will shortly be
30 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
32 # set the version for version checking
37 C4::Acquisitions - FIXME
54 @EXPORT = qw(&getorders &bookseller &breakdown &basket &newbasket &bookfunds
55 &ordersearch &newbiblio &newbiblioitem &newsubject &newsubtitle &neworder
56 &newordernum &modbiblio &modorder &getsingleorder &invoice &receiveorder
57 &bookfundbreakdown &curconvert &updatesup &insertsup &newitems &modbibitem
58 &getcurrencies &modsubtitle &modsubject &modaddauthor &moditem &countitems
59 &findall &needsmod &delitem &deletebiblioitem &delbiblio &delorder &branches
60 &getallorders &getrecorders &updatecurrencies &getorder &getcurrency &updaterecorder
61 &updatecost &checkitems &modnote &getitemtypes &getbiblio
62 &getbiblioitembybiblionumber
63 &getbiblioitem &getitemsbybiblioitem &isbnsearch
64 &websitesearch &addwebsite &updatewebsite &deletewebsite);
65 %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ],
67 # your exported package globals go here,
68 # as well as any optionally exported functions
70 @EXPORT_OK = qw($Var1 %Hashit); # FIXME - Never used
73 # non-exported package globals go here
74 use vars qw(@more $stuff); # FIXME - Never used
76 # initalize package globals, first exported ones
83 # then the others (which are still accessible as $Some::Module::stuff)
88 # all file-scoped lexicals must be created before
89 # the functions below that use them.
91 # file-private lexicals go here
97 # here's a file-private function as a closure,
98 # callable as &$priv_func; it cannot be prototyped.
103 # make all your functions, whether exported or not;
107 ($count, $orders) = &getorders($booksellerid);
109 Finds pending orders from the bookseller with the given ID. Ignores
110 completed and cancelled orders.
112 C<$count> is the number of elements in C<@{$orders}>.
114 C<$orders> is a reference-to-array; each element is a
115 reference-to-hash with the following fields:
121 Gives the number of orders in with this basket number.
123 =item C<authorizedby>
129 These give the value of the corresponding field in the aqorders table
130 of the Koha database.
134 Results are ordered from most to least recent.
138 # FIXME - This exact function already exists in C4::Catalogue
141 my $dbh = C4::Context->dbh;
142 my $query = "Select count(*),authorisedby,entrydate,basketno from aqorders where
143 booksellerid='$supplierid' and (quantity > quantityreceived or
144 quantityreceived is NULL)
145 and (datecancellationprinted is NULL or datecancellationprinted = '0000-00-00')";
146 $query.=" group by basketno order by entrydate desc";
148 my $sth=$dbh->prepare($query);
152 while (my $data=$sth->fetchrow_hashref){
157 return ($i,\@results);
160 # Only used internally
161 # FIXME - This is the same as &C4::Biblio::itemcount, but not
162 # the same as &C4::Search::itemcount
165 my $dbh = C4::Context->dbh;
166 my $query="Select count(*) from items where biblionumber=$biblio";
168 my $sth=$dbh->prepare($query);
170 my $data=$sth->fetchrow_hashref;
172 return($data->{'count(*)'});
177 ($order, $ordernumber) = &getorder($biblioitemnumber, $biblionumber);
179 Looks up the order with the given biblionumber and biblioitemnumber.
181 Returns a two-element array. C<$ordernumber> is the order number.
182 C<$order> is a reference-to-hash describing the order; its keys are
183 fields from the biblio, biblioitems, aqorders, and aqorderbreakdown
184 tables of the Koha database.
188 # FIXME - There are functions &getorder and &getorders. Isn't this
189 # somewhat likely to cause confusion?
190 # FIXME - Almost the exact same function is already in C4::Catalogue
193 my $dbh = C4::Context->dbh;
194 my $query="Select ordernumber
196 where biblionumber=? and biblioitemnumber=?";
197 my $sth=$dbh->prepare($query);
198 $sth->execute($bib,$bi);
199 my $ordnum=$sth->fetchrow_hashref;
201 my $order=getsingleorder($ordnum->{'ordernumber'});
203 return ($order,$ordnum->{'ordernumber'});
208 $order = &getsingleorder($ordernumber);
210 Looks up an order by order number.
212 Returns a reference-to-hash describing the order. The keys of
213 C<$order> are fields from the biblio, biblioitems, aqorders, and
214 aqorderbreakdown tables of the Koha database.
218 # FIXME - This is practically the same function as
219 # &C4::Catalogue::getsingleorder and &C4::Biblio::getsingleorder.
222 my $dbh = C4::Context->dbh;
223 my $query="Select * from biblio,biblioitems,aqorders,aqorderbreakdown
224 where aqorders.ordernumber=?
225 and biblio.biblionumber=aqorders.biblionumber and
226 biblioitems.biblioitemnumber=aqorders.biblioitemnumber and
227 aqorders.ordernumber=aqorderbreakdown.ordernumber";
228 my $sth=$dbh->prepare($query);
229 $sth->execute($ordnum);
230 my $data=$sth->fetchrow_hashref;
237 ($count, @results) = &invoice($booksellerinvoicenumber);
239 Looks up orders by invoice number.
241 Returns an array. C<$count> is the number of elements in C<@results>.
242 C<@results> is an array of references-to-hash; the keys of each
243 elements are fields from the aqorders, biblio, and biblioitems tables
244 of the Koha database.
248 # FIXME - This exact function is already in C4::Catalogue
251 my $dbh = C4::Context->dbh;
252 my $query="Select * from aqorders,biblio,biblioitems where
253 booksellerinvoicenumber='$invoice'
254 and biblio.biblionumber=aqorders.biblionumber and biblioitems.biblioitemnumber=
255 aqorders.biblioitemnumber group by aqorders.ordernumber,aqorders.biblioitemnumber";
258 my $sth=$dbh->prepare($query);
260 while (my $data=$sth->fetchrow_hashref){
270 ($count, @results) = &getallorders($booksellerid);
272 Looks up all of the pending orders from the supplier with the given
273 bookseller ID. Ignores cancelled orders.
275 C<$count> is the number of elements in C<@results>. C<@results> is an
276 array of references-to-hash. The keys of each element are fields from
277 the aqorders, biblio, and biblioitems tables of the Koha database.
279 C<@results> is sorted alphabetically by book title.
283 # FIXME - Almost (but not quite) the same function appears in C4::Catalogue
284 # That one only lists incomplete orders.
286 #gets all orders from a certain supplier, orders them alphabetically
288 my $dbh = C4::Context->dbh;
289 my $query="Select * from aqorders,biblio,biblioitems where booksellerid='$supid'
290 and (cancelledby is NULL or cancelledby = '')
291 and biblio.biblionumber=aqorders.biblionumber and biblioitems.biblioitemnumber=
292 aqorders.biblioitemnumber
293 group by aqorders.biblioitemnumber
298 my $sth=$dbh->prepare($query);
300 while (my $data=$sth->fetchrow_hashref){
308 # FIXME - There's a getrecorders in C4::Catalogue
309 # FIXME - Never used (neither is the other one, actually)
311 #gets all orders from a certain supplier, orders them alphabetically
313 my $dbh = C4::Context->dbh;
314 my $query="Select * from aqorders,biblio,biblioitems where booksellerid='$supid'
315 and (cancelledby is NULL or cancelledby = '')
316 and biblio.biblionumber=aqorders.biblionumber and biblioitems.biblioitemnumber=
317 aqorders.biblioitemnumber and
318 aqorders.quantityreceived>0
319 and aqorders.datereceived >=now()
320 group by aqorders.biblioitemnumber
325 my $sth=$dbh->prepare($query);
327 while (my $data=$sth->fetchrow_hashref){
337 ($count, @results) = &ordersearch($search, $biblionumber, $complete);
341 C<$search> may take one of several forms: if it is an ISBN,
342 C<&ordersearch> returns orders with that ISBN. If C<$search> is an
343 order number, C<&ordersearch> returns orders with that order number
344 and biblionumber C<$biblionumber>. Otherwise, C<$search> is considered
345 to be a space-separated list of search terms; in this case, all of the
346 terms must appear in the title (matching the beginning of title
349 If C<$complete> is C<yes>, the results will include only completed
350 orders. In any case, C<&ordersearch> ignores cancelled orders.
352 C<&ordersearch> returns an array. C<$count> is the number of elements
353 in C<@results>. C<@results> is an array of references-to-hash with the
370 # FIXME - The same function (modulo whitespace) appears in C4::Catalogue
372 my ($search,$biblio,$catview)=@_;
373 my $dbh = C4::Context->dbh;
374 my $query="Select *,biblio.title from aqorders,biblioitems,biblio
375 where aqorders.biblioitemnumber = biblioitems.biblioitemnumber
376 and biblio.biblionumber=aqorders.biblionumber
377 and ((datecancellationprinted is NULL)
378 or (datecancellationprinted = '0000-00-00'))
380 my @data=split(' ',$search);
382 for (my $i=0;$i<$count;$i++){
383 $query.= "(biblio.title like '$data[$i]%' or biblio.title like '% $data[$i]%') and ";
386 $query.=" ) or biblioitems.isbn='$search'
387 or (aqorders.ordernumber='$search' and aqorders.biblionumber='$biblio')) ";
388 if ($catview ne 'yes'){
389 $query.=" and (quantityreceived < quantity or quantityreceived is NULL)";
391 $query.=" group by aqorders.ordernumber";
392 my $sth=$dbh->prepare($query);
397 while (my $data=$sth->fetchrow_hashref){
398 my $sth2=$dbh->prepare("Select * from biblio where
399 biblionumber='$data->{'biblionumber'}'");
401 my $data2=$sth2->fetchrow_hashref;
403 $data->{'author'}=$data2->{'author'};
404 $data->{'seriestitle'}=$data2->{'seriestitle'};
405 $sth2=$dbh->prepare("Select * from aqorderbreakdown where
406 ordernumber=$data->{'ordernumber'}");
408 $data2=$sth2->fetchrow_hashref;
410 $data->{'branchcode'}=$data2->{'branchcode'};
411 $data->{'bookfundid'}=$data2->{'bookfundid'};
421 ($count, @results) = &bookseller($searchstring);
423 Looks up a book seller. C<$searchstring> may be either a book seller
424 ID, or a string to look for in the book seller's name.
426 C<$count> is the number of elements in C<@results>. C<@results> is an
427 array of references-to-hash, whose keys are the fields of of the
428 aqbooksellers table in the Koha database.
432 # FIXME - This function appears in C4::Catalogue
434 my ($searchstring)=@_;
435 my $dbh = C4::Context->dbh;
436 my $query="Select * from aqbooksellers where name like '%$searchstring%' or
437 id = '$searchstring'";
438 my $sth=$dbh->prepare($query);
442 while (my $data=$sth->fetchrow_hashref){
452 ($count, $results) = &breakdown($ordernumber);
454 Looks up an order by order ID, and returns its breakdown.
456 C<$count> is the number of elements in C<$results>. C<$results> is a
457 reference-to-array; its elements are references-to-hash, whose keys
458 are the fields of the aqorderbreakdown table in the Koha database.
462 # FIXME - This function appears in C4::Catalogue.
465 my $dbh = C4::Context->dbh;
466 my $query="Select * from aqorderbreakdown where ordernumber='$id'";
467 my $sth=$dbh->prepare($query);
471 while (my $data=$sth->fetchrow_hashref){
476 return($i,\@results);
481 ($count, @orders) = &basket($basketnumber, $booksellerID);
483 Looks up the pending (non-cancelled) orders with the given basket
484 number. If C<$booksellerID> is non-empty, only orders from that seller
487 C<&basket> returns a two-element array. C<@orders> is an array of
488 references-to-hash, whose keys are the fields from the aqorders,
489 biblio, and biblioitems tables in the Koha database. C<$count> is the
490 number of elements in C<@orders>.
494 # FIXME - Almost the same function (with less error-checking) appears in
497 my ($basketno,$supplier)=@_;
498 my $dbh = C4::Context->dbh;
499 my $query="Select *,biblio.title from aqorders,biblio,biblioitems
500 where basketno='$basketno'
501 and biblio.biblionumber=aqorders.biblionumber and biblioitems.biblioitemnumber
502 =aqorders.biblioitemnumber
503 and (datecancellationprinted is NULL or datecancellationprinted =
505 if (defined $supplier && $supplier ne ''){
506 $query.=" and aqorders.booksellerid='$supplier'";
508 $query.=" group by aqorders.ordernumber";
509 my $sth=$dbh->prepare($query);
514 while (my $data=$sth->fetchrow_hashref){
524 $basket = &newbasket();
526 Finds the next unused basket number in the aqorders table of the Koha
527 database, and returns it.
531 # FIXME - There's a race condition here:
533 # B calls &newbasket (gets the same number as A)
534 # A updates the basket
535 # B updates the basket, and clobbers A's result.
536 # A better approach might be to create a dummy order (with, say,
537 # requisitionedby == "Dummy-$$" or notes == "dummy <time> <pid>"), and
538 # see which basket number it gets. Then have a cron job periodically
539 # remove out-of-date dummy orders.
540 # FIXME - This function appears in C4::Catalogue.pm
542 my $dbh = C4::Context->dbh;
543 my $query="Select max(basketno) from aqorders";
544 my $sth=$dbh->prepare($query);
546 my $data=$sth->fetchrow_arrayref;
547 my $basket=$$data[0];
555 ($count, @results) = &bookfunds();
557 Returns a list of all book funds started on Sep 1, 2001.
559 C<$count> is the number of elements in C<@results>. C<@results> is an
560 array of references-to-hash, whose keys are fields from the aqbookfund
561 and aqbudget tables of the Koha database. Results are ordered
562 alphabetically by book fund name.
566 # FIXME - An identical function (without the hardcoded date) appears in
569 my $dbh = C4::Context->dbh;
570 my $query="Select * from aqbookfund,aqbudget where aqbookfund.bookfundid
572 and aqbudget.startdate='2001-07-01'
573 group by aqbookfund.bookfundid order by bookfundname";
574 my $sth=$dbh->prepare($query);
578 while (my $data=$sth->fetchrow_hashref){
588 ($count, @results) = &branches();
590 Returns a list of all library branches.
592 C<$count> is the number of elements in C<@results>. C<@results> is an
593 array of references-to-hash, whose keys are the fields of the branches
594 table of the Koha database.
598 # FIXME - This function (modulo whitespace) appears in C4::Catalogue
600 my $dbh = C4::Context->dbh;
601 my $query="Select * from branches";
602 my $sth=$dbh->prepare($query);
607 while (my $data = $sth->fetchrow_hashref){
613 return($i, @results);
616 # FIXME - POD. But I can't figure out what this function is doing
617 # FIXME - An almost identical function appears in C4::Catalogue
618 sub bookfundbreakdown {
620 my $dbh = C4::Context->dbh;
621 my $query="Select quantity,datereceived,freight,unitprice,listprice,ecost,quantityreceived,subscription
622 from aqorders,aqorderbreakdown where bookfundid='$id' and
623 aqorders.ordernumber=aqorderbreakdown.ordernumber and ((budgetdate >=
624 '2001-07-01' and budgetdate <'2002-07-01') or
625 (datereceived >= '2001-07-01' and datereceived < '2002-07-01'))
626 and (datecancellationprinted is NULL or
627 datecancellationprinted='0000-00-00')";
628 my $sth=$dbh->prepare($query);
632 while (my $data=$sth->fetchrow_hashref){
633 if ($data->{'subscription'} == 1){
634 $spent+=$data->{'quantity'}*$data->{'unitprice'};
636 my $leftover=$data->{'quantity'}-$data->{'quantityreceived'};
637 $comtd+=($data->{'ecost'})*$leftover;
638 $spent+=($data->{'unitprice'})*$data->{'quantityreceived'};
642 return($spent,$comtd);
645 # FIXME - This is in effect identical to &C4::Biblio::newbiblio.
646 # Pick one and stick with it.
650 my $dbh = C4::Context->dbh;
651 my $query = "Select max(biblionumber) from biblio";
652 my $sth = $dbh->prepare($query);
654 my $data = $sth->fetchrow_arrayref;
655 my $bibnum = $$data[0] + 1;
658 $biblio->{'title'} = $dbh->quote($biblio->{'title'});
659 $biblio->{'author'} = $dbh->quote($biblio->{'author'});
660 $biblio->{'copyright'} = $dbh->quote($biblio->{'copyright'});
661 $biblio->{'seriestitle'} = $dbh->quote($biblio->{'seriestitle'});
662 $biblio->{'notes'} = $dbh->quote($biblio->{'notes'});
663 $biblio->{'abstract'} = $dbh->quote($biblio->{'abstract'});
664 if ($biblio->{'seriestitle'}) { $series = 1 };
667 # FIXME - Use $dbh->do();
668 $query = "insert into biblio set
669 biblionumber = $bibnum,
670 title = $biblio->{'title'},
671 author = $biblio->{'author'},
672 copyrightdate = $biblio->{'copyright'},
674 seriestitle = $biblio->{'seriestitle'},
675 notes = $biblio->{'notes'},
676 abstract = $biblio->{'abstract'}";
678 $sth = $dbh->prepare($query);
685 # FIXME - This is in effect the same as &C4::Biblio::modbiblio.
686 # Pick one and stick with it.
690 my $dbh = C4::Context->dbh;
694 $biblio->{'title'} = $dbh->quote($biblio->{'title'});
695 $biblio->{'author'} = $dbh->quote($biblio->{'author'});
696 $biblio->{'abstract'} = $dbh->quote($biblio->{'abstract'});
697 $biblio->{'copyrightdate'} = $dbh->quote($biblio->{'copyrightdate'});
698 $biblio->{'seriestitle'} = $dbh->quote($biblio->{'serirestitle'});
699 $biblio->{'serial'} = $dbh->quote($biblio->{'serial'});
700 $biblio->{'unititle'} = $dbh->quote($biblio->{'unititle'});
701 $biblio->{'notes'} = $dbh->quote($biblio->{'notes'});
703 $query = "Update biblio set
704 title = $biblio->{'title'},
705 author = $biblio->{'author'},
706 abstract = $biblio->{'abstract'},
707 copyrightdate = $biblio->{'copyrightdate'},
708 seriestitle = $biblio->{'seriestitle'},
709 serial = $biblio->{'serial'},
710 unititle = $biblio->{'unititle'},
711 notes = $biblio->{'notes'}
712 where biblionumber = $biblio->{'biblionumber'}";
713 $sth = $dbh->prepare($query);
718 return($biblio->{'biblionumber'});
721 # FIXME - This is in effect identical to &C4::Biblio::modsubtitle.
722 # Pick one and stick with it.
725 my ($bibnum, $subtitle) = @_;
726 my $dbh = C4::Context->dbh;
727 my $query = "update bibliosubtitle set
728 subtitle = '$subtitle'
729 where biblionumber = $bibnum";
730 my $sth = $dbh->prepare($query);
737 # FIXME - This is functionally identical to &C4::Biblio::modaddauthor
738 # Pick one and stick with it.
740 my ($bibnum, $author) = @_;
741 my $dbh = C4::Context->dbh;
742 my $query = "Delete from additionalauthors where biblionumber = $bibnum";
743 my $sth = $dbh->prepare($query);
749 $query = "Insert into additionalauthors set
751 biblionumber = '$bibnum'";
752 $sth = $dbh->prepare($query);
760 # FIXME - This is in effect identical to &C4::Biblio::modsubject.
761 # Pick one and stick with it.
764 my ($bibnum, $force, @subject) = @_;
765 my $dbh = C4::Context->dbh;
766 my $count = @subject;
768 for (my $i = 0; $i < $count; $i++) {
769 $subject[$i] =~ s/^ //g;
770 $subject[$i] =~ s/ $//g;
771 my $query = "select * from catalogueentry
772 where entrytype = 's'
773 and catalogueentry = '$subject[$i]'";
774 my $sth = $dbh->prepare($query);
777 if (my $data = $sth->fetchrow_hashref) {
779 if ($force eq $subject[$i]) {
781 # subject not in aut, chosen to force anway
782 # so insert into cataloguentry so its in auth file
783 $query = "Insert into catalogueentry
784 (entrytype,catalogueentry)
785 values ('s','$subject[$i]')";
786 my $sth2 = $dbh->prepare($query);
793 $error = "$subject[$i]\n does not exist in the subject authority file";
794 $query = "Select * from catalogueentry
795 where entrytype = 's'
796 and (catalogueentry like '$subject[$i] %'
797 or catalogueentry like '% $subject[$i] %'
798 or catalogueentry like '% $subject[$i]')";
799 my $sth2 = $dbh->prepare($query);
802 while (my $data = $sth2->fetchrow_hashref) {
803 $error = $error."<br>$data->{'catalogueentry'}";
812 my $query = "Delete from bibliosubject where biblionumber = $bibnum";
813 my $sth = $dbh->prepare($query);
818 for (my $i = 0; $i < $count; $i++) {
819 $sth = $dbh->prepare("Insert into bibliosubject
820 values ('$subject[$i]', $bibnum)");
830 # FIXME - This is very similar to &C4::Biblio::modbibitem.
831 # Pick one and stick with it.
834 my ($biblioitem) = @_;
835 my $dbh = C4::Context->dbh;
839 # foreach my $field (qw( ... ))
841 # $biblioitem->{$field} = $dbh->quote($biblioitem->{$field});
843 $biblioitem->{'itemtype'} = $dbh->quote($biblioitem->{'itemtype'});
844 $biblioitem->{'url'} = $dbh->quote($biblioitem->{'url'});
845 $biblioitem->{'isbn'} = $dbh->quote($biblioitem->{'isbn'});
846 $biblioitem->{'publishercode'} = $dbh->quote($biblioitem->{'publishercode'});
847 $biblioitem->{'publicationyear'} = $dbh->quote($biblioitem->{'publicationyear'});
848 $biblioitem->{'classification'} = $dbh->quote($biblioitem->{'classification'});
849 $biblioitem->{'dewey'} = $dbh->quote($biblioitem->{'dewey'});
850 $biblioitem->{'subclass'} = $dbh->quote($biblioitem->{'subclass'});
851 $biblioitem->{'illus'} = $dbh->quote($biblioitem->{'illus'});
852 $biblioitem->{'pages'} = $dbh->quote($biblioitem->{'pages'});
853 $biblioitem->{'volumeddesc'} = $dbh->quote($biblioitem->{'volumeddesc'});
854 $biblioitem->{'notes'} = $dbh->quote($biblioitem->{'notes'});
855 $biblioitem->{'size'} = $dbh->quote($biblioitem->{'size'});
856 $biblioitem->{'place'} = $dbh->quote($biblioitem->{'place'});
858 $query = "Update biblioitems set
859 itemtype = $biblioitem->{'itemtype'},
860 url = $biblioitem->{'url'},
861 isbn = $biblioitem->{'isbn'},
862 publishercode = $biblioitem->{'publishercode'},
863 publicationyear = $biblioitem->{'publicationyear'},
864 classification = $biblioitem->{'classification'},
865 dewey = $biblioitem->{'dewey'},
866 subclass = $biblioitem->{'subclass'},
867 illus = $biblioitem->{'illus'},
868 pages = $biblioitem->{'pages'},
869 volumeddesc = $biblioitem->{'volumeddesc'},
870 notes = $biblioitem->{'notes'},
871 size = $biblioitem->{'size'},
872 place = $biblioitem->{'place'}
873 where biblioitemnumber = $biblioitem->{'biblioitemnumber'}";
878 # FIXME - This is in effect identical to &C4::Biblio::modnote.
879 # Pick one and stick with it.
882 my ($bibitemnum,$note)=@_;
883 my $dbh = C4::Context->dbh;
884 # FIXME - Use $dbh->do();
885 my $query="update biblioitems set notes='$note' where
886 biblioitemnumber='$bibitemnum'";
887 my $sth=$dbh->prepare($query);
893 # FIXME - &C4::Biblio::newbiblioitem is quite similar to this
895 my ($biblioitem) = @_;
896 my $dbh = C4::Context->dbh;
897 my $query = "Select max(biblioitemnumber) from biblioitems";
898 my $sth = $dbh->prepare($query);
902 $biblioitem->{'volume'} = $dbh->quote($biblioitem->{'volume'});
903 $biblioitem->{'number'} = $dbh->quote($biblioitem->{'number'});
904 $biblioitem->{'classification'} = $dbh->quote($biblioitem->{'classification'});
905 $biblioitem->{'itemtype'} = $dbh->quote($biblioitem->{'itemtype'});
906 $biblioitem->{'url'} = $dbh->quote($biblioitem->{'url'});
907 $biblioitem->{'isbn'} = $dbh->quote($biblioitem->{'isbn'});
908 $biblioitem->{'issn'} = $dbh->quote($biblioitem->{'issn'});
909 $biblioitem->{'dewey'} = $dbh->quote($biblioitem->{'dewey'});
910 $biblioitem->{'subclass'} = $dbh->quote($biblioitem->{'subclass'});
911 $biblioitem->{'publicationyear'} = $dbh->quote($biblioitem->{'publicationyear'});
912 $biblioitem->{'publishercode'} = $dbh->quote($biblioitem->{'publishercode'});
913 $biblioitem->{'volumedate'} = $dbh->quote($biblioitem->{'volumedate'});
914 $biblioitem->{'volumeddesc'} = $dbh->quote($biblioitem->{'volumeddesc'}); $biblioitem->{'illus'} = $dbh->quote($biblioitem->{'illus'});
915 $biblioitem->{'illus'} = $dbh->quote($biblioitem->{'illus'});
916 $biblioitem->{'pages'} = $dbh->quote($biblioitem->{'pages'});
917 $biblioitem->{'notes'} = $dbh->quote($biblioitem->{'notes'});
918 $biblioitem->{'size'} = $dbh->quote($biblioitem->{'size'});
919 $biblioitem->{'place'} = $dbh->quote($biblioitem->{'place'});
920 $biblioitem->{'lccn'} = $dbh->quote($biblioitem->{'lccn'});
921 $biblioitem->{'marc'} = $dbh->quote($biblioitem->{'marc'});
924 $data = $sth->fetchrow_arrayref;
925 $bibitemnum = $$data[0] + 1;
929 $query = "insert into biblioitems set
930 biblioitemnumber = $bibitemnum,
931 biblionumber = $biblioitem->{'biblionumber'},
932 volume = $biblioitem->{'volume'},
933 number = $biblioitem->{'number'},
934 classification = $biblioitem->{'classification'},
935 itemtype = $biblioitem->{'itemtype'},
936 url = $biblioitem->{'url'},
937 isbn = $biblioitem->{'isbn'},
938 issn = $biblioitem->{'issn'},
939 dewey = $biblioitem->{'dewey'},
940 subclass = $biblioitem->{'subclass'},
941 publicationyear = $biblioitem->{'publicationyear'},
942 publishercode = $biblioitem->{'publishercode'},
943 volumedate = $biblioitem->{'volumedate'},
944 volumeddesc = $biblioitem->{'volumeddesc'},
945 illus = $biblioitem->{'illus'},
946 pages = $biblioitem->{'pages'},
947 notes = $biblioitem->{'notes'},
948 size = $biblioitem->{'size'},
949 lccn = $biblioitem->{'lccn'},
950 marc = $biblioitem->{'marc'},
951 place = $biblioitem->{'place'}";
953 $sth = $dbh->prepare($query);
960 # FIXME - This is in effect identical to &C4::Biblio::newsubject.
961 # Pick one and stick with it.
965 my $dbh = C4::Context->dbh;
966 my $query="insert into bibliosubject (biblionumber) values
968 my $sth=$dbh->prepare($query);
975 # FIXME - This is in effect the same as &C4::Biblio::newsubtitle
976 # Pick one and stick with it.
978 my ($bibnum, $subtitle) = @_;
979 my $dbh = C4::Context->dbh;
980 $subtitle = $dbh->quote($subtitle);
981 my $query = "insert into bibliosubtitle set
982 biblionumber = $bibnum,
983 subtitle = $subtitle";
984 my $sth = $dbh->prepare($query);
993 &neworder($biblionumber, $title, $ordnum, $basket, $quantity, $listprice,
994 $booksellerid, $who, $notes, $bookfund, $biblioitemnumber, $rrp,
995 $ecost, $gst, $budget, $unitprice, $subscription,
996 $booksellerinvoicenumber);
998 Adds a new order to the database. Any argument that isn't described
999 below is the new value of the field with the same name in the aqorders
1000 table of the Koha database.
1002 C<$ordnum> is a "minimum order number." After adding the new entry to
1003 the aqorders table, C<&neworder> finds the first entry in aqorders
1004 with order number greater than or equal to C<$ordnum>, and adds an
1005 entry to the aqorderbreakdown table, with the order number just found,
1006 and the book fund ID of the newly-added order.
1008 C<$budget> is effectively ignored.
1010 C<$subscription> may be either "yes", or anything else for "no".
1014 # FIXME - This function appears in C4::Catalogue
1016 my ($bibnum,$title,$ordnum,$basket,$quantity,$listprice,$supplier,$who,$notes,$bookfund,$bibitemnum,$rrp,$ecost,$gst,$budget,$cost,$sub,$invoice)=@_;
1017 if ($budget eq 'now'){
1020 $budget="'2001-07-01'";
1027 my $dbh = C4::Context->dbh;
1028 my $query="insert into aqorders (biblionumber,title,basketno,
1029 quantity,listprice,booksellerid,entrydate,requisitionedby,authorisedby,notes,
1030 biblioitemnumber,rrp,ecost,gst,unitprice,subscription,booksellerinvoicenumber)
1033 ($bibnum,'$title',$basket,$quantity,$listprice,'$supplier',now(),
1034 '$who','$who','$notes',$bibitemnum,'$rrp','$ecost','$gst','$cost',
1035 '$sub','$invoice')";
1036 my $sth=$dbh->prepare($query);
1040 $query="select * from aqorders where
1041 biblionumber=$bibnum and basketno=$basket and ordernumber >=$ordnum";
1042 $sth=$dbh->prepare($query);
1044 my $data=$sth->fetchrow_hashref;
1046 $ordnum=$data->{'ordernumber'};
1047 $query="insert into aqorderbreakdown (ordernumber,bookfundid) values
1048 ($ordnum,'$bookfund')";
1049 $sth=$dbh->prepare($query);
1057 &delorder($biblionumber, $ordernumber);
1059 Cancel the order with the given order and biblio numbers. It does not
1060 delete any entries in the aqorders table, it merely marks them as
1063 If there are no items remaining with the given biblionumber,
1064 C<&delorder> also deletes them from the marc_subfield_table and
1065 marc_biblio tables of the Koha database.
1069 # FIXME - This function appears in C4::Catalogue
1071 my ($bibnum,$ordnum)=@_;
1072 my $dbh = C4::Context->dbh;
1073 my $query="update aqorders set datecancellationprinted=now()
1074 where biblionumber='$bibnum' and
1075 ordernumber='$ordnum'";
1076 my $sth=$dbh->prepare($query);
1080 my $count=itemcount($bibnum);
1088 &modorder($title, $ordernumber, $quantity, $listprice,
1089 $biblionumber, $basketno, $supplier, $who, $notes,
1090 $bookfundid, $bibitemnum, $rrp, $ecost, $gst, $budget,
1091 $unitprice, $booksellerinvoicenumber);
1093 Modifies an existing order. Updates the order with order number
1094 C<$ordernumber> and biblionumber C<$biblionumber>. All other arguments
1095 update the fields with the same name in the aqorders table of the Koha
1098 Entries with order number C<$ordernumber> in the aqorderbreakdown
1099 table are also updated to the new book fund ID.
1103 # FIXME - This function appears in C4::Catalogue
1105 my ($title,$ordnum,$quantity,$listprice,$bibnum,$basketno,$supplier,$who,$notes,$bookfund,$bibitemnum,$rrp,$ecost,$gst,$budget,$cost,$invoice)=@_;
1106 my $dbh = C4::Context->dbh;
1107 my $query="update aqorders set title='$title',
1108 quantity='$quantity',listprice='$listprice',basketno='$basketno',
1109 rrp='$rrp',ecost='$ecost',unitprice='$cost',
1110 booksellerinvoicenumber='$invoice'
1112 ordernumber=$ordnum and biblionumber=$bibnum";
1113 my $sth=$dbh->prepare($query);
1117 $query="update aqorderbreakdown set bookfundid=$bookfund where
1118 ordernumber=$ordnum";
1119 $sth=$dbh->prepare($query);
1127 $order = &newordernum();
1129 Finds the next unused order number in the aqorders table of the Koha
1130 database, and returns it.
1134 # FIXME - Race condition
1135 # FIXME - This function appears in C4::Catalogue
1137 my $dbh = C4::Context->dbh;
1138 my $query="Select max(ordernumber) from aqorders";
1139 my $sth=$dbh->prepare($query);
1141 my $data=$sth->fetchrow_arrayref;
1142 my $ordnum=$$data[0];
1150 &receiveorder($biblionumber, $ordernumber, $quantityreceived, $user,
1151 $unitprice, $booksellerinvoicenumber, $biblioitemnumber,
1152 $freight, $bookfund, $rrp);
1154 Updates an order, to reflect the fact that it was received, at least
1155 in part. All arguments not mentioned below update the fields with the
1156 same name in the aqorders table of the Koha database.
1158 Updates the order with bibilionumber C<$biblionumber> and ordernumber
1161 Also updates the book fund ID in the aqorderbreakdown table.
1165 # FIXME - This function appears in C4::Catalogue
1167 my ($biblio,$ordnum,$quantrec,$user,$cost,$invoiceno,$bibitemno,$freight,$bookfund,$rrp)=@_;
1168 my $dbh = C4::Context->dbh;
1169 my $query="update aqorders set quantityreceived='$quantrec',
1170 datereceived=now(),booksellerinvoicenumber='$invoiceno',
1171 biblioitemnumber=$bibitemno,unitprice='$cost',freight='$freight',
1173 where biblionumber=$biblio and ordernumber=$ordnum
1176 my $sth=$dbh->prepare($query);
1179 $query="update aqorderbreakdown set bookfundid=$bookfund where
1180 ordernumber=$ordnum";
1181 $sth=$dbh->prepare($query);
1187 =item updaterecorder
1189 &updaterecorder($biblionumber, $ordernumber, $user, $unitprice,
1192 Updates the order with biblionumber C<$biblionumber> and order number
1193 C<$ordernumber>. C<$bookfundid> is the new value for the book fund ID
1194 in the aqorderbreakdown table of the Koha database. All other
1195 arguments update the fields with the same name in the aqorders table.
1197 C<$user> is ignored.
1201 # FIXME - This function appears in C4::Catalogue
1203 my($biblio,$ordnum,$user,$cost,$bookfund,$rrp)=@_;
1204 my $dbh = C4::Context->dbh;
1205 my $query="update aqorders set
1206 unitprice='$cost', rrp='$rrp'
1207 where biblionumber=$biblio and ordernumber=$ordnum
1210 my $sth=$dbh->prepare($query);
1213 $query="update aqorderbreakdown set bookfundid=$bookfund where
1214 ordernumber=$ordnum";
1215 $sth=$dbh->prepare($query);
1223 $foreignprice = &curconvert($currency, $localprice);
1225 Converts the price C<$localprice> to foreign currency C<$currency> by
1226 dividing by the exchange rate, and returns the result.
1228 If no exchange rate is found, C<&curconvert> assumes the rate is one
1233 # FIXME - An almost identical version of this function appears in
1236 my ($currency,$price)=@_;
1237 my $dbh = C4::Context->dbh;
1238 my $query="Select rate from currency where currency='$currency'";
1239 my $sth=$dbh->prepare($query);
1241 my $data=$sth->fetchrow_hashref;
1243 my $cur=$data->{'rate'};
1247 $price=$price / $cur;
1253 ($count, $currencies) = &getcurrencies();
1255 Returns the list of all known currencies.
1257 C<$count> is the number of elements in C<$currencies>. C<$currencies>
1258 is a reference-to-array; its elements are references-to-hash, whose
1259 keys are the fields from the currency table in the Koha database.
1263 # FIXME - This function appears in C4::Catalogue
1265 my $dbh = C4::Context->dbh;
1266 my $query="Select * from currency";
1267 my $sth=$dbh->prepare($query);
1271 while (my $data=$sth->fetchrow_hashref){
1276 return($i,\@results);
1279 # FIXME - This function appears in C4::Catalogue. Neither one is used.
1282 my $dbh = C4::Context->dbh;
1283 my $query="Select * from currency where currency='$cur'";
1284 my $sth=$dbh->prepare($query);
1287 my $data=$sth->fetchrow_hashref;
1292 =item updatecurrencies
1294 &updatecurrencies($currency, $newrate);
1296 Sets the exchange rate for C<$currency> to be C<$newrate>.
1300 # FIXME - This function appears in C4::Catalogue
1301 sub updatecurrencies {
1302 my ($currency,$rate)=@_;
1303 my $dbh = C4::Context->dbh;
1304 my $query="update currency set rate=$rate where currency='$currency'";
1305 my $sth=$dbh->prepare($query);
1312 &updatesup($bookseller);
1314 Updates the information for a given bookseller. C<$bookseller> is a
1315 reference-to-hash whose keys are the fields of the aqbooksellers table
1316 in the Koha database. It must contain entries for all of the fields.
1317 The entry to modify is determined by C<$bookseller-E<gt>{id}>.
1319 The easiest way to get all of the necessary fields is to look up a
1320 book seller with C<&booksellers>, modify what's necessary, then call
1321 C<&updatesup> with the result.
1325 # FIXME - This function appears in C4::Catalogue
1328 my $dbh = C4::Context->dbh;
1329 my $query="Update aqbooksellers set
1330 name='$data->{'name'}',address1='$data->{'address1'}',address2='$data->{'address2'}',
1331 address3='$data->{'address3'}',address4='$data->{'address4'}',postal='$data->{'postal'}',
1332 phone='$data->{'phone'}',fax='$data->{'fax'}',url='$data->{'url'}',
1333 contact='$data->{'contact'}',contpos='$data->{'contpos'}',
1334 contphone='$data->{'contphone'}', contfax='$data->{'contfax'}', contaltphone=
1335 '$data->{'contaltphone'}', contemail='$data->{'contemail'}', contnotes=
1336 '$data->{'contnotes'}', active=$data->{'active'},
1337 listprice='$data->{'listprice'}', invoiceprice='$data->{'invoiceprice'}',
1338 gstreg=$data->{'gstreg'}, listincgst=$data->{'listincgst'},
1339 invoiceincgst=$data->{'invoiceincgst'}, specialty='$data->{'specialty'}',
1340 discount='$data->{'discount'}',invoicedisc='$data->{'invoicedisc'}',
1341 nocalc='$data->{'nocalc'}'
1342 where id='$data->{'id'}'";
1343 my $sth=$dbh->prepare($query);
1352 my $dbh = C4::Context->dbh;
1353 my $sth=$dbh->prepare("Select max(id) from aqbooksellers");
1355 my $data2=$sth->fetchrow_hashref;
1357 $data2->{'max(id)'}++;
1358 $sth=$dbh->prepare("Insert into aqbooksellers (id) values ($data2->{'max(id)'})");
1361 $data->{'id'}=$data2->{'max(id)'};
1363 return($data->{'id'});
1368 $id = &insertsup($bookseller);
1370 Creates a new bookseller. C<$bookseller> is a reference-to-hash whose
1371 keys are the fields of the aqbooksellers table in the Koha database.
1372 All fields must be present.
1374 Returns the ID of the newly-created bookseller.
1378 # FIXME - This function appears in C4::Catalogue
1379 # FIXME - This is different from &C4::Biblio::newitems, though both
1382 my ($item, @barcodes) = @_;
1383 my $dbh = C4::Context->dbh;
1384 my $query = "Select max(itemnumber) from items";
1385 my $sth = $dbh->prepare($query);
1391 $data = $sth->fetchrow_hashref;
1392 $itemnumber = $data->{'max(itemnumber)'} + 1;
1395 $item->{'booksellerid'} = $dbh->quote($item->{'booksellerid'});
1396 $item->{'homebranch'} = $dbh->quote($item->{'homebranch'});
1397 $item->{'price'} = $dbh->quote($item->{'price'});
1398 $item->{'replacementprice'} = $dbh->quote($item->{'replacementprice'});
1399 $item->{'itemnotes'} = $dbh->quote($item->{'itemnotes'});
1401 foreach my $barcode (@barcodes) {
1402 $barcode = uc($barcode);
1403 $barcode = $dbh->quote($barcode);
1404 $query = "Insert into items set
1405 itemnumber = $itemnumber,
1406 biblionumber = $item->{'biblionumber'},
1407 biblioitemnumber = $item->{'biblioitemnumber'},
1409 booksellerid = $item->{'booksellerid'},
1410 dateaccessioned = NOW(),
1411 homebranch = $item->{'homebranch'},
1412 holdingbranch = $item->{'homebranch'},
1413 price = $item->{'price'},
1414 replacementprice = $item->{'replacementprice'},
1415 replacementpricedate = NOW(),
1416 itemnotes = $item->{'itemnotes'}";
1418 if ($item->{'loan'}) {
1420 notforloan = $item->{'loan'}";
1423 $sth = $dbh->prepare($query);
1426 $error .= $sth->errstr;
1435 # FIXME - This is the same as &C4::Biblio::Checkitems.
1436 # Pick one and stick with it.
1439 my ($count,@barcodes)=@_;
1440 my $dbh = C4::Context->dbh;
1442 for (my $i=0;$i<$count;$i++){
1443 $barcodes[$i]=uc $barcodes[$i];
1444 my $query="Select * from items where barcode='$barcodes[$i]'";
1445 my $sth=$dbh->prepare($query);
1447 if (my $data=$sth->fetchrow_hashref){
1448 $error.=" Duplicate Barcode: $barcodes[$i]";
1455 # FIXME - This appears to be functionally equivalent to
1456 # &C4::Biblio::moditem.
1457 # Pick one and stick with it.
1460 my ($loan,$itemnum,$bibitemnum,$barcode,$notes,$homebranch,$lost,$wthdrawn,$replacement)=@_;
1461 my $dbh = C4::Context->dbh;
1462 my $query="update items set biblioitemnumber=$bibitemnum,
1463 barcode='$barcode',itemnotes='$notes'
1464 where itemnumber=$itemnum";
1465 if ($barcode eq ''){
1466 $query="update items set biblioitemnumber=$bibitemnum,notforloan=$loan where itemnumber=$itemnum";
1469 $query="update items set biblioitemnumber=$bibitemnum,
1470 barcode='$barcode',itemnotes='$notes',homebranch='$homebranch',
1471 itemlost='$lost',wthdrawn='$wthdrawn' where itemnumber=$itemnum";
1473 if ($replacement ne ''){
1474 $query=~ s/ where/,replacementprice='$replacement' where/;
1477 my $sth=$dbh->prepare($query);
1482 # FIXME - This function appears in C4::Catalogue. Neither one is used
1484 my($price,$rrp,$itemnum)=@_;
1485 my $dbh = C4::Context->dbh;
1486 my $query="update items set price='$price',replacementprice='$rrp'
1487 where itemnumber=$itemnum";
1488 my $sth=$dbh->prepare($query);
1493 # FIXME - This is identical to &C4::Biblio::countitems.
1494 # Pick one and stick with it.
1497 my ($bibitemnum)=@_;
1498 my $dbh = C4::Context->dbh;
1499 my $query="Select count(*) from items where biblioitemnumber='$bibitemnum'";
1500 my $sth=$dbh->prepare($query);
1502 my $data=$sth->fetchrow_hashref;
1504 return($data->{'count(*)'});
1507 # FIXME - This function appears in C4::Catalogue. Neither one is used.
1509 my ($biblionumber)=@_;
1510 my $dbh = C4::Context->dbh;
1511 my $query="Select * from biblioitems,items,itemtypes where
1512 biblioitems.biblionumber=$biblionumber
1513 and biblioitems.biblioitemnumber=items.biblioitemnumber and
1514 itemtypes.itemtype=biblioitems.itemtype
1515 order by items.biblioitemnumber";
1516 my $sth=$dbh->prepare($query);
1520 while (my $data=$sth->fetchrow_hashref){
1528 # FIXME - This function appears in C4::Catalogue. Neither one is used
1530 my ($bibitemnum,$itemtype)=@_;
1531 my $dbh = C4::Context->dbh;
1532 my $query="Select * from biblioitems where biblioitemnumber=$bibitemnum
1533 and itemtype='$itemtype'";
1534 my $sth=$dbh->prepare($query);
1537 if (my $data=$sth->fetchrow_hashref){
1544 # FIXME - A nearly-identical function, appears in C4::Biblio
1545 # Pick one and stick with it.
1549 my $dbh = C4::Context->dbh;
1550 my $query="select * from items where itemnumber=$itemnum";
1551 my $sth=$dbh->prepare($query);
1553 my @data=$sth->fetchrow_array;
1555 $query="Insert into deleteditems values (";
1556 foreach my $temp (@data){
1557 $query=$query."'$temp',";
1561 $sth=$dbh->prepare($query);
1564 $query = "Delete from items where itemnumber=$itemnum";
1565 $sth=$dbh->prepare($query);
1570 # FIXME - This is functionally identical to &C4::Biblio::deletebiblioitem.
1571 # Pick one and stick with it.
1573 sub deletebiblioitem {
1574 my ($biblioitemnumber) = @_;
1575 my $dbh = C4::Context->dbh;
1576 my $query = "Select * from biblioitems
1577 where biblioitemnumber = $biblioitemnumber";
1578 my $sth = $dbh->prepare($query);
1583 if (@results = $sth->fetchrow_array) {
1585 $query = "Insert into deletedbiblioitems values (";
1586 foreach my $value (@results) {
1587 $value = $dbh->quote($value);
1588 $query .= "$value,";
1591 $query =~ s/\,$/\)/;
1594 $query = "Delete from biblioitems
1595 where biblioitemnumber = $biblioitemnumber";
1601 # Now delete all the items attached to the biblioitem
1603 $query = "Select * from items where biblioitemnumber = $biblioitemnumber";
1604 $sth = $dbh->prepare($query);
1608 while (@results = $sth->fetchrow_array) {
1610 $query = "Insert into deleteditems values (";
1611 foreach my $value (@results) {
1612 $value = $dbh->quote($value);
1613 $query .= "$value,";
1616 $query =~ s/\,$/\)/;
1622 $query = "Delete from items where biblioitemnumber = $biblioitemnumber";
1625 } # sub deletebiblioitem
1627 # FIXME - This is functionally identical to &C4::Biblio::delbiblio.
1628 # Pick one and stick with it.
1632 my $dbh = C4::Context->dbh;
1633 my $query="select * from biblio where biblionumber=$biblio";
1634 my $sth=$dbh->prepare($query);
1636 if (my @data=$sth->fetchrow_array){
1638 $query="Insert into deletedbiblio values (";
1639 foreach my $temp (@data){
1640 $temp=~ s/\'/\\\'/g;
1641 $query=$query."'$temp',";
1645 $sth=$dbh->prepare($query);
1648 $query = "Delete from biblio where biblionumber=$biblio";
1649 $sth=$dbh->prepare($query);
1659 my $dbh = C4::Context->dbh;
1660 my $query = "select * from itemtypes";
1661 my $sth = $dbh->prepare($query);
1662 # || die "Cannot prepare $query" . $dbh->errstr;
1667 # || die "Cannot execute $query\n" . $sth->errstr;
1668 while (my $data = $sth->fetchrow_hashref) {
1669 $results[$count] = $data;
1674 return($count, @results);
1675 } # sub getitemtypes
1677 # FIXME - This is identical to &C4::Biblio::getitemtypes.
1678 # Pick one and stick with it.
1681 my ($biblionumber) = @_;
1682 my $dbh = C4::Context->dbh;
1683 my $query = "Select * from biblio where biblionumber = $biblionumber";
1684 my $sth = $dbh->prepare($query);
1685 # || die "Cannot prepare $query\n" . $dbh->errstr;
1690 # || die "Cannot execute $query\n" . $sth->errstr;
1691 while (my $data = $sth->fetchrow_hashref) {
1692 $results[$count] = $data;
1697 return($count, @results);
1702 my ($biblioitemnum) = @_;
1703 my $dbh = C4::Context->dbh;
1704 my $query = "Select * from biblioitems where
1705 biblioitemnumber = $biblioitemnum";
1706 my $sth = $dbh->prepare($query);
1712 while (my $data = $sth->fetchrow_hashref) {
1713 $results[$count] = $data;
1718 return($count, @results);
1719 } # sub getbiblioitem
1721 # FIXME - This is identical to &C4::Biblio::getbiblioitem.
1722 # Pick one and stick with it.
1724 sub getbiblioitembybiblionumber {
1725 my ($biblionumber) = @_;
1726 my $dbh = C4::Context->dbh;
1727 my $query = "Select * from biblioitems where biblionumber =
1729 my $sth = $dbh->prepare($query);
1735 while (my $data = $sth->fetchrow_hashref) {
1736 $results[$count] = $data;
1741 return($count, @results);
1744 # FIXME - This is identical to
1745 # &C4::Biblio::getbiblioitembybiblionumber.
1746 # Pick one and stick with it.
1748 sub getitemsbybiblioitem {
1749 my ($biblioitemnum) = @_;
1750 my $dbh = C4::Context->dbh;
1751 my $query = "Select * from items, biblio where
1752 biblio.biblionumber = items.biblionumber and biblioitemnumber
1754 my $sth = $dbh->prepare($query);
1755 # || die "Cannot prepare $query\n" . $dbh->errstr;
1760 # || die "Cannot execute $query\n" . $sth->errstr;
1761 while (my $data = $sth->fetchrow_hashref) {
1762 $results[$count] = $data;
1767 return($count, @results);
1768 } # sub getitemsbybiblioitem
1770 # FIXME - This is identical to &C4::Biblio::isbnsearch.
1771 # Pick one and stick with it.
1775 my $dbh = C4::Context->dbh;
1781 $isbn = $dbh->quote($isbn);
1782 $query = "Select biblio.* from biblio, biblioitems where
1783 biblio.biblionumber = biblioitems.biblionumber
1785 $sth = $dbh->prepare($query);
1788 while (my $data = $sth->fetchrow_hashref) {
1789 $results[$count] = $data;
1794 return($count, @results);
1799 ($count, @results) = &websitesearch($keywordlist);
1801 Looks up biblioitems by URL.
1803 C<$keywordlist> is a space-separated list of search terms.
1804 C<&websitesearch> returns those biblioitems whose URL contains at
1805 least one of the search terms.
1807 C<$count> is the number of elements in C<@results>. C<@results> is an
1808 array of references-to-hash, whose keys are the fields of the biblio
1809 and biblioitems tables in the Koha database.
1813 # FIXME - This function appears in C4::Catalogue
1815 my ($keywordlist) = @_;
1816 my $dbh = C4::Context->dbh;
1817 my $query = "Select distinct biblio.* from biblio, biblioitems where
1818 biblio.biblionumber = biblioitems.biblionumber and (";
1822 my @keywords = split(/ +/, $keywordlist);
1823 my $keyword = shift(@keywords);
1825 $keyword =~ s/%/\\%/g;
1826 $keyword =~ s/_/\\_/;
1827 $keyword = "%" . $keyword . "%";
1828 $keyword = $dbh->quote($keyword);
1829 $query .= " (url like $keyword)";
1831 foreach $keyword (@keywords) {
1832 $keyword =~ s/%/\\%/;
1833 $keyword =~ s/_/\\_/;
1834 $keyword = "%" . $keyword . "%";
1835 $keyword = $dbh->quote($keyword);
1836 $query .= " or (url like $keyword)";
1840 $sth = $dbh->prepare($query);
1843 while (my $data = $sth->fetchrow_hashref) {
1844 $results[$count] = $data;
1849 return($count, @results);
1850 } # sub websitesearch
1854 &addwebsite($website);
1856 Adds a new web site. C<$website> is a reference-to-hash, with the keys
1857 C<biblionumber>, C<title>, C<description>, and C<url>. All of these
1862 # FIXME - This function appears in C4::Catalogue
1865 my $dbh = C4::Context->dbh;
1868 $website->{'biblionumber'} = $dbh->quote($website->{'biblionumber'});
1869 $website->{'title'} = $dbh->quote($website->{'title'});
1870 $website->{'description'} = $dbh->quote($website->{'description'});
1871 $website->{'url'} = $dbh->quote($website->{'url'});
1873 $query = "Insert into websites set
1874 biblionumber = $website->{'biblionumber'},
1875 title = $website->{'title'},
1876 description = $website->{'description'},
1877 url = $website->{'url'}";
1884 &updatewebsite($website);
1886 Updates an existing web site. C<$website> is a reference-to-hash with
1887 the keys C<websitenumber>, C<title>, C<description>, and C<url>. All
1888 of these are mandatory. C<$website-E<gt>{websitenumber}> identifies
1889 the entry to update.
1893 # FIXME - This function appears in C4::Catalogue
1896 my $dbh = C4::Context->dbh;
1899 $website->{'title'} = $dbh->quote($website->{'title'});
1900 $website->{'description'} = $dbh->quote($website->{'description'});
1901 $website->{'url'} = $dbh->quote($website->{'url'});
1903 $query = "Update websites set
1904 title = $website->{'title'},
1905 description = $website->{'description'},
1906 url = $website->{'url'}
1907 where websitenumber = $website->{'websitenumber'}";
1910 } # sub updatewebsite
1914 &deletewebsite($websitenumber);
1916 Deletes the web site with number C<$websitenumber>.
1920 # FIXME - This function appears in C4::Catalogue
1922 my ($websitenumber) = @_;
1923 my $dbh = C4::Context->dbh;
1924 # FIXME - $query is unnecessary: just use
1926 # DELETE FROM websites where websitenumber=$websitenumber
1928 my $query = "Delete from websites where websitenumber = $websitenumber";
1931 } # sub deletewebsite
1934 END { } # module clean-up code here (global destructor)
1943 Koha Developement team <info@koha.org>