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 # FIXME - patronflags calls GetMemberAccountRecords... just have patronflags return $amount
356 my $flags = patronflags( $borrower);
359 $sth = $dbh->prepare("select bit,flag from userflags");
361 while ( my ( $bit, $flag ) = $sth->fetchrow ) {
362 if ( $borrower->{'flags'} && $borrower->{'flags'} & 2**$bit ) {
363 $accessflagshash->{$flag} = 1;
367 $borrower->{'flags'} = $flags;
368 $borrower->{'authflags'} = $accessflagshash;
370 # find out how long the membership lasts
373 "select enrolmentperiod from categories where categorycode = ?");
374 $sth->execute( $borrower->{'categorycode'} );
375 my $enrolment = $sth->fetchrow;
376 $borrower->{'enrolmentperiod'} = $enrolment;
377 return ($borrower); #, $flags, $accessflagshash);
384 NOTE!: If you change this function, be sure to update the POD for
387 $flags = &patronflags($patron);
390 {message} Message showing patron's credit or debt
391 {noissues} Set if patron owes >$5.00
392 {GNA} Set if patron gone w/o address
393 {message} "Borrower has no valid address"
395 {LOST} Set if patron's card reported lost
396 {message} Message to this effect
398 {DBARRED} Set is patron is debarred
399 {message} Message to this effect
401 {NOTES} Set if patron has notes
402 {message} Notes about patron
403 {ODUES} Set if patron has overdue books
405 {itemlist} ref-to-array: list of overdue books
406 {itemlisttext} Text list of overdue items
407 {WAITING} Set if there are items available that the
409 {message} Message to this effect
410 {itemlist} ref-to-array: list of available items
413 # FIXME rename this function.
416 my ( $patroninformation) = @_;
417 my $dbh=C4::Context->dbh;
418 my ($amount) = GetMemberAccountRecords( $patroninformation->{'borrowernumber'});
421 my $noissuescharge = C4::Context->preference("noissuescharge");
422 $flaginfo{'message'} = sprintf "Patron owes \$%.02f", $amount;
423 $flaginfo{'amount'} = sprintf "%.02f",$amount;
424 if ( $amount > $noissuescharge ) {
425 $flaginfo{'noissues'} = 1;
427 $flags{'CHARGES'} = \%flaginfo;
429 elsif ( $amount < 0 ) {
431 $flaginfo{'message'} = sprintf "Patron has credit of \$%.02f", -$amount;
432 $flags{'CHARGES'} = \%flaginfo;
434 if ( $patroninformation->{'gonenoaddress'}
435 && $patroninformation->{'gonenoaddress'} == 1 )
438 $flaginfo{'message'} = 'Borrower has no valid address.';
439 $flaginfo{'noissues'} = 1;
440 $flags{'GNA'} = \%flaginfo;
442 if ( $patroninformation->{'lost'} && $patroninformation->{'lost'} == 1 ) {
444 $flaginfo{'message'} = 'Borrower\'s card reported lost.';
445 $flaginfo{'noissues'} = 1;
446 $flags{'LOST'} = \%flaginfo;
448 if ( $patroninformation->{'debarred'}
449 && $patroninformation->{'debarred'} == 1 )
452 $flaginfo{'message'} = 'Borrower is Debarred.';
453 $flaginfo{'noissues'} = 1;
454 $flags{'DBARRED'} = \%flaginfo;
456 if ( $patroninformation->{'borrowernotes'}
457 && $patroninformation->{'borrowernotes'} )
460 $flaginfo{'message'} = "$patroninformation->{'borrowernotes'}";
461 $flags{'NOTES'} = \%flaginfo;
463 my ( $odues, $itemsoverdue ) =
464 checkoverdues( $patroninformation->{'borrowernumber'}, $dbh );
467 $flaginfo{'message'} = "Yes";
468 $flaginfo{'itemlist'} = $itemsoverdue;
469 foreach ( sort { $a->{'date_due'} cmp $b->{'date_due'} }
472 $flaginfo{'itemlisttext'} .=
473 "$_->{'date_due'} $_->{'barcode'} $_->{'title'} \n";
475 $flags{'ODUES'} = \%flaginfo;
477 my @itemswaiting = C4::Reserves::GetReservesFromBorrowernumber( $patroninformation->{'borrowernumber'},'W' );
478 my $nowaiting = scalar @itemswaiting;
479 if ( $nowaiting > 0 ) {
481 $flaginfo{'message'} = "Reserved items available";
482 $flaginfo{'itemlist'} = \@itemswaiting;
483 $flags{'WAITING'} = \%flaginfo;
491 $borrower = &GetMember($information, $type);
493 Looks up information about a patron (borrower) by either card number
494 ,firstname, or borrower number, depending on $type value.
495 If C<$type> == 'cardnumber', C<&GetBorrower>
496 searches by cardnumber then by firstname if not found in cardnumber;
497 otherwise, it searches by borrowernumber.
499 C<&GetBorrower> returns a reference-to-hash whose keys are the fields of
500 the C<borrowers> table in the Koha database.
506 my ( $information, $type ) = @_;
507 my $dbh = C4::Context->dbh;
509 if ($type eq 'cardnumber' || $type eq 'firstname'|| $type eq 'userid'|| $type eq 'borrowernumber'){
510 $information = uc $information;
513 "Select borrowers.*,categories.category_type,categories.description from borrowers left join categories on borrowers.categorycode=categories.categorycode where $type=?"
515 $sth->execute($information);
520 "Select borrowers.*,categories.category_type, categories.description from borrowers left join categories on borrowers.categorycode=categories.categorycode where borrowernumber=?"
522 $sth->execute($information);
524 my $data = $sth->fetchrow_hashref;
530 elsif ($type eq 'cardnumber' ||$type eq 'firstname') { # try with firstname
533 "Select borrowers.*,categories.category_type,categories.description from borrowers left join categories on borrowers.categorycode=categories.categorycode where firstname like ?"
535 $sth->execute($information);
536 my $data = $sth->fetchrow_hashref;
545 =item GetMemberIssuesAndFines
547 ($borrowed, $due, $fine) = &GetMemberIssuesAndFines($borrowernumber);
549 Returns aggregate data about items borrowed by the patron with the
550 given borrowernumber.
552 C<&GetMemberIssuesAndFines> returns a three-element array. C<$borrowed> is the
553 number of books the patron currently has borrowed. C<$due> is the
554 number of overdue items the patron currently has borrowed. C<$fine> is
555 the total fine currently due by the borrower.
560 sub GetMemberIssuesAndFines {
561 my ( $borrowernumber ) = @_;
562 my $dbh = C4::Context->dbh;
564 "Select count(*) from issues where borrowernumber='$borrowernumber' and
568 my $sth = $dbh->prepare($query);
570 my $data = $sth->fetchrow_hashref;
572 $sth = $dbh->prepare(
573 "Select count(*) from issues where
574 borrowernumber='$borrowernumber' and date_due < now() and returndate is NULL"
577 my $data2 = $sth->fetchrow_hashref;
579 $sth = $dbh->prepare(
580 "Select sum(amountoutstanding) from accountlines where
581 borrowernumber='$borrowernumber'"
584 my $data3 = $sth->fetchrow_hashref;
587 return ( $data2->{'count(*)'}, $data->{'count(*)'},
588 $data3->{'sum(amountoutstanding)'} );
595 &ModMember($borrowernumber);
597 Modify borrower's data
604 my $dbh = C4::Context->dbh;
605 $data{'dateofbirth'} = format_date_in_iso( $data{'dateofbirth'} ) if ($data{'dateofbirth'} );
606 $data{'dateexpiry'} = format_date_in_iso( $data{'dateexpiry'} ) if ($data{'dateexpiry'} );
607 $data{'dateenrolled'} = format_date_in_iso( $data{'dateenrolled'} ) if ($data{'dateenrolled'} );
608 my $qborrower=$dbh->prepare("SHOW columns from borrowers");
610 my %hashborrowerfields;
611 while (my ($field)=$qborrower->fetchrow){
612 $hashborrowerfields{$field}=1;
618 # test to know if u must update or not the borrower password
619 if ( $data{'password'} eq '****' ) {
620 delete $data{'password'};
622 {push @parameters,"$_ = ".$dbh->quote($data{$_}) if ($_ ne "borrowernumber" and $_ ne "flags" and $hashborrowerfields{$_}) } ;
623 $query = "UPDATE borrowers SET ".join (",",@parameters)
624 ." WHERE borrowernumber=$data{'borrowernumber'}";
626 $sth = $dbh->prepare($query);
630 $data{'password'} = md5_base64( $data{'password'} ) if ( $data{'password'} ne '' );
631 delete $data{'password'} if ($data{password} eq "");
633 {push @parameters,"$_ = ".$dbh->quote($data{$_}) if ($_ ne "borrowernumber" and $_ ne "flags" and $hashborrowerfields{$_})} ;
635 $query = "UPDATE borrowers SET ".join (",",@parameters)." WHERE borrowernumber=$data{'borrowernumber'}";
637 $sth = $dbh->prepare($query);
642 # ok if its an adult (type) it may have borrowers that depend on it as a guarantor
643 # so when we update information for an adult we should check for guarantees and update the relevant part
644 # of their records, ie addresses and phone numbers
645 my $borrowercategory= GetBorrowercategory( $data{'category_type'} );
646 if ( $borrowercategory->{'category_type'} eq ('A' || 'S') ) {
647 # is adult check guarantees;
648 UpdateGuarantees(%data);
651 &logaction(C4::Context->userenv->{'number'},"MEMBERS","MODIFY",$data{'borrowernumber'},"")
652 if C4::Context->preference("BorrowersLog");
660 $borrowernumber = &AddMember(%borrower);
662 insert new borrower into table
663 Returns the borrowernumber
670 my $dbh = C4::Context->dbh;
671 $data{'userid'} = '' unless $data{'password'};
672 $data{'password'} = md5_base64( $data{'password'} ) if $data{'password'};
673 $data{'dateofbirth'} = format_date_in_iso( $data{'dateofbirth'} );
674 $data{'dateenrolled'} = format_date_in_iso( $data{'dateenrolled'});
675 $data{'dateexpiry'} = format_date_in_iso( $data{'dateexpiry'} );
677 "insert into borrowers set cardnumber="
678 . $dbh->quote( $data{'cardnumber'} )
680 . $dbh->quote( $data{'surname'} )
682 . $dbh->quote( $data{'firstname'} )
684 . $dbh->quote( $data{'title'} )
686 . $dbh->quote( $data{'othernames'} )
688 . $dbh->quote( $data{'initials'} )
690 . $dbh->quote( $data{'streetnumber'} )
692 . $dbh->quote( $data{'streettype'} )
694 . $dbh->quote( $data{'address'} )
696 . $dbh->quote( $data{'address2'} )
698 . $dbh->quote( $data{'zipcode'} )
700 . $dbh->quote( $data{'city'} )
702 . $dbh->quote( $data{'phone'} )
704 . $dbh->quote( $data{'email'} )
706 . $dbh->quote( $data{'mobile'} )
708 . $dbh->quote( $data{'phonepro'} )
710 . $dbh->quote( $data{'opacnote'} )
712 . $dbh->quote( $data{'guarantorid'} )
714 . $dbh->quote( $data{'dateofbirth'} )
716 . $dbh->quote( $data{'branchcode'} )
718 . $dbh->quote( $data{'categorycode'} )
720 . $dbh->quote( $data{'dateenrolled'} )
722 . $dbh->quote( $data{'contactname'} )
724 . $dbh->quote( $data{'borrowernotes'} )
726 . $dbh->quote( $data{'dateexpiry'} )
728 . $dbh->quote( $data{'contactnote'} )
730 . $dbh->quote( $data{'B_address'} )
732 . $dbh->quote( $data{'B_zipcode'} )
734 . $dbh->quote( $data{'B_city'} )
736 . $dbh->quote( $data{'B_phone'} )
738 . $dbh->quote( $data{'B_email'} )
740 . $dbh->quote( $data{'password'} )
742 . $dbh->quote( $data{'userid'} )
744 . $dbh->quote( $data{'sort1'} )
746 . $dbh->quote( $data{'sort2'} )
748 . $dbh->quote( $data{'contacttitle'} )
750 . $dbh->quote( $data{'emailpro'} )
751 . ",contactfirstname="
752 . $dbh->quote( $data{'contactfirstname'} ) . ",sex="
753 . $dbh->quote( $data{'sex'} ) . ",fax="
754 . $dbh->quote( $data{'fax'} )
756 . $dbh->quote( $data{'relationship'} )
758 . $dbh->quote( $data{'B_streetnumber'} )
760 . $dbh->quote( $data{'B_streettype'} )
762 . $dbh->quote( $data{'gonenoaddress'} )
764 . $dbh->quote( $data{'lost'} )
766 . $dbh->quote( $data{'debarred'} )
768 . $dbh->quote( $data{'ethnicity'} )
770 . $dbh->quote( $data{'ethnotes'} );
772 my $sth = $dbh->prepare($query);
775 $data{'borrowernumber'} = $dbh->{'mysql_insertid'};
777 &logaction(C4::Context->userenv->{'number'},"MEMBERS","CREATE",$data{'borrowernumber'},"")
778 if C4::Context->preference("BorrowersLog");
780 return $data{'borrowernumber'};
784 my ($uid,$member) = @_;
785 my $dbh = C4::Context->dbh;
786 # Make sure the userid chosen is unique and not theirs if non-empty. If it is not,
787 # Then we need to tell the user and have them create a new one.
790 "SELECT * FROM borrowers WHERE userid=? AND borrowernumber != ?");
791 $sth->execute( $uid, $member );
792 if ( ( $uid ne '' ) && ( my $row = $sth->fetchrow_hashref ) ) {
802 my ( $uid, $member, $digest ) = @_;
803 my $dbh = C4::Context->dbh;
805 #Make sure the userid chosen is unique and not theirs if non-empty. If it is not,
806 #Then we need to tell the user and have them create a new one.
809 "SELECT * FROM borrowers WHERE userid=? AND borrowernumber != ?");
810 $sth->execute( $uid, $member );
811 if ( ( $uid ne '' ) && ( my $row = $sth->fetchrow_hashref ) ) {
815 #Everything is good so we can update the information.
818 "update borrowers set userid=?, password=? where borrowernumber=?");
819 $sth->execute( $uid, $digest, $member );
823 &logaction(C4::Context->userenv->{'number'},"MEMBERS","CHANGE PASS",$member,"")
824 if C4::Context->preference("BorrowersLog");
829 =item fixup_cardnumber
831 Warning: The caller is responsible for locking the members table in write
832 mode, to avoid database corruption.
836 use vars qw( @weightings );
837 my @weightings = ( 8, 4, 6, 3, 5, 2, 1 );
839 sub fixup_cardnumber ($) {
840 my ($cardnumber) = @_;
841 my $autonumber_members = C4::Context->boolean_preference('autoMemberNum');
842 $autonumber_members = 0 unless defined $autonumber_members;
844 # Find out whether member numbers should be generated
845 # automatically. Should be either "1" or something else.
846 # Defaults to "0", which is interpreted as "no".
848 # if ($cardnumber !~ /\S/ && $autonumber_members) {
849 if ($autonumber_members) {
850 my $dbh = C4::Context->dbh;
851 if ( C4::Context->preference('checkdigit') eq 'katipo' ) {
853 # if checkdigit is selected, calculate katipo-style cardnumber.
854 # otherwise, just use the max()
855 # purpose: generate checksum'd member numbers.
856 # We'll assume we just got the max value of digits 2-8 of member #'s
857 # from the database and our job is to increment that by one,
858 # determine the 1st and 9th digits and return the full string.
861 "select max(substring(borrowers.cardnumber,2,7)) from borrowers"
865 my $data = $sth->fetchrow_hashref;
866 $cardnumber = $data->{'max(substring(borrowers.cardnumber,2,7))'};
868 if ( !$cardnumber ) { # If DB has no values,
869 $cardnumber = 1000000; # start at 1000000
876 for ( my $i = 0 ; $i < 8 ; $i += 1 ) {
878 # read weightings, left to right, 1 char at a time
879 my $temp1 = $weightings[$i];
881 # sequence left to right, 1 char at a time
882 my $temp2 = substr( $cardnumber, $i, 1 );
884 # mult each char 1-7 by its corresponding weighting
885 $sum += $temp1 * $temp2;
888 my $rem = ( $sum % 11 );
889 $rem = 'X' if $rem == 10;
891 $cardnumber = "V$cardnumber$rem";
895 # MODIFIED BY JF: mysql4.1 allows casting as an integer, which is probably
896 # better. I'll leave the original in in case it needs to be changed for you
899 "select max(cast(cardnumber as signed)) from borrowers");
901 #my $sth=$dbh->prepare("select max(borrowers.cardnumber) from borrowers");
905 my ($result) = $sth->fetchrow;
907 $cardnumber = $result + 1;
915 ($num_children, $children_arrayref) = &GetGuarantees($parent_borrno);
916 $child0_cardno = $children_arrayref->[0]{"cardnumber"};
917 $child0_borrno = $children_arrayref->[0]{"borrowernumber"};
919 C<&GetGuarantees> takes a borrower number (e.g., that of a patron
920 with children) and looks up the borrowers who are guaranteed by that
921 borrower (i.e., the patron's children).
923 C<&GetGuarantees> returns two values: an integer giving the number of
924 borrowers guaranteed by C<$parent_borrno>, and a reference to an array
925 of references to hash, which gives the actual results.
931 my ($borrowernumber) = @_;
932 my $dbh = C4::Context->dbh;
935 "select cardnumber,borrowernumber, firstname, surname from borrowers where guarantorid=?"
937 $sth->execute($borrowernumber);
940 my $data = $sth->fetchall_arrayref({});
942 return ( scalar(@$data), $data );
945 =head2 UpdateGuarantees
947 &UpdateGuarantees($parent_borrno);
950 C<&UpdateGuarantees> borrower data for an adulte and updates all the guarantees
951 with the modified information
956 sub UpdateGuarantees {
958 my $dbh = C4::Context->dbh;
959 my ( $count, $guarantees ) = GetGuarantees( $data{'borrowernumber'} );
960 for ( my $i = 0 ; $i < $count ; $i++ ) {
963 # It looks like the $i is only being returned to handle walking through
964 # the array, which is probably better done as a foreach loop.
966 my $guaquery = qq|UPDATE borrowers
967 SET address='$data{'address'}',fax='$data{'fax'}',
968 B_city='$data{'B_city'}',mobile='$data{'mobile'}',city='$data{'city'}',phone='$data{'phone'}'
969 WHERE borrowernumber='$guarantees->[$i]->{'borrowernumber'}'
971 my $sth3 = $dbh->prepare($guaquery);
976 =head2 GetPendingIssues
978 ($count, $issues) = &GetPendingIssues($borrowernumber);
980 Looks up what the patron with the given borrowernumber has borrowed.
982 C<&GetPendingIssues> returns a two-element array. C<$issues> is a
983 reference-to-array, where each element is a reference-to-hash; the
984 keys are the fields from the C<issues>, C<biblio>, and C<items> tables
985 in the Koha database. C<$count> is the number of elements in
991 sub GetPendingIssues {
992 my ($borrowernumber) = @_;
993 my $dbh = C4::Context->dbh;
995 my $sth = $dbh->prepare(
996 "SELECT * FROM issues
997 LEFT JOIN items ON issues.itemnumber=items.itemnumber
998 LEFT JOIN biblio ON items.biblionumber=biblio.biblionumber
999 LEFT JOIN biblioitems ON items.biblioitemnumber=biblioitems.biblioitemnumber
1002 AND returndate IS NULL
1003 ORDER BY issues.issuedate"
1005 $sth->execute($borrowernumber);
1006 my $data = $sth->fetchall_arrayref({});
1007 my $today = POSIX::strftime("%Y%m%d", localtime);
1009 my $datedue = $_->{'date_due'};
1011 if ( $datedue < $today ) {
1012 $_->{'overdue'} = 1;
1016 return ( scalar(@$data), $data );
1021 ($count, $issues) = &GetAllIssues($borrowernumber, $sortkey, $limit);
1023 Looks up what the patron with the given borrowernumber has borrowed,
1024 and sorts the results.
1026 C<$sortkey> is the name of a field on which to sort the results. This
1027 should be the name of a field in the C<issues>, C<biblio>,
1028 C<biblioitems>, or C<items> table in the Koha database.
1030 C<$limit> is the maximum number of results to return.
1032 C<&GetAllIssues> returns a two-element array. C<$issues> is a
1033 reference-to-array, where each element is a reference-to-hash; the
1034 keys are the fields from the C<issues>, C<biblio>, C<biblioitems>, and
1035 C<items> tables of the Koha database. C<$count> is the number of
1036 elements in C<$issues>
1042 my ( $borrowernumber, $order, $limit ) = @_;
1044 #FIXME: sanity-check order and limit
1045 my $dbh = C4::Context->dbh;
1048 "Select *,items.timestamp AS itemstimestamp from
1050 LEFT JOIN items on items.itemnumber=issues.itemnumber
1051 LEFT JOIN biblio ON items.biblionumber=biblio.biblionumber
1052 LEFT JOIN biblioitems ON items.biblioitemnumber=biblioitems.biblioitemnumber
1053 where borrowernumber=?
1055 if ( $limit != 0 ) {
1056 $query .= " limit $limit";
1060 my $sth = $dbh->prepare($query);
1061 $sth->execute($borrowernumber);
1064 while ( my $data = $sth->fetchrow_hashref ) {
1065 $result[$i] = $data;
1070 # get all issued items for borrowernumber from oldissues table
1071 # large chunk of older issues data put into table oldissues
1072 # to speed up db calls for issuing items
1073 if ( C4::Context->preference("ReadingHistory") ) {
1074 my $query2 = "SELECT * FROM oldissues
1075 LEFT JOIN items ON items.itemnumber=oldissues.itemnumber
1076 LEFT JOIN biblio ON items.biblionumber=biblio.biblionumber
1077 LEFT JOIN biblioitems ON items.biblioitemnumber=biblioitems.biblioitemnumber
1078 WHERE borrowernumber=?
1080 if ( $limit != 0 ) {
1081 $limit = $limit - $count;
1082 $query2 .= " limit $limit";
1085 my $sth2 = $dbh->prepare($query2);
1086 $sth2->execute($borrowernumber);
1088 while ( my $data2 = $sth2->fetchrow_hashref ) {
1089 $result[$i] = $data2;
1096 return ( $i, \@result );
1100 =head2 GetMemberAccountRecords
1102 ($total, $acctlines, $count) = &GetMemberAccountRecords($borrowernumber);
1104 Looks up accounting data for the patron with the given borrowernumber.
1106 C<&GetMemberAccountRecords> returns a three-element array. C<$acctlines> is a
1107 reference-to-array, where each element is a reference-to-hash; the
1108 keys are the fields of the C<accountlines> table in the Koha database.
1109 C<$count> is the number of elements in C<$acctlines>. C<$total> is the
1110 total amount outstanding for all of the account lines.
1115 sub GetMemberAccountRecords {
1116 my ($borrowernumber,$date) = @_;
1117 my $dbh = C4::Context->dbh;
1123 WHERE borrowernumber=?);
1124 my @bind = ($borrowernumber);
1125 if ($date && $date ne ''){
1126 $strsth.=" AND date < ? ";
1129 $strsth.=" ORDER BY date desc,timestamp DESC";
1130 my $sth= $dbh->prepare( $strsth );
1131 $sth->execute( @bind );
1133 while ( my $data = $sth->fetchrow_hashref ) {
1134 $acctlines[$numlines] = $data;
1136 $total += $data->{'amountoutstanding'};
1139 return ( $total, \@acctlines,$numlines);
1142 =head2 GetBorNotifyAcctRecord
1144 ($count, $acctlines, $total) = &GetBorNotifyAcctRecord($params,$notifyid);
1146 Looks up accounting data for the patron with the given borrowernumber per file number.
1148 (FIXME - I'm not at all sure what this is about.)
1150 C<&GetBorNotifyAcctRecord> returns a three-element array. C<$acctlines> is a
1151 reference-to-array, where each element is a reference-to-hash; the
1152 keys are the fields of the C<accountlines> table in the Koha database.
1153 C<$count> is the number of elements in C<$acctlines>. C<$total> is the
1154 total amount outstanding for all of the account lines.
1158 sub GetBorNotifyAcctRecord {
1159 my ( $borrowernumber, $notifyid ) = @_;
1160 my $dbh = C4::Context->dbh;
1163 my $sth = $dbh->prepare(
1166 WHERE borrowernumber=?
1168 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')
1169 AND amountoutstanding != '0'
1170 ORDER BY notify_id,accounttype
1172 $sth->execute( $borrowernumber, $notifyid );
1174 while ( my $data = $sth->fetchrow_hashref ) {
1175 $acctlines[$numlines] = $data;
1177 $total += $data->{'amountoutstanding'};
1180 return ( $total, \@acctlines, $numlines );
1183 =head2 checkuniquemember (OUEST-PROVENCE)
1185 $result = &checkuniquemember($collectivity,$surname,$categorycode,$firstname,$dateofbirth);
1187 Checks that a member exists or not in the database.
1189 C<&result> is 1 (=exist) or 0 (=does not exist)
1190 C<&collectivity> is 1 (= we add a collectivity) or 0 (= we add a physical member)
1191 C<&surname> is the surname
1192 C<&categorycode> is from categorycode table
1193 C<&firstname> is the firstname (only if collectivity=0)
1194 C<&dateofbirth> is the date of birth (only if collectivity=0)
1198 sub checkuniquemember {
1199 my ( $collectivity, $surname, $firstname, $dateofbirth ) = @_;
1200 my $dbh = C4::Context->dbh;
1202 if ($collectivity) {
1204 # $request="select count(*) from borrowers where surname=? and categorycode=?";
1206 "select borrowernumber,categorycode from borrowers where surname=? ";
1210 # $request="select count(*) from borrowers where surname=? and categorycode=? and firstname=? and dateofbirth=?";
1212 "select borrowernumber,categorycode from borrowers where surname=? and firstname=? and dateofbirth=?";
1214 my $sth = $dbh->prepare($request);
1215 if ($collectivity) {
1216 $sth->execute( uc($surname) );
1219 $sth->execute( uc($surname), ucfirst($firstname), $dateofbirth );
1221 my @data = $sth->fetchrow;
1224 return $data[0], $data[1];
1234 sub checkcardnumber {
1235 my ($cardnumber,$borrowernumber) = @_;
1236 my $dbh = C4::Context->dbh;
1237 my $query = "SELECT * FROM borrowers WHERE cardnumber=?";
1238 $query .= " AND borrowernumber <> ?" if ($borrowernumber);
1239 my $sth = $dbh->prepare($query);
1240 if ($borrowernumber) {
1241 $sth->execute($cardnumber,$borrowernumber);
1243 $sth->execute($cardnumber);
1245 if (my $data= $sth->fetchrow_hashref()){
1255 =head2 getzipnamecity (OUEST-PROVENCE)
1257 take all info from table city for the fields city and zip
1258 check for the name and the zip code of the city selected
1262 sub getzipnamecity {
1264 my $dbh = C4::Context->dbh;
1267 "select city_name,city_zipcode from cities where cityid=? ");
1268 $sth->execute($cityid);
1269 my @data = $sth->fetchrow;
1270 return $data[0], $data[1];
1274 =head2 getdcity (OUEST-PROVENCE)
1276 recover cityid with city_name condition
1281 my ($city_name) = @_;
1282 my $dbh = C4::Context->dbh;
1283 my $sth = $dbh->prepare("select cityid from cities where city_name=? ");
1284 $sth->execute($city_name);
1285 my $data = $sth->fetchrow;
1290 =head2 GetExpiryDate
1292 $expirydate = GetExpiryDate($categorycode, $dateenrolled);
1293 process expiry date given a date and a categorycode
1297 my ( $categorycode, $dateenrolled ) = @_;
1298 my $dbh = C4::Context->dbh;
1301 "select enrolmentperiod from categories where categorycode=?");
1302 $sth->execute($categorycode);
1303 my ($enrolmentperiod) = $sth->fetchrow;
1304 $enrolmentperiod = 12 unless ($enrolmentperiod);
1305 my @date=split /-/,format_date_in_iso($dateenrolled);
1306 @date=Add_Delta_YM($date[0],$date[1],$date[2],0,$enrolmentperiod);
1307 return sprintf("%04d-%02d-%02d",$date[0],$date[1],$date[2]);
1310 =head2 checkuserpassword (OUEST-PROVENCE)
1312 check for the password and login are not used
1313 return the number of record
1314 0=> NOT USED 1=> USED
1318 sub checkuserpassword {
1319 my ( $borrowernumber, $userid, $password ) = @_;
1320 $password = md5_base64($password);
1321 my $dbh = C4::Context->dbh;
1324 "Select count(*) from borrowers where borrowernumber !=? and userid =? and password=? "
1326 $sth->execute( $borrowernumber, $userid, $password );
1327 my $number_rows = $sth->fetchrow;
1328 return $number_rows;
1332 =head2 GetborCatFromCatType
1334 ($codes_arrayref, $labels_hashref) = &GetborCatFromCatType();
1336 Looks up the different types of borrowers in the database. Returns two
1337 elements: a reference-to-array, which lists the borrower category
1338 codes, and a reference-to-hash, which maps the borrower category codes
1339 to category descriptions.
1344 sub GetborCatFromCatType {
1345 my ( $category_type, $action ) = @_;
1346 my $dbh = C4::Context->dbh;
1347 my $request = qq| SELECT categorycode,description
1350 ORDER BY categorycode|;
1351 my $sth = $dbh->prepare($request);
1353 $sth->execute($category_type);
1362 while ( my $data = $sth->fetchrow_hashref ) {
1363 push @codes, $data->{'categorycode'};
1364 $labels{ $data->{'categorycode'} } = $data->{'description'};
1367 return ( \@codes, \%labels );
1370 =head2 GetBorrowercategory
1372 $hashref = &GetBorrowercategory($categorycode);
1374 Given the borrower's category code, the function returns the corresponding
1375 data hashref for a comprehensive information display.
1379 sub GetBorrowercategory {
1381 my $dbh = C4::Context->dbh;
1384 "SELECT description,dateofbirthrequired,upperagelimit,category_type
1386 WHERE categorycode = ?"
1388 $sth->execute($catcode);
1390 $sth->fetchrow_hashref;
1393 } # sub getborrowercategory
1395 =head2 ethnicitycategories
1397 ($codes_arrayref, $labels_hashref) = ðnicitycategories();
1399 Looks up the different ethnic types in the database. Returns two
1400 elements: a reference-to-array, which lists the ethnicity codes, and a
1401 reference-to-hash, which maps the ethnicity codes to ethnicity
1408 sub ethnicitycategories {
1409 my $dbh = C4::Context->dbh;
1410 my $sth = $dbh->prepare("Select code,name from ethnicity order by name");
1414 while ( my $data = $sth->fetchrow_hashref ) {
1415 push @codes, $data->{'code'};
1416 $labels{ $data->{'code'} } = $data->{'name'};
1419 return ( \@codes, \%labels );
1424 $ethn_name = &fixEthnicity($ethn_code);
1426 Takes an ethnicity code (e.g., "european" or "pi") and returns the
1427 corresponding descriptive name from the C<ethnicity> table in the
1428 Koha database ("European" or "Pacific Islander").
1435 my $ethnicity = shift;
1436 return unless $ethnicity;
1437 my $dbh = C4::Context->dbh;
1438 my $sth = $dbh->prepare("Select name from ethnicity where code = ?");
1439 $sth->execute($ethnicity);
1440 my $data = $sth->fetchrow_hashref;
1442 return $data->{'name'};
1443 } # sub fixEthnicity
1447 $dateofbirth,$date = &GetAge($date);
1449 this function return the borrowers age with the value of dateofbirth
1455 my ( $date, $date_ref ) = @_;
1457 if ( not defined $date_ref ) {
1458 $date_ref = sprintf( '%04d-%02d-%02d', Today() );
1461 my ( $year1, $month1, $day1 ) = split /-/, $date;
1462 my ( $year2, $month2, $day2 ) = split /-/, $date_ref;
1464 my $age = $year2 - $year1;
1465 if ( $month1 . $day1 > $month2 . $day2 ) {
1472 =head2 get_institutions
1473 $insitutions = get_institutions();
1475 Just returns a list of all the borrowers of type I, borrownumber and name
1480 sub get_institutions {
1481 my $dbh = C4::Context->dbh();
1484 "SELECT borrowernumber,surname FROM borrowers WHERE categorycode=? ORDER BY surname"
1488 while ( my $data = $sth->fetchrow_hashref() ) {
1489 $orgs{ $data->{'borrowernumber'} } = $data;
1494 } # sub get_institutions
1496 =head2 add_member_orgs
1498 add_member_orgs($borrowernumber,$borrowernumbers);
1500 Takes a borrowernumber and a list of other borrowernumbers and inserts them into the borrowers_to_borrowers table
1505 sub add_member_orgs {
1506 my ( $borrowernumber, $otherborrowers ) = @_;
1507 my $dbh = C4::Context->dbh();
1509 "INSERT INTO borrowers_to_borrowers (borrower1,borrower2) VALUES (?,?)";
1510 my $sth = $dbh->prepare($query);
1511 foreach my $otherborrowernumber (@$otherborrowers) {
1512 $sth->execute( $borrowernumber, $otherborrowernumber );
1516 } # sub add_member_orgs
1518 =head2 GetCities (OUEST-PROVENCE)
1520 ($id_cityarrayref, $city_hashref) = &GetCities();
1522 Looks up the different city and zip in the database. Returns two
1523 elements: a reference-to-array, which lists the zip city
1524 codes, and a reference-to-hash, which maps the name of the city.
1525 WHERE =>OUEST PROVENCE OR EXTERIEUR
1531 #my ($type_city) = @_;
1532 my $dbh = C4::Context->dbh;
1533 my $query = qq|SELECT cityid,city_name
1535 ORDER BY city_name|;
1536 my $sth = $dbh->prepare($query);
1538 #$sth->execute($type_city);
1543 # insert empty value to create a empty choice in cgi popup
1545 while ( my $data = $sth->fetchrow_hashref ) {
1547 push @id, $data->{'cityid'};
1548 $city{ $data->{'cityid'} } = $data->{'city_name'};
1551 #test to know if the table contain some records if no the function return nothing
1559 return ( \@id, \%city );
1563 =head2 GetSortDetails (OUEST-PROVENCE)
1565 ($lib) = &GetSortDetails($category,$sortvalue);
1567 Returns the authorized value details
1568 C<&$lib>return value of authorized value details
1569 C<&$sortvalue>this is the value of authorized value
1570 C<&$category>this is the value of authorized value category
1574 sub GetSortDetails {
1575 my ( $category, $sortvalue ) = @_;
1576 my $dbh = C4::Context->dbh;
1577 my $query = qq|SELECT lib
1578 FROM authorised_values
1580 AND authorised_value=? |;
1581 my $sth = $dbh->prepare($query);
1582 $sth->execute( $category, $sortvalue );
1583 my $lib = $sth->fetchrow;
1587 =head2 DeleteBorrower
1589 () = &DeleteBorrower($member);
1591 delete all data fo borrowers and add record to deletedborrowers table
1592 C<&$member>this is the borrowernumber
1596 sub MoveMemberToDeleted {
1598 my $dbh = C4::Context->dbh;
1600 $query = qq|SELECT *
1602 WHERE borrowernumber=?|;
1603 my $sth = $dbh->prepare($query);
1604 $sth->execute($member);
1605 my @data = $sth->fetchrow_array;
1608 $dbh->prepare( "INSERT INTO deletedborrowers VALUES ("
1609 . ( "?," x ( scalar(@data) - 1 ) )
1611 $sth->execute(@data);
1617 DelMember($borrowernumber);
1619 This function remove directly a borrower whitout writing it on deleteborrower.
1620 + Deletes reserves for the borrower
1625 my $dbh = C4::Context->dbh;
1626 my $borrowernumber = shift;
1627 warn "in delmember with $borrowernumber";
1628 return unless $borrowernumber; # borrowernumber is mandatory.
1630 my $query = qq|DELETE
1632 WHERE borrowernumber=?|;
1633 my $sth = $dbh->prepare($query);
1634 $sth->execute($borrowernumber);
1639 WHERE borrowernumber = ?
1641 $sth = $dbh->prepare($query);
1642 $sth->execute($borrowernumber);
1644 &logaction(C4::Context->userenv->{'number'},"MEMBERS","DELETE",$borrowernumber,"")
1645 if C4::Context->preference("BorrowersLog");
1649 =head2 ExtendMemberSubscriptionTo (OUEST-PROVENCE)
1651 $date= ExtendMemberSubscriptionTo($borrowerid, $date);
1652 Extending the subscription to a given date or to the expiry date calculated on local date.
1656 sub ExtendMemberSubscriptionTo {
1657 my ( $borrowerid,$date) = @_;
1658 my $dbh = C4::Context->dbh;
1660 $date=POSIX::strftime("%Y-%m-%d",localtime(time));
1661 my $borrower = GetMember($borrowerid,'borrowernumber');
1662 $date = GetExpiryDate( $borrower->{'categorycode'}, $date );
1664 my $sth = $dbh->do(<<EOF);
1666 SET dateexpiry='$date'
1667 WHERE borrowernumber='$borrowerid'
1669 return $date if ($sth);
1673 =head2 GetRoadTypes (OUEST-PROVENCE)
1675 ($idroadtypearrayref, $roadttype_hashref) = &GetRoadTypes();
1677 Looks up the different road type . Returns two
1678 elements: a reference-to-array, which lists the id_roadtype
1679 codes, and a reference-to-hash, which maps the road type of the road .
1685 my $dbh = C4::Context->dbh;
1687 SELECT roadtypeid,road_type
1689 ORDER BY road_type|;
1690 my $sth = $dbh->prepare($query);
1695 # insert empty value to create a empty choice in cgi popup
1697 while ( my $data = $sth->fetchrow_hashref ) {
1699 push @id, $data->{'roadtypeid'};
1700 $roadtype{ $data->{'roadtypeid'} } = $data->{'road_type'};
1703 #test to know if the table contain some records if no the function return nothing
1711 return ( \@id, \%roadtype );
1717 =head2 GetTitles (OUEST-PROVENCE)
1719 ($borrowertitle)= &GetTitles();
1721 Looks up the different title . Returns array with all borrowers title
1726 my @borrowerTitle = split /,|\|/,C4::Context->preference('BorrowersTitles');
1727 unshift( @borrowerTitle, "" );
1728 return ( \@borrowerTitle);
1733 =head2 GetRoadTypeDetails (OUEST-PROVENCE)
1735 ($roadtype) = &GetRoadTypeDetails($roadtypeid);
1737 Returns the description of roadtype
1738 C<&$roadtype>return description of road type
1739 C<&$roadtypeid>this is the value of roadtype s
1743 sub GetRoadTypeDetails {
1744 my ($roadtypeid) = @_;
1745 my $dbh = C4::Context->dbh;
1749 WHERE roadtypeid=?|;
1750 my $sth = $dbh->prepare($query);
1751 $sth->execute($roadtypeid);
1752 my $roadtype = $sth->fetchrow;
1756 =head2 GetBorrowersWhoHaveNotBorrowedSince
1758 &GetBorrowersWhoHaveNotBorrowedSince($date)
1760 this function get all borrowers who haven't borrowed since the date given on input arg.
1764 sub GetBorrowersWhoHaveNotBorrowedSince {
1766 return unless $date; # date is mandatory.
1767 my $dbh = C4::Context->dbh;
1769 SELECT borrowers.borrowernumber,max(timestamp)
1771 LEFT JOIN issues ON borrowers.borrowernumber = issues.borrowernumber
1772 WHERE issues.borrowernumber IS NOT NULL
1773 GROUP BY borrowers.borrowernumber
1775 my $sth = $dbh->prepare($query);
1779 while ( my $data = $sth->fetchrow_hashref ) {
1780 push @results, $data;
1785 =head2 GetBorrowersWhoHaveNeverBorrowed
1787 $results = &GetBorrowersWhoHaveNeverBorrowed
1789 this function get all borrowers who have never borrowed.
1791 I<$result> is a ref to an array which all elements are a hasref.
1795 sub GetBorrowersWhoHaveNeverBorrowed {
1796 my $dbh = C4::Context->dbh;
1798 SELECT borrowers.borrowernumber,max(timestamp)
1800 LEFT JOIN issues ON borrowers.borrowernumber = issues.borrowernumber
1801 WHERE issues.borrowernumber IS NULL
1803 my $sth = $dbh->prepare($query);
1806 while ( my $data = $sth->fetchrow_hashref ) {
1807 push @results, $data;
1812 =head2 GetBorrowersWithIssuesHistoryOlderThan
1814 $results = &GetBorrowersWithIssuesHistoryOlderThan($date)
1816 this function get all borrowers who has an issue history older than I<$date> given on input arg.
1818 I<$result> is a ref to an array which all elements are a hashref.
1819 This hashref is containt the number of time this borrowers has borrowed before I<$date> and the borrowernumber.
1823 sub GetBorrowersWithIssuesHistoryOlderThan {
1824 my $dbh = C4::Context->dbh;
1826 return unless $date; # date is mandatory.
1828 SELECT count(borrowernumber) as n,borrowernumber
1830 WHERE returndate < ?
1831 AND borrowernumber IS NOT NULL
1832 GROUP BY borrowernumber
1834 my $sth = $dbh->prepare($query);
1835 $sth->execute($date);
1838 while ( my $data = $sth->fetchrow_hashref ) {
1839 push @results, $data;
1844 END { } # module clean-up code here (global destructor)