3 # Copyright 2000-2003 Katipo Communications
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
25 use Digest
::MD5
qw(md5_base64);
26 use Date
::Calc qw
/Today Add_Delta_YM/;
27 use C4
::Log
; # logaction
31 our ($VERSION,@ISA,@EXPORT,@EXPORT_OK);
37 C4::Members - Perl Module containing convenience functions for member handling
45 This module contains routines for adding, modifying and deleting members/patrons/borrowers
63 &GetMemberIssuesAndFines
78 &GetMemberAccountRecords
79 &GetBorNotifyAcctRecord
85 &GetBorrowersWhoHaveNotBorrowedSince
86 &GetBorrowersWhoHaveNeverBorrowed
87 &GetBorrowersWithIssuesHistoryOlderThan
108 &ExtendMemberSubscriptionTo
124 ($count, $borrowers) = &SearchMember($searchstring, $type,$category_type,$filter,$showallbranches);
126 Looks up patrons (borrowers) by name.
128 BUGFIX 499: C<$type> is now used to determine type of search.
129 if $type is "simple", search is performed on the first letter of the
132 $category_type is used to get a specified type of user.
133 (mainly adults when creating a child.)
135 C<$searchstring> is a space-separated list of search terms. Each term
136 must match the beginning a borrower's surname, first name, or other
139 C<$filter> is assumed to be a list of elements to filter results on
141 C<$showallbranches> is used in IndependantBranches Context to display all branches results.
143 C<&SearchMember> returns a two-element list. C<$borrowers> is a
144 reference-to-array; each element is a reference-to-hash, whose keys
145 are the fields of the C<borrowers> table in the Koha database.
146 C<$count> is the number of elements in C<$borrowers>.
151 #used by member enquiries from the intranet
152 #called by member.pl and circ/circulation.pl
154 my ($searchstring, $orderby, $type,$category_type,$filter,$showallbranches ) = @_;
155 my $dbh = C4
::Context
->dbh;
161 # this is used by circulation everytime a new borrowers cardnumber is scanned
162 # so we can check an exact match first, if that works return, otherwise do the rest
163 $query = "SELECT * FROM borrowers
164 LEFT JOIN categories ON borrowers.categorycode=categories.categorycode
165 WHERE cardnumber = ?";
166 my $sth = $dbh->prepare($query);
167 $sth->execute($searchstring);
168 my $data = $sth->fetchall_arrayref({});
170 return ( scalar(@
$data), $data );
174 if ( $type eq "simple" ) # simple search for one letter only
178 LEFT JOIN categories ON borrowers.categorycode=categories.categorycode ".
179 ($category_type?
" AND category_type = ".$dbh->quote($category_type):"");
182 " WHERE (surname LIKE ? OR cardnumber like ?) ";
183 if (C4
::Context
->preference("IndependantBranches") && !$showallbranches){
184 if (C4
::Context
->userenv && C4
::Context
->userenv->{flags
}!=1 && C4
::Context
->userenv->{'branch'}){
185 $query.=" AND borrowers.branchcode =".$dbh->quote(C4
::Context
->userenv->{'branch'}) unless (C4
::Context
->userenv->{'branch'} eq "insecure");
188 $query.=" ORDER BY $orderby";
189 @bind = ("$searchstring%","$searchstring");
191 else # advanced search looking in surname, firstname and othernames
193 @data = split( ' ', $searchstring );
195 $query = "SELECT * FROM borrowers
196 LEFT JOIN categories ON borrowers.categorycode=categories.categorycode
198 if (C4
::Context
->preference("IndependantBranches") && !$showallbranches){
199 if (C4
::Context
->userenv && C4
::Context
->userenv->{flags
}!=1 && C4
::Context
->userenv->{'branch'}){
200 $query.=" borrowers.branchcode =".$dbh->quote(C4
::Context
->userenv->{'branch'})." AND " unless (C4
::Context
->userenv->{'branch'} eq "insecure");
203 $query.="((surname LIKE ? OR surname LIKE ?
204 OR firstname LIKE ? OR firstname LIKE ?
205 OR othernames LIKE ? OR othernames LIKE ?)
207 ($category_type?
" AND category_type = ".$dbh->quote($category_type):"");
209 "$data[0]%", "% $data[0]%", "$data[0]%", "% $data[0]%",
210 "$data[0]%", "% $data[0]%"
212 for ( my $i = 1 ; $i < $count ; $i++ ) {
213 $query = $query . " AND (" . " surname LIKE ? OR surname LIKE ?
214 OR firstname LIKE ? OR firstname LIKE ?
215 OR othernames LIKE ? OR othernames LIKE ?)";
217 "$data[$i]%", "% $data[$i]%", "$data[$i]%",
218 "% $data[$i]%", "$data[$i]%", "% $data[$i]%" );
222 $query = $query . ") OR cardnumber LIKE ?
224 push( @bind, $searchstring );
229 my $sth = $dbh->prepare($query);
231 # warn "Q $orderby : $query";
232 $sth->execute(@bind);
234 my $data = $sth->fetchall_arrayref({});
237 return ( scalar(@
$data), $data );
240 =head2 GetMemberDetails
242 ($borrower, $flags) = &GetMemberDetails($borrowernumber, $cardnumber);
244 Looks up a patron and returns information about him or her. If
245 C<$borrowernumber> is true (nonzero), C<&GetMemberDetails> looks
246 up the borrower by number; otherwise, it looks up the borrower by card
249 C<$borrower> is a reference-to-hash whose keys are the fields of the
250 borrowers table in the Koha database. In addition,
251 C<$borrower-E<gt>{flags}> is a hash giving more detailed information
252 about the patron. Its keys act as flags :
254 if $borrower->{flags}->{LOST} {
255 # Patron's card was reported lost
258 Each flag has a C<message> key, giving a human-readable explanation of
259 the flag. If the state of a flag means that the patron should not be
260 allowed to borrow any more books, then it will have a C<noissues> key
263 The possible flags are:
269 =item Shows the patron's credit or debt, if any.
277 =item (Gone, no address.) Set if the patron has left without giving a
286 =item Set if the patron's card has been reported as lost.
294 =item Set if the patron has been debarred.
302 =item Any additional notes about the patron.
310 =item Set if the patron has overdue items. This flag has several keys:
312 C<$flags-E<gt>{ODUES}{itemlist}> is a reference-to-array listing the
313 overdue items. Its elements are references-to-hash, each describing an
314 overdue item. The keys are selected fields from the issues, biblio,
315 biblioitems, and items tables of the Koha database.
317 C<$flags-E<gt>{ODUES}{itemlist}> is a string giving a text listing of
318 the overdue items, one per line.
326 =item Set if any items that the patron has reserved are available.
328 C<$flags-E<gt>{WAITING}{itemlist}> is a reference-to-array listing the
329 available items. Each element is a reference-to-hash whose keys are
330 fields from the reserves table of the Koha database.
336 sub GetMemberDetails
{
337 my ( $borrowernumber, $cardnumber ) = @_;
338 my $dbh = C4
::Context
->dbh;
341 if ($borrowernumber) {
342 $sth = $dbh->prepare("select * from borrowers where borrowernumber=?");
343 $sth->execute($borrowernumber);
345 elsif ($cardnumber) {
346 $sth = $dbh->prepare("select * from borrowers where cardnumber=?");
347 $sth->execute($cardnumber);
352 my $borrower = $sth->fetchrow_hashref;
353 my ($amount) = GetMemberAccountRecords
( $borrowernumber);
354 $borrower->{'amountoutstanding'} = $amount;
355 my $flags = patronflags
( $borrower);
358 $sth = $dbh->prepare("select bit,flag from userflags");
360 while ( my ( $bit, $flag ) = $sth->fetchrow ) {
361 if ( $borrower->{'flags'} && $borrower->{'flags'} & 2**$bit ) {
362 $accessflagshash->{$flag} = 1;
366 $borrower->{'flags'} = $flags;
367 $borrower->{'authflags'} = $accessflagshash;
369 # find out how long the membership lasts
372 "select enrolmentperiod from categories where categorycode = ?");
373 $sth->execute( $borrower->{'categorycode'} );
374 my $enrolment = $sth->fetchrow;
375 $borrower->{'enrolmentperiod'} = $enrolment;
376 return ($borrower); #, $flags, $accessflagshash);
383 NOTE!: If you change this function, be sure to update the POD for
386 $flags = &patronflags($patron);
389 {message} Message showing patron's credit or debt
390 {noissues} Set if patron owes >$5.00
391 {GNA} Set if patron gone w/o address
392 {message} "Borrower has no valid address"
394 {LOST} Set if patron's card reported lost
395 {message} Message to this effect
397 {DBARRED} Set is patron is debarred
398 {message} Message to this effect
400 {NOTES} Set if patron has notes
401 {message} Notes about patron
402 {ODUES} Set if patron has overdue books
404 {itemlist} ref-to-array: list of overdue books
405 {itemlisttext} Text list of overdue items
406 {WAITING} Set if there are items available that the
408 {message} Message to this effect
409 {itemlist} ref-to-array: list of available items
415 my ( $patroninformation) = @_;
416 my $dbh=C4
::Context
->dbh;
417 my ($amount) = GetMemberAccountRecords
( $patroninformation->{'borrowernumber'});
420 my $noissuescharge = C4
::Context
->preference("noissuescharge");
421 $flaginfo{'message'} = sprintf "Patron owes \$%.02f", $amount;
422 if ( $amount > $noissuescharge ) {
423 $flaginfo{'noissues'} = 1;
425 $flags{'CHARGES'} = \
%flaginfo;
427 elsif ( $amount < 0 ) {
429 $flaginfo{'message'} = sprintf "Patron has credit of \$%.02f", -$amount;
430 $flags{'CHARGES'} = \
%flaginfo;
432 if ( $patroninformation->{'gonenoaddress'}
433 && $patroninformation->{'gonenoaddress'} == 1 )
436 $flaginfo{'message'} = 'Borrower has no valid address.';
437 $flaginfo{'noissues'} = 1;
438 $flags{'GNA'} = \
%flaginfo;
440 if ( $patroninformation->{'lost'} && $patroninformation->{'lost'} == 1 ) {
442 $flaginfo{'message'} = 'Borrower\'s card reported lost.';
443 $flaginfo{'noissues'} = 1;
444 $flags{'LOST'} = \
%flaginfo;
446 if ( $patroninformation->{'debarred'}
447 && $patroninformation->{'debarred'} == 1 )
450 $flaginfo{'message'} = 'Borrower is Debarred.';
451 $flaginfo{'noissues'} = 1;
452 $flags{'DBARRED'} = \
%flaginfo;
454 if ( $patroninformation->{'borrowernotes'}
455 && $patroninformation->{'borrowernotes'} )
458 $flaginfo{'message'} = "$patroninformation->{'borrowernotes'}";
459 $flags{'NOTES'} = \
%flaginfo;
461 my ( $odues, $itemsoverdue ) =
462 checkoverdues
( $patroninformation->{'borrowernumber'}, $dbh );
465 $flaginfo{'message'} = "Yes";
466 $flaginfo{'itemlist'} = $itemsoverdue;
467 foreach ( sort { $a->{'date_due'} cmp $b->{'date_due'} }
470 $flaginfo{'itemlisttext'} .=
471 "$_->{'date_due'} $_->{'barcode'} $_->{'title'} \n";
473 $flags{'ODUES'} = \
%flaginfo;
475 my @itemswaiting = C4
::Reserves
::GetReservesFromBorrowernumber
( $patroninformation->{'borrowernumber'},'W' );
476 my $nowaiting = scalar @itemswaiting;
477 if ( $nowaiting > 0 ) {
479 $flaginfo{'message'} = "Reserved items available";
480 $flaginfo{'itemlist'} = \
@itemswaiting;
481 $flags{'WAITING'} = \
%flaginfo;
489 $borrower = &GetMember($information, $type);
491 Looks up information about a patron (borrower) by either card number
492 ,firstname, or borrower number, depending on $type value.
493 If C<$type> == 'cardnumber', C<&GetBorrower>
494 searches by cardnumber then by firstname if not found in cardnumber;
495 otherwise, it searches by borrowernumber.
497 C<&GetBorrower> returns a reference-to-hash whose keys are the fields of
498 the C<borrowers> table in the Koha database.
504 my ( $information, $type ) = @_;
505 my $dbh = C4
::Context
->dbh;
507 if ($type eq 'cardnumber' || $type eq 'firstname'|| $type eq 'userid'|| $type eq 'borrowernumber'){
508 $information = uc $information;
511 "Select borrowers.*,categories.category_type,categories.description from borrowers left join categories on borrowers.categorycode=categories.categorycode where $type=?"
513 $sth->execute($information);
518 "Select borrowers.*,categories.category_type, categories.description from borrowers left join categories on borrowers.categorycode=categories.categorycode where borrowernumber=?"
520 $sth->execute($information);
522 my $data = $sth->fetchrow_hashref;
528 elsif ($type eq 'cardnumber' ||$type eq 'firstname') { # try with firstname
531 "Select borrowers.*,categories.category_type,categories.description from borrowers left join categories on borrowers.categorycode=categories.categorycode where firstname like ?"
533 $sth->execute($information);
534 my $data = $sth->fetchrow_hashref;
543 =item GetMemberIssuesAndFines
545 ($borrowed, $due, $fine) = &GetMemberIssuesAndFines($borrowernumber);
547 Returns aggregate data about items borrowed by the patron with the
548 given borrowernumber.
550 C<&GetMemberIssuesAndFines> returns a three-element array. C<$borrowed> is the
551 number of books the patron currently has borrowed. C<$due> is the
552 number of overdue items the patron currently has borrowed. C<$fine> is
553 the total fine currently due by the borrower.
558 sub GetMemberIssuesAndFines
{
559 my ( $borrowernumber ) = @_;
560 my $dbh = C4
::Context
->dbh;
562 "Select count(*) from issues where borrowernumber='$borrowernumber' and
566 my $sth = $dbh->prepare($query);
568 my $data = $sth->fetchrow_hashref;
570 $sth = $dbh->prepare(
571 "Select count(*) from issues where
572 borrowernumber='$borrowernumber' and date_due < now() and returndate is NULL"
575 my $data2 = $sth->fetchrow_hashref;
577 $sth = $dbh->prepare(
578 "Select sum(amountoutstanding) from accountlines where
579 borrowernumber='$borrowernumber'"
582 my $data3 = $sth->fetchrow_hashref;
585 return ( $data2->{'count(*)'}, $data->{'count(*)'},
586 $data3->{'sum(amountoutstanding)'} );
593 &ModMember($borrowernumber);
595 Modify borrower's data
602 my $dbh = C4
::Context
->dbh;
603 $data{'dateofbirth'} = format_date_in_iso
( $data{'dateofbirth'} ) if ($data{'dateofbirth'} );
604 $data{'dateexpiry'} = format_date_in_iso
( $data{'dateexpiry'} ) if ($data{'dateexpiry'} );
605 $data{'dateenrolled'} = format_date_in_iso
( $data{'dateenrolled'} ) if ($data{'dateenrolled'} );
606 my $qborrower=$dbh->prepare("SHOW columns from borrowers");
608 my %hashborrowerfields;
609 while (my ($field)=$qborrower->fetchrow){
610 $hashborrowerfields{$field}=1;
616 # test to know if u must update or not the borrower password
617 if ( $data{'password'} eq '****' ) {
618 delete $data{'password'};
620 {push @parameters,"$_ = ".$dbh->quote($data{$_}) if ($_ ne "borrowernumber" and $_ ne "flags" and $hashborrowerfields{$_}) } ;
621 $query = "UPDATE borrowers SET ".join (",",@parameters)
622 ." WHERE borrowernumber=$data{'borrowernumber'}";
624 $sth = $dbh->prepare($query);
628 $data{'password'} = md5_base64
( $data{'password'} ) if ( $data{'password'} ne '' );
629 delete $data{'password'} if ($data{password
} eq "");
631 {push @parameters,"$_ = ".$dbh->quote($data{$_}) if ($_ ne "borrowernumber" and $_ ne "flags" and $hashborrowerfields{$_})} ;
633 $query = "UPDATE borrowers SET ".join (",",@parameters)." WHERE borrowernumber=$data{'borrowernumber'}";
635 $sth = $dbh->prepare($query);
640 # ok if its an adult (type) it may have borrowers that depend on it as a guarantor
641 # so when we update information for an adult we should check for guarantees and update the relevant part
642 # of their records, ie addresses and phone numbers
643 my $borrowercategory= GetBorrowercategory
( $data{'category_type'} );
644 if ( $borrowercategory->{'category_type'} eq 'A' ) {
645 # is adult check guarantees;
646 UpdateGuarantees
(%data);
649 &logaction
(C4
::Context
->userenv->{'number'},"MEMBERS","MODIFY",$data{'borrowernumber'},"")
650 if C4
::Context
->preference("BorrowersLog");
658 $borrowernumber = &AddMember(%borrower);
660 insert new borrower into table
661 Returns the borrowernumber
668 my $dbh = C4
::Context
->dbh;
669 $data{'userid'} = '' unless $data{'password'};
670 $data{'password'} = md5_base64
( $data{'password'} ) if $data{'password'};
671 $data{'dateofbirth'} = format_date_in_iso
( $data{'dateofbirth'} );
672 $data{'dateenrolled'} = format_date_in_iso
( $data{'dateenrolled'} );
673 $data{'dateexpiry'} = format_date_in_iso
( $data{'dateexpiry'} );
675 "insert into borrowers set cardnumber="
676 . $dbh->quote( $data{'cardnumber'} )
678 . $dbh->quote( $data{'surname'} )
680 . $dbh->quote( $data{'firstname'} )
682 . $dbh->quote( $data{'title'} )
684 . $dbh->quote( $data{'othernames'} )
686 . $dbh->quote( $data{'initials'} )
688 . $dbh->quote( $data{'streetnumber'} )
690 . $dbh->quote( $data{'streettype'} )
692 . $dbh->quote( $data{'address'} )
694 . $dbh->quote( $data{'address2'} )
696 . $dbh->quote( $data{'zipcode'} )
698 . $dbh->quote( $data{'city'} )
700 . $dbh->quote( $data{'phone'} )
702 . $dbh->quote( $data{'email'} )
704 . $dbh->quote( $data{'mobile'} )
706 . $dbh->quote( $data{'phonepro'} )
708 . $dbh->quote( $data{'opacnote'} )
710 . $dbh->quote( $data{'guarantorid'} )
712 . $dbh->quote( $data{'dateofbirth'} )
714 . $dbh->quote( $data{'branchcode'} )
716 . $dbh->quote( $data{'categorycode'} )
718 . $dbh->quote( $data{'dateenrolled'} )
720 . $dbh->quote( $data{'contactname'} )
722 . $dbh->quote( $data{'borrowernotes'} )
724 . $dbh->quote( $data{'dateexpiry'} )
726 . $dbh->quote( $data{'contactnote'} )
728 . $dbh->quote( $data{'B_address'} )
730 . $dbh->quote( $data{'B_zipcode'} )
732 . $dbh->quote( $data{'B_city'} )
734 . $dbh->quote( $data{'B_phone'} )
736 . $dbh->quote( $data{'B_email'}, )
738 . $dbh->quote( $data{'password'} )
740 . $dbh->quote( $data{'userid'} )
742 . $dbh->quote( $data{'sort1'} )
744 . $dbh->quote( $data{'sort2'} )
746 . $dbh->quote( $data{'contacttitle'} )
748 . $dbh->quote( $data{'emailpro'} )
749 . ",contactfirstname="
750 . $dbh->quote( $data{'contactfirstname'} ) . ",sex="
751 . $dbh->quote( $data{'sex'} ) . ",fax="
752 . $dbh->quote( $data{'fax'} )
754 . $dbh->quote( $data{'relationship'} )
756 . $dbh->quote( $data{'B_streetnumber'} )
758 . $dbh->quote( $data{'B_streettype'} )
760 . $dbh->quote( $data{'gonenoaddress'} )
762 . $dbh->quote( $data{'lost'} )
764 . $dbh->quote( $data{'debarred'} )
766 . $dbh->quote( $data{'ethnicity'} )
768 . $dbh->quote( $data{'ethnotes'} );
770 my $sth = $dbh->prepare($query);
773 $data{'borrowernumber'} = $dbh->{'mysql_insertid'};
775 &logaction
(C4
::Context
->userenv->{'number'},"MEMBERS","CREATE",$data{'borrowernumber'},"")
776 if C4
::Context
->preference("BorrowersLog");
778 return $data{'borrowernumber'};
782 my ($uid,$member) = @_;
783 my $dbh = C4
::Context
->dbh;
784 # Make sure the userid chosen is unique and not theirs if non-empty. If it is not,
785 # Then we need to tell the user and have them create a new one.
788 "SELECT * FROM borrowers WHERE userid=? AND borrowernumber != ?");
789 $sth->execute( $uid, $member );
790 if ( ( $uid ne '' ) && ( my $row = $sth->fetchrow_hashref ) ) {
800 my ( $uid, $member, $digest ) = @_;
801 my $dbh = C4
::Context
->dbh;
803 #Make sure the userid chosen is unique and not theirs if non-empty. If it is not,
804 #Then we need to tell the user and have them create a new one.
807 "SELECT * FROM borrowers WHERE userid=? AND borrowernumber != ?");
808 $sth->execute( $uid, $member );
809 if ( ( $uid ne '' ) && ( my $row = $sth->fetchrow_hashref ) ) {
813 #Everything is good so we can update the information.
816 "update borrowers set userid=?, password=? where borrowernumber=?");
817 $sth->execute( $uid, $digest, $member );
821 &logaction
(C4
::Context
->userenv->{'number'},"MEMBERS","CHANGE PASS",$member,"")
822 if C4
::Context
->preference("BorrowersLog");
827 =item fixup_cardnumber
829 Warning: The caller is responsible for locking the members table in write
830 mode, to avoid database corruption.
834 use vars
qw( @weightings );
835 my @weightings = ( 8, 4, 6, 3, 5, 2, 1 );
837 sub fixup_cardnumber ($) {
838 my ($cardnumber) = @_;
839 my $autonumber_members = C4::Context->boolean_preference('autoMemberNum');
840 $autonumber_members = 0 unless defined $autonumber_members;
842 # Find out whether member numbers should be generated
843 # automatically. Should be either "1" or something else.
844 # Defaults to "0", which is interpreted as "no".
846 # if ($cardnumber !~ /\S/ && $autonumber_members) {
847 if ($autonumber_members) {
848 my $dbh = C4::Context->dbh;
849 if ( C4::Context->preference('checkdigit') eq 'katipo' ) {
851 # if checkdigit is selected, calculate katipo-style cardnumber.
852 # otherwise, just use the max()
853 # purpose: generate checksum'd member numbers.
854 # We'll assume we just got the max value of digits 2-8 of member #'s
855 # from the database and our job is to increment that by one,
856 # determine the 1st and 9th digits and return the full string.
859 "select max(substring(borrowers.cardnumber,2,7)) from borrowers"
863 my $data = $sth->fetchrow_hashref;
864 $cardnumber = $data->{'max(substring(borrowers.cardnumber,2,7))'};
866 if ( !$cardnumber ) { # If DB has no values,
867 $cardnumber = 1000000; # start at 1000000
874 for ( my $i = 0 ; $i < 8 ; $i += 1 ) {
876 # read weightings, left to right, 1 char at a time
877 my $temp1 = $weightings[$i];
879 # sequence left to right, 1 char at a time
880 my $temp2 = substr( $cardnumber, $i, 1 );
882 # mult each char 1-7 by its corresponding weighting
883 $sum += $temp1 * $temp2;
886 my $rem = ( $sum % 11 );
887 $rem = 'X' if $rem == 10;
889 $cardnumber = "V$cardnumber$rem";
893 # MODIFIED BY JF: mysql4.1 allows casting as an integer, which is probably
894 # better. I'll leave the original in in case it needs to be changed for you
897 "select max(cast(cardnumber as signed)) from borrowers");
899 #my $sth=$dbh->prepare("select max(borrowers.cardnumber) from borrowers");
903 my ($result) = $sth->fetchrow;
905 $cardnumber = $result + 1;
913 ($num_children, $children_arrayref) = &GetGuarantees($parent_borrno);
914 $child0_cardno = $children_arrayref->[0]{"cardnumber"};
915 $child0_borrno = $children_arrayref->[0]{"borrowernumber"};
917 C<&GetGuarantees> takes a borrower number (e.g., that of a patron
918 with children) and looks up the borrowers who are guaranteed by that
919 borrower (i.e., the patron's children).
921 C<&GetGuarantees> returns two values: an integer giving the number of
922 borrowers guaranteed by C<$parent_borrno>, and a reference to an array
923 of references to hash, which gives the actual results.
929 my ($borrowernumber) = @_;
930 my $dbh = C4::Context->dbh;
933 "select cardnumber,borrowernumber, firstname, surname from borrowers where guarantorid=?"
935 $sth->execute($borrowernumber);
938 my $data = $sth->fetchall_arrayref({});
940 return ( scalar(@$data), $data );
943 =head2 UpdateGuarantees
945 &UpdateGuarantees($parent_borrno);
948 C<&UpdateGuarantees> borrower data for an adulte and updates all the guarantees
949 with the modified information
954 sub UpdateGuarantees {
956 my $dbh = C4::Context->dbh;
957 my ( $count, $guarantees ) = GetGuarantees( $data{'borrowernumber'} );
958 for ( my $i = 0 ; $i < $count ; $i++ ) {
961 # It looks like the $i is only being returned to handle walking through
962 # the array, which is probably better done as a foreach loop.
964 my $guaquery = qq|UPDATE borrowers
965 SET address='$data{'address'}',fax='$data{'fax'}',
966 B_city='$data{'B_city'}',mobile='$data{'mobile'}',city='$data{'city'}',phone='$data{'phone'}'
967 WHERE borrowernumber='$guarantees->[$i]->{'borrowernumber'}'
969 my $sth3 = $dbh->prepare($guaquery);
974 =head2 GetPendingIssues
976 ($count, $issues) = &GetPendingIssues($borrowernumber);
978 Looks up what the patron with the given borrowernumber has borrowed.
980 C<&GetPendingIssues> returns a two-element array. C<$issues> is a
981 reference-to-array, where each element is a reference-to-hash; the
982 keys are the fields from the C<issues>, C<biblio>, and C<items> tables
983 in the Koha database. C<$count> is the number of elements in
989 sub GetPendingIssues {
990 my ($borrowernumber) = @_;
991 my $dbh = C4::Context->dbh;
993 my $sth = $dbh->prepare(
994 "SELECT * FROM issues
995 LEFT JOIN items ON issues.itemnumber=items.itemnumber
996 LEFT JOIN biblio ON items.biblionumber=biblio.biblionumber
997 LEFT JOIN biblioitems ON items.biblioitemnumber=biblioitems.biblioitemnumber
1000 AND returndate IS NULL
1001 ORDER BY issues.issuedate"
1003 $sth->execute($borrowernumber);
1004 my $data = $sth->fetchall_arrayref({});
1005 my $today = POSIX::strftime("%Y%m%d", localtime);
1007 my $datedue = $_->{'date_due'};
1009 if ( $datedue < $today ) {
1010 $_->{'overdue'} = 1;
1014 return ( scalar(@$data), $data );
1019 ($count, $issues) = &GetAllIssues($borrowernumber, $sortkey, $limit);
1021 Looks up what the patron with the given borrowernumber has borrowed,
1022 and sorts the results.
1024 C<$sortkey> is the name of a field on which to sort the results. This
1025 should be the name of a field in the C<issues>, C<biblio>,
1026 C<biblioitems>, or C<items> table in the Koha database.
1028 C<$limit> is the maximum number of results to return.
1030 C<&GetAllIssues> returns a two-element array. C<$issues> is a
1031 reference-to-array, where each element is a reference-to-hash; the
1032 keys are the fields from the C<issues>, C<biblio>, C<biblioitems>, and
1033 C<items> tables of the Koha database. C<$count> is the number of
1034 elements in C<$issues>
1040 my ( $borrowernumber, $order, $limit ) = @_;
1042 #FIXME: sanity-check order and limit
1043 my $dbh = C4::Context->dbh;
1046 "Select *,items.timestamp AS itemstimestamp from
1048 LEFT JOIN items on items.itemnumber=issues.itemnumber
1049 LEFT JOIN biblio ON items.biblionumber=biblio.biblionumber
1050 LEFT JOIN biblioitems ON items.biblioitemnumber=biblioitems.biblioitemnumber
1051 where borrowernumber=?
1053 if ( $limit != 0 ) {
1054 $query .= " limit $limit";
1058 my $sth = $dbh->prepare($query);
1059 $sth->execute($borrowernumber);
1062 while ( my $data = $sth->fetchrow_hashref ) {
1063 $result[$i] = $data;
1068 # get all issued items for borrowernumber from oldissues table
1069 # large chunk of older issues data put into table oldissues
1070 # to speed up db calls for issuing items
1071 if ( C4::Context->preference("ReadingHistory") ) {
1072 my $query2 = "SELECT * FROM oldissues
1073 LEFT JOIN items ON items.itemnumber=oldissues.itemnumber
1074 LEFT JOIN biblio ON items.biblionumber=biblio.biblionumber
1075 LEFT JOIN biblioitems ON items.biblioitemnumber=biblioitems.biblioitemnumber
1076 WHERE borrowernumber=?
1078 if ( $limit != 0 ) {
1079 $limit = $limit - $count;
1080 $query2 .= " limit $limit";
1083 my $sth2 = $dbh->prepare($query2);
1084 $sth2->execute($borrowernumber);
1086 while ( my $data2 = $sth2->fetchrow_hashref ) {
1087 $result[$i] = $data2;
1094 return ( $i, \@result );
1098 =head2 GetMemberAccountRecords
1100 ($total, $acctlines, $count) = &GetMemberAccountRecords($borrowernumber);
1102 Looks up accounting data for the patron with the given borrowernumber.
1104 C<&GetMemberAccountRecords> returns a three-element array. C<$acctlines> is a
1105 reference-to-array, where each element is a reference-to-hash; the
1106 keys are the fields of the C<accountlines> table in the Koha database.
1107 C<$count> is the number of elements in C<$acctlines>. C<$total> is the
1108 total amount outstanding for all of the account lines.
1113 sub GetMemberAccountRecords {
1114 my ($borrowernumber,$date) = @_;
1115 my $dbh = C4::Context->dbh;
1121 WHERE borrowernumber=?);
1122 my @bind = ($borrowernumber);
1123 if ($date && $date ne ''){
1124 $strsth.=" AND date < ? ";
1127 $strsth.=" ORDER BY date desc,timestamp DESC";
1128 my $sth= $dbh->prepare( $strsth );
1129 $sth->execute( @bind );
1131 while ( my $data = $sth->fetchrow_hashref ) {
1132 $acctlines[$numlines] = $data;
1134 $total += $data->{'amountoutstanding'};
1137 return ( $total, \@acctlines,$numlines);
1140 =head2 GetBorNotifyAcctRecord
1142 ($count, $acctlines, $total) = &GetBorNotifyAcctRecord($params,$notifyid);
1144 Looks up accounting data for the patron with the given borrowernumber per file number.
1146 (FIXME - I'm not at all sure what this is about.)
1148 C<&GetBorNotifyAcctRecord> returns a three-element array. C<$acctlines> is a
1149 reference-to-array, where each element is a reference-to-hash; the
1150 keys are the fields of the C<accountlines> table in the Koha database.
1151 C<$count> is the number of elements in C<$acctlines>. C<$total> is the
1152 total amount outstanding for all of the account lines.
1156 sub GetBorNotifyAcctRecord {
1157 my ( $borrowernumber, $notifyid ) = @_;
1158 my $dbh = C4::Context->dbh;
1161 my $sth = $dbh->prepare(
1164 WHERE borrowernumber=?
1166 AND (accounttype='FU' OR accounttype='N' OR accounttype='M'OR accounttype='A'OR accounttype='F'OR accounttype='L' OR accounttype='IP' OR accounttype='CH' OR accounttype='RE' OR accounttype='RL')
1167 AND amountoutstanding != '0'
1168 ORDER BY notify_id,accounttype
1170 $sth->execute( $borrowernumber, $notifyid );
1172 while ( my $data = $sth->fetchrow_hashref ) {
1173 $acctlines[$numlines] = $data;
1175 $total += $data->{'amountoutstanding'};
1178 return ( $total, \@acctlines, $numlines );
1181 =head2 checkuniquemember (OUEST-PROVENCE)
1183 $result = &checkuniquemember($collectivity,$surname,$categorycode,$firstname,$dateofbirth);
1185 Checks that a member exists or not in the database.
1187 C<&result> is 1 (=exist) or 0 (=does not exist)
1188 C<&collectivity> is 1 (= we add a collectivity) or 0 (= we add a physical member)
1189 C<&surname> is the surname
1190 C<&categorycode> is from categorycode table
1191 C<&firstname> is the firstname (only if collectivity=0)
1192 C<&dateofbirth> is the date of birth (only if collectivity=0)
1196 sub checkuniquemember {
1197 my ( $collectivity, $surname, $firstname, $dateofbirth ) = @_;
1198 my $dbh = C4::Context->dbh;
1200 if ($collectivity) {
1202 # $request="select count(*) from borrowers where surname=? and categorycode=?";
1204 "select borrowernumber,categorycode from borrowers where surname=? ";
1208 # $request="select count(*) from borrowers where surname=? and categorycode=? and firstname=? and dateofbirth=?";
1210 "select borrowernumber,categorycode from borrowers where surname=? and firstname=? and dateofbirth=?";
1212 my $sth = $dbh->prepare($request);
1213 if ($collectivity) {
1214 $sth->execute( uc($surname) );
1217 $sth->execute( uc($surname), ucfirst($firstname), $dateofbirth );
1219 my @data = $sth->fetchrow;
1222 return $data[0], $data[1];
1232 sub checkcardnumber {
1233 my ($cardnumber,$borrowernumber) = @_;
1234 my $dbh = C4::Context->dbh;
1235 my $query = "SELECT * FROM borrowers WHERE cardnumber=?";
1236 $query .= " AND borrowernumber <> ?" if ($borrowernumber);
1237 my $sth = $dbh->prepare($query);
1238 if ($borrowernumber) {
1239 $sth->execute($cardnumber,$borrowernumber);
1241 $sth->execute($cardnumber);
1243 if (my $data= $sth->fetchrow_hashref()){
1253 =head2 getzipnamecity (OUEST-PROVENCE)
1255 take all info from table city for the fields city and zip
1256 check for the name and the zip code of the city selected
1260 sub getzipnamecity {
1262 my $dbh = C4::Context->dbh;
1265 "select city_name,city_zipcode from cities where cityid=? ");
1266 $sth->execute($cityid);
1267 my @data = $sth->fetchrow;
1268 return $data[0], $data[1];
1272 =head2 getdcity (OUEST-PROVENCE)
1274 recover cityid with city_name condition
1279 my ($city_name) = @_;
1280 my $dbh = C4::Context->dbh;
1281 my $sth = $dbh->prepare("select cityid from cities where city_name=? ");
1282 $sth->execute($city_name);
1283 my $data = $sth->fetchrow;
1288 =head2 GetExpiryDate
1290 $expirydate = GetExpiryDate($categorycode, $dateenrolled);
1291 process expiry date given a date and a categorycode
1295 my ( $categorycode, $dateenrolled ) = @_;
1296 my $dbh = C4::Context->dbh;
1299 "select enrolmentperiod from categories where categorycode=?");
1300 $sth->execute($categorycode);
1301 my ($enrolmentperiod) = $sth->fetchrow;
1302 $enrolmentperiod = 12 unless ($enrolmentperiod);
1303 my @date=split /-/,format_date_in_iso($dateenrolled);
1304 @date=Add_Delta_YM($date[0],$date[1],$date[2],0,$enrolmentperiod);
1305 return sprintf("%04d-%02d-%02d",$date[0],$date[1],$date[2]);
1308 =head2 checkuserpassword (OUEST-PROVENCE)
1310 check for the password and login are not used
1311 return the number of record
1312 0=> NOT USED 1=> USED
1316 sub checkuserpassword {
1317 my ( $borrowernumber, $userid, $password ) = @_;
1318 $password = md5_base64($password);
1319 my $dbh = C4::Context->dbh;
1322 "Select count(*) from borrowers where borrowernumber !=? and userid =? and password=? "
1324 $sth->execute( $borrowernumber, $userid, $password );
1325 my $number_rows = $sth->fetchrow;
1326 return $number_rows;
1330 =head2 GetborCatFromCatType
1332 ($codes_arrayref, $labels_hashref) = &GetborCatFromCatType();
1334 Looks up the different types of borrowers in the database. Returns two
1335 elements: a reference-to-array, which lists the borrower category
1336 codes, and a reference-to-hash, which maps the borrower category codes
1337 to category descriptions.
1342 sub GetborCatFromCatType {
1343 my ( $category_type, $action ) = @_;
1344 my $dbh = C4::Context->dbh;
1345 my $request = qq| SELECT categorycode,description
1348 ORDER BY categorycode|;
1349 my $sth = $dbh->prepare($request);
1351 $sth->execute($category_type);
1360 while ( my $data = $sth->fetchrow_hashref ) {
1361 push @codes, $data->{'categorycode'};
1362 $labels{ $data->{'categorycode'} } = $data->{'description'};
1365 return ( \@codes, \%labels );
1368 =head2 GetBorrowercategory
1370 $hashref = &GetBorrowercategory($categorycode);
1372 Given the borrower's category code, the function returns the corresponding
1373 data hashref for a comprehensive information display.
1377 sub GetBorrowercategory {
1379 my $dbh = C4::Context->dbh;
1382 "SELECT description,dateofbirthrequired,upperagelimit,category_type
1384 WHERE categorycode = ?"
1386 $sth->execute($catcode);
1388 $sth->fetchrow_hashref;
1391 } # sub getborrowercategory
1393 =head2 ethnicitycategories
1395 ($codes_arrayref, $labels_hashref) = ðnicitycategories();
1397 Looks up the different ethnic types in the database. Returns two
1398 elements: a reference-to-array, which lists the ethnicity codes, and a
1399 reference-to-hash, which maps the ethnicity codes to ethnicity
1406 sub ethnicitycategories {
1407 my $dbh = C4::Context->dbh;
1408 my $sth = $dbh->prepare("Select code,name from ethnicity order by name");
1412 while ( my $data = $sth->fetchrow_hashref ) {
1413 push @codes, $data->{'code'};
1414 $labels{ $data->{'code'} } = $data->{'name'};
1417 return ( \@codes, \%labels );
1422 $ethn_name = &fixEthnicity($ethn_code);
1424 Takes an ethnicity code (e.g., "european" or "pi") and returns the
1425 corresponding descriptive name from the C<ethnicity> table in the
1426 Koha database ("European" or "Pacific Islander").
1433 my $ethnicity = shift;
1434 return unless $ethnicity;
1435 my $dbh = C4::Context->dbh;
1436 my $sth = $dbh->prepare("Select name from ethnicity where code = ?");
1437 $sth->execute($ethnicity);
1438 my $data = $sth->fetchrow_hashref;
1440 return $data->{'name'};
1441 } # sub fixEthnicity
1445 $dateofbirth,$date = &GetAge($date);
1447 this function return the borrowers age with the value of dateofbirth
1453 my ( $date, $date_ref ) = @_;
1455 if ( not defined $date_ref ) {
1456 $date_ref = sprintf( '%04d-%02d-%02d', Today() );
1459 my ( $year1, $month1, $day1 ) = split /-/, $date;
1460 my ( $year2, $month2, $day2 ) = split /-/, $date_ref;
1462 my $age = $year2 - $year1;
1463 if ( $month1 . $day1 > $month2 . $day2 ) {
1470 =head2 get_institutions
1471 $insitutions = get_institutions();
1473 Just returns a list of all the borrowers of type I, borrownumber and name
1478 sub get_institutions {
1479 my $dbh = C4::Context->dbh();
1482 "SELECT borrowernumber,surname FROM borrowers WHERE categorycode=? ORDER BY surname"
1486 while ( my $data = $sth->fetchrow_hashref() ) {
1487 $orgs{ $data->{'borrowernumber'} } = $data;
1492 } # sub get_institutions
1494 =head2 add_member_orgs
1496 add_member_orgs($borrowernumber,$borrowernumbers);
1498 Takes a borrowernumber and a list of other borrowernumbers and inserts them into the borrowers_to_borrowers table
1503 sub add_member_orgs {
1504 my ( $borrowernumber, $otherborrowers ) = @_;
1505 my $dbh = C4::Context->dbh();
1507 "INSERT INTO borrowers_to_borrowers (borrower1,borrower2) VALUES (?,?)";
1508 my $sth = $dbh->prepare($query);
1509 foreach my $otherborrowernumber (@$otherborrowers) {
1510 $sth->execute( $borrowernumber, $otherborrowernumber );
1514 } # sub add_member_orgs
1516 =head2 GetCities (OUEST-PROVENCE)
1518 ($id_cityarrayref, $city_hashref) = &GetCities();
1520 Looks up the different city and zip in the database. Returns two
1521 elements: a reference-to-array, which lists the zip city
1522 codes, and a reference-to-hash, which maps the name of the city.
1523 WHERE =>OUEST PROVENCE OR EXTERIEUR
1529 #my ($type_city) = @_;
1530 my $dbh = C4::Context->dbh;
1531 my $query = qq|SELECT cityid,city_name
1533 ORDER BY city_name|;
1534 my $sth = $dbh->prepare($query);
1536 #$sth->execute($type_city);
1541 # insert empty value to create a empty choice in cgi popup
1543 while ( my $data = $sth->fetchrow_hashref ) {
1545 push @id, $data->{'cityid'};
1546 $city{ $data->{'cityid'} } = $data->{'city_name'};
1549 #test to know if the table contain some records if no the function return nothing
1557 return ( \@id, \%city );
1561 =head2 GetSortDetails (OUEST-PROVENCE)
1563 ($lib) = &GetSortDetails($category,$sortvalue);
1565 Returns the authorized value details
1566 C<&$lib>return value of authorized value details
1567 C<&$sortvalue>this is the value of authorized value
1568 C<&$category>this is the value of authorized value category
1572 sub GetSortDetails {
1573 my ( $category, $sortvalue ) = @_;
1574 my $dbh = C4::Context->dbh;
1575 my $query = qq|SELECT lib
1576 FROM authorised_values
1578 AND authorised_value=? |;
1579 my $sth = $dbh->prepare($query);
1580 $sth->execute( $category, $sortvalue );
1581 my $lib = $sth->fetchrow;
1585 =head2 DeleteBorrower
1587 () = &DeleteBorrower($member);
1589 delete all data fo borrowers and add record to deletedborrowers table
1590 C<&$member>this is the borrowernumber
1594 sub MoveMemberToDeleted {
1596 my $dbh = C4::Context->dbh;
1598 $query = qq|SELECT *
1600 WHERE borrowernumber=?|;
1601 my $sth = $dbh->prepare($query);
1602 $sth->execute($member);
1603 my @data = $sth->fetchrow_array;
1606 $dbh->prepare( "INSERT INTO deletedborrowers VALUES ("
1607 . ( "?," x ( scalar(@data) - 1 ) )
1609 $sth->execute(@data);
1615 DelMember($borrowernumber);
1617 This function remove directly a borrower whitout writing it on deleteborrower.
1618 + Deletes reserves for the borrower
1623 my $dbh = C4::Context->dbh;
1624 my $borrowernumber = shift;
1625 warn "in delmember with $borrowernumber";
1626 return unless $borrowernumber; # borrowernumber is mandatory.
1628 my $query = qq|DELETE
1630 WHERE borrowernumber=?|;
1631 my $sth = $dbh->prepare($query);
1632 $sth->execute($borrowernumber);
1637 WHERE borrowernumber = ?
1639 $sth = $dbh->prepare($query);
1640 $sth->execute($borrowernumber);
1642 &logaction(C4::Context->userenv->{'number'},"MEMBERS","DELETE",$borrowernumber,"")
1643 if C4::Context->preference("BorrowersLog");
1647 =head2 ExtendMemberSubscriptionTo (OUEST-PROVENCE)
1649 $date= ExtendMemberSubscriptionTo($borrowerid, $date);
1650 Extending the subscription to a given date or to the expiry date calculated on local date.
1654 sub ExtendMemberSubscriptionTo {
1655 my ( $borrowerid,$date) = @_;
1656 my $dbh = C4::Context->dbh;
1658 $date=POSIX::strftime("%Y-%m-%d",localtime(time));
1659 my $borrower = GetMember($borrowerid,'borrowernumber');
1660 $date = GetExpiryDate( $borrower->{'categorycode'}, $date );
1662 my $sth = $dbh->do(<<EOF);
1664 SET dateexpiry='$date'
1665 WHERE borrowernumber='$borrowerid'
1667 return $date if ($sth);
1671 =head2 GetRoadTypes (OUEST-PROVENCE)
1673 ($idroadtypearrayref, $roadttype_hashref) = &GetRoadTypes();
1675 Looks up the different road type . Returns two
1676 elements: a reference-to-array, which lists the id_roadtype
1677 codes, and a reference-to-hash, which maps the road type of the road .
1683 my $dbh = C4
::Context
->dbh;
1685 SELECT roadtypeid
,road_type
1687 ORDER BY road_type
|;
1688 my $sth = $dbh->prepare($query);
1693 # insert empty value to create a empty choice in cgi popup
1695 while ( my $data = $sth->fetchrow_hashref ) {
1697 push @id, $data->{'roadtypeid'};
1698 $roadtype{ $data->{'roadtypeid'} } = $data->{'road_type'};
1701 #test to know if the table contain some records if no the function return nothing
1709 return ( \
@id, \
%roadtype );
1715 =head2 GetTitles (OUEST-PROVENCE)
1717 ($borrowertitle)= &GetTitles();
1719 Looks up the different title . Returns array with all borrowers title
1724 my @borrowerTitle = split /,|\|/,C4
::Context
->preference('BorrowersTitles');
1725 unshift( @borrowerTitle, "" );
1726 return ( \
@borrowerTitle);
1731 =head2 GetRoadTypeDetails (OUEST-PROVENCE)
1733 ($roadtype) = &GetRoadTypeDetails($roadtypeid);
1735 Returns the description of roadtype
1736 C<&$roadtype>return description of road type
1737 C<&$roadtypeid>this is the value of roadtype s
1741 sub GetRoadTypeDetails
{
1742 my ($roadtypeid) = @_;
1743 my $dbh = C4
::Context
->dbh;
1747 WHERE roadtypeid
=?
|;
1748 my $sth = $dbh->prepare($query);
1749 $sth->execute($roadtypeid);
1750 my $roadtype = $sth->fetchrow;
1754 =head2 GetBorrowersWhoHaveNotBorrowedSince
1756 &GetBorrowersWhoHaveNotBorrowedSince($date)
1758 this function get all borrowers who haven't borrowed since the date given on input arg.
1762 sub GetBorrowersWhoHaveNotBorrowedSince
{
1764 return unless $date; # date is mandatory.
1765 my $dbh = C4
::Context
->dbh;
1767 SELECT borrowers.borrowernumber,max(timestamp)
1769 LEFT JOIN issues ON borrowers.borrowernumber = issues.borrowernumber
1770 WHERE issues.borrowernumber IS NOT NULL
1771 GROUP BY borrowers.borrowernumber
1773 my $sth = $dbh->prepare($query);
1777 while ( my $data = $sth->fetchrow_hashref ) {
1778 push @results, $data;
1783 =head2 GetBorrowersWhoHaveNeverBorrowed
1785 $results = &GetBorrowersWhoHaveNeverBorrowed
1787 this function get all borrowers who have never borrowed.
1789 I<$result> is a ref to an array which all elements are a hasref.
1793 sub GetBorrowersWhoHaveNeverBorrowed
{
1794 my $dbh = C4
::Context
->dbh;
1796 SELECT borrowers.borrowernumber,max(timestamp)
1798 LEFT JOIN issues ON borrowers.borrowernumber = issues.borrowernumber
1799 WHERE issues.borrowernumber IS NULL
1801 my $sth = $dbh->prepare($query);
1804 while ( my $data = $sth->fetchrow_hashref ) {
1805 push @results, $data;
1810 =head2 GetBorrowersWithIssuesHistoryOlderThan
1812 $results = &GetBorrowersWithIssuesHistoryOlderThan($date)
1814 this function get all borrowers who has an issue history older than I<$date> given on input arg.
1816 I<$result> is a ref to an array which all elements are a hashref.
1817 This hashref is containt the number of time this borrowers has borrowed before I<$date> and the borrowernumber.
1821 sub GetBorrowersWithIssuesHistoryOlderThan
{
1822 my $dbh = C4
::Context
->dbh;
1824 return unless $date; # date is mandatory.
1826 SELECT count(borrowernumber) as n,borrowernumber
1828 WHERE returndate < ?
1829 AND borrowernumber IS NOT NULL
1830 GROUP BY borrowernumber
1832 my $sth = $dbh->prepare($query);
1833 $sth->execute($date);
1836 while ( my $data = $sth->fetchrow_hashref ) {
1837 push @results, $data;
1842 END { } # module clean-up code here (global destructor)