Cleaned up contents of location information
[koha.git] / C4 / Catalogue.pm
1 package C4::Catalogue; #asummes C4/Acquisitions.pm
2
3 # Continue working on updateItem!!!!!!
4 #
5 # updateItem is looking not bad.  Need to add addSubfield and deleteSubfield
6 # functions
7 #
8 # Trying to track down $dbh's that aren't disconnected....
9 #
10
11
12 use strict;
13 require Exporter;
14 use C4::Database;
15 use MARC::Record;
16 use C4::Biblio;
17
18 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
19
20 # set the version for version checking
21 $VERSION = 0.01;
22
23 @ISA = qw(Exporter);
24 @EXPORT = qw(
25              &basket &newbasket
26
27              &getorders &getallorders &getrecorders 
28              &getorder &neworder &delorder
29              &ordersearch
30              &modorder &getsingleorder &invoice &receiveorder
31              &updaterecorder &newordernum 
32
33              &bookfunds &bookfundbreakdown &updatecost 
34              &curconvert &getcurrencies &updatecurrencies &getcurrency 
35
36              &findall &needsmod &branches &updatesup &insertsup
37              &bookseller &breakdown &checkitems
38              &websitesearch &addwebsite &updatewebsite &deletewebsite
39 );
40 %EXPORT_TAGS = ( );     # eg: TAG => [ qw!name1 name2! ],
41
42 # your exported package globals go here,
43 # as well as any optionally exported functions
44
45 @EXPORT_OK   = qw($Var1 %Hashit);
46
47
48 # non-exported package globals go here
49 use vars qw(@more $stuff);
50
51 # initalize package globals, first exported ones
52
53 my $Var1   = '';
54 my %Hashit = ();
55
56
57 # then the others (which are still accessible as $Some::Module::stuff)
58 my $stuff  = '';
59 my @more   = ();
60
61 # all file-scoped lexicals must be created before
62 # the functions below that use them.
63
64 # file-private lexicals go here
65 my $priv_var    = '';
66 my %secret_hash = ();
67
68 # here's a file-private function as a closure,
69 # callable as &$priv_func;  it cannot be prototyped.
70 my $priv_func = sub {
71   # stuff goes here.
72   };
73   
74 # make all your functions, whether exported or not;
75
76
77 #
78 #
79 #
80 # BASKETS
81 #
82 #
83 #
84 sub basket {
85   my ($basketno,$supplier)=@_;
86   my $dbh=C4Connect;
87   my $query="Select *,biblio.title from aqorders,biblio,biblioitems 
88   where basketno='$basketno'
89   and biblio.biblionumber=aqorders.biblionumber and biblioitems.biblioitemnumber
90   =aqorders.biblioitemnumber 
91   and (datecancellationprinted is NULL or datecancellationprinted =
92   '0000-00-00')";
93   if ($supplier ne ''){
94     $query.=" and aqorders.booksellerid='$supplier'";
95   }
96   $query.=" group by aqorders.ordernumber";
97   my $sth=$dbh->prepare($query);
98   $sth->execute;
99   my @results;
100 #  print $query;
101   my $i=0;
102   while (my $data=$sth->fetchrow_hashref){
103     $results[$i]=$data;
104     $i++;
105   }
106   $sth->finish;
107   $dbh->disconnect;
108   return($i,@results);
109 }
110
111 sub newbasket {
112   my $dbh=C4Connect;
113   my $query="Select max(basketno) from aqorders";
114   my $sth=$dbh->prepare($query);
115   $sth->execute;
116   my $data=$sth->fetchrow_arrayref;
117   my $basket=$$data[0];
118   $basket++;
119   $sth->finish;
120   $dbh->disconnect;
121   return($basket);
122 }
123 sub neworder {
124   my ($bibnum,$title,$ordnum,$basket,$quantity,$listprice,$supplier,$who,$notes,$bookfund,$bibitemnum,$rrp,$ecost,$gst,$budget,$cost,$sub,$invoice)=@_;
125   if ($budget eq 'now'){
126     $budget="now()";
127   } else {
128     $budget="'2001-07-01'";
129   }
130   if ($sub eq 'yes'){
131     $sub=1;
132   } else {
133     $sub=0;
134   }
135   my $dbh=C4Connect;
136   my $query="insert into aqorders (biblionumber,title,basketno,
137   quantity,listprice,booksellerid,entrydate,requisitionedby,authorisedby,notes,
138   biblioitemnumber,rrp,ecost,gst,unitprice,subscription,booksellerinvoicenumber)
139
140   values
141   ($bibnum,'$title',$basket,$quantity,$listprice,'$supplier',now(),
142   '$who','$who','$notes',$bibitemnum,'$rrp','$ecost','$gst','$cost',
143   '$sub','$invoice')";
144   my $sth=$dbh->prepare($query);
145 #  print $query;
146   $sth->execute;
147   $sth->finish;
148   $query="select * from aqorders where
149   biblionumber=$bibnum and basketno=$basket and ordernumber >=$ordnum";
150   $sth=$dbh->prepare($query);
151   $sth->execute;
152   my $data=$sth->fetchrow_hashref;
153   $sth->finish;
154   $ordnum=$data->{'ordernumber'};
155   $query="insert into aqorderbreakdown (ordernumber,bookfundid) values
156   ($ordnum,'$bookfund')";
157   $sth=$dbh->prepare($query);
158 #  print $query;
159   $sth->execute;
160   $sth->finish;
161   $dbh->disconnect;
162 }
163
164 sub delorder {
165   my ($bibnum,$ordnum)=@_;
166   my $dbh=C4Connect;
167   my $query="update aqorders set datecancellationprinted=now()
168   where biblionumber='$bibnum' and
169   ordernumber='$ordnum'";
170   my $sth=$dbh->prepare($query);
171   #print $query;
172   $sth->execute;
173   $sth->finish;
174   my $count=itemcount($bibnum);
175   if ($count == 0){
176     delbiblio($bibnum);
177   }
178   $dbh->disconnect;
179 }
180
181 sub modorder {
182   my ($title,$ordnum,$quantity,$listprice,$bibnum,$basketno,$supplier,$who,$notes,$bookfund,$bibitemnum,$rrp,$ecost,$gst,$budget,$cost,$invoice)=@_;
183   my $dbh=C4Connect;
184   my $query="update aqorders set title='$title',
185   quantity='$quantity',listprice='$listprice',basketno='$basketno', 
186   rrp='$rrp',ecost='$ecost',unitprice='$cost',
187   booksellerinvoicenumber='$invoice'
188   where
189   ordernumber=$ordnum and biblionumber=$bibnum";
190   my $sth=$dbh->prepare($query);
191 #  print $query;
192   $sth->execute;
193   $sth->finish;
194   $query="update aqorderbreakdown set bookfundid=$bookfund where
195   ordernumber=$ordnum";
196   $sth=$dbh->prepare($query);
197 #  print $query;
198   $sth->execute;
199   $sth->finish;
200   $dbh->disconnect;
201 }
202
203 sub newordernum {
204   my $dbh=C4Connect;
205   my $query="Select max(ordernumber) from aqorders";
206   my $sth=$dbh->prepare($query);
207   $sth->execute;
208   my $data=$sth->fetchrow_arrayref;
209   my $ordnum=$$data[0];
210   $ordnum++;
211   $sth->finish;
212   $dbh->disconnect;
213   return($ordnum);
214 }
215
216 sub receiveorder {
217   my ($biblio,$ordnum,$quantrec,$user,$cost,$invoiceno,$bibitemno,$freight,$bookfund,$rrp)=@_;
218   my $dbh=C4Connect;
219   my $query="update aqorders set quantityreceived='$quantrec',
220   datereceived=now(),booksellerinvoicenumber='$invoiceno',
221   biblioitemnumber=$bibitemno,unitprice='$cost',freight='$freight',
222   rrp='$rrp'
223   where biblionumber=$biblio and ordernumber=$ordnum
224   ";
225 #  print $query;
226   my $sth=$dbh->prepare($query);
227   $sth->execute;
228   $sth->finish;
229   $query="update aqorderbreakdown set bookfundid=$bookfund where
230   ordernumber=$ordnum";
231   $sth=$dbh->prepare($query);
232 #  print $query;
233   $sth->execute;
234   $sth->finish;  
235   $dbh->disconnect;
236 }
237 sub updaterecorder{
238   my($biblio,$ordnum,$user,$cost,$bookfund,$rrp)=@_;
239   my $dbh=C4Connect;
240   my $query="update aqorders set
241   unitprice='$cost', rrp='$rrp'
242   where biblionumber=$biblio and ordernumber=$ordnum
243   ";
244 #  print $query;
245   my $sth=$dbh->prepare($query);
246   $sth->execute;
247   $sth->finish;
248   $query="update aqorderbreakdown set bookfundid=$bookfund where
249   ordernumber=$ordnum";
250   $sth=$dbh->prepare($query);
251 #  print $query;
252   $sth->execute;
253   $sth->finish;  
254   $dbh->disconnect;
255 }
256
257 #
258 #
259 # ORDERS
260 #
261 #
262
263 sub getorders {
264   my ($supplierid)=@_;
265   my $dbh=C4Connect;
266   my $query = "Select count(*),authorisedby,entrydate,basketno from aqorders where 
267   booksellerid='$supplierid' and (quantity > quantityreceived or
268   quantityreceived is NULL)
269   and (datecancellationprinted is NULL or datecancellationprinted = '0000-00-00')";
270   $query.=" group by basketno order by entrydate desc";
271   #print $query;
272   my $sth=$dbh->prepare($query);
273   $sth->execute;
274   my @results;
275   my $i=0;
276   while (my $data=$sth->fetchrow_hashref){
277     $results[$i]=$data;
278     $i++;
279   }
280   $sth->finish;
281   $dbh->disconnect;
282   return ($i,\@results);
283 }
284
285 sub getorder{
286   my ($bi,$bib)=@_;
287   my $dbh=C4Connect;
288   my $query="Select ordernumber from aqorders where biblionumber=$bib and
289   biblioitemnumber='$bi'";
290   my $sth=$dbh->prepare($query);
291   $sth->execute;
292   my $ordnum=$sth->fetchrow_hashref;
293   $sth->finish;
294   my $order=getsingleorder($ordnum->{'ordernumber'});
295   $dbh->disconnect;
296 #  print $query;
297   return ($order,$ordnum->{'ordernumber'});
298 }
299
300 sub getsingleorder {
301   my ($ordnum)=@_;
302   my $dbh=C4Connect;
303   my $query="Select * from biblio,biblioitems,aqorders,aqorderbreakdown 
304   where aqorders.ordernumber='$ordnum' 
305   and biblio.biblionumber=aqorders.biblionumber and
306   biblioitems.biblioitemnumber=aqorders.biblioitemnumber and
307   aqorders.ordernumber=aqorderbreakdown.ordernumber";
308   my $sth=$dbh->prepare($query);
309   $sth->execute;
310   my $data=$sth->fetchrow_hashref;
311   $sth->finish;
312   $dbh->disconnect;
313   return($data);
314 }
315
316 sub getallorders {
317   #gets all orders from a certain supplier, orders them alphabetically
318   my ($supid)=@_;
319   my $dbh=C4Connect;
320   my $query="Select * from aqorders,biblio,biblioitems where booksellerid='$supid'
321   and (cancelledby is NULL or cancelledby = '')
322   and (quantityreceived < quantity or quantityreceived is NULL)
323   and biblio.biblionumber=aqorders.biblionumber and biblioitems.biblioitemnumber=
324   aqorders.biblioitemnumber
325   group by aqorders.biblioitemnumber
326   order by
327   biblio.title";
328   my $i=0;
329   my @results;
330   my $sth=$dbh->prepare($query);
331   $sth->execute;
332   while (my $data=$sth->fetchrow_hashref){
333     $results[$i]=$data;
334     $i++;
335   }
336   $sth->finish;
337   $dbh->disconnect;
338   return($i,@results);
339 }
340
341 sub getrecorders {
342   #gets all orders from a certain supplier, orders them alphabetically
343   my ($supid)=@_;
344   my $dbh=C4Connect;
345   my $query="Select * from aqorders,biblio,biblioitems where booksellerid='$supid'
346   and (cancelledby is NULL or cancelledby = '')
347   and biblio.biblionumber=aqorders.biblionumber and biblioitems.biblioitemnumber=                    
348   aqorders.biblioitemnumber and
349   aqorders.quantityreceived>0
350   and aqorders.datereceived >=now()
351   group by aqorders.biblioitemnumber 
352   order by
353   biblio.title";
354   my $i=0;
355   my @results;
356   my $sth=$dbh->prepare($query);
357   $sth->execute;
358   while (my $data=$sth->fetchrow_hashref){
359     $results[$i]=$data;
360     $i++;
361   }
362   $sth->finish;
363   $dbh->disconnect;
364   return($i,@results);
365 }
366
367 sub ordersearch {
368   my ($search,$biblio,$catview) = @_;
369   my $dbh   = C4Connect;
370   my $query = "Select *,biblio.title from aqorders,biblioitems,biblio
371 where aqorders.biblioitemnumber = biblioitems.biblioitemnumber
372 and biblio.biblionumber=aqorders.biblionumber
373 and ((datecancellationprinted is NULL)
374 or (datecancellationprinted = '0000-00-00'))
375 and ((";
376   my @data  = split(' ',$search);
377   my $count = @data;
378   for (my $i = 0; $i < $count; $i++) {
379     $query .= "(biblio.title like '$data[$i]%' or biblio.title like '% $data[$i]%') and ";
380   }
381   $query=~ s/ and $//;
382   $query.=" ) or biblioitems.isbn='$search'
383   or (aqorders.ordernumber='$search' and aqorders.biblionumber='$biblio')) ";
384   if ($catview ne 'yes'){
385     $query.=" and (quantityreceived < quantity or quantityreceived is NULL)";
386   }
387   $query.=" group by aqorders.ordernumber";
388   my $sth=$dbh->prepare($query);
389   $sth->execute;
390   my $i=0;
391   my @results;
392   while (my $data=$sth->fetchrow_hashref){
393      my $sth2=$dbh->prepare("Select * from biblio where
394      biblionumber='$data->{'biblionumber'}'");
395      $sth2->execute;
396      my $data2=$sth2->fetchrow_hashref;
397      $sth2->finish;
398      $data->{'author'}=$data2->{'author'};
399      $data->{'seriestitle'}=$data2->{'seriestitle'};
400      $sth2=$dbh->prepare("Select * from aqorderbreakdown where
401     ordernumber=$data->{'ordernumber'}");
402     $sth2->execute;
403     $data2=$sth2->fetchrow_hashref;
404     $sth2->finish;
405     $data->{'branchcode'}=$data2->{'branchcode'};
406     $data->{'bookfundid'}=$data2->{'bookfundid'};
407     $results[$i]=$data;
408     $i++;
409   }
410   $sth->finish;
411   $dbh->disconnect;
412   return($i,@results);
413 }
414
415 #
416 #
417 # MONEY
418 #
419 #
420 sub invoice {
421   my ($invoice)=@_;
422   my $dbh=C4Connect;
423   my $query="Select * from aqorders,biblio,biblioitems where
424   booksellerinvoicenumber='$invoice'
425   and biblio.biblionumber=aqorders.biblionumber and biblioitems.biblioitemnumber=
426   aqorders.biblioitemnumber group by aqorders.ordernumber,aqorders.biblioitemnumber";
427   my $i=0;
428   my @results;
429   my $sth=$dbh->prepare($query);
430   $sth->execute;
431   while (my $data=$sth->fetchrow_hashref){
432     $results[$i]=$data;
433     $i++;
434   }
435   $sth->finish;
436   $dbh->disconnect;
437   return($i,@results);
438 }
439
440 sub bookfunds {
441   my $dbh=C4Connect;
442   my $query="Select * from aqbookfund,aqbudget where aqbookfund.bookfundid
443   =aqbudget.bookfundid
444   group by aqbookfund.bookfundid order by bookfundname";
445   my $sth=$dbh->prepare($query);
446   $sth->execute;
447   my @results;
448   my $i=0;
449   while (my $data=$sth->fetchrow_hashref){
450     $results[$i]=$data;
451     $i++;
452   }
453   $sth->finish;
454   $dbh->disconnect;
455   return($i,@results);
456 }
457
458 sub bookfundbreakdown {
459   my ($id)=@_;
460   my $dbh=C4Connect;
461   my $query="Select quantity,datereceived,freight,unitprice,listprice,ecost,quantityreceived,subscription
462   from aqorders,aqorderbreakdown where bookfundid='$id' and 
463   aqorders.ordernumber=aqorderbreakdown.ordernumber
464   and (datecancellationprinted is NULL or
465   datecancellationprinted='0000-00-00')";
466   my $sth=$dbh->prepare($query);
467   $sth->execute;
468   my $comtd=0;
469   my $spent=0;
470   while (my $data=$sth->fetchrow_hashref){
471     if ($data->{'subscription'} == 1){
472       $spent+=$data->{'quantity'}*$data->{'unitprice'};
473     } else {
474       my $leftover=$data->{'quantity'}-$data->{'quantityreceived'};
475       $comtd+=($data->{'ecost'})*$leftover;
476       $spent+=($data->{'unitprice'})*$data->{'quantityreceived'};
477     }
478   }
479   $sth->finish;
480   $dbh->disconnect;
481   return($spent,$comtd);
482 }
483
484 sub curconvert {
485   my ($currency,$price)=@_;
486   my $dbh=C4Connect;
487   my $query="Select rate from currency where currency='$currency'";
488   my $sth=$dbh->prepare($query);
489   $sth->execute;
490   my $data=$sth->fetchrow_hashref;
491   $sth->finish;
492   $dbh->disconnect;
493   my $cur=$data->{'rate'};
494   if ($cur==0){
495     $cur=1;
496   }
497   my $price=$price / $cur;
498   return($price);
499 }
500
501 sub getcurrencies {
502   my $dbh=C4Connect;
503   my $query="Select * from currency";
504   my $sth=$dbh->prepare($query);
505   $sth->execute;
506   my @results;
507   my $i=0;
508   while (my $data=$sth->fetchrow_hashref){
509     $results[$i]=$data;
510     $i++;
511   }
512   $sth->finish;
513   $dbh->disconnect;
514   return($i,\@results);
515
516
517 sub getcurrency {
518   my ($cur)=@_;
519   my $dbh=C4Connect;
520   my $query="Select * from currency where currency='$cur'";
521   my $sth=$dbh->prepare($query);
522   $sth->execute;
523
524   my $data=$sth->fetchrow_hashref;
525   $sth->finish;
526   $dbh->disconnect;
527   return($data);
528
529
530 sub updatecurrencies {
531   my ($currency,$rate)=@_;
532   my $dbh=C4Connect;
533   my $query="update currency set rate=$rate where currency='$currency'";
534   my $sth=$dbh->prepare($query);
535   $sth->execute;
536   $sth->finish;
537   $dbh->disconnect;
538
539
540 sub updatecost{
541   my($price,$rrp,$itemnum)=@_;
542   my $dbh=C4Connect;
543   my $query="update items set price='$price',replacementprice='$rrp'
544   where itemnumber=$itemnum";
545   my $sth=$dbh->prepare($query);
546   $sth->execute;
547   $sth->finish;
548   $dbh->disconnect;
549 }
550
551 #
552 #
553 # OTHERS
554 #
555 #
556
557 sub bookseller {
558   my ($searchstring)=@_;
559   my $dbh=C4Connect;
560   my $query="Select * from aqbooksellers where name like '%$searchstring%' or
561   id = '$searchstring'";
562   my $sth=$dbh->prepare($query);
563   $sth->execute;
564   my @results;
565   my $i=0;
566   while (my $data=$sth->fetchrow_hashref){
567     $results[$i]=$data;
568     $i++;
569   }
570   $sth->finish;
571   $dbh->disconnect;
572   return($i,@results);
573 }
574 sub breakdown {
575   my ($id)=@_;
576   my $dbh=C4Connect;
577   my $query="Select * from aqorderbreakdown where ordernumber='$id'";
578   my $sth=$dbh->prepare($query);
579   $sth->execute;
580   my @results;
581   my $i=0;
582   while (my $data=$sth->fetchrow_hashref){
583     $results[$i]=$data;
584     $i++;
585   }
586   $sth->finish;
587   $dbh->disconnect;
588   return($i,\@results);
589 }
590
591 sub branches {
592     my $dbh   = C4Connect;
593     my $query = "Select * from branches";
594     my $sth   = $dbh->prepare($query);
595     my $i     = 0;
596     my @results;
597
598     $sth->execute;
599     while (my $data = $sth->fetchrow_hashref) {
600         $results[$i] = $data;
601         $i++;
602     } # while
603
604     $sth->finish;
605     $dbh->disconnect;
606     return($i, @results);
607 } # sub branches
608
609 sub findall {
610   my ($biblionumber)=@_;
611   my $dbh=C4Connect;
612   my $query="Select * from biblioitems,items,itemtypes where 
613   biblioitems.biblionumber=$biblionumber 
614   and biblioitems.biblioitemnumber=items.biblioitemnumber and
615   itemtypes.itemtype=biblioitems.itemtype
616   order by items.biblioitemnumber";
617   my $sth=$dbh->prepare($query);
618   $sth->execute;
619   my @results;
620   my $i;
621   while (my $data=$sth->fetchrow_hashref){
622     $results[$i]=$data;
623     $i++;
624   }
625   $sth->finish;
626   $dbh->disconnect;
627   return(@results);
628 }
629
630 sub needsmod{
631   my ($bibitemnum,$itemtype)=@_;
632   my $dbh=C4Connect;
633   my $query="Select * from biblioitems where biblioitemnumber=$bibitemnum
634   and itemtype='$itemtype'";
635   my $sth=$dbh->prepare($query);
636   $sth->execute;
637   my $result=0;
638   if (my $data=$sth->fetchrow_hashref){
639     $result=1;
640   }
641   $sth->finish;
642   $dbh->disconnect;
643   return($result);
644 }
645
646 sub updatesup {
647    my ($data)=@_;
648    my $dbh=C4Connect;
649    my $query="Update aqbooksellers set
650    name='$data->{'name'}',address1='$data->{'address1'}',address2='$data->{'address2'}',
651    address3='$data->{'address3'}',address4='$data->{'address4'}',postal='$data->{'postal'}',
652    phone='$data->{'phone'}',fax='$data->{'fax'}',url='$data->{'url'}',
653    contact='$data->{'contact'}',contpos='$data->{'contpos'}',
654    contphone='$data->{'contphone'}', contfax='$data->{'contfax'}', contaltphone=
655    '$data->{'contaltphone'}', contemail='$data->{'contemail'}', contnotes=
656    '$data->{'contnotes'}', active=$data->{'active'},
657    listprice='$data->{'listprice'}', invoiceprice='$data->{'invoiceprice'}',
658    gstreg=$data->{'gstreg'}, listincgst=$data->{'listincgst'},
659    invoiceincgst=$data->{'invoiceincgst'}, specialty='$data->{'specialty'}',
660    discount='$data->{'discount'}',invoicedisc='$data->{'invoicedisc'}',
661    nocalc='$data->{'nocalc'}'
662    where id='$data->{'id'}'";
663    my $sth=$dbh->prepare($query);
664    $sth->execute;
665    $sth->finish;
666    $dbh->disconnect;
667 #   print $query;
668 }
669
670 sub insertsup {
671   my ($data)=@_;
672   my $dbh=C4Connect;
673   my $sth=$dbh->prepare("Select max(id) from aqbooksellers");
674   $sth->execute;
675   my $data2=$sth->fetchrow_hashref;
676   $sth->finish;
677   $data2->{'max(id)'}++;
678   $sth=$dbh->prepare("Insert into aqbooksellers (id) values ($data2->{'max(id)'})");
679   $sth->execute;
680   $sth->finish;
681   $data->{'id'}=$data2->{'max(id)'};
682   $dbh->disconnect;
683   updatesup($data);
684   return($data->{'id'});
685 }
686
687 sub websitesearch {
688     my ($keywordlist) = @_;
689     my $dbh   = C4Connect;
690     my $query = "Select distinct biblio.* from biblio, biblioitems where
691 biblio.biblionumber = biblioitems.biblionumber and (";
692     my $count = 0;
693     my $sth;
694     my @results;
695     my @keywords = split(/ +/, $keywordlist);
696     my $keyword = shift(@keywords);
697
698     $keyword =~ s/%/\\%/g;
699     $keyword =~ s/_/\\_/;
700     $keyword = "%" . $keyword . "%";
701     $keyword = $dbh->quote($keyword);
702     $query  .= " (url like $keyword)";
703
704     foreach $keyword (@keywords) {
705         $keyword =~ s/%/\\%/;
706         $keyword =~ s/_/\\_/;
707         $keyword = "%" . $keyword . "%";
708         $keyword = $dbh->quote($keyword);
709         $query  .= " or (url like $keyword)";
710     } # foreach
711
712     $query .= ")";
713     $sth    = $dbh->prepare($query);
714     $sth->execute;
715
716     while (my $data = $sth->fetchrow_hashref) {
717         $results[$count] = $data;
718         $count++;
719     } # while
720
721     $sth->finish;
722     $dbh->disconnect;
723     return($count, @results);
724 } # sub websitesearch
725
726
727 sub addwebsite {
728     my ($website) = @_;
729     my $dbh = C4Connect;
730     my $query;
731     
732     $website->{'biblionumber'} = $dbh->quote($website->{'biblionumber'});
733     $website->{'title'}        = $dbh->quote($website->{'title'});
734     $website->{'description'}  = $dbh->quote($website->{'description'});
735     $website->{'url'}          = $dbh->quote($website->{'url'});
736     
737     $query = "Insert into websites set
738 biblionumber = $website->{'biblionumber'},
739 title        = $website->{'title'},
740 description  = $website->{'description'},
741 url          = $website->{'url'}";
742     
743     $dbh->do($query);
744     
745     $dbh->disconnect;
746 } # sub website
747
748
749 sub updatewebsite {
750     my ($website) = @_;
751     my $dbh = C4Connect;
752     my $query;
753     
754     $website->{'title'}      = $dbh->quote($website->{'title'});
755     $website->{'description'} = $dbh->quote($website->{'description'});
756     $website->{'url'}        = $dbh->quote($website->{'url'});
757     
758     $query = "Update websites set
759 title       = $website->{'title'},
760 description = $website->{'description'},
761 url         = $website->{'url'}
762 where websitenumber = $website->{'websitenumber'}";
763
764     $dbh->do($query);
765     
766     $dbh->disconnect;
767 } # sub updatewebsite
768
769
770 sub deletewebsite {
771     my ($websitenumber) = @_;
772     my $dbh = C4Connect;
773     my $query = "Delete from websites where websitenumber = $websitenumber";
774     
775     $dbh->do($query);
776     
777     $dbh->disconnect;
778 } # sub deletewebsite
779
780 END { }       # module clean-up code here (global destructor)