Added a partial POD.
[koha.git] / C4 / Acquisitions.pm
1 package C4::Acquisitions; #assumes C4/Acquisitions.pm
2
3
4 # Copyright 2000-2002 Katipo Communications
5 #
6 # This file is part of Koha.
7 #
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
11 # version.
12 #
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.
16 #
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
20
21 # ***
22 # NOTE: This module is deprecated in Koha 1.3.x, and will shortly be
23 # deleted.
24 # ***
25
26 use strict;
27 require Exporter;
28 use C4::Context;
29  #use C4::Biblio;
30 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
31
32 # set the version for version checking
33 $VERSION = 0.01;
34
35 =head1 NAME
36
37 C4::Acquisitions - Koha module dealing with acquisitions and orders
38
39 =head1 SYNOPSIS
40
41   use C4::Acquisitions;
42
43 =head1 DESCRIPTION
44
45 B<NOTE:> This module is deprecated in Koha 1.3.x.
46
47 The functions in this module deal with acquisitions, managing book
48 orders, converting money to different currencies, and so forth.
49
50 =head1 FUNCTIONS
51
52 =over 2
53
54 =cut
55
56 @ISA = qw(Exporter);
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);
68 %EXPORT_TAGS = ( );     # eg: TAG => [ qw!name1 name2! ],
69
70 # your exported package globals go here,
71 # as well as any optionally exported functions
72
73 @EXPORT_OK   = qw($Var1 %Hashit);       # FIXME - Never used
74
75
76 # non-exported package globals go here
77 use vars qw(@more $stuff);              # FIXME - Never used
78
79 # initalize package globals, first exported ones
80 # FIXME - Never used
81 my $Var1   = '';
82 my %Hashit = ();
83
84
85
86 # then the others (which are still accessible as $Some::Module::stuff)
87 # FIXME - Never used
88 my $stuff  = '';
89 my @more   = ();
90
91 # all file-scoped lexicals must be created before
92 # the functions below that use them.
93
94 # file-private lexicals go here
95 # FIXME - Never used
96 my $priv_var    = '';
97 my %secret_hash = ();
98
99 # FIXME - Never used
100 # here's a file-private function as a closure,
101 # callable as &$priv_func;  it cannot be prototyped.
102 my $priv_func = sub {
103   # stuff goes here.
104   };
105   
106 # make all your functions, whether exported or not;
107
108 =item getorders
109
110   ($count, $orders) = &getorders($booksellerid);
111
112 Finds pending orders from the bookseller with the given ID. Ignores
113 completed and cancelled orders.
114
115 C<$count> is the number of elements in C<@{$orders}>.
116
117 C<$orders> is a reference-to-array; each element is a
118 reference-to-hash with the following fields:
119
120 =over 4
121
122 =item C<count(*)>
123
124 Gives the number of orders in with this basket number.
125
126 =item C<authorizedby>
127
128 =item C<entrydate>
129
130 =item C<basketno>
131
132 These give the value of the corresponding field in the aqorders table
133 of the Koha database.
134
135 =back
136
137 Results are ordered from most to least recent.
138
139 =cut
140 #'
141 # FIXME - This exact function already exists in C4::Catalogue
142 sub getorders {
143   my ($supplierid)=@_;
144   my $dbh = C4::Context->dbh;
145   my $query = "Select count(*),authorisedby,entrydate,basketno from aqorders where 
146   booksellerid='$supplierid' and (quantity > quantityreceived or
147   quantityreceived is NULL)
148   and (datecancellationprinted is NULL or datecancellationprinted = '0000-00-00')";
149   $query.=" group by basketno order by entrydate desc";
150   #print $query;
151   my $sth=$dbh->prepare($query);
152   $sth->execute;
153   my @results;
154   my $i=0;
155   while (my $data=$sth->fetchrow_hashref){
156     $results[$i]=$data;
157     $i++;
158   }
159   $sth->finish;
160   return ($i,\@results);
161 }
162
163 # Only used internally
164 # FIXME - This is the same as &C4::Biblio::itemcount, but not
165 # the same as &C4::Search::itemcount
166 sub itemcount{
167   my ($biblio)=@_;
168   my $dbh = C4::Context->dbh;
169   my $query="Select count(*) from items where biblionumber=$biblio";
170 #  print $query;
171   my $sth=$dbh->prepare($query);
172   $sth->execute;
173   my $data=$sth->fetchrow_hashref;
174   $sth->finish;
175   return($data->{'count(*)'});
176 }
177
178 =item getorder
179
180   ($order, $ordernumber) = &getorder($biblioitemnumber, $biblionumber);
181
182 Looks up the order with the given biblionumber and biblioitemnumber.
183
184 Returns a two-element array. C<$ordernumber> is the order number.
185 C<$order> is a reference-to-hash describing the order; its keys are
186 fields from the biblio, biblioitems, aqorders, and aqorderbreakdown
187 tables of the Koha database.
188
189 =cut
190 #'
191 # FIXME - There are functions &getorder and &getorders. Isn't this
192 # somewhat likely to cause confusion?
193 # FIXME - Almost the exact same function is already in C4::Catalogue
194 sub getorder{
195   my ($bi,$bib)=@_;
196   my $dbh = C4::Context->dbh;
197   my $query="Select ordernumber 
198         from aqorders 
199         where biblionumber=? and biblioitemnumber=?";
200   my $sth=$dbh->prepare($query);
201   $sth->execute($bib,$bi);
202   my $ordnum=$sth->fetchrow_hashref;
203   $sth->finish;
204   my $order=getsingleorder($ordnum->{'ordernumber'});
205 #  print $query;
206   return ($order,$ordnum->{'ordernumber'});
207 }
208
209 =item getsingleorder
210
211   $order = &getsingleorder($ordernumber);
212
213 Looks up an order by order number.
214
215 Returns a reference-to-hash describing the order. The keys of
216 C<$order> are fields from the biblio, biblioitems, aqorders, and
217 aqorderbreakdown tables of the Koha database.
218
219 =cut
220 #'
221 # FIXME - This is practically the same function as
222 # &C4::Catalogue::getsingleorder and &C4::Biblio::getsingleorder.
223 sub getsingleorder {
224   my ($ordnum)=@_;
225   my $dbh = C4::Context->dbh;
226   my $query="Select * from biblio,biblioitems,aqorders,aqorderbreakdown 
227   where aqorders.ordernumber=? 
228   and biblio.biblionumber=aqorders.biblionumber and
229   biblioitems.biblioitemnumber=aqorders.biblioitemnumber and
230   aqorders.ordernumber=aqorderbreakdown.ordernumber";
231   my $sth=$dbh->prepare($query);
232   $sth->execute($ordnum);
233   my $data=$sth->fetchrow_hashref;
234   $sth->finish;
235   return($data);
236 }
237
238 =item invoice
239
240   ($count, @results) = &invoice($booksellerinvoicenumber);
241
242 Looks up orders by invoice number.
243
244 Returns an array. C<$count> is the number of elements in C<@results>.
245 C<@results> is an array of references-to-hash; the keys of each
246 elements are fields from the aqorders, biblio, and biblioitems tables
247 of the Koha database.
248
249 =cut
250 #'
251 # FIXME - This exact function is already in C4::Catalogue
252 sub invoice {
253   my ($invoice)=@_;
254   my $dbh = C4::Context->dbh;
255   my $query="Select * from aqorders,biblio,biblioitems where
256   booksellerinvoicenumber='$invoice'
257   and biblio.biblionumber=aqorders.biblionumber and biblioitems.biblioitemnumber=
258   aqorders.biblioitemnumber group by aqorders.ordernumber,aqorders.biblioitemnumber";
259   my $i=0;
260   my @results;
261   my $sth=$dbh->prepare($query);
262   $sth->execute;
263   while (my $data=$sth->fetchrow_hashref){
264     $results[$i]=$data;
265     $i++;
266   }
267   $sth->finish;
268   return($i,@results);
269 }
270
271 =item getallorders
272
273   ($count, @results) = &getallorders($booksellerid);
274
275 Looks up all of the pending orders from the supplier with the given
276 bookseller ID. Ignores cancelled orders.
277
278 C<$count> is the number of elements in C<@results>. C<@results> is an
279 array of references-to-hash. The keys of each element are fields from
280 the aqorders, biblio, and biblioitems tables of the Koha database.
281
282 C<@results> is sorted alphabetically by book title.
283
284 =cut
285 #'
286 # FIXME - Almost (but not quite) the same function appears in C4::Catalogue
287 # That one only lists incomplete orders.
288 sub getallorders {
289   #gets all orders from a certain supplier, orders them alphabetically
290   my ($supid)=@_;
291   my $dbh = C4::Context->dbh;
292   my $query="Select * from aqorders,biblio,biblioitems where booksellerid='$supid'
293   and (cancelledby is NULL or cancelledby = '')
294   and biblio.biblionumber=aqorders.biblionumber and biblioitems.biblioitemnumber=                    
295   aqorders.biblioitemnumber 
296   group by aqorders.biblioitemnumber 
297   order by
298   biblio.title";
299   my $i=0;
300   my @results;
301   my $sth=$dbh->prepare($query);
302   $sth->execute;
303   while (my $data=$sth->fetchrow_hashref){
304     $results[$i]=$data;
305     $i++;
306   }
307   $sth->finish;
308   return($i,@results);
309 }
310
311 # FIXME - There's a getrecorders in C4::Catalogue
312 # FIXME - Never used (neither is the other one, actually)
313 sub getrecorders {
314   #gets all orders from a certain supplier, orders them alphabetically
315   my ($supid)=@_;
316   my $dbh = C4::Context->dbh;
317   my $query="Select * from aqorders,biblio,biblioitems where booksellerid='$supid'
318   and (cancelledby is NULL or cancelledby = '')
319   and biblio.biblionumber=aqorders.biblionumber and biblioitems.biblioitemnumber=                    
320   aqorders.biblioitemnumber and
321   aqorders.quantityreceived>0
322   and aqorders.datereceived >=now()
323   group by aqorders.biblioitemnumber 
324   order by
325   biblio.title";
326   my $i=0;
327   my @results;
328   my $sth=$dbh->prepare($query);
329   $sth->execute;
330   while (my $data=$sth->fetchrow_hashref){
331     $results[$i]=$data;
332     $i++;
333   }
334   $sth->finish;
335   return($i,@results);
336 }
337
338 =item ordersearch
339
340   ($count, @results) = &ordersearch($search, $biblionumber, $complete);
341
342 Searches for orders.
343
344 C<$search> may take one of several forms: if it is an ISBN,
345 C<&ordersearch> returns orders with that ISBN. If C<$search> is an
346 order number, C<&ordersearch> returns orders with that order number
347 and biblionumber C<$biblionumber>. Otherwise, C<$search> is considered
348 to be a space-separated list of search terms; in this case, all of the
349 terms must appear in the title (matching the beginning of title
350 words).
351
352 If C<$complete> is C<yes>, the results will include only completed
353 orders. In any case, C<&ordersearch> ignores cancelled orders.
354
355 C<&ordersearch> returns an array. C<$count> is the number of elements
356 in C<@results>. C<@results> is an array of references-to-hash with the
357 following keys:
358
359 =over 4
360
361 =item C<author>
362
363 =item C<seriestitle>
364
365 =item C<branchcode>
366
367 =item C<bookfundid>
368
369 =back
370
371 =cut
372 #'
373 # FIXME - The same function (modulo whitespace) appears in C4::Catalogue
374 sub ordersearch {
375   my ($search,$biblio,$catview)=@_;
376   my $dbh = C4::Context->dbh;
377   my $query="Select *,biblio.title from aqorders,biblioitems,biblio
378         where aqorders.biblioitemnumber = biblioitems.biblioitemnumber
379         and biblio.biblionumber=aqorders.biblionumber
380         and ((datecancellationprinted is NULL)
381         or (datecancellationprinted = '0000-00-00'))
382   and ((";
383   my @data=split(' ',$search);
384   my $count=@data;
385   for (my $i=0;$i<$count;$i++){
386     $query.= "(biblio.title like '$data[$i]%' or biblio.title like '% $data[$i]%') and ";
387   }
388   $query=~ s/ and $//;
389   $query.=" ) or biblioitems.isbn='$search' 
390   or (aqorders.ordernumber='$search' and aqorders.biblionumber='$biblio')) ";
391   if ($catview ne 'yes'){
392     $query.=" and (quantityreceived < quantity or quantityreceived is NULL)";
393   }
394   $query.=" group by aqorders.ordernumber";
395   my $sth=$dbh->prepare($query);
396 #  print $query;
397   $sth->execute;
398   my $i=0;
399   my @results;
400   while (my $data=$sth->fetchrow_hashref){
401      my $sth2=$dbh->prepare("Select * from biblio where
402      biblionumber='$data->{'biblionumber'}'");
403      $sth2->execute;
404      my $data2=$sth2->fetchrow_hashref;
405      $sth2->finish;
406      $data->{'author'}=$data2->{'author'};
407      $data->{'seriestitle'}=$data2->{'seriestitle'};
408      $sth2=$dbh->prepare("Select * from aqorderbreakdown where
409     ordernumber=$data->{'ordernumber'}");
410     $sth2->execute;
411     $data2=$sth2->fetchrow_hashref;
412     $sth2->finish;
413     $data->{'branchcode'}=$data2->{'branchcode'};
414     $data->{'bookfundid'}=$data2->{'bookfundid'};
415     $results[$i]=$data;
416     $i++;
417   }
418   $sth->finish;
419   return($i,@results);
420 }
421
422 =item bookseller
423
424   ($count, @results) = &bookseller($searchstring);
425
426 Looks up a book seller. C<$searchstring> may be either a book seller
427 ID, or a string to look for in the book seller's name.
428
429 C<$count> is the number of elements in C<@results>. C<@results> is an
430 array of references-to-hash, whose keys are the fields of of the
431 aqbooksellers table in the Koha database.
432
433 =cut
434 #'
435 # FIXME - This function appears in C4::Catalogue
436 sub bookseller {
437   my ($searchstring)=@_;
438   my $dbh = C4::Context->dbh;
439   my $query="Select * from aqbooksellers where name like '%$searchstring%' or
440   id = '$searchstring'";
441   my $sth=$dbh->prepare($query);
442   $sth->execute;
443   my @results;
444   my $i=0;
445   while (my $data=$sth->fetchrow_hashref){
446     $results[$i]=$data;
447     $i++;
448   }
449   $sth->finish;
450   return($i,@results);
451 }
452
453 =item breakdown
454
455   ($count, $results) = &breakdown($ordernumber);
456
457 Looks up an order by order ID, and returns its breakdown.
458
459 C<$count> is the number of elements in C<$results>. C<$results> is a
460 reference-to-array; its elements are references-to-hash, whose keys
461 are the fields of the aqorderbreakdown table in the Koha database.
462
463 =cut
464 #'
465 # FIXME - This function appears in C4::Catalogue.
466 sub breakdown {
467   my ($id)=@_;
468   my $dbh = C4::Context->dbh;
469   my $query="Select * from aqorderbreakdown where ordernumber='$id'";
470   my $sth=$dbh->prepare($query);
471   $sth->execute;
472   my @results;
473   my $i=0;
474   while (my $data=$sth->fetchrow_hashref){
475     $results[$i]=$data;
476     $i++;
477   }
478   $sth->finish;
479   return($i,\@results);
480 }
481
482 =item basket
483
484   ($count, @orders) = &basket($basketnumber, $booksellerID);
485
486 Looks up the pending (non-cancelled) orders with the given basket
487 number. If C<$booksellerID> is non-empty, only orders from that seller
488 are returned.
489
490 C<&basket> returns a two-element array. C<@orders> is an array of
491 references-to-hash, whose keys are the fields from the aqorders,
492 biblio, and biblioitems tables in the Koha database. C<$count> is the
493 number of elements in C<@orders>.
494
495 =cut
496 #'
497 # FIXME - Almost the same function (with less error-checking) appears in
498 # C4::Catalogue.pm
499 sub basket {
500   my ($basketno,$supplier)=@_;
501   my $dbh = C4::Context->dbh;
502   my $query="Select *,biblio.title from aqorders,biblio,biblioitems 
503   where basketno='$basketno'
504   and biblio.biblionumber=aqorders.biblionumber and biblioitems.biblioitemnumber
505   =aqorders.biblioitemnumber 
506   and (datecancellationprinted is NULL or datecancellationprinted =
507   '0000-00-00')";
508   if (defined $supplier && $supplier ne ''){
509     $query.=" and aqorders.booksellerid='$supplier'";
510   } 
511   $query.=" group by aqorders.ordernumber";
512   my $sth=$dbh->prepare($query);
513   $sth->execute;
514   my @results;
515 #  print $query;
516   my $i=0;
517   while (my $data=$sth->fetchrow_hashref){
518     $results[$i]=$data;
519     $i++;
520   }
521   $sth->finish;
522   return($i,@results);
523 }
524
525 =item newbasket
526
527   $basket = &newbasket();
528
529 Finds the next unused basket number in the aqorders table of the Koha
530 database, and returns it.
531
532 =cut
533 #'
534 # FIXME - There's a race condition here:
535 #       A calls &newbasket
536 #       B calls &newbasket (gets the same number as A)
537 #       A updates the basket
538 #       B updates the basket, and clobbers A's result.
539 # A better approach might be to create a dummy order (with, say,
540 # requisitionedby == "Dummy-$$" or notes == "dummy <time> <pid>"), and
541 # see which basket number it gets. Then have a cron job periodically
542 # remove out-of-date dummy orders.
543 # FIXME - This function appears in C4::Catalogue.pm
544 sub newbasket {
545   my $dbh = C4::Context->dbh;
546   my $query="Select max(basketno) from aqorders";
547   my $sth=$dbh->prepare($query);
548   $sth->execute;
549   my $data=$sth->fetchrow_arrayref;
550   my $basket=$$data[0];
551   $basket++;
552   $sth->finish;
553   return($basket);
554 }
555
556 =item bookfunds
557
558   ($count, @results) = &bookfunds();
559
560 Returns a list of all book funds started on Sep 1, 2001.
561
562 C<$count> is the number of elements in C<@results>. C<@results> is an
563 array of references-to-hash, whose keys are fields from the aqbookfund
564 and aqbudget tables of the Koha database. Results are ordered
565 alphabetically by book fund name.
566
567 =cut
568 #'
569 # FIXME - An identical function (without the hardcoded date) appears in
570 # C4::Catalogue
571 sub bookfunds {
572   my $dbh = C4::Context->dbh;
573   my $query="Select * from aqbookfund,aqbudget where aqbookfund.bookfundid
574   =aqbudget.bookfundid 
575    and aqbudget.startdate='2001-07-01'
576   group by aqbookfund.bookfundid order by bookfundname";
577   my $sth=$dbh->prepare($query);
578   $sth->execute;
579   my @results;
580   my $i=0;
581   while (my $data=$sth->fetchrow_hashref){
582     $results[$i]=$data;
583     $i++;
584   }
585   $sth->finish;
586   return($i,@results);
587 }
588
589 =item branches
590
591   ($count, @results) = &branches();
592
593 Returns a list of all library branches.
594
595 C<$count> is the number of elements in C<@results>. C<@results> is an
596 array of references-to-hash, whose keys are the fields of the branches
597 table of the Koha database.
598
599 =cut
600 #'
601 # FIXME - This function (modulo whitespace) appears in C4::Catalogue
602 sub branches {
603   my $dbh = C4::Context->dbh;
604   my $query="Select * from branches";
605   my $sth=$dbh->prepare($query);
606   my $i=0;
607   my @results;
608
609     $sth->execute;
610   while (my $data = $sth->fetchrow_hashref){
611     $results[$i]=$data;
612     $i++;
613     } # while
614
615   $sth->finish;
616   return($i, @results);
617 } # sub branches
618
619 # FIXME - POD. But I can't figure out what this function is doing
620 # FIXME - An almost identical function appears in C4::Catalogue
621 sub bookfundbreakdown {
622   my ($id)=@_;
623   my $dbh = C4::Context->dbh;
624   my $query="Select quantity,datereceived,freight,unitprice,listprice,ecost,quantityreceived,subscription
625   from aqorders,aqorderbreakdown where bookfundid='$id' and 
626    aqorders.ordernumber=aqorderbreakdown.ordernumber and ((budgetdate >=
627    '2001-07-01' and budgetdate <'2002-07-01') or
628    (datereceived >= '2001-07-01' and datereceived < '2002-07-01'))
629   and (datecancellationprinted is NULL or
630   datecancellationprinted='0000-00-00')";
631   my $sth=$dbh->prepare($query);
632   $sth->execute;
633   my $comtd=0;
634   my $spent=0;
635   while (my $data=$sth->fetchrow_hashref){
636     if ($data->{'subscription'} == 1){
637       $spent+=$data->{'quantity'}*$data->{'unitprice'};
638     } else {
639       my $leftover=$data->{'quantity'}-$data->{'quantityreceived'};
640       $comtd+=($data->{'ecost'})*$leftover;
641       $spent+=($data->{'unitprice'})*$data->{'quantityreceived'};
642     }
643   }
644   $sth->finish;
645   return($spent,$comtd);
646 }
647
648 # FIXME - This is in effect identical to &C4::Biblio::newbiblio.
649 # Pick one and stick with it.
650
651 # FIXME - Never used (anything that uses &newbiblio uses
652 # &C4::Biblio::newbiblio). Nuke this.
653 sub newbiblio {
654   my ($biblio) = @_;
655   my $dbh    = C4::Context->dbh;
656   my $query  = "Select max(biblionumber) from biblio";
657   my $sth    = $dbh->prepare($query);
658   $sth->execute;
659   my $data   = $sth->fetchrow_arrayref;
660   my $bibnum = $$data[0] + 1;
661   my $series = 0;
662
663   $biblio->{'title'}       = $dbh->quote($biblio->{'title'});
664   $biblio->{'author'}      = $dbh->quote($biblio->{'author'});
665   $biblio->{'copyright'}   = $dbh->quote($biblio->{'copyright'});
666   $biblio->{'seriestitle'} = $dbh->quote($biblio->{'seriestitle'});
667   $biblio->{'notes'}       = $dbh->quote($biblio->{'notes'});
668   $biblio->{'abstract'}    = $dbh->quote($biblio->{'abstract'});
669   if ($biblio->{'seriestitle'}) { $series = 1 };
670
671   $sth->finish;
672
673   $dbh->do(<<EOT);
674         INSERT INTO     biblio
675         SET             biblionumber  = $bibnum,
676                         title         = $biblio->{'title'},
677                         author        = $biblio->{'author'},
678                         copyrightdate = $biblio->{'copyright'},
679                         serial        = $series,
680                         seriestitle   = $biblio->{'seriestitle'},
681                         notes         = $biblio->{'notes'},
682                         abstract      = $biblio->{'abstract'}
683 EOT
684
685   return($bibnum);
686 }
687
688 =item modbiblio
689
690   $biblionumber = &modbiblio($biblio);
691
692 Update a biblio record.
693
694 C<$biblio> is a reference-to-hash whose keys are the fields in the
695 biblio table in the Koha database. All fields must be present, not
696 just the ones you wish to change.
697
698 C<&modbiblio> updates the record defined by
699 C<$biblio-E<gt>{biblionumber}> with the values in C<$biblio>.
700
701 C<&modbiblio> returns C<$biblio-E<gt>{biblionumber}> whether it was
702 successful or not.
703
704 =cut
705 #'
706 # FIXME - This is in effect the same as &C4::Biblio::modbiblio.
707 # Pick one and stick with it.
708 sub modbiblio {
709   my ($biblio) = @_;
710   my $dbh   = C4::Context->dbh;
711   my $query;
712   my $sth;
713   
714   $biblio->{'title'}         = $dbh->quote($biblio->{'title'});
715   $biblio->{'author'}        = $dbh->quote($biblio->{'author'});
716   $biblio->{'abstract'}      = $dbh->quote($biblio->{'abstract'});
717   $biblio->{'copyrightdate'} = $dbh->quote($biblio->{'copyrightdate'});
718   $biblio->{'seriestitle'}   = $dbh->quote($biblio->{'serirestitle'});
719   $biblio->{'serial'}        = $dbh->quote($biblio->{'serial'});
720   $biblio->{'unititle'}      = $dbh->quote($biblio->{'unititle'});
721   $biblio->{'notes'}         = $dbh->quote($biblio->{'notes'});
722
723   $query = "Update biblio set
724 title         = $biblio->{'title'},
725 author        = $biblio->{'author'},
726 abstract      = $biblio->{'abstract'},
727 copyrightdate = $biblio->{'copyrightdate'},
728 seriestitle   = $biblio->{'seriestitle'},
729 serial        = $biblio->{'serial'},
730 unititle      = $biblio->{'unititle'},
731 notes         = $biblio->{'notes'}
732 where biblionumber = $biblio->{'biblionumber'}";
733   $sth   = $dbh->prepare($query);
734
735   $sth->execute;
736
737   $sth->finish;
738   return($biblio->{'biblionumber'});
739 } # sub modbiblio
740
741 =item modsubtitle
742
743   &modsubtitle($biblionumber, $subtitle);
744
745 Sets the subtitle of a book.
746
747 C<$biblionumber> is the biblionumber of the book to modify.
748
749 C<$subtitle> is the new subtitle.
750
751 =cut
752 #'
753 # FIXME - This is in effect identical to &C4::Biblio::modsubtitle.
754 # Pick one and stick with it.
755 sub modsubtitle {
756   my ($bibnum, $subtitle) = @_;
757   my $dbh   = C4::Context->dbh;
758   my $query = "update bibliosubtitle set
759 subtitle = '$subtitle'
760 where biblionumber = $bibnum";
761   my $sth   = $dbh->prepare($query);
762
763   $sth->execute;
764   $sth->finish;
765 } # sub modsubtitle
766
767 =item modaddauthor
768
769   &modaddauthor($biblionumber, $author);
770
771 Replaces all additional authors for the book with biblio number
772 C<$biblionumber> with C<$author>. If C<$author> is the empty string,
773 C<&modaddauthor> deletes all additional authors.
774
775 =cut
776 #'
777 # FIXME - This is functionally identical to &C4::Biblio::modaddauthor
778 # Pick one and stick with it.
779 # FIXME - This API is bogus: you should be able to have more than 2
780 # authors on a book.
781 sub modaddauthor {
782     my ($bibnum, $author) = @_;
783     my $dbh   = C4::Context->dbh;
784     # FIXME - Use $dbh->do()
785     my $query = "Delete from additionalauthors where biblionumber = $bibnum";
786     my $sth = $dbh->prepare($query);
787
788     $sth->execute;
789     $sth->finish;
790
791     if ($author ne '') {
792         $query = "Insert into additionalauthors set
793 author       = '$author',
794 biblionumber = '$bibnum'";
795         $sth   = $dbh->prepare($query);
796
797         $sth->execute;
798
799         $sth->finish;
800     } # if
801 } # sub modaddauthor
802
803 =item modsubject
804
805   $error = &modsubject($biblionumber, $force, @subjects);
806
807 $force - a subject to force
808
809 $error - Error message, or undef if successful.
810
811 =cut
812 #'
813 # FIXME - This is in effect identical to &C4::Biblio::modsubject.
814 # Pick one and stick with it.
815 # FIXME - Bogus API: either $force should force all subjects to be
816 # added to catalogueentry, or else you should be able to specify a
817 # list of subjects to force.
818 sub modsubject {
819   my ($bibnum, $force, @subject) = @_;
820   my $dbh   = C4::Context->dbh;
821   my $count = @subject;
822   my $error;
823
824   # Loop over list of subjects
825   # FIXME - Use foreach my $subject (@subjects)
826   for (my $i = 0; $i < $count; $i++) {
827     $subject[$i] =~ s/^ //g;                    # Trim whitespace
828     $subject[$i] =~ s/ $//g;
829
830     # Look up the subject in the authority file.
831     my $query = "select * from catalogueentry
832 where entrytype = 's'
833 and catalogueentry = '$subject[$i]'";
834     my $sth   = $dbh->prepare($query);
835     $sth->execute;
836
837     if (my $data = $sth->fetchrow_hashref) {
838                 # FIXME - Ick! Empty if-clauses suck. Use a "not" or something.
839     } else {
840       if ($force eq $subject[$i]) {
841
842          # subject not in aut, chosen to force anway
843          # so insert into cataloguentry so its in auth file
844          $query = "Insert into catalogueentry
845 (entrytype,catalogueentry)
846 values ('s','$subject[$i]')";
847          my $sth2 = $dbh->prepare($query);
848
849          $sth2->execute;
850          $sth2->finish;
851
852       } else {
853
854         $error = "$subject[$i]\n does not exist in the subject authority file";
855         $query = "Select * from catalogueentry
856 where entrytype = 's'
857 and (catalogueentry like '$subject[$i] %'
858 or catalogueentry like '% $subject[$i] %'
859 or catalogueentry like '% $subject[$i]')";
860         my $sth2 = $dbh->prepare($query);
861
862         $sth2->execute;
863         while (my $data = $sth2->fetchrow_hashref) {
864           $error = $error."<br>$data->{'catalogueentry'}";      # FIXME - .=
865         } # while
866         $sth2->finish;
867       } # else
868     } # else
869     $sth->finish;
870   } # else
871
872   if ($error eq '') {
873     my $query = "Delete from bibliosubject where biblionumber = $bibnum";
874     my $sth   = $dbh->prepare($query);
875
876     $sth->execute;
877     $sth->finish;
878
879     for (my $i = 0; $i < $count; $i++) {
880       $sth = $dbh->prepare("Insert into bibliosubject
881 values ('$subject[$i]', $bibnum)");
882
883       $sth->execute;
884       $sth->finish;
885     } # for
886   } # if
887
888   return($error);
889 } # sub modsubject
890
891 # FIXME - This is very similar to &C4::Biblio::modbibitem.
892 # Pick one and stick with it.
893 # If it's this one, it needs a POD.
894 sub modbibitem {
895     my ($biblioitem) = @_;
896     my $dbh   = C4::Context->dbh;
897
898     # FIXME -
899     #   foreach my $field (qw( ... ))
900     #   {
901     #           $biblioitem->{$field} = $dbh->quote($biblioitem->{$field});
902     #   }
903     $biblioitem->{'itemtype'}        = $dbh->quote($biblioitem->{'itemtype'});
904     $biblioitem->{'url'}             = $dbh->quote($biblioitem->{'url'});
905     $biblioitem->{'isbn'}            = $dbh->quote($biblioitem->{'isbn'});
906     $biblioitem->{'publishercode'}   = $dbh->quote($biblioitem->{'publishercode'});
907     $biblioitem->{'publicationyear'} = $dbh->quote($biblioitem->{'publicationyear'});
908     $biblioitem->{'classification'}  = $dbh->quote($biblioitem->{'classification'});
909     $biblioitem->{'dewey'}           = $dbh->quote($biblioitem->{'dewey'});
910     $biblioitem->{'subclass'}        = $dbh->quote($biblioitem->{'subclass'});
911     $biblioitem->{'illus'}           = $dbh->quote($biblioitem->{'illus'});
912     $biblioitem->{'pages'}           = $dbh->quote($biblioitem->{'pages'});
913     $biblioitem->{'volumeddesc'}     = $dbh->quote($biblioitem->{'volumeddesc'});
914     $biblioitem->{'notes'}           = $dbh->quote($biblioitem->{'notes'});
915     $biblioitem->{'size'}            = $dbh->quote($biblioitem->{'size'});
916     $biblioitem->{'place'}           = $dbh->quote($biblioitem->{'place'});
917
918     $dbh->do(<<EOT);
919         UPDATE  biblioitems
920         SET     itemtype        = $biblioitem->{'itemtype'},
921                 url             = $biblioitem->{'url'},
922                 isbn            = $biblioitem->{'isbn'},
923                 publishercode   = $biblioitem->{'publishercode'},
924                 publicationyear = $biblioitem->{'publicationyear'},
925                 classification  = $biblioitem->{'classification'},
926                 dewey           = $biblioitem->{'dewey'},
927                 subclass        = $biblioitem->{'subclass'},
928                 illus           = $biblioitem->{'illus'},
929                 pages           = $biblioitem->{'pages'},
930                 volumeddesc     = $biblioitem->{'volumeddesc'},
931                 notes           = $biblioitem->{'notes'},
932                 size            = $biblioitem->{'size'},
933                 place           = $biblioitem->{'place'}
934         WHERE   biblioitemnumber = $biblioitem->{'biblioitemnumber'}
935 EOT
936 } # sub modbibitem
937
938 # FIXME - This is in effect identical to &C4::Biblio::modnote.
939 # Pick one and stick with it.
940 # If it's this one, it needs a POD.
941 sub modnote {
942   my ($bibitemnum,$note)=@_;
943   my $dbh = C4::Context->dbh;
944
945   $dbh->do(<<EOT);
946         UPDATE  biblioitems
947         SET     notes = '$note'
948         WHERE   biblioitemnumber = '$bibitemnum'
949 EOT
950 }
951
952 # FIXME - &C4::Biblio::newbiblioitem is quite similar to this
953 # Pick one and stick with it.
954 # If it's this one, it needs a POD.
955 sub newbiblioitem {
956   my ($biblioitem) = @_;
957   my $dbh   = C4::Context->dbh;
958   my $query = "Select max(biblioitemnumber) from biblioitems";
959   my $sth   = $dbh->prepare($query);
960   my $data;
961   my $bibitemnum;
962
963   $biblioitem->{'volume'}          = $dbh->quote($biblioitem->{'volume'});
964   $biblioitem->{'number'}          = $dbh->quote($biblioitem->{'number'});
965   $biblioitem->{'classification'}  = $dbh->quote($biblioitem->{'classification'});
966   $biblioitem->{'itemtype'}        = $dbh->quote($biblioitem->{'itemtype'});
967   $biblioitem->{'url'}             = $dbh->quote($biblioitem->{'url'});
968   $biblioitem->{'isbn'}            = $dbh->quote($biblioitem->{'isbn'});
969   $biblioitem->{'issn'}            = $dbh->quote($biblioitem->{'issn'});
970   $biblioitem->{'dewey'}           = $dbh->quote($biblioitem->{'dewey'});
971   $biblioitem->{'subclass'}        = $dbh->quote($biblioitem->{'subclass'});
972   $biblioitem->{'publicationyear'} = $dbh->quote($biblioitem->{'publicationyear'});
973   $biblioitem->{'publishercode'}   = $dbh->quote($biblioitem->{'publishercode'});
974   $biblioitem->{'volumedate'}      = $dbh->quote($biblioitem->{'volumedate'});
975   $biblioitem->{'volumeddesc'}     = $dbh->quote($biblioitem->{'volumeddesc'});  $biblioitem->{'illus'}            = $dbh->quote($biblioitem->{'illus'});
976   $biblioitem->{'illus'}           = $dbh->quote($biblioitem->{'illus'});
977   $biblioitem->{'pages'}           = $dbh->quote($biblioitem->{'pages'});
978   $biblioitem->{'notes'}           = $dbh->quote($biblioitem->{'notes'});
979   $biblioitem->{'size'}            = $dbh->quote($biblioitem->{'size'});
980   $biblioitem->{'place'}           = $dbh->quote($biblioitem->{'place'});
981   $biblioitem->{'lccn'}            = $dbh->quote($biblioitem->{'lccn'});
982   $biblioitem->{'marc'}            = $dbh->quote($biblioitem->{'marc'});
983   
984   $sth->execute;
985   $data       = $sth->fetchrow_arrayref;
986   $bibitemnum = $$data[0] + 1;
987
988   $sth->finish;
989
990   $query = "insert into biblioitems set
991 biblioitemnumber = $bibitemnum,
992 biblionumber     = $biblioitem->{'biblionumber'},
993 volume           = $biblioitem->{'volume'},
994 number           = $biblioitem->{'number'},
995 classification   = $biblioitem->{'classification'},
996 itemtype         = $biblioitem->{'itemtype'},
997 url              = $biblioitem->{'url'},
998 isbn             = $biblioitem->{'isbn'},
999 issn             = $biblioitem->{'issn'},
1000 dewey            = $biblioitem->{'dewey'},
1001 subclass         = $biblioitem->{'subclass'},
1002 publicationyear  = $biblioitem->{'publicationyear'},
1003 publishercode    = $biblioitem->{'publishercode'},
1004 volumedate       = $biblioitem->{'volumedate'},
1005 volumeddesc      = $biblioitem->{'volumeddesc'},
1006 illus            = $biblioitem->{'illus'},
1007 pages            = $biblioitem->{'pages'},
1008 notes            = $biblioitem->{'notes'},
1009 size             = $biblioitem->{'size'},
1010 lccn             = $biblioitem->{'lccn'},
1011 marc             = $biblioitem->{'marc'},
1012 place            = $biblioitem->{'place'}";
1013
1014   $sth = $dbh->prepare($query);
1015   $sth->execute;
1016
1017   $sth->finish;
1018   return($bibitemnum);
1019 }
1020
1021 # FIXME - This is in effect identical to &C4::Biblio::newsubject.
1022 # Pick one and stick with it.
1023 # If it's this one, it needs a POD.
1024 sub newsubject {
1025   my ($bibnum)=@_;
1026   my $dbh = C4::Context->dbh;
1027   my $query="insert into bibliosubject (biblionumber) values
1028   ($bibnum)";
1029   my $sth=$dbh->prepare($query);
1030 #  print $query;
1031   $sth->execute;
1032   $sth->finish;
1033 }
1034
1035 # FIXME - This is in effect the same as &C4::Biblio::newsubtitle
1036 # Pick one and stick with it.
1037 # If it's this one, it needs a POD.
1038 sub newsubtitle {
1039   my ($bibnum, $subtitle) = @_;
1040   my $dbh   = C4::Context->dbh;
1041   $subtitle = $dbh->quote($subtitle);
1042   my $query = "insert into bibliosubtitle set
1043 biblionumber = $bibnum,
1044 subtitle = $subtitle";
1045   my $sth   = $dbh->prepare($query);
1046
1047   $sth->execute;
1048
1049   $sth->finish;
1050 }
1051
1052 =item neworder
1053
1054   &neworder($biblionumber, $title, $ordnum, $basket, $quantity, $listprice,
1055         $booksellerid, $who, $notes, $bookfund, $biblioitemnumber, $rrp,
1056         $ecost, $gst, $budget, $unitprice, $subscription,
1057         $booksellerinvoicenumber);
1058
1059 Adds a new order to the database. Any argument that isn't described
1060 below is the new value of the field with the same name in the aqorders
1061 table of the Koha database.
1062
1063 C<$ordnum> is a "minimum order number." After adding the new entry to
1064 the aqorders table, C<&neworder> finds the first entry in aqorders
1065 with order number greater than or equal to C<$ordnum>, and adds an
1066 entry to the aqorderbreakdown table, with the order number just found,
1067 and the book fund ID of the newly-added order.
1068
1069 C<$budget> is effectively ignored.
1070
1071 C<$subscription> may be either "yes", or anything else for "no".
1072
1073 =cut
1074 #'
1075 # FIXME - This function appears in C4::Catalogue
1076 sub neworder {
1077   my ($bibnum,$title,$ordnum,$basket,$quantity,$listprice,$supplier,$who,$notes,$bookfund,$bibitemnum,$rrp,$ecost,$gst,$budget,$cost,$sub,$invoice)=@_;
1078   if ($budget eq 'now'){
1079     $budget="now()";
1080   } else {
1081     $budget="'2001-07-01'";
1082   }
1083   if ($sub eq 'yes'){
1084     $sub=1;
1085   } else {
1086     $sub=0;
1087   }
1088   my $dbh = C4::Context->dbh;
1089   my $query="insert into aqorders (biblionumber,title,basketno,
1090   quantity,listprice,booksellerid,entrydate,requisitionedby,authorisedby,notes,
1091   biblioitemnumber,rrp,ecost,gst,unitprice,subscription,booksellerinvoicenumber)
1092
1093   values
1094   ($bibnum,'$title',$basket,$quantity,$listprice,'$supplier',now(),
1095   '$who','$who','$notes',$bibitemnum,'$rrp','$ecost','$gst','$cost',
1096   '$sub','$invoice')";
1097   my $sth=$dbh->prepare($query);
1098 #  print $query;
1099   $sth->execute;
1100   $sth->finish;
1101   $query="select * from aqorders where
1102   biblionumber=$bibnum and basketno=$basket and ordernumber >=$ordnum";
1103   $sth=$dbh->prepare($query);
1104   $sth->execute;
1105   my $data=$sth->fetchrow_hashref;
1106   $sth->finish;
1107   $ordnum=$data->{'ordernumber'};
1108   $query="insert into aqorderbreakdown (ordernumber,bookfundid) values
1109   ($ordnum,'$bookfund')";
1110   $sth=$dbh->prepare($query);
1111 #  print $query;
1112   $sth->execute;
1113   $sth->finish;
1114 }
1115
1116 =item delorder
1117
1118   &delorder($biblionumber, $ordernumber);
1119
1120 Cancel the order with the given order and biblio numbers. It does not
1121 delete any entries in the aqorders table, it merely marks them as
1122 cancelled.
1123
1124 If there are no items remaining with the given biblionumber,
1125 C<&delorder> also deletes them from the marc_subfield_table and
1126 marc_biblio tables of the Koha database.
1127
1128 =cut
1129 #'
1130 # FIXME - This function appears in C4::Catalogue
1131 sub delorder {
1132   my ($bibnum,$ordnum)=@_;
1133   my $dbh = C4::Context->dbh;
1134   my $query="update aqorders set datecancellationprinted=now()
1135   where biblionumber='$bibnum' and
1136   ordernumber='$ordnum'";
1137   my $sth=$dbh->prepare($query);
1138   #print $query;
1139   $sth->execute;
1140   $sth->finish;
1141   my $count=itemcount($bibnum);
1142   if ($count == 0){
1143     delbiblio($bibnum);
1144   }
1145 }
1146
1147 =item modorder
1148
1149   &modorder($title, $ordernumber, $quantity, $listprice,
1150         $biblionumber, $basketno, $supplier, $who, $notes,
1151         $bookfundid, $bibitemnum, $rrp, $ecost, $gst, $budget,
1152         $unitprice, $booksellerinvoicenumber);
1153
1154 Modifies an existing order. Updates the order with order number
1155 C<$ordernumber> and biblionumber C<$biblionumber>. All other arguments
1156 update the fields with the same name in the aqorders table of the Koha
1157 database.
1158
1159 Entries with order number C<$ordernumber> in the aqorderbreakdown
1160 table are also updated to the new book fund ID.
1161
1162 =cut
1163 #'
1164 # FIXME - This function appears in C4::Catalogue
1165 sub modorder {
1166   my ($title,$ordnum,$quantity,$listprice,$bibnum,$basketno,$supplier,$who,$notes,$bookfund,$bibitemnum,$rrp,$ecost,$gst,$budget,$cost,$invoice)=@_;
1167   my $dbh = C4::Context->dbh;
1168   my $query="update aqorders set title='$title',
1169   quantity='$quantity',listprice='$listprice',basketno='$basketno', 
1170   rrp='$rrp',ecost='$ecost',unitprice='$cost',
1171   booksellerinvoicenumber='$invoice'
1172   where
1173   ordernumber=$ordnum and biblionumber=$bibnum";
1174   my $sth=$dbh->prepare($query);
1175 #  print $query;
1176   $sth->execute;
1177   $sth->finish;
1178   $query="update aqorderbreakdown set bookfundid=$bookfund where
1179   ordernumber=$ordnum";
1180   $sth=$dbh->prepare($query);
1181 #  print $query;
1182   $sth->execute;
1183   $sth->finish;
1184 }
1185
1186 =item newordernum
1187
1188   $order = &newordernum();
1189
1190 Finds the next unused order number in the aqorders table of the Koha
1191 database, and returns it.
1192
1193 =cut
1194 #'
1195 # FIXME - Race condition
1196 # FIXME - This function appears in C4::Catalogue
1197 sub newordernum {
1198   my $dbh = C4::Context->dbh;
1199   my $query="Select max(ordernumber) from aqorders";
1200   my $sth=$dbh->prepare($query);
1201   $sth->execute;
1202   my $data=$sth->fetchrow_arrayref;
1203   my $ordnum=$$data[0];
1204   $ordnum++;
1205   $sth->finish;
1206   return($ordnum);
1207 }
1208
1209 =item receiveorder
1210
1211   &receiveorder($biblionumber, $ordernumber, $quantityreceived, $user,
1212         $unitprice, $booksellerinvoicenumber, $biblioitemnumber,
1213         $freight, $bookfund, $rrp);
1214
1215 Updates an order, to reflect the fact that it was received, at least
1216 in part. All arguments not mentioned below update the fields with the
1217 same name in the aqorders table of the Koha database.
1218
1219 Updates the order with bibilionumber C<$biblionumber> and ordernumber
1220 C<$ordernumber>.
1221
1222 Also updates the book fund ID in the aqorderbreakdown table.
1223
1224 =cut
1225 #'
1226 # FIXME - This function appears in C4::Catalogue
1227 sub receiveorder {
1228   my ($biblio,$ordnum,$quantrec,$user,$cost,$invoiceno,$bibitemno,$freight,$bookfund,$rrp)=@_;
1229   my $dbh = C4::Context->dbh;
1230   my $query="update aqorders set quantityreceived='$quantrec',
1231   datereceived=now(),booksellerinvoicenumber='$invoiceno',
1232   biblioitemnumber=$bibitemno,unitprice='$cost',freight='$freight',
1233   rrp='$rrp'
1234   where biblionumber=$biblio and ordernumber=$ordnum
1235   ";
1236 #  print $query;
1237   my $sth=$dbh->prepare($query);
1238   $sth->execute;
1239   $sth->finish;
1240   $query="update aqorderbreakdown set bookfundid=$bookfund where
1241   ordernumber=$ordnum";
1242   $sth=$dbh->prepare($query);
1243 #  print $query;
1244   $sth->execute;
1245   $sth->finish;  
1246 }
1247
1248 =item updaterecorder
1249
1250   &updaterecorder($biblionumber, $ordernumber, $user, $unitprice,
1251         $bookfundid, $rrp);
1252
1253 Updates the order with biblionumber C<$biblionumber> and order number
1254 C<$ordernumber>. C<$bookfundid> is the new value for the book fund ID
1255 in the aqorderbreakdown table of the Koha database. All other
1256 arguments update the fields with the same name in the aqorders table.
1257
1258 C<$user> is ignored.
1259
1260 =cut
1261 #'
1262 # FIXME - This function appears in C4::Catalogue
1263 sub updaterecorder{
1264   my($biblio,$ordnum,$user,$cost,$bookfund,$rrp)=@_;
1265   my $dbh = C4::Context->dbh;
1266   my $query="update aqorders set
1267   unitprice='$cost', rrp='$rrp'
1268   where biblionumber=$biblio and ordernumber=$ordnum
1269   ";
1270 #  print $query;
1271   my $sth=$dbh->prepare($query);
1272   $sth->execute;
1273   $sth->finish;
1274   $query="update aqorderbreakdown set bookfundid=$bookfund where
1275   ordernumber=$ordnum";
1276   $sth=$dbh->prepare($query);
1277 #  print $query;
1278   $sth->execute;
1279   $sth->finish;  
1280 }
1281
1282 =item curconvert
1283
1284   $foreignprice = &curconvert($currency, $localprice);
1285
1286 Converts the price C<$localprice> to foreign currency C<$currency> by
1287 dividing by the exchange rate, and returns the result.
1288
1289 If no exchange rate is found, C<&curconvert> assumes the rate is one
1290 to one.
1291
1292 =cut
1293 #'
1294 # FIXME - An almost identical version of this function appears in
1295 # C4::Catalogue
1296 sub curconvert {
1297   my ($currency,$price)=@_;
1298   my $dbh = C4::Context->dbh;
1299   my $query="Select rate from currency where currency='$currency'";
1300   my $sth=$dbh->prepare($query);
1301   $sth->execute;
1302   my $data=$sth->fetchrow_hashref;
1303   $sth->finish;
1304   my $cur=$data->{'rate'};
1305   if ($cur==0){
1306     $cur=1;
1307   }
1308   $price=$price / $cur;         # FIXME - /=
1309   return($price);
1310 }
1311
1312 =item getcurrencies
1313
1314   ($count, $currencies) = &getcurrencies();
1315
1316 Returns the list of all known currencies.
1317
1318 C<$count> is the number of elements in C<$currencies>. C<$currencies>
1319 is a reference-to-array; its elements are references-to-hash, whose
1320 keys are the fields from the currency table in the Koha database.
1321
1322 =cut
1323 #'
1324 # FIXME - This function appears in C4::Catalogue
1325 sub getcurrencies {
1326   my $dbh = C4::Context->dbh;
1327   my $query="Select * from currency";
1328   my $sth=$dbh->prepare($query);
1329   $sth->execute;
1330   my @results;
1331   my $i=0;
1332   while (my $data=$sth->fetchrow_hashref){
1333     $results[$i]=$data;
1334     $i++;
1335   }
1336   $sth->finish;
1337   return($i,\@results);
1338
1339
1340 # FIXME - This function appears in C4::Catalogue. Neither one is used.
1341 sub getcurrency {
1342   my ($cur)=@_;
1343   my $dbh = C4::Context->dbh;
1344   my $query="Select * from currency where currency='$cur'";
1345   my $sth=$dbh->prepare($query);
1346   $sth->execute;
1347
1348   my $data=$sth->fetchrow_hashref;
1349   $sth->finish;
1350   return($data);
1351
1352
1353 =item updatecurrencies
1354
1355   &updatecurrencies($currency, $newrate);
1356
1357 Sets the exchange rate for C<$currency> to be C<$newrate>.
1358
1359 =cut
1360 #'
1361 # FIXME - This function appears in C4::Catalogue
1362 sub updatecurrencies {
1363   my ($currency,$rate)=@_;
1364   my $dbh = C4::Context->dbh;
1365   my $query="update currency set rate=$rate where currency='$currency'";
1366   my $sth=$dbh->prepare($query);
1367   $sth->execute;
1368   $sth->finish;
1369
1370
1371 =item updatesup
1372
1373   &updatesup($bookseller);
1374
1375 Updates the information for a given bookseller. C<$bookseller> is a
1376 reference-to-hash whose keys are the fields of the aqbooksellers table
1377 in the Koha database. It must contain entries for all of the fields.
1378 The entry to modify is determined by C<$bookseller-E<gt>{id}>.
1379
1380 The easiest way to get all of the necessary fields is to look up a
1381 book seller with C<&booksellers>, modify what's necessary, then call
1382 C<&updatesup> with the result.
1383
1384 =cut
1385 #'
1386 # FIXME - This function appears in C4::Catalogue
1387 sub updatesup {
1388    my ($data)=@_;
1389    my $dbh = C4::Context->dbh;
1390    my $query="Update aqbooksellers set
1391    name='$data->{'name'}',address1='$data->{'address1'}',address2='$data->{'address2'}',
1392    address3='$data->{'address3'}',address4='$data->{'address4'}',postal='$data->{'postal'}',
1393    phone='$data->{'phone'}',fax='$data->{'fax'}',url='$data->{'url'}',
1394    contact='$data->{'contact'}',contpos='$data->{'contpos'}',
1395    contphone='$data->{'contphone'}', contfax='$data->{'contfax'}', contaltphone=
1396    '$data->{'contaltphone'}', contemail='$data->{'contemail'}', contnotes=
1397    '$data->{'contnotes'}', active=$data->{'active'},
1398    listprice='$data->{'listprice'}', invoiceprice='$data->{'invoiceprice'}',
1399    gstreg=$data->{'gstreg'}, listincgst=$data->{'listincgst'},
1400    invoiceincgst=$data->{'invoiceincgst'}, specialty='$data->{'specialty'}',
1401    discount='$data->{'discount'}',invoicedisc='$data->{'invoicedisc'}',
1402    nocalc='$data->{'nocalc'}'
1403    where id='$data->{'id'}'";
1404    my $sth=$dbh->prepare($query);
1405    $sth->execute;
1406    $sth->finish;
1407 #   print $query;
1408 }
1409
1410 =item insertsup
1411
1412   $id = &insertsup($bookseller);
1413
1414 Creates a new bookseller. C<$bookseller> is a reference-to-hash whose
1415 keys are the fields of the aqbooksellers table in the Koha database.
1416 All fields must be present.
1417
1418 Returns the ID of the newly-created bookseller.
1419
1420 =cut
1421 #'
1422 # FIXME - This function also appears in C4::Catalogue. Pick one and
1423 # stick with it.
1424 sub insertsup {
1425   my ($data)=@_;
1426   my $dbh = C4::Context->dbh;
1427   my $sth=$dbh->prepare("Select max(id) from aqbooksellers");
1428   $sth->execute;
1429   my $data2=$sth->fetchrow_hashref;
1430   $sth->finish;
1431   $data2->{'max(id)'}++;
1432   $sth=$dbh->prepare("Insert into aqbooksellers (id) values ($data2->{'max(id)'})");
1433   $sth->execute;
1434   $sth->finish;
1435   $data->{'id'}=$data2->{'max(id)'};
1436   updatesup($data);
1437   return($data->{'id'});
1438 }
1439
1440 # FIXME - This is different from &C4::Biblio::newitems, though both
1441 # are exported.
1442 # FIXME - Never used AFAICT. Obsolete.
1443 # Otherwise, this needs a POD.
1444 sub newitems {
1445   my ($item, @barcodes) = @_;
1446   my $dbh   = C4::Context->dbh;
1447   my $query = "Select max(itemnumber) from items";
1448   my $sth   = $dbh->prepare($query);
1449   my $data;
1450   my $itemnumber;
1451   my $error;
1452
1453   $sth->execute;
1454   $data       = $sth->fetchrow_hashref;
1455   $itemnumber = $data->{'max(itemnumber)'} + 1;
1456   $sth->finish;
1457   
1458   $item->{'booksellerid'}     = $dbh->quote($item->{'booksellerid'});
1459   $item->{'homebranch'}       = $dbh->quote($item->{'homebranch'});
1460   $item->{'price'}            = $dbh->quote($item->{'price'});
1461   $item->{'replacementprice'} = $dbh->quote($item->{'replacementprice'});
1462   $item->{'itemnotes'}        = $dbh->quote($item->{'itemnotes'});
1463
1464   foreach my $barcode (@barcodes) {
1465     $barcode = uc($barcode);
1466     $barcode = $dbh->quote($barcode);
1467     $query   = "Insert into items set
1468 itemnumber           = $itemnumber,
1469 biblionumber         = $item->{'biblionumber'},
1470 biblioitemnumber     = $item->{'biblioitemnumber'},
1471 barcode              = $barcode,
1472 booksellerid         = $item->{'booksellerid'},
1473 dateaccessioned      = NOW(),
1474 homebranch           = $item->{'homebranch'},
1475 holdingbranch        = $item->{'homebranch'},
1476 price                = $item->{'price'},
1477 replacementprice     = $item->{'replacementprice'},
1478 replacementpricedate = NOW(),
1479 itemnotes            = $item->{'itemnotes'}";
1480
1481     if ($item->{'loan'}) {
1482       $query .= ",
1483 notforloan           = $item->{'loan'}";
1484     } # if
1485
1486     $sth = $dbh->prepare($query);
1487     $sth->execute;
1488
1489     $error .= $sth->errstr;
1490
1491     $sth->finish;
1492     $itemnumber++;
1493   } # for
1494
1495   return($error);
1496 }
1497
1498 # FIXME - This is the same as &C4::Biblio::Checkitems.
1499 # Pick one and stick with it.
1500 # If it's this one, it needs a POD.
1501 sub checkitems{
1502   my ($count,@barcodes)=@_;
1503   my $dbh = C4::Context->dbh;
1504   my $error;
1505   for (my $i=0;$i<$count;$i++){
1506     $barcodes[$i]=uc $barcodes[$i];
1507     my $query="Select * from items where barcode='$barcodes[$i]'";
1508     my $sth=$dbh->prepare($query);
1509     $sth->execute;
1510     if (my $data=$sth->fetchrow_hashref){
1511       $error.=" Duplicate Barcode: $barcodes[$i]";
1512     }
1513     $sth->finish;
1514   }
1515   return($error);
1516 }
1517
1518 # FIXME - This appears to be functionally equivalent to
1519 # &C4::Biblio::moditem.
1520 # Pick one and stick with it.
1521 # If it's this one, it needs a POD.
1522 sub moditem {
1523   my ($loan,$itemnum,$bibitemnum,$barcode,$notes,$homebranch,$lost,$wthdrawn,$replacement)=@_;
1524   my $dbh = C4::Context->dbh;
1525   my $query="update items set biblioitemnumber=$bibitemnum,
1526   barcode='$barcode',itemnotes='$notes'
1527   where itemnumber=$itemnum";
1528   if ($barcode eq ''){
1529     $query="update items set biblioitemnumber=$bibitemnum,notforloan=$loan where itemnumber=$itemnum";
1530   }
1531   if ($lost ne ''){
1532     $query="update items set biblioitemnumber=$bibitemnum,
1533       barcode='$barcode',itemnotes='$notes',homebranch='$homebranch',
1534       itemlost='$lost',wthdrawn='$wthdrawn' where itemnumber=$itemnum";
1535   }
1536   if ($replacement ne ''){
1537     $query=~ s/ where/,replacementprice='$replacement' where/;
1538   }
1539
1540   my $sth=$dbh->prepare($query);
1541   $sth->execute;
1542   $sth->finish;
1543 }
1544
1545 # FIXME - This function appears in C4::Catalogue. Neither one is used
1546 sub updatecost{
1547   my($price,$rrp,$itemnum)=@_;
1548   my $dbh = C4::Context->dbh;
1549   my $query="update items set price='$price',replacementprice='$rrp'
1550   where itemnumber=$itemnum";
1551   my $sth=$dbh->prepare($query);
1552   $sth->execute;
1553   $sth->finish;
1554 }
1555
1556 # FIXME - This is identical to &C4::Biblio::countitems.
1557 # Pick one and stick with it.
1558 # If it's this one, it needs a POD.
1559 sub countitems{
1560   my ($bibitemnum)=@_;
1561   my $dbh = C4::Context->dbh;
1562   my $query="Select count(*) from items where biblioitemnumber='$bibitemnum'";
1563   my $sth=$dbh->prepare($query);
1564   $sth->execute;
1565   my $data=$sth->fetchrow_hashref;
1566   $sth->finish;
1567   return($data->{'count(*)'});
1568 }
1569
1570 # FIXME - This function appears in C4::Catalogue. Neither one is used.
1571 sub findall {
1572   my ($biblionumber)=@_;
1573   my $dbh = C4::Context->dbh;
1574   my $query="Select * from biblioitems,items,itemtypes where 
1575   biblioitems.biblionumber=$biblionumber 
1576   and biblioitems.biblioitemnumber=items.biblioitemnumber and
1577   itemtypes.itemtype=biblioitems.itemtype
1578   order by items.biblioitemnumber";
1579   my $sth=$dbh->prepare($query);
1580   $sth->execute;
1581   my @results;
1582   my $i;
1583   while (my $data=$sth->fetchrow_hashref){
1584     $results[$i]=$data;
1585     $i++;
1586   }
1587   $sth->finish;
1588   return(@results);
1589 }
1590
1591 # FIXME - This function appears in C4::Catalogue. Neither one is used
1592 sub needsmod{
1593   my ($bibitemnum,$itemtype)=@_;
1594   my $dbh = C4::Context->dbh;
1595   my $query="Select * from biblioitems where biblioitemnumber=$bibitemnum
1596   and itemtype='$itemtype'";
1597   my $sth=$dbh->prepare($query);
1598   $sth->execute;
1599   my $result=0;
1600   if (my $data=$sth->fetchrow_hashref){
1601     $result=1;
1602   }
1603   $sth->finish;
1604   return($result);
1605 }
1606
1607 # FIXME - A nearly-identical function, appears in C4::Biblio
1608 # Pick one and stick with it.
1609 # If it's this one, it needs a POD.
1610 sub delitem{
1611   my ($itemnum)=@_;
1612   my $dbh = C4::Context->dbh;
1613   my $query="select * from items where itemnumber=$itemnum";
1614   my $sth=$dbh->prepare($query);
1615   $sth->execute;
1616   my @data=$sth->fetchrow_array;
1617   $sth->finish;
1618   $query="Insert into deleteditems values (";
1619   foreach my $temp (@data){
1620     $query=$query."'$temp',";           # FIXME - .=
1621   }
1622   $query=~ s/\,$/\)/;
1623 #  print $query;
1624   $sth=$dbh->prepare($query);
1625   $sth->execute;
1626   $sth->finish;
1627   $query = "Delete from items where itemnumber=$itemnum";
1628   $sth=$dbh->prepare($query);
1629   $sth->execute;
1630   $sth->finish;
1631 }
1632
1633 # FIXME - This is functionally identical to &C4::Biblio::deletebiblioitem.
1634 # Pick one and stick with it.
1635 # If it's this one, it needs a POD.
1636 sub deletebiblioitem {
1637     my ($biblioitemnumber) = @_;
1638     my $dbh   = C4::Context->dbh;
1639     my $query = "Select * from biblioitems
1640 where biblioitemnumber = $biblioitemnumber";
1641     my $sth   = $dbh->prepare($query);
1642     my @results;
1643
1644     $sth->execute;
1645   
1646     if (@results = $sth->fetchrow_array) {
1647
1648         $query = "Insert into deletedbiblioitems values (";
1649         foreach my $value (@results) {
1650             $value  = $dbh->quote($value);
1651             $query .= "$value,";
1652         } # foreach
1653
1654         $query =~ s/\,$/\)/;
1655         $dbh->do($query);
1656
1657         $dbh->do(<<EOT);
1658                 DELETE FROM     biblioitems
1659                 WHERE           biblioitemnumber = $biblioitemnumber
1660 EOT
1661     } # if
1662
1663     $sth->finish;
1664
1665 # Now delete all the items attached to the biblioitem
1666
1667     $query = "Select * from items where biblioitemnumber = $biblioitemnumber";
1668     $sth   = $dbh->prepare($query);
1669
1670     $sth->execute;
1671
1672     while (@results = $sth->fetchrow_array) {
1673
1674         $query = "Insert into deleteditems values (";
1675         foreach my $value (@results) {
1676             $value  = $dbh->quote($value);
1677             $query .= "$value,";
1678         } # foreach
1679
1680         $query =~ s/\,$/\)/;
1681         $dbh->do($query);
1682     } # while
1683
1684     $sth->finish;       # FIXME - This is bogus, isn't it?
1685
1686     $dbh->do(<<EOT);
1687         DELETE FROM     items
1688         WHERE           biblioitemnumber = $biblioitemnumber
1689 EOT
1690     
1691 } # sub deletebiblioitem
1692
1693 # FIXME - This is functionally identical to &C4::Biblio::delbiblio.
1694 # Pick one and stick with it.
1695 # If it's this one, it needs a POD.
1696 sub delbiblio{
1697   my ($biblio)=@_;
1698   my $dbh = C4::Context->dbh;
1699   my $query="select * from biblio where biblionumber=$biblio";
1700   my $sth=$dbh->prepare($query);
1701   $sth->execute;
1702   if (my @data=$sth->fetchrow_array){
1703     $sth->finish;
1704     $query="Insert into deletedbiblio values (";
1705     foreach my $temp (@data){
1706       $temp=~ s/\'/\\\'/g;
1707       $query=$query."'$temp',";         # FIXME - .=
1708     }
1709     $query=~ s/\,$/\)/;
1710 #   print $query;
1711     $sth=$dbh->prepare($query);
1712     $sth->execute;
1713     $sth->finish;
1714     $query = "Delete from biblio where biblionumber=$biblio";
1715     $sth=$dbh->prepare($query);
1716     $sth->execute;
1717     $sth->finish;
1718   }
1719
1720   $sth->finish;
1721 }
1722
1723 # FIXME - There's also a C4::Biblio::getitemtypes.
1724 # FIXME - Never used AFAICT. This function is obsolete.
1725 # If not, it needs a POD.
1726 sub getitemtypes {
1727   my $dbh   = C4::Context->dbh;
1728   my $query = "select * from itemtypes";
1729   my $sth   = $dbh->prepare($query);
1730     # || die "Cannot prepare $query" . $dbh->errstr;
1731   my $count = 0;
1732   my @results;
1733   
1734   $sth->execute;
1735     # || die "Cannot execute $query\n" . $sth->errstr;
1736   while (my $data = $sth->fetchrow_hashref) {
1737     $results[$count] = $data;
1738     $count++;
1739   } # while
1740   
1741   $sth->finish;
1742   return($count, @results);
1743 } # sub getitemtypes
1744
1745 # FIXME - This is identical to &C4::Biblio::getitemtypes.
1746 # Pick one and stick with it.
1747 # If it's this one, it needs a POD.
1748 sub getbiblio {
1749     my ($biblionumber) = @_;
1750     my $dbh   = C4::Context->dbh;
1751     my $query = "Select * from biblio where biblionumber = $biblionumber";
1752     my $sth   = $dbh->prepare($query);
1753       # || die "Cannot prepare $query\n" . $dbh->errstr;
1754     my $count = 0;
1755     my @results;
1756     
1757     $sth->execute;
1758       # || die "Cannot execute $query\n" . $sth->errstr;
1759     while (my $data = $sth->fetchrow_hashref) {
1760       $results[$count] = $data;
1761       $count++;
1762     } # while
1763     
1764     $sth->finish;
1765     return($count, @results);
1766 } # sub getbiblio
1767
1768 # FIXME - There's also a &C4::Biblio::getbiblioitem.
1769 # Pick one and stick with it.
1770 # If it's this one, it needs a POD.
1771 sub getbiblioitem {
1772     my ($biblioitemnum) = @_;
1773     my $dbh   = C4::Context->dbh;
1774     my $query = "Select * from biblioitems where
1775 biblioitemnumber = $biblioitemnum";
1776     my $sth   = $dbh->prepare($query);
1777     my $count = 0;
1778     my @results;
1779
1780     $sth->execute;
1781
1782     while (my $data = $sth->fetchrow_hashref) {
1783         $results[$count] = $data;
1784         $count++;
1785     } # while
1786
1787     $sth->finish;
1788     return($count, @results);
1789 } # sub getbiblioitem
1790
1791 # FIXME - This is identical to &C4::Biblio::getbiblioitem.
1792 # Pick one and stick with it.
1793 # If it's this one, it needs a POD.
1794 sub getbiblioitembybiblionumber {
1795     my ($biblionumber) = @_;
1796     my $dbh   = C4::Context->dbh;
1797     my $query = "Select * from biblioitems where biblionumber =
1798 $biblionumber";
1799     my $sth   = $dbh->prepare($query);
1800     my $count = 0;
1801     my @results;
1802
1803     $sth->execute;
1804
1805     while (my $data = $sth->fetchrow_hashref) {
1806         $results[$count] = $data;
1807         $count++;
1808     } # while
1809
1810     $sth->finish;
1811     return($count, @results);
1812 } # sub
1813
1814 # FIXME - This is identical to
1815 # &C4::Biblio::getbiblioitembybiblionumber.
1816 # Pick one and stick with it.
1817 # If it's this one, it needs a POD.
1818 sub getitemsbybiblioitem {
1819     my ($biblioitemnum) = @_;
1820     my $dbh   = C4::Context->dbh;
1821     my $query = "Select * from items, biblio where
1822 biblio.biblionumber = items.biblionumber and biblioitemnumber
1823 = $biblioitemnum";
1824     my $sth   = $dbh->prepare($query);
1825       # || die "Cannot prepare $query\n" . $dbh->errstr;
1826     my $count = 0;
1827     my @results;
1828     
1829     $sth->execute;
1830       # || die "Cannot execute $query\n" . $sth->errstr;
1831     while (my $data = $sth->fetchrow_hashref) {
1832       $results[$count] = $data;
1833       $count++;
1834     } # while
1835     
1836     $sth->finish;
1837     return($count, @results);
1838 } # sub getitemsbybiblioitem
1839
1840 # FIXME - This is identical to &C4::Biblio::isbnsearch.
1841 # Pick one and stick with it.
1842 # If it's this one, it needs a POD.
1843 sub isbnsearch {
1844     my ($isbn) = @_;
1845     my $dbh   = C4::Context->dbh;
1846     my $count = 0;
1847     my $query;
1848     my $sth;
1849     my @results;
1850     
1851     $isbn  = $dbh->quote($isbn);
1852     $query = "Select biblio.* from biblio, biblioitems where
1853 biblio.biblionumber = biblioitems.biblionumber
1854 and isbn = $isbn";
1855     $sth   = $dbh->prepare($query);
1856     
1857     $sth->execute;
1858     while (my $data = $sth->fetchrow_hashref) {
1859         $results[$count] = $data;
1860         $count++;
1861     } # while
1862
1863     $sth->finish;
1864     return($count, @results);
1865 } # sub isbnsearch
1866
1867 =item websitesearch
1868
1869   ($count, @results) = &websitesearch($keywordlist);
1870
1871 Looks up biblioitems by URL.
1872
1873 C<$keywordlist> is a space-separated list of search terms.
1874 C<&websitesearch> returns those biblioitems whose URL contains at
1875 least one of the search terms.
1876
1877 C<$count> is the number of elements in C<@results>. C<@results> is an
1878 array of references-to-hash, whose keys are the fields of the biblio
1879 and biblioitems tables in the Koha database.
1880
1881 =cut
1882 #'
1883 # FIXME - This function appears in C4::Catalogue
1884 sub websitesearch {
1885     my ($keywordlist) = @_;
1886     my $dbh   = C4::Context->dbh;
1887     my $query = "Select distinct biblio.* from biblio, biblioitems where
1888 biblio.biblionumber = biblioitems.biblionumber and (";
1889     my $count = 0;
1890     my $sth;
1891     my @results;
1892     my @keywords = split(/ +/, $keywordlist);
1893     my $keyword = shift(@keywords);
1894
1895     $keyword =~ s/%/\\%/g;
1896     $keyword =~ s/_/\\_/;
1897     $keyword = "%" . $keyword . "%";
1898     $keyword = $dbh->quote($keyword);
1899     $query  .= " (url like $keyword)";
1900
1901     foreach $keyword (@keywords) {
1902         $keyword =~ s/%/\\%/;
1903         $keyword =~ s/_/\\_/;
1904         $keyword = "%" . $keyword . "%";
1905         $keyword = $dbh->quote($keyword);
1906         $query  .= " or (url like $keyword)";
1907     } # foreach
1908
1909     $query .= ")";
1910     $sth    = $dbh->prepare($query);
1911     $sth->execute;
1912
1913     while (my $data = $sth->fetchrow_hashref) {
1914         $results[$count] = $data;
1915         $count++;
1916     } # while
1917
1918     $sth->finish;
1919     return($count, @results);
1920 } # sub websitesearch
1921
1922 =item addwebsite
1923
1924   &addwebsite($website);
1925
1926 Adds a new web site. C<$website> is a reference-to-hash, with the keys
1927 C<biblionumber>, C<title>, C<description>, and C<url>. All of these
1928 are mandatory.
1929
1930 =cut
1931 #'
1932 # FIXME - This function appears in C4::Catalogue
1933 sub addwebsite {
1934     my ($website) = @_;
1935     my $dbh = C4::Context->dbh;
1936     
1937     $website->{'biblionumber'} = $dbh->quote($website->{'biblionumber'});
1938     $website->{'title'}        = $dbh->quote($website->{'title'});
1939     $website->{'description'}  = $dbh->quote($website->{'description'});
1940     $website->{'url'}          = $dbh->quote($website->{'url'});
1941     
1942     $dbh->do(<<EOT);
1943         INSERT INTO     websites
1944         SET             biblionumber = $website->{'biblionumber'},
1945                         title        = $website->{'title'},
1946                         description  = $website->{'description'},
1947                         url          = $website->{'url'}
1948 EOT
1949 } # sub website
1950
1951 =item updatewebsite
1952
1953   &updatewebsite($website);
1954
1955 Updates an existing web site. C<$website> is a reference-to-hash with
1956 the keys C<websitenumber>, C<title>, C<description>, and C<url>. All
1957 of these are mandatory. C<$website-E<gt>{websitenumber}> identifies
1958 the entry to update.
1959
1960 =cut
1961 #'
1962 # FIXME - This function appears in C4::Catalogue
1963 sub updatewebsite {
1964     my ($website) = @_;
1965     my $dbh = C4::Context->dbh;
1966     
1967     $website->{'title'}      = $dbh->quote($website->{'title'});
1968     $website->{'description'} = $dbh->quote($website->{'description'});
1969     $website->{'url'}        = $dbh->quote($website->{'url'});
1970     
1971     $dbh->do(<<EOT);
1972         UPDATE  websites
1973         SET     title       = $website->{'title'},
1974                 description = $website->{'description'},
1975                 url         = $website->{'url'}
1976                 where websitenumber = $website->{'websitenumber'}
1977 EOT
1978 } # sub updatewebsite
1979
1980 =item deletewebsite
1981
1982   &deletewebsite($websitenumber);
1983
1984 Deletes the web site with number C<$websitenumber>.
1985
1986 =cut
1987 #'
1988 # FIXME - This function appears in C4::Catalogue
1989 sub deletewebsite {
1990     my ($websitenumber) = @_;
1991     my $dbh = C4::Context->dbh;
1992
1993     $dbh->do(<<EOT);
1994         DELETE FROM     websites
1995         WHERE           websitenumber = $websitenumber
1996 EOT
1997 } # sub deletewebsite
1998
1999
2000 END { }       # module clean-up code here (global destructor)
2001
2002 1;
2003 __END__
2004
2005 =back
2006
2007 =head1 AUTHOR
2008
2009 Koha Developement team <info@koha.org>
2010
2011 =cut