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);
32 # set the version for version checking
37 C4::Acquisitions - Koha module dealing with acquisitions and orders
45 B<NOTE:> This module is deprecated in Koha 1.3.x.
47 The functions in this module deal with acquisitions, managing book
48 orders, converting money to different currencies, and so forth.
57 @EXPORT = qw(&getorders &bookseller &breakdown &basket &newbasket &bookfunds
58 &ordersearch &newbiblio &newbiblioitem &newsubject &newsubtitle &neworder
59 &newordernum &modbiblio &modorder &getsingleorder &invoice &receiveorder
60 &bookfundbreakdown &curconvert &updatesup &insertsup &newitems &modbibitem
61 &getcurrencies &modsubtitle &modsubject &modaddauthor &moditem &countitems
62 &findall &needsmod &delitem &deletebiblioitem &delbiblio &delorder &branches
63 &getallorders &getrecorders &updatecurrencies &getorder &getcurrency &updaterecorder
64 &updatecost &checkitems &modnote &getitemtypes &getbiblio
65 &getbiblioitembybiblionumber
66 &getbiblioitem &getitemsbybiblioitem &isbnsearch
67 &websitesearch &addwebsite &updatewebsite &deletewebsite);
71 ($count, $orders) = &getorders($booksellerid);
73 Finds pending orders from the bookseller with the given ID. Ignores
74 completed and cancelled orders.
76 C<$count> is the number of elements in C<@{$orders}>.
78 C<$orders> is a reference-to-array; each element is a
79 reference-to-hash with the following fields:
85 Gives the number of orders in with this basket number.
93 These give the value of the corresponding field in the aqorders table
98 Results are ordered from most to least recent.
102 # FIXME - This exact function already exists in C4::Catalogue
105 my $dbh = C4::Context->dbh;
106 my $query = "Select count(*),authorisedby,entrydate,basketno from aqorders where
107 booksellerid='$supplierid' and (quantity > quantityreceived or
108 quantityreceived is NULL)
109 and (datecancellationprinted is NULL or datecancellationprinted = '0000-00-00')";
110 $query.=" group by basketno order by entrydate desc";
112 my $sth=$dbh->prepare($query);
116 while (my $data=$sth->fetchrow_hashref){
121 return ($i,\@results);
124 # Only used internally
125 # FIXME - This is the same as &C4::Biblio::itemcount, but not
126 # the same as &C4::Search::itemcount
129 my $dbh = C4::Context->dbh;
130 my $query="Select count(*) from items where biblionumber=$biblio";
132 my $sth=$dbh->prepare($query);
134 my $data=$sth->fetchrow_hashref;
136 return($data->{'count(*)'});
141 ($order, $ordernumber) = &getorder($biblioitemnumber, $biblionumber);
143 Looks up the order with the given biblionumber and biblioitemnumber.
145 Returns a two-element array. C<$ordernumber> is the order number.
146 C<$order> is a reference-to-hash describing the order; its keys are
147 fields from the biblio, biblioitems, aqorders, and aqorderbreakdown
148 tables of the Koha database.
152 # FIXME - There are functions &getorder and &getorders. Isn't this
153 # somewhat likely to cause confusion?
154 # FIXME - Almost the exact same function is already in C4::Catalogue
157 my $dbh = C4::Context->dbh;
158 my $query="Select ordernumber
160 where biblionumber=? and biblioitemnumber=?";
161 my $sth=$dbh->prepare($query);
162 $sth->execute($bib,$bi);
163 my $ordnum=$sth->fetchrow_hashref;
165 my $order=getsingleorder($ordnum->{'ordernumber'});
167 return ($order,$ordnum->{'ordernumber'});
172 $order = &getsingleorder($ordernumber);
174 Looks up an order by order number.
176 Returns a reference-to-hash describing the order. The keys of
177 C<$order> are fields from the biblio, biblioitems, aqorders, and
178 aqorderbreakdown tables of the Koha database.
182 # FIXME - This is practically the same function as
183 # &C4::Catalogue::getsingleorder and &C4::Biblio::getsingleorder.
186 my $dbh = C4::Context->dbh;
187 my $query="Select * from biblio,biblioitems,aqorders,aqorderbreakdown
188 where aqorders.ordernumber=?
189 and biblio.biblionumber=aqorders.biblionumber and
190 biblioitems.biblioitemnumber=aqorders.biblioitemnumber and
191 aqorders.ordernumber=aqorderbreakdown.ordernumber";
192 my $sth=$dbh->prepare($query);
193 $sth->execute($ordnum);
194 my $data=$sth->fetchrow_hashref;
201 ($count, @results) = &invoice($booksellerinvoicenumber);
203 Looks up orders by invoice number.
205 Returns an array. C<$count> is the number of elements in C<@results>.
206 C<@results> is an array of references-to-hash; the keys of each
207 elements are fields from the aqorders, biblio, and biblioitems tables
208 of the Koha database.
212 # FIXME - This exact function is already in C4::Catalogue
215 my $dbh = C4::Context->dbh;
216 my $query="Select * from aqorders,biblio,biblioitems where
217 booksellerinvoicenumber='$invoice'
218 and biblio.biblionumber=aqorders.biblionumber and biblioitems.biblioitemnumber=
219 aqorders.biblioitemnumber group by aqorders.ordernumber,aqorders.biblioitemnumber";
222 my $sth=$dbh->prepare($query);
224 while (my $data=$sth->fetchrow_hashref){
234 ($count, @results) = &getallorders($booksellerid);
236 Looks up all of the pending orders from the supplier with the given
237 bookseller ID. Ignores cancelled orders.
239 C<$count> is the number of elements in C<@results>. C<@results> is an
240 array of references-to-hash. The keys of each element are fields from
241 the aqorders, biblio, and biblioitems tables of the Koha database.
243 C<@results> is sorted alphabetically by book title.
247 # FIXME - Almost (but not quite) the same function appears in C4::Catalogue
248 # That one only lists incomplete orders.
250 #gets all orders from a certain supplier, orders them alphabetically
252 my $dbh = C4::Context->dbh;
253 my $query="Select * from aqorders,biblio,biblioitems where booksellerid='$supid'
254 and (cancelledby is NULL or cancelledby = '')
255 and biblio.biblionumber=aqorders.biblionumber and biblioitems.biblioitemnumber=
256 aqorders.biblioitemnumber
257 group by aqorders.biblioitemnumber
262 my $sth=$dbh->prepare($query);
264 while (my $data=$sth->fetchrow_hashref){
272 # FIXME - There's a getrecorders in C4::Catalogue
273 # FIXME - Never used (neither is the other one, actually)
275 #gets all orders from a certain supplier, orders them alphabetically
277 my $dbh = C4::Context->dbh;
278 my $query="Select * from aqorders,biblio,biblioitems where booksellerid='$supid'
279 and (cancelledby is NULL or cancelledby = '')
280 and biblio.biblionumber=aqorders.biblionumber and biblioitems.biblioitemnumber=
281 aqorders.biblioitemnumber and
282 aqorders.quantityreceived>0
283 and aqorders.datereceived >=now()
284 group by aqorders.biblioitemnumber
289 my $sth=$dbh->prepare($query);
291 while (my $data=$sth->fetchrow_hashref){
301 ($count, @results) = &ordersearch($search, $biblionumber, $complete);
305 C<$search> may take one of several forms: if it is an ISBN,
306 C<&ordersearch> returns orders with that ISBN. If C<$search> is an
307 order number, C<&ordersearch> returns orders with that order number
308 and biblionumber C<$biblionumber>. Otherwise, C<$search> is considered
309 to be a space-separated list of search terms; in this case, all of the
310 terms must appear in the title (matching the beginning of title
313 If C<$complete> is C<yes>, the results will include only completed
314 orders. In any case, C<&ordersearch> ignores cancelled orders.
316 C<&ordersearch> returns an array. C<$count> is the number of elements
317 in C<@results>. C<@results> is an array of references-to-hash with the
334 # FIXME - The same function (modulo whitespace) appears in C4::Catalogue
336 my ($search,$biblio,$catview)=@_;
337 my $dbh = C4::Context->dbh;
338 my $query="Select *,biblio.title from aqorders,biblioitems,biblio
339 where aqorders.biblioitemnumber = biblioitems.biblioitemnumber
340 and biblio.biblionumber=aqorders.biblionumber
341 and ((datecancellationprinted is NULL)
342 or (datecancellationprinted = '0000-00-00'))
344 my @data=split(' ',$search);
346 for (my $i=0;$i<$count;$i++){
347 $query.= "(biblio.title like '$data[$i]%' or biblio.title like '% $data[$i]%') and ";
350 $query.=" ) or biblioitems.isbn='$search'
351 or (aqorders.ordernumber='$search' and aqorders.biblionumber='$biblio')) ";
352 if ($catview ne 'yes'){
353 $query.=" and (quantityreceived < quantity or quantityreceived is NULL)";
355 $query.=" group by aqorders.ordernumber";
356 my $sth=$dbh->prepare($query);
361 while (my $data=$sth->fetchrow_hashref){
362 my $sth2=$dbh->prepare("Select * from biblio where
363 biblionumber='$data->{'biblionumber'}'");
365 my $data2=$sth2->fetchrow_hashref;
367 $data->{'author'}=$data2->{'author'};
368 $data->{'seriestitle'}=$data2->{'seriestitle'};
369 $sth2=$dbh->prepare("Select * from aqorderbreakdown where
370 ordernumber=$data->{'ordernumber'}");
372 $data2=$sth2->fetchrow_hashref;
374 $data->{'branchcode'}=$data2->{'branchcode'};
375 $data->{'bookfundid'}=$data2->{'bookfundid'};
385 ($count, @results) = &bookseller($searchstring);
387 Looks up a book seller. C<$searchstring> may be either a book seller
388 ID, or a string to look for in the book seller's name.
390 C<$count> is the number of elements in C<@results>. C<@results> is an
391 array of references-to-hash, whose keys are the fields of of the
392 aqbooksellers table in the Koha database.
396 # FIXME - This function appears in C4::Catalogue
398 my ($searchstring)=@_;
399 my $dbh = C4::Context->dbh;
400 my $query="Select * from aqbooksellers where name like '%$searchstring%' or
401 id = '$searchstring'";
402 my $sth=$dbh->prepare($query);
406 while (my $data=$sth->fetchrow_hashref){
416 ($count, $results) = &breakdown($ordernumber);
418 Looks up an order by order ID, and returns its breakdown.
420 C<$count> is the number of elements in C<$results>. C<$results> is a
421 reference-to-array; its elements are references-to-hash, whose keys
422 are the fields of the aqorderbreakdown table in the Koha database.
426 # FIXME - This function appears in C4::Catalogue.
429 my $dbh = C4::Context->dbh;
430 my $query="Select * from aqorderbreakdown where ordernumber='$id'";
431 my $sth=$dbh->prepare($query);
435 while (my $data=$sth->fetchrow_hashref){
440 return($i,\@results);
445 ($count, @orders) = &basket($basketnumber, $booksellerID);
447 Looks up the pending (non-cancelled) orders with the given basket
448 number. If C<$booksellerID> is non-empty, only orders from that seller
451 C<&basket> returns a two-element array. C<@orders> is an array of
452 references-to-hash, whose keys are the fields from the aqorders,
453 biblio, and biblioitems tables in the Koha database. C<$count> is the
454 number of elements in C<@orders>.
458 # FIXME - Almost the same function (with less error-checking) appears in
461 my ($basketno,$supplier)=@_;
462 my $dbh = C4::Context->dbh;
463 my $query="Select *,biblio.title from aqorders,biblio,biblioitems
464 where basketno='$basketno'
465 and biblio.biblionumber=aqorders.biblionumber and biblioitems.biblioitemnumber
466 =aqorders.biblioitemnumber
467 and (datecancellationprinted is NULL or datecancellationprinted =
469 if (defined $supplier && $supplier ne ''){
470 $query.=" and aqorders.booksellerid='$supplier'";
472 $query.=" group by aqorders.ordernumber";
473 my $sth=$dbh->prepare($query);
478 while (my $data=$sth->fetchrow_hashref){
488 $basket = &newbasket();
490 Finds the next unused basket number in the aqorders table of the Koha
491 database, and returns it.
495 # FIXME - There's a race condition here:
497 # B calls &newbasket (gets the same number as A)
498 # A updates the basket
499 # B updates the basket, and clobbers A's result.
500 # A better approach might be to create a dummy order (with, say,
501 # requisitionedby == "Dummy-$$" or notes == "dummy <time> <pid>"), and
502 # see which basket number it gets. Then have a cron job periodically
503 # remove out-of-date dummy orders.
504 # FIXME - This function appears in C4::Catalogue.pm
506 my $dbh = C4::Context->dbh;
507 my $query="Select max(basketno) from aqorders";
508 my $sth=$dbh->prepare($query);
510 my $data=$sth->fetchrow_arrayref;
511 my $basket=$$data[0];
519 ($count, @results) = &bookfunds();
521 Returns a list of all book funds started on Sep 1, 2001.
523 C<$count> is the number of elements in C<@results>. C<@results> is an
524 array of references-to-hash, whose keys are fields from the aqbookfund
525 and aqbudget tables of the Koha database. Results are ordered
526 alphabetically by book fund name.
530 # FIXME - An identical function (without the hardcoded date) appears in
533 my $dbh = C4::Context->dbh;
534 my $query="Select * from aqbookfund,aqbudget where aqbookfund.bookfundid
536 and aqbudget.startdate='2001-07-01'
537 group by aqbookfund.bookfundid order by bookfundname";
538 my $sth=$dbh->prepare($query);
542 while (my $data=$sth->fetchrow_hashref){
552 ($count, @results) = &branches();
554 Returns a list of all library branches.
556 C<$count> is the number of elements in C<@results>. C<@results> is an
557 array of references-to-hash, whose keys are the fields of the branches
558 table of the Koha database.
562 # FIXME - This function (modulo whitespace) appears in C4::Catalogue
564 my $dbh = C4::Context->dbh;
565 my $query="Select * from branches";
566 my $sth=$dbh->prepare($query);
571 while (my $data = $sth->fetchrow_hashref){
577 return($i, @results);
580 # FIXME - POD. But I can't figure out what this function is doing
581 # FIXME - An almost identical function appears in C4::Catalogue
582 sub bookfundbreakdown {
584 my $dbh = C4::Context->dbh;
585 my $query="Select quantity,datereceived,freight,unitprice,listprice,ecost,quantityreceived,subscription
586 from aqorders,aqorderbreakdown where bookfundid='$id' and
587 aqorders.ordernumber=aqorderbreakdown.ordernumber and ((budgetdate >=
588 '2001-07-01' and budgetdate <'2002-07-01') or
589 (datereceived >= '2001-07-01' and datereceived < '2002-07-01'))
590 and (datecancellationprinted is NULL or
591 datecancellationprinted='0000-00-00')";
592 my $sth=$dbh->prepare($query);
596 while (my $data=$sth->fetchrow_hashref){
597 if ($data->{'subscription'} == 1){
598 $spent+=$data->{'quantity'}*$data->{'unitprice'};
600 my $leftover=$data->{'quantity'}-$data->{'quantityreceived'};
601 $comtd+=($data->{'ecost'})*$leftover;
602 $spent+=($data->{'unitprice'})*$data->{'quantityreceived'};
606 return($spent,$comtd);
609 # FIXME - This is in effect identical to &C4::Biblio::newbiblio.
610 # Pick one and stick with it.
612 # FIXME - Never used (anything that uses &newbiblio uses
613 # &C4::Biblio::newbiblio). Nuke this.
616 my $dbh = C4::Context->dbh;
617 my $query = "Select max(biblionumber) from biblio";
618 my $sth = $dbh->prepare($query);
620 my $data = $sth->fetchrow_arrayref;
621 my $bibnum = $$data[0] + 1;
624 $biblio->{'title'} = $dbh->quote($biblio->{'title'});
625 $biblio->{'author'} = $dbh->quote($biblio->{'author'});
626 $biblio->{'copyright'} = $dbh->quote($biblio->{'copyright'});
627 $biblio->{'seriestitle'} = $dbh->quote($biblio->{'seriestitle'});
628 $biblio->{'notes'} = $dbh->quote($biblio->{'notes'});
629 $biblio->{'abstract'} = $dbh->quote($biblio->{'abstract'});
630 if ($biblio->{'seriestitle'}) { $series = 1 };
636 SET biblionumber = $bibnum,
637 title = $biblio->{'title'},
638 author = $biblio->{'author'},
639 copyrightdate = $biblio->{'copyright'},
641 seriestitle = $biblio->{'seriestitle'},
642 notes = $biblio->{'notes'},
643 abstract = $biblio->{'abstract'}
651 $biblionumber = &modbiblio($biblio);
653 Update a biblio record.
655 C<$biblio> is a reference-to-hash whose keys are the fields in the
656 biblio table in the Koha database. All fields must be present, not
657 just the ones you wish to change.
659 C<&modbiblio> updates the record defined by
660 C<$biblio-E<gt>{biblionumber}> with the values in C<$biblio>.
662 C<&modbiblio> returns C<$biblio-E<gt>{biblionumber}> whether it was
667 # FIXME - This is in effect the same as &C4::Biblio::modbiblio.
668 # Pick one and stick with it.
671 my $dbh = C4::Context->dbh;
675 $biblio->{'title'} = $dbh->quote($biblio->{'title'});
676 $biblio->{'author'} = $dbh->quote($biblio->{'author'});
677 $biblio->{'abstract'} = $dbh->quote($biblio->{'abstract'});
678 $biblio->{'copyrightdate'} = $dbh->quote($biblio->{'copyrightdate'});
679 $biblio->{'seriestitle'} = $dbh->quote($biblio->{'serirestitle'});
680 $biblio->{'serial'} = $dbh->quote($biblio->{'serial'});
681 $biblio->{'unititle'} = $dbh->quote($biblio->{'unititle'});
682 $biblio->{'notes'} = $dbh->quote($biblio->{'notes'});
684 $query = "Update biblio set
685 title = $biblio->{'title'},
686 author = $biblio->{'author'},
687 abstract = $biblio->{'abstract'},
688 copyrightdate = $biblio->{'copyrightdate'},
689 seriestitle = $biblio->{'seriestitle'},
690 serial = $biblio->{'serial'},
691 unititle = $biblio->{'unititle'},
692 notes = $biblio->{'notes'}
693 where biblionumber = $biblio->{'biblionumber'}";
694 $sth = $dbh->prepare($query);
699 return($biblio->{'biblionumber'});
704 &modsubtitle($biblionumber, $subtitle);
706 Sets the subtitle of a book.
708 C<$biblionumber> is the biblionumber of the book to modify.
710 C<$subtitle> is the new subtitle.
714 # FIXME - This is in effect identical to &C4::Biblio::modsubtitle.
715 # Pick one and stick with it.
717 my ($bibnum, $subtitle) = @_;
718 my $dbh = C4::Context->dbh;
719 my $query = "update bibliosubtitle set
720 subtitle = '$subtitle'
721 where biblionumber = $bibnum";
722 my $sth = $dbh->prepare($query);
730 &modaddauthor($biblionumber, $author);
732 Replaces all additional authors for the book with biblio number
733 C<$biblionumber> with C<$author>. If C<$author> is the empty string,
734 C<&modaddauthor> deletes all additional authors.
738 # FIXME - This is functionally identical to &C4::Biblio::modaddauthor
739 # Pick one and stick with it.
740 # FIXME - This API is bogus: you should be able to have more than 2
743 my ($bibnum, $author) = @_;
744 my $dbh = C4::Context->dbh;
745 # FIXME - Use $dbh->do()
746 my $query = "Delete from additionalauthors where biblionumber = $bibnum";
747 my $sth = $dbh->prepare($query);
753 $query = "Insert into additionalauthors set
755 biblionumber = '$bibnum'";
756 $sth = $dbh->prepare($query);
766 $error = &modsubject($biblionumber, $force, @subjects);
768 $force - a subject to force
770 $error - Error message, or undef if successful.
774 # FIXME - This is in effect identical to &C4::Biblio::modsubject.
775 # Pick one and stick with it.
776 # FIXME - Bogus API: either $force should force all subjects to be
777 # added to catalogueentry, or else you should be able to specify a
778 # list of subjects to force.
780 my ($bibnum, $force, @subject) = @_;
781 my $dbh = C4::Context->dbh;
782 my $count = @subject;
785 # Loop over list of subjects
786 # FIXME - Use foreach my $subject (@subjects)
787 for (my $i = 0; $i < $count; $i++) {
788 $subject[$i] =~ s/^ //g; # Trim whitespace
789 $subject[$i] =~ s/ $//g;
791 # Look up the subject in the authority file.
792 my $query = "select * from catalogueentry
793 where entrytype = 's'
794 and catalogueentry = '$subject[$i]'";
795 my $sth = $dbh->prepare($query);
798 if (my $data = $sth->fetchrow_hashref) {
799 # FIXME - Ick! Empty if-clauses suck. Use a "not" or something.
801 if ($force eq $subject[$i]) {
803 # subject not in aut, chosen to force anway
804 # so insert into cataloguentry so its in auth file
805 $query = "Insert into catalogueentry
806 (entrytype,catalogueentry)
807 values ('s','$subject[$i]')";
808 my $sth2 = $dbh->prepare($query);
815 $error = "$subject[$i]\n does not exist in the subject authority file";
816 $query = "Select * from catalogueentry
817 where entrytype = 's'
818 and (catalogueentry like '$subject[$i] %'
819 or catalogueentry like '% $subject[$i] %'
820 or catalogueentry like '% $subject[$i]')";
821 my $sth2 = $dbh->prepare($query);
824 while (my $data = $sth2->fetchrow_hashref) {
825 $error .= "<br>$data->{'catalogueentry'}";
834 my $query = "Delete from bibliosubject where biblionumber = $bibnum";
835 my $sth = $dbh->prepare($query);
840 for (my $i = 0; $i < $count; $i++) {
841 $sth = $dbh->prepare("Insert into bibliosubject
842 values ('$subject[$i]', $bibnum)");
852 # FIXME - This is very similar to &C4::Biblio::modbibitem.
853 # Pick one and stick with it.
854 # If it's this one, it needs a POD.
856 my ($biblioitem) = @_;
857 my $dbh = C4::Context->dbh;
860 # foreach my $field (qw( ... ))
862 # $biblioitem->{$field} = $dbh->quote($biblioitem->{$field});
864 $biblioitem->{'itemtype'} = $dbh->quote($biblioitem->{'itemtype'});
865 $biblioitem->{'url'} = $dbh->quote($biblioitem->{'url'});
866 $biblioitem->{'isbn'} = $dbh->quote($biblioitem->{'isbn'});
867 $biblioitem->{'publishercode'} = $dbh->quote($biblioitem->{'publishercode'});
868 $biblioitem->{'publicationyear'} = $dbh->quote($biblioitem->{'publicationyear'});
869 $biblioitem->{'classification'} = $dbh->quote($biblioitem->{'classification'});
870 $biblioitem->{'dewey'} = $dbh->quote($biblioitem->{'dewey'});
871 $biblioitem->{'subclass'} = $dbh->quote($biblioitem->{'subclass'});
872 $biblioitem->{'illus'} = $dbh->quote($biblioitem->{'illus'});
873 $biblioitem->{'pages'} = $dbh->quote($biblioitem->{'pages'});
874 $biblioitem->{'volumeddesc'} = $dbh->quote($biblioitem->{'volumeddesc'});
875 $biblioitem->{'notes'} = $dbh->quote($biblioitem->{'notes'});
876 $biblioitem->{'size'} = $dbh->quote($biblioitem->{'size'});
877 $biblioitem->{'place'} = $dbh->quote($biblioitem->{'place'});
881 SET itemtype = $biblioitem->{'itemtype'},
882 url = $biblioitem->{'url'},
883 isbn = $biblioitem->{'isbn'},
884 publishercode = $biblioitem->{'publishercode'},
885 publicationyear = $biblioitem->{'publicationyear'},
886 classification = $biblioitem->{'classification'},
887 dewey = $biblioitem->{'dewey'},
888 subclass = $biblioitem->{'subclass'},
889 illus = $biblioitem->{'illus'},
890 pages = $biblioitem->{'pages'},
891 volumeddesc = $biblioitem->{'volumeddesc'},
892 notes = $biblioitem->{'notes'},
893 size = $biblioitem->{'size'},
894 place = $biblioitem->{'place'}
895 WHERE biblioitemnumber = $biblioitem->{'biblioitemnumber'}
899 # FIXME - This is in effect identical to &C4::Biblio::modnote.
900 # Pick one and stick with it.
901 # If it's this one, it needs a POD.
903 my ($bibitemnum,$note)=@_;
904 my $dbh = C4::Context->dbh;
909 WHERE biblioitemnumber = '$bibitemnum'
913 # FIXME - &C4::Biblio::newbiblioitem is quite similar to this
914 # Pick one and stick with it.
915 # If it's this one, it needs a POD.
917 my ($biblioitem) = @_;
918 my $dbh = C4::Context->dbh;
919 my $query = "Select max(biblioitemnumber) from biblioitems";
920 my $sth = $dbh->prepare($query);
924 $biblioitem->{'volume'} = $dbh->quote($biblioitem->{'volume'});
925 $biblioitem->{'number'} = $dbh->quote($biblioitem->{'number'});
926 $biblioitem->{'classification'} = $dbh->quote($biblioitem->{'classification'});
927 $biblioitem->{'itemtype'} = $dbh->quote($biblioitem->{'itemtype'});
928 $biblioitem->{'url'} = $dbh->quote($biblioitem->{'url'});
929 $biblioitem->{'isbn'} = $dbh->quote($biblioitem->{'isbn'});
930 $biblioitem->{'issn'} = $dbh->quote($biblioitem->{'issn'});
931 $biblioitem->{'dewey'} = $dbh->quote($biblioitem->{'dewey'});
932 $biblioitem->{'subclass'} = $dbh->quote($biblioitem->{'subclass'});
933 $biblioitem->{'publicationyear'} = $dbh->quote($biblioitem->{'publicationyear'});
934 $biblioitem->{'publishercode'} = $dbh->quote($biblioitem->{'publishercode'});
935 $biblioitem->{'volumedate'} = $dbh->quote($biblioitem->{'volumedate'});
936 $biblioitem->{'volumeddesc'} = $dbh->quote($biblioitem->{'volumeddesc'}); $biblioitem->{'illus'} = $dbh->quote($biblioitem->{'illus'});
937 $biblioitem->{'illus'} = $dbh->quote($biblioitem->{'illus'});
938 $biblioitem->{'pages'} = $dbh->quote($biblioitem->{'pages'});
939 $biblioitem->{'notes'} = $dbh->quote($biblioitem->{'notes'});
940 $biblioitem->{'size'} = $dbh->quote($biblioitem->{'size'});
941 $biblioitem->{'place'} = $dbh->quote($biblioitem->{'place'});
942 $biblioitem->{'lccn'} = $dbh->quote($biblioitem->{'lccn'});
943 $biblioitem->{'marc'} = $dbh->quote($biblioitem->{'marc'});
946 $data = $sth->fetchrow_arrayref;
947 $bibitemnum = $$data[0] + 1;
951 $query = "insert into biblioitems set
952 biblioitemnumber = $bibitemnum,
953 biblionumber = $biblioitem->{'biblionumber'},
954 volume = $biblioitem->{'volume'},
955 number = $biblioitem->{'number'},
956 classification = $biblioitem->{'classification'},
957 itemtype = $biblioitem->{'itemtype'},
958 url = $biblioitem->{'url'},
959 isbn = $biblioitem->{'isbn'},
960 issn = $biblioitem->{'issn'},
961 dewey = $biblioitem->{'dewey'},
962 subclass = $biblioitem->{'subclass'},
963 publicationyear = $biblioitem->{'publicationyear'},
964 publishercode = $biblioitem->{'publishercode'},
965 volumedate = $biblioitem->{'volumedate'},
966 volumeddesc = $biblioitem->{'volumeddesc'},
967 illus = $biblioitem->{'illus'},
968 pages = $biblioitem->{'pages'},
969 notes = $biblioitem->{'notes'},
970 size = $biblioitem->{'size'},
971 lccn = $biblioitem->{'lccn'},
972 marc = $biblioitem->{'marc'},
973 place = $biblioitem->{'place'}";
975 $sth = $dbh->prepare($query);
982 # FIXME - This is in effect identical to &C4::Biblio::newsubject.
983 # Pick one and stick with it.
984 # If it's this one, it needs a POD.
987 my $dbh = C4::Context->dbh;
988 my $query="insert into bibliosubject (biblionumber) values
990 my $sth=$dbh->prepare($query);
996 # FIXME - This is in effect the same as &C4::Biblio::newsubtitle
997 # Pick one and stick with it.
998 # If it's this one, it needs a POD.
1000 my ($bibnum, $subtitle) = @_;
1001 my $dbh = C4::Context->dbh;
1002 $subtitle = $dbh->quote($subtitle);
1003 my $query = "insert into bibliosubtitle set
1004 biblionumber = $bibnum,
1005 subtitle = $subtitle";
1006 my $sth = $dbh->prepare($query);
1015 &neworder($biblionumber, $title, $ordnum, $basket, $quantity, $listprice,
1016 $booksellerid, $who, $notes, $bookfund, $biblioitemnumber, $rrp,
1017 $ecost, $gst, $budget, $unitprice, $subscription,
1018 $booksellerinvoicenumber);
1020 Adds a new order to the database. Any argument that isn't described
1021 below is the new value of the field with the same name in the aqorders
1022 table of the Koha database.
1024 C<$ordnum> is a "minimum order number." After adding the new entry to
1025 the aqorders table, C<&neworder> finds the first entry in aqorders
1026 with order number greater than or equal to C<$ordnum>, and adds an
1027 entry to the aqorderbreakdown table, with the order number just found,
1028 and the book fund ID of the newly-added order.
1030 C<$budget> is effectively ignored.
1032 C<$subscription> may be either "yes", or anything else for "no".
1036 # FIXME - This function appears in C4::Catalogue
1038 my ($bibnum,$title,$ordnum,$basket,$quantity,$listprice,$supplier,$who,$notes,$bookfund,$bibitemnum,$rrp,$ecost,$gst,$budget,$cost,$sub,$invoice)=@_;
1039 if ($budget eq 'now'){
1042 $budget="'2001-07-01'";
1049 my $dbh = C4::Context->dbh;
1050 my $query="insert into aqorders (biblionumber,title,basketno,
1051 quantity,listprice,booksellerid,entrydate,requisitionedby,authorisedby,notes,
1052 biblioitemnumber,rrp,ecost,gst,unitprice,subscription,booksellerinvoicenumber)
1055 ($bibnum,'$title',$basket,$quantity,$listprice,'$supplier',now(),
1056 '$who','$who','$notes',$bibitemnum,'$rrp','$ecost','$gst','$cost',
1057 '$sub','$invoice')";
1058 my $sth=$dbh->prepare($query);
1062 $query="select * from aqorders where
1063 biblionumber=$bibnum and basketno=$basket and ordernumber >=$ordnum";
1064 $sth=$dbh->prepare($query);
1066 my $data=$sth->fetchrow_hashref;
1068 $ordnum=$data->{'ordernumber'};
1069 $query="insert into aqorderbreakdown (ordernumber,bookfundid) values
1070 ($ordnum,'$bookfund')";
1071 $sth=$dbh->prepare($query);
1079 &delorder($biblionumber, $ordernumber);
1081 Cancel the order with the given order and biblio numbers. It does not
1082 delete any entries in the aqorders table, it merely marks them as
1085 If there are no items remaining with the given biblionumber,
1086 C<&delorder> also deletes them from the marc_subfield_table and
1087 marc_biblio tables of the Koha database.
1091 # FIXME - This function appears in C4::Catalogue
1093 my ($bibnum,$ordnum)=@_;
1094 my $dbh = C4::Context->dbh;
1095 my $query="update aqorders set datecancellationprinted=now()
1096 where biblionumber='$bibnum' and
1097 ordernumber='$ordnum'";
1098 my $sth=$dbh->prepare($query);
1102 my $count=itemcount($bibnum);
1110 &modorder($title, $ordernumber, $quantity, $listprice,
1111 $biblionumber, $basketno, $supplier, $who, $notes,
1112 $bookfundid, $bibitemnum, $rrp, $ecost, $gst, $budget,
1113 $unitprice, $booksellerinvoicenumber);
1115 Modifies an existing order. Updates the order with order number
1116 C<$ordernumber> and biblionumber C<$biblionumber>. All other arguments
1117 update the fields with the same name in the aqorders table of the Koha
1120 Entries with order number C<$ordernumber> in the aqorderbreakdown
1121 table are also updated to the new book fund ID.
1125 # FIXME - This function appears in C4::Catalogue
1127 my ($title,$ordnum,$quantity,$listprice,$bibnum,$basketno,$supplier,$who,$notes,$bookfund,$bibitemnum,$rrp,$ecost,$gst,$budget,$cost,$invoice)=@_;
1128 my $dbh = C4::Context->dbh;
1129 my $query="update aqorders set title='$title',
1130 quantity='$quantity',listprice='$listprice',basketno='$basketno',
1131 rrp='$rrp',ecost='$ecost',unitprice='$cost',
1132 booksellerinvoicenumber='$invoice'
1134 ordernumber=$ordnum and biblionumber=$bibnum";
1135 my $sth=$dbh->prepare($query);
1139 $query="update aqorderbreakdown set bookfundid=$bookfund where
1140 ordernumber=$ordnum";
1141 $sth=$dbh->prepare($query);
1149 $order = &newordernum();
1151 Finds the next unused order number in the aqorders table of the Koha
1152 database, and returns it.
1156 # FIXME - Race condition
1157 # FIXME - This function appears in C4::Catalogue
1159 my $dbh = C4::Context->dbh;
1160 my $query="Select max(ordernumber) from aqorders";
1161 my $sth=$dbh->prepare($query);
1163 my $data=$sth->fetchrow_arrayref;
1164 my $ordnum=$$data[0];
1172 &receiveorder($biblionumber, $ordernumber, $quantityreceived, $user,
1173 $unitprice, $booksellerinvoicenumber, $biblioitemnumber,
1174 $freight, $bookfund, $rrp);
1176 Updates an order, to reflect the fact that it was received, at least
1177 in part. All arguments not mentioned below update the fields with the
1178 same name in the aqorders table of the Koha database.
1180 Updates the order with bibilionumber C<$biblionumber> and ordernumber
1183 Also updates the book fund ID in the aqorderbreakdown table.
1187 # FIXME - This function appears in C4::Catalogue
1189 my ($biblio,$ordnum,$quantrec,$user,$cost,$invoiceno,$bibitemno,$freight,$bookfund,$rrp)=@_;
1190 my $dbh = C4::Context->dbh;
1191 my $query="update aqorders set quantityreceived='$quantrec',
1192 datereceived=now(),booksellerinvoicenumber='$invoiceno',
1193 biblioitemnumber=$bibitemno,unitprice='$cost',freight='$freight',
1195 where biblionumber=$biblio and ordernumber=$ordnum
1198 my $sth=$dbh->prepare($query);
1201 $query="update aqorderbreakdown set bookfundid=$bookfund where
1202 ordernumber=$ordnum";
1203 $sth=$dbh->prepare($query);
1209 =item updaterecorder
1211 &updaterecorder($biblionumber, $ordernumber, $user, $unitprice,
1214 Updates the order with biblionumber C<$biblionumber> and order number
1215 C<$ordernumber>. C<$bookfundid> is the new value for the book fund ID
1216 in the aqorderbreakdown table of the Koha database. All other
1217 arguments update the fields with the same name in the aqorders table.
1219 C<$user> is ignored.
1223 # FIXME - This function appears in C4::Catalogue
1225 my($biblio,$ordnum,$user,$cost,$bookfund,$rrp)=@_;
1226 my $dbh = C4::Context->dbh;
1227 my $query="update aqorders set
1228 unitprice='$cost', rrp='$rrp'
1229 where biblionumber=$biblio and ordernumber=$ordnum
1232 my $sth=$dbh->prepare($query);
1235 $query="update aqorderbreakdown set bookfundid=$bookfund where
1236 ordernumber=$ordnum";
1237 $sth=$dbh->prepare($query);
1245 $foreignprice = &curconvert($currency, $localprice);
1247 Converts the price C<$localprice> to foreign currency C<$currency> by
1248 dividing by the exchange rate, and returns the result.
1250 If no exchange rate is found, C<&curconvert> assumes the rate is one
1255 # FIXME - An almost identical version of this function appears in
1258 my ($currency,$price)=@_;
1259 my $dbh = C4::Context->dbh;
1260 my $query="Select rate from currency where currency='$currency'";
1261 my $sth=$dbh->prepare($query);
1263 my $data=$sth->fetchrow_hashref;
1265 my $cur=$data->{'rate'};
1275 ($count, $currencies) = &getcurrencies();
1277 Returns the list of all known currencies.
1279 C<$count> is the number of elements in C<$currencies>. C<$currencies>
1280 is a reference-to-array; its elements are references-to-hash, whose
1281 keys are the fields from the currency table in the Koha database.
1285 # FIXME - This function appears in C4::Catalogue
1287 my $dbh = C4::Context->dbh;
1288 my $query="Select * from currency";
1289 my $sth=$dbh->prepare($query);
1293 while (my $data=$sth->fetchrow_hashref){
1298 return($i,\@results);
1301 # FIXME - This function appears in C4::Catalogue. Neither one is used.
1304 my $dbh = C4::Context->dbh;
1305 my $query="Select * from currency where currency='$cur'";
1306 my $sth=$dbh->prepare($query);
1309 my $data=$sth->fetchrow_hashref;
1314 =item updatecurrencies
1316 &updatecurrencies($currency, $newrate);
1318 Sets the exchange rate for C<$currency> to be C<$newrate>.
1322 # FIXME - This function appears in C4::Catalogue
1323 sub updatecurrencies {
1324 my ($currency,$rate)=@_;
1325 my $dbh = C4::Context->dbh;
1326 my $query="update currency set rate=$rate where currency='$currency'";
1327 my $sth=$dbh->prepare($query);
1334 &updatesup($bookseller);
1336 Updates the information for a given bookseller. C<$bookseller> is a
1337 reference-to-hash whose keys are the fields of the aqbooksellers table
1338 in the Koha database. It must contain entries for all of the fields.
1339 The entry to modify is determined by C<$bookseller-E<gt>{id}>.
1341 The easiest way to get all of the necessary fields is to look up a
1342 book seller with C<&booksellers>, modify what's necessary, then call
1343 C<&updatesup> with the result.
1347 # FIXME - This function appears in C4::Catalogue
1350 my $dbh = C4::Context->dbh;
1351 my $query="Update aqbooksellers set
1352 name='$data->{'name'}',address1='$data->{'address1'}',address2='$data->{'address2'}',
1353 address3='$data->{'address3'}',address4='$data->{'address4'}',postal='$data->{'postal'}',
1354 phone='$data->{'phone'}',fax='$data->{'fax'}',url='$data->{'url'}',
1355 contact='$data->{'contact'}',contpos='$data->{'contpos'}',
1356 contphone='$data->{'contphone'}', contfax='$data->{'contfax'}', contaltphone=
1357 '$data->{'contaltphone'}', contemail='$data->{'contemail'}', contnotes=
1358 '$data->{'contnotes'}', active=$data->{'active'},
1359 listprice='$data->{'listprice'}', invoiceprice='$data->{'invoiceprice'}',
1360 gstreg=$data->{'gstreg'}, listincgst=$data->{'listincgst'},
1361 invoiceincgst=$data->{'invoiceincgst'}, specialty='$data->{'specialty'}',
1362 discount='$data->{'discount'}',invoicedisc='$data->{'invoicedisc'}',
1363 nocalc='$data->{'nocalc'}'
1364 where id='$data->{'id'}'";
1365 my $sth=$dbh->prepare($query);
1373 $id = &insertsup($bookseller);
1375 Creates a new bookseller. C<$bookseller> is a reference-to-hash whose
1376 keys are the fields of the aqbooksellers table in the Koha database.
1377 All fields must be present.
1379 Returns the ID of the newly-created bookseller.
1383 # FIXME - This function also appears in C4::Catalogue. Pick one and
1387 my $dbh = C4::Context->dbh;
1388 my $sth=$dbh->prepare("Select max(id) from aqbooksellers");
1390 my $data2=$sth->fetchrow_hashref;
1392 $data2->{'max(id)'}++;
1393 $sth=$dbh->prepare("Insert into aqbooksellers (id) values ($data2->{'max(id)'})");
1396 $data->{'id'}=$data2->{'max(id)'};
1398 return($data->{'id'});
1401 # FIXME - This is different from &C4::Biblio::newitems, though both
1403 # FIXME - Never used AFAICT. Obsolete.
1404 # Otherwise, this needs a POD.
1406 my ($item, @barcodes) = @_;
1407 my $dbh = C4::Context->dbh;
1408 my $query = "Select max(itemnumber) from items";
1409 my $sth = $dbh->prepare($query);
1415 $data = $sth->fetchrow_hashref;
1416 $itemnumber = $data->{'max(itemnumber)'} + 1;
1419 $item->{'booksellerid'} = $dbh->quote($item->{'booksellerid'});
1420 $item->{'homebranch'} = $dbh->quote($item->{'homebranch'});
1421 $item->{'price'} = $dbh->quote($item->{'price'});
1422 $item->{'replacementprice'} = $dbh->quote($item->{'replacementprice'});
1423 $item->{'itemnotes'} = $dbh->quote($item->{'itemnotes'});
1425 foreach my $barcode (@barcodes) {
1426 $barcode = uc($barcode);
1427 $barcode = $dbh->quote($barcode);
1428 $query = "Insert into items set
1429 itemnumber = $itemnumber,
1430 biblionumber = $item->{'biblionumber'},
1431 biblioitemnumber = $item->{'biblioitemnumber'},
1433 booksellerid = $item->{'booksellerid'},
1434 dateaccessioned = NOW(),
1435 homebranch = $item->{'homebranch'},
1436 holdingbranch = $item->{'homebranch'},
1437 price = $item->{'price'},
1438 replacementprice = $item->{'replacementprice'},
1439 replacementpricedate = NOW(),
1440 itemnotes = $item->{'itemnotes'}";
1442 if ($item->{'loan'}) {
1444 notforloan = $item->{'loan'}";
1447 $sth = $dbh->prepare($query);
1450 $error .= $sth->errstr;
1459 # FIXME - This is the same as &C4::Biblio::Checkitems.
1460 # Pick one and stick with it.
1461 # If it's this one, it needs a POD.
1463 my ($count,@barcodes)=@_;
1464 my $dbh = C4::Context->dbh;
1466 for (my $i=0;$i<$count;$i++){
1467 $barcodes[$i]=uc $barcodes[$i];
1468 my $query="Select * from items where barcode='$barcodes[$i]'";
1469 my $sth=$dbh->prepare($query);
1471 if (my $data=$sth->fetchrow_hashref){
1472 $error.=" Duplicate Barcode: $barcodes[$i]";
1479 # FIXME - This appears to be functionally equivalent to
1480 # &C4::Biblio::moditem.
1481 # Pick one and stick with it.
1482 # If it's this one, it needs a POD.
1484 my ($loan,$itemnum,$bibitemnum,$barcode,$notes,$homebranch,$lost,$wthdrawn,$replacement)=@_;
1485 my $dbh = C4::Context->dbh;
1486 my $query="update items set biblioitemnumber=$bibitemnum,
1487 barcode='$barcode',itemnotes='$notes'
1488 where itemnumber=$itemnum";
1489 if ($barcode eq ''){
1490 $query="update items set biblioitemnumber=$bibitemnum,notforloan=$loan where itemnumber=$itemnum";
1493 $query="update items set biblioitemnumber=$bibitemnum,
1494 barcode='$barcode',itemnotes='$notes',homebranch='$homebranch',
1495 itemlost='$lost',wthdrawn='$wthdrawn' where itemnumber=$itemnum";
1497 if ($replacement ne ''){
1498 $query=~ s/ where/,replacementprice='$replacement' where/;
1501 my $sth=$dbh->prepare($query);
1506 # FIXME - This function appears in C4::Catalogue. Neither one is used
1508 my($price,$rrp,$itemnum)=@_;
1509 my $dbh = C4::Context->dbh;
1510 my $query="update items set price='$price',replacementprice='$rrp'
1511 where itemnumber=$itemnum";
1512 my $sth=$dbh->prepare($query);
1517 # FIXME - This is identical to &C4::Biblio::countitems.
1518 # Pick one and stick with it.
1519 # If it's this one, it needs a POD.
1521 my ($bibitemnum)=@_;
1522 my $dbh = C4::Context->dbh;
1523 my $query="Select count(*) from items where biblioitemnumber='$bibitemnum'";
1524 my $sth=$dbh->prepare($query);
1526 my $data=$sth->fetchrow_hashref;
1528 return($data->{'count(*)'});
1531 # FIXME - This function appears in C4::Catalogue. Neither one is used.
1533 my ($biblionumber)=@_;
1534 my $dbh = C4::Context->dbh;
1535 my $query="Select * from biblioitems,items,itemtypes where
1536 biblioitems.biblionumber=$biblionumber
1537 and biblioitems.biblioitemnumber=items.biblioitemnumber and
1538 itemtypes.itemtype=biblioitems.itemtype
1539 order by items.biblioitemnumber";
1540 my $sth=$dbh->prepare($query);
1544 while (my $data=$sth->fetchrow_hashref){
1552 # FIXME - This function appears in C4::Catalogue. Neither one is used
1554 my ($bibitemnum,$itemtype)=@_;
1555 my $dbh = C4::Context->dbh;
1556 my $query="Select * from biblioitems where biblioitemnumber=$bibitemnum
1557 and itemtype='$itemtype'";
1558 my $sth=$dbh->prepare($query);
1561 if (my $data=$sth->fetchrow_hashref){
1568 # FIXME - A nearly-identical function, appears in C4::Biblio
1569 # Pick one and stick with it.
1570 # If it's this one, it needs a POD.
1573 my $dbh = C4::Context->dbh;
1574 my $query="select * from items where itemnumber=$itemnum";
1575 my $sth=$dbh->prepare($query);
1577 my @data=$sth->fetchrow_array;
1579 $query="Insert into deleteditems values (";
1580 foreach my $temp (@data){
1581 $query .= "'$temp',";
1585 $sth=$dbh->prepare($query);
1588 $query = "Delete from items where itemnumber=$itemnum";
1589 $sth=$dbh->prepare($query);
1594 # FIXME - This is functionally identical to &C4::Biblio::deletebiblioitem.
1595 # Pick one and stick with it.
1596 # If it's this one, it needs a POD.
1597 sub deletebiblioitem {
1598 my ($biblioitemnumber) = @_;
1599 my $dbh = C4::Context->dbh;
1600 my $query = "Select * from biblioitems
1601 where biblioitemnumber = $biblioitemnumber";
1602 my $sth = $dbh->prepare($query);
1607 if (@results = $sth->fetchrow_array) {
1609 $query = "Insert into deletedbiblioitems values (";
1610 foreach my $value (@results) {
1611 $value = $dbh->quote($value);
1612 $query .= "$value,";
1615 $query =~ s/\,$/\)/;
1619 DELETE FROM biblioitems
1620 WHERE biblioitemnumber = $biblioitemnumber
1626 # Now delete all the items attached to the biblioitem
1628 $query = "Select * from items where biblioitemnumber = $biblioitemnumber";
1629 $sth = $dbh->prepare($query);
1633 while (@results = $sth->fetchrow_array) {
1635 $query = "Insert into deleteditems values (";
1636 foreach my $value (@results) {
1637 $value = $dbh->quote($value);
1638 $query .= "$value,";
1641 $query =~ s/\,$/\)/;
1645 $sth->finish; # FIXME - This is bogus, isn't it?
1649 WHERE biblioitemnumber = $biblioitemnumber
1652 } # sub deletebiblioitem
1654 # FIXME - This is functionally identical to &C4::Biblio::delbiblio.
1655 # Pick one and stick with it.
1656 # If it's this one, it needs a POD.
1659 my $dbh = C4::Context->dbh;
1660 my $query="select * from biblio where biblionumber=$biblio";
1661 my $sth=$dbh->prepare($query);
1663 if (my @data=$sth->fetchrow_array){
1665 $query="Insert into deletedbiblio values (";
1666 foreach my $temp (@data){
1667 $temp=~ s/\'/\\\'/g;
1668 $query .= "'$temp',";
1672 $sth=$dbh->prepare($query);
1675 $query = "Delete from biblio where biblionumber=$biblio";
1676 $sth=$dbh->prepare($query);
1684 # FIXME - There's also a C4::Biblio::getitemtypes.
1685 # FIXME - Never used AFAICT. This function is obsolete.
1686 # If not, it needs a POD.
1688 my $dbh = C4::Context->dbh;
1689 my $query = "select * from itemtypes";
1690 my $sth = $dbh->prepare($query);
1691 # || die "Cannot prepare $query" . $dbh->errstr;
1696 # || die "Cannot execute $query\n" . $sth->errstr;
1697 while (my $data = $sth->fetchrow_hashref) {
1698 $results[$count] = $data;
1703 return($count, @results);
1704 } # sub getitemtypes
1706 # FIXME - This is identical to &C4::Biblio::getitemtypes.
1707 # Pick one and stick with it.
1708 # If it's this one, it needs a POD.
1710 my ($biblionumber) = @_;
1711 my $dbh = C4::Context->dbh;
1712 my $query = "Select * from biblio where biblionumber = $biblionumber";
1713 my $sth = $dbh->prepare($query);
1714 # || die "Cannot prepare $query\n" . $dbh->errstr;
1719 # || die "Cannot execute $query\n" . $sth->errstr;
1720 while (my $data = $sth->fetchrow_hashref) {
1721 $results[$count] = $data;
1726 return($count, @results);
1729 # FIXME - There's also a &C4::Biblio::getbiblioitem.
1730 # Pick one and stick with it.
1731 # If it's this one, it needs a POD.
1733 my ($biblioitemnum) = @_;
1734 my $dbh = C4::Context->dbh;
1735 my $query = "Select * from biblioitems where
1736 biblioitemnumber = $biblioitemnum";
1737 my $sth = $dbh->prepare($query);
1743 while (my $data = $sth->fetchrow_hashref) {
1744 $results[$count] = $data;
1749 return($count, @results);
1750 } # sub getbiblioitem
1752 # FIXME - This is identical to &C4::Biblio::getbiblioitem.
1753 # Pick one and stick with it.
1754 # If it's this one, it needs a POD.
1755 sub getbiblioitembybiblionumber {
1756 my ($biblionumber) = @_;
1757 my $dbh = C4::Context->dbh;
1758 my $query = "Select * from biblioitems where biblionumber =
1760 my $sth = $dbh->prepare($query);
1766 while (my $data = $sth->fetchrow_hashref) {
1767 $results[$count] = $data;
1772 return($count, @results);
1775 # FIXME - This is identical to
1776 # &C4::Biblio::getbiblioitembybiblionumber.
1777 # Pick one and stick with it.
1778 # If it's this one, it needs a POD.
1779 sub getitemsbybiblioitem {
1780 my ($biblioitemnum) = @_;
1781 my $dbh = C4::Context->dbh;
1782 my $query = "Select * from items, biblio where
1783 biblio.biblionumber = items.biblionumber and biblioitemnumber
1785 my $sth = $dbh->prepare($query);
1786 # || die "Cannot prepare $query\n" . $dbh->errstr;
1791 # || die "Cannot execute $query\n" . $sth->errstr;
1792 while (my $data = $sth->fetchrow_hashref) {
1793 $results[$count] = $data;
1798 return($count, @results);
1799 } # sub getitemsbybiblioitem
1801 # FIXME - This is identical to &C4::Biblio::isbnsearch.
1802 # Pick one and stick with it.
1803 # If it's this one, it needs a POD.
1806 my $dbh = C4::Context->dbh;
1812 $isbn = $dbh->quote($isbn);
1813 $query = "Select biblio.* from biblio, biblioitems where
1814 biblio.biblionumber = biblioitems.biblionumber
1816 $sth = $dbh->prepare($query);
1819 while (my $data = $sth->fetchrow_hashref) {
1820 $results[$count] = $data;
1825 return($count, @results);
1830 ($count, @results) = &websitesearch($keywordlist);
1832 Looks up biblioitems by URL.
1834 C<$keywordlist> is a space-separated list of search terms.
1835 C<&websitesearch> returns those biblioitems whose URL contains at
1836 least one of the search terms.
1838 C<$count> is the number of elements in C<@results>. C<@results> is an
1839 array of references-to-hash, whose keys are the fields of the biblio
1840 and biblioitems tables in the Koha database.
1844 # FIXME - This function appears in C4::Catalogue
1846 my ($keywordlist) = @_;
1847 my $dbh = C4::Context->dbh;
1848 my $query = "Select distinct biblio.* from biblio, biblioitems where
1849 biblio.biblionumber = biblioitems.biblionumber and (";
1853 my @keywords = split(/ +/, $keywordlist);
1854 my $keyword = shift(@keywords);
1856 $keyword =~ s/%/\\%/g;
1857 $keyword =~ s/_/\\_/;
1858 $keyword = "%" . $keyword . "%";
1859 $keyword = $dbh->quote($keyword);
1860 $query .= " (url like $keyword)";
1862 foreach $keyword (@keywords) {
1863 $keyword =~ s/%/\\%/;
1864 $keyword =~ s/_/\\_/;
1865 $keyword = "%" . $keyword . "%";
1866 $keyword = $dbh->quote($keyword);
1867 $query .= " or (url like $keyword)";
1871 $sth = $dbh->prepare($query);
1874 while (my $data = $sth->fetchrow_hashref) {
1875 $results[$count] = $data;
1880 return($count, @results);
1881 } # sub websitesearch
1885 &addwebsite($website);
1887 Adds a new web site. C<$website> is a reference-to-hash, with the keys
1888 C<biblionumber>, C<title>, C<description>, and C<url>. All of these
1893 # FIXME - This function appears in C4::Catalogue
1896 my $dbh = C4::Context->dbh;
1898 $website->{'biblionumber'} = $dbh->quote($website->{'biblionumber'});
1899 $website->{'title'} = $dbh->quote($website->{'title'});
1900 $website->{'description'} = $dbh->quote($website->{'description'});
1901 $website->{'url'} = $dbh->quote($website->{'url'});
1904 INSERT INTO websites
1905 SET biblionumber = $website->{'biblionumber'},
1906 title = $website->{'title'},
1907 description = $website->{'description'},
1908 url = $website->{'url'}
1914 &updatewebsite($website);
1916 Updates an existing web site. C<$website> is a reference-to-hash with
1917 the keys C<websitenumber>, C<title>, C<description>, and C<url>. All
1918 of these are mandatory. C<$website-E<gt>{websitenumber}> identifies
1919 the entry to update.
1923 # FIXME - This function appears in C4::Catalogue
1926 my $dbh = C4::Context->dbh;
1928 $website->{'title'} = $dbh->quote($website->{'title'});
1929 $website->{'description'} = $dbh->quote($website->{'description'});
1930 $website->{'url'} = $dbh->quote($website->{'url'});
1934 SET title = $website->{'title'},
1935 description = $website->{'description'},
1936 url = $website->{'url'}
1937 where websitenumber = $website->{'websitenumber'}
1939 } # sub updatewebsite
1943 &deletewebsite($websitenumber);
1945 Deletes the web site with number C<$websitenumber>.
1949 # FIXME - This function appears in C4::Catalogue
1951 my ($websitenumber) = @_;
1952 my $dbh = C4::Context->dbh;
1955 DELETE FROM websites
1956 WHERE websitenumber = $websitenumber
1958 } # sub deletewebsite
1961 END { } # module clean-up code here (global destructor)
1970 Koha Developement team <info@koha.org>