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 if ( $amount > $noissuescharge ) {
424 $flaginfo{'noissues'} = 1;
426 $flags{'CHARGES'} = \%flaginfo;
428 elsif ( $amount < 0 ) {
430 $flaginfo{'message'} = sprintf "Patron has credit of \$%.02f", -$amount;
431 $flags{'CHARGES'} = \%flaginfo;
433 if ( $patroninformation->{'gonenoaddress'}
434 && $patroninformation->{'gonenoaddress'} == 1 )
437 $flaginfo{'message'} = 'Borrower has no valid address.';
438 $flaginfo{'noissues'} = 1;
439 $flags{'GNA'} = \%flaginfo;
441 if ( $patroninformation->{'lost'} && $patroninformation->{'lost'} == 1 ) {
443 $flaginfo{'message'} = 'Borrower\'s card reported lost.';
444 $flaginfo{'noissues'} = 1;
445 $flags{'LOST'} = \%flaginfo;
447 if ( $patroninformation->{'debarred'}
448 && $patroninformation->{'debarred'} == 1 )
451 $flaginfo{'message'} = 'Borrower is Debarred.';
452 $flaginfo{'noissues'} = 1;
453 $flags{'DBARRED'} = \%flaginfo;
455 if ( $patroninformation->{'borrowernotes'}
456 && $patroninformation->{'borrowernotes'} )
459 $flaginfo{'message'} = "$patroninformation->{'borrowernotes'}";
460 $flags{'NOTES'} = \%flaginfo;
462 my ( $odues, $itemsoverdue ) =
463 checkoverdues( $patroninformation->{'borrowernumber'}, $dbh );
466 $flaginfo{'message'} = "Yes";
467 $flaginfo{'itemlist'} = $itemsoverdue;
468 foreach ( sort { $a->{'date_due'} cmp $b->{'date_due'} }
471 $flaginfo{'itemlisttext'} .=
472 "$_->{'date_due'} $_->{'barcode'} $_->{'title'} \n";
474 $flags{'ODUES'} = \%flaginfo;
476 my @itemswaiting = C4::Reserves::GetReservesFromBorrowernumber( $patroninformation->{'borrowernumber'},'W' );
477 my $nowaiting = scalar @itemswaiting;
478 if ( $nowaiting > 0 ) {
480 $flaginfo{'message'} = "Reserved items available";
481 $flaginfo{'itemlist'} = \@itemswaiting;
482 $flags{'WAITING'} = \%flaginfo;
490 $borrower = &GetMember($information, $type);
492 Looks up information about a patron (borrower) by either card number
493 ,firstname, or borrower number, depending on $type value.
494 If C<$type> == 'cardnumber', C<&GetBorrower>
495 searches by cardnumber then by firstname if not found in cardnumber;
496 otherwise, it searches by borrowernumber.
498 C<&GetBorrower> returns a reference-to-hash whose keys are the fields of
499 the C<borrowers> table in the Koha database.
505 my ( $information, $type ) = @_;
506 my $dbh = C4::Context->dbh;
508 if ($type eq 'cardnumber' || $type eq 'firstname'|| $type eq 'userid'|| $type eq 'borrowernumber'){
509 $information = uc $information;
512 "Select borrowers.*,categories.category_type,categories.description from borrowers left join categories on borrowers.categorycode=categories.categorycode where $type=?"
514 $sth->execute($information);
519 "Select borrowers.*,categories.category_type, categories.description from borrowers left join categories on borrowers.categorycode=categories.categorycode where borrowernumber=?"
521 $sth->execute($information);
523 my $data = $sth->fetchrow_hashref;
529 elsif ($type eq 'cardnumber' ||$type eq 'firstname') { # try with firstname
532 "Select borrowers.*,categories.category_type,categories.description from borrowers left join categories on borrowers.categorycode=categories.categorycode where firstname like ?"
534 $sth->execute($information);
535 my $data = $sth->fetchrow_hashref;
544 =item GetMemberIssuesAndFines
546 ($borrowed, $due, $fine) = &GetMemberIssuesAndFines($borrowernumber);
548 Returns aggregate data about items borrowed by the patron with the
549 given borrowernumber.
551 C<&GetMemberIssuesAndFines> returns a three-element array. C<$borrowed> is the
552 number of books the patron currently has borrowed. C<$due> is the
553 number of overdue items the patron currently has borrowed. C<$fine> is
554 the total fine currently due by the borrower.
559 sub GetMemberIssuesAndFines {
560 my ( $borrowernumber ) = @_;
561 my $dbh = C4::Context->dbh;
563 "Select count(*) from issues where borrowernumber='$borrowernumber' and
567 my $sth = $dbh->prepare($query);
569 my $data = $sth->fetchrow_hashref;
571 $sth = $dbh->prepare(
572 "Select count(*) from issues where
573 borrowernumber='$borrowernumber' and date_due < now() and returndate is NULL"
576 my $data2 = $sth->fetchrow_hashref;
578 $sth = $dbh->prepare(
579 "Select sum(amountoutstanding) from accountlines where
580 borrowernumber='$borrowernumber'"
583 my $data3 = $sth->fetchrow_hashref;
586 return ( $data2->{'count(*)'}, $data->{'count(*)'},
587 $data3->{'sum(amountoutstanding)'} );
594 &ModMember($borrowernumber);
596 Modify borrower's data
603 my $dbh = C4::Context->dbh;
604 $data{'dateofbirth'} = format_date_in_iso( $data{'dateofbirth'} ) if ($data{'dateofbirth'} );
605 $data{'dateexpiry'} = format_date_in_iso( $data{'dateexpiry'} ) if ($data{'dateexpiry'} );
606 $data{'dateenrolled'} = format_date_in_iso( $data{'dateenrolled'} ) if ($data{'dateenrolled'} );
607 my $qborrower=$dbh->prepare("SHOW columns from borrowers");
609 my %hashborrowerfields;
610 while (my ($field)=$qborrower->fetchrow){
611 $hashborrowerfields{$field}=1;
617 # test to know if u must update or not the borrower password
618 if ( $data{'password'} eq '****' ) {
619 delete $data{'password'};
621 {push @parameters,"$_ = ".$dbh->quote($data{$_}) if ($_ ne "borrowernumber" and $_ ne "flags" and $hashborrowerfields{$_}) } ;
622 $query = "UPDATE borrowers SET ".join (",",@parameters)
623 ." WHERE borrowernumber=$data{'borrowernumber'}";
625 $sth = $dbh->prepare($query);
629 $data{'password'} = md5_base64( $data{'password'} ) if ( $data{'password'} ne '' );
630 delete $data{'password'} if ($data{password} eq "");
632 {push @parameters,"$_ = ".$dbh->quote($data{$_}) if ($_ ne "borrowernumber" and $_ ne "flags" and $hashborrowerfields{$_})} ;
634 $query = "UPDATE borrowers SET ".join (",",@parameters)." WHERE borrowernumber=$data{'borrowernumber'}";
636 $sth = $dbh->prepare($query);
641 # ok if its an adult (type) it may have borrowers that depend on it as a guarantor
642 # so when we update information for an adult we should check for guarantees and update the relevant part
643 # of their records, ie addresses and phone numbers
644 my $borrowercategory= GetBorrowercategory( $data{'category_type'} );
645 if ( $borrowercategory->{'category_type'} eq ('A' || 'S') ) {
646 # is adult check guarantees;
647 UpdateGuarantees(%data);
650 &logaction(C4::Context->userenv->{'number'},"MEMBERS","MODIFY",$data{'borrowernumber'},"")
651 if C4::Context->preference("BorrowersLog");
659 $borrowernumber = &AddMember(%borrower);
661 insert new borrower into table
662 Returns the borrowernumber
669 my $dbh = C4::Context->dbh;
670 $data{'userid'} = '' unless $data{'password'};
671 $data{'password'} = md5_base64( $data{'password'} ) if $data{'password'};
672 $data{'dateofbirth'} = format_date_in_iso( $data{'dateofbirth'} );
673 $data{'dateenrolled'} = format_date_in_iso( $data{'dateenrolled'});
674 $data{'dateexpiry'} = format_date_in_iso( $data{'dateexpiry'} );
676 "insert into borrowers set cardnumber="
677 . $dbh->quote( $data{'cardnumber'} )
679 . $dbh->quote( $data{'surname'} )
681 . $dbh->quote( $data{'firstname'} )
683 . $dbh->quote( $data{'title'} )
685 . $dbh->quote( $data{'othernames'} )
687 . $dbh->quote( $data{'initials'} )
689 . $dbh->quote( $data{'streetnumber'} )
691 . $dbh->quote( $data{'streettype'} )
693 . $dbh->quote( $data{'address'} )
695 . $dbh->quote( $data{'address2'} )
697 . $dbh->quote( $data{'zipcode'} )
699 . $dbh->quote( $data{'city'} )
701 . $dbh->quote( $data{'phone'} )
703 . $dbh->quote( $data{'email'} )
705 . $dbh->quote( $data{'mobile'} )
707 . $dbh->quote( $data{'phonepro'} )
709 . $dbh->quote( $data{'opacnote'} )
711 . $dbh->quote( $data{'guarantorid'} )
713 . $dbh->quote( $data{'dateofbirth'} )
715 . $dbh->quote( $data{'branchcode'} )
717 . $dbh->quote( $data{'categorycode'} )
719 . $dbh->quote( $data{'dateenrolled'} )
721 . $dbh->quote( $data{'contactname'} )
723 . $dbh->quote( $data{'borrowernotes'} )
725 . $dbh->quote( $data{'dateexpiry'} )
727 . $dbh->quote( $data{'contactnote'} )
729 . $dbh->quote( $data{'B_address'} )
731 . $dbh->quote( $data{'B_zipcode'} )
733 . $dbh->quote( $data{'B_city'} )
735 . $dbh->quote( $data{'B_phone'} )
737 . $dbh->quote( $data{'B_email'} )
739 . $dbh->quote( $data{'password'} )
741 . $dbh->quote( $data{'userid'} )
743 . $dbh->quote( $data{'sort1'} )
745 . $dbh->quote( $data{'sort2'} )
747 . $dbh->quote( $data{'contacttitle'} )
749 . $dbh->quote( $data{'emailpro'} )
750 . ",contactfirstname="
751 . $dbh->quote( $data{'contactfirstname'} ) . ",sex="
752 . $dbh->quote( $data{'sex'} ) . ",fax="
753 . $dbh->quote( $data{'fax'} )
755 . $dbh->quote( $data{'relationship'} )
757 . $dbh->quote( $data{'B_streetnumber'} )
759 . $dbh->quote( $data{'B_streettype'} )
761 . $dbh->quote( $data{'gonenoaddress'} )
763 . $dbh->quote( $data{'lost'} )
765 . $dbh->quote( $data{'debarred'} )
767 . $dbh->quote( $data{'ethnicity'} )
769 . $dbh->quote( $data{'ethnotes'} );
771 my $sth = $dbh->prepare($query);
774 $data{'borrowernumber'} = $dbh->{'mysql_insertid'};
776 &logaction(C4::Context->userenv->{'number'},"MEMBERS","CREATE",$data{'borrowernumber'},"")
777 if C4::Context->preference("BorrowersLog");
779 return $data{'borrowernumber'};
783 my ($uid,$member) = @_;
784 my $dbh = C4::Context->dbh;
785 # Make sure the userid chosen is unique and not theirs if non-empty. If it is not,
786 # Then we need to tell the user and have them create a new one.
789 "SELECT * FROM borrowers WHERE userid=? AND borrowernumber != ?");
790 $sth->execute( $uid, $member );
791 if ( ( $uid ne '' ) && ( my $row = $sth->fetchrow_hashref ) ) {
801 my ( $uid, $member, $digest ) = @_;
802 my $dbh = C4::Context->dbh;
804 #Make sure the userid chosen is unique and not theirs if non-empty. If it is not,
805 #Then we need to tell the user and have them create a new one.
808 "SELECT * FROM borrowers WHERE userid=? AND borrowernumber != ?");
809 $sth->execute( $uid, $member );
810 if ( ( $uid ne '' ) && ( my $row = $sth->fetchrow_hashref ) ) {
814 #Everything is good so we can update the information.
817 "update borrowers set userid=?, password=? where borrowernumber=?");
818 $sth->execute( $uid, $digest, $member );
822 &logaction(C4::Context->userenv->{'number'},"MEMBERS","CHANGE PASS",$member,"")
823 if C4::Context->preference("BorrowersLog");
828 =item fixup_cardnumber
830 Warning: The caller is responsible for locking the members table in write
831 mode, to avoid database corruption.
835 use vars qw( @weightings );
836 my @weightings = ( 8, 4, 6, 3, 5, 2, 1 );
838 sub fixup_cardnumber ($) {
839 my ($cardnumber) = @_;
840 my $autonumber_members = C4::Context->boolean_preference('autoMemberNum');
841 $autonumber_members = 0 unless defined $autonumber_members;
843 # Find out whether member numbers should be generated
844 # automatically. Should be either "1" or something else.
845 # Defaults to "0", which is interpreted as "no".
847 # if ($cardnumber !~ /\S/ && $autonumber_members) {
848 if ($autonumber_members) {
849 my $dbh = C4::Context->dbh;
850 if ( C4::Context->preference('checkdigit') eq 'katipo' ) {
852 # if checkdigit is selected, calculate katipo-style cardnumber.
853 # otherwise, just use the max()
854 # purpose: generate checksum'd member numbers.
855 # We'll assume we just got the max value of digits 2-8 of member #'s
856 # from the database and our job is to increment that by one,
857 # determine the 1st and 9th digits and return the full string.
860 "select max(substring(borrowers.cardnumber,2,7)) from borrowers"
864 my $data = $sth->fetchrow_hashref;
865 $cardnumber = $data->{'max(substring(borrowers.cardnumber,2,7))'};
867 if ( !$cardnumber ) { # If DB has no values,
868 $cardnumber = 1000000; # start at 1000000
875 for ( my $i = 0 ; $i < 8 ; $i += 1 ) {
877 # read weightings, left to right, 1 char at a time
878 my $temp1 = $weightings[$i];
880 # sequence left to right, 1 char at a time
881 my $temp2 = substr( $cardnumber, $i, 1 );
883 # mult each char 1-7 by its corresponding weighting
884 $sum += $temp1 * $temp2;
887 my $rem = ( $sum % 11 );
888 $rem = 'X' if $rem == 10;
890 $cardnumber = "V$cardnumber$rem";
894 # MODIFIED BY JF: mysql4.1 allows casting as an integer, which is probably
895 # better. I'll leave the original in in case it needs to be changed for you
898 "select max(cast(cardnumber as signed)) from borrowers");
900 #my $sth=$dbh->prepare("select max(borrowers.cardnumber) from borrowers");
904 my ($result) = $sth->fetchrow;
906 $cardnumber = $result + 1;
914 ($num_children, $children_arrayref) = &GetGuarantees($parent_borrno);
915 $child0_cardno = $children_arrayref->[0]{"cardnumber"};
916 $child0_borrno = $children_arrayref->[0]{"borrowernumber"};
918 C<&GetGuarantees> takes a borrower number (e.g., that of a patron
919 with children) and looks up the borrowers who are guaranteed by that
920 borrower (i.e., the patron's children).
922 C<&GetGuarantees> returns two values: an integer giving the number of
923 borrowers guaranteed by C<$parent_borrno>, and a reference to an array
924 of references to hash, which gives the actual results.
930 my ($borrowernumber) = @_;
931 my $dbh = C4::Context->dbh;
934 "select cardnumber,borrowernumber, firstname, surname from borrowers where guarantorid=?"
936 $sth->execute($borrowernumber);
939 my $data = $sth->fetchall_arrayref({});
941 return ( scalar(@$data), $data );
944 =head2 UpdateGuarantees
946 &UpdateGuarantees($parent_borrno);
949 C<&UpdateGuarantees> borrower data for an adulte and updates all the guarantees
950 with the modified information
955 sub UpdateGuarantees {
957 my $dbh = C4::Context->dbh;
958 my ( $count, $guarantees ) = GetGuarantees( $data{'borrowernumber'} );
959 for ( my $i = 0 ; $i < $count ; $i++ ) {
962 # It looks like the $i is only being returned to handle walking through
963 # the array, which is probably better done as a foreach loop.
965 my $guaquery = qq|UPDATE borrowers
966 SET address='$data{'address'}',fax='$data{'fax'}',
967 B_city='$data{'B_city'}',mobile='$data{'mobile'}',city='$data{'city'}',phone='$data{'phone'}'
968 WHERE borrowernumber='$guarantees->[$i]->{'borrowernumber'}'
970 my $sth3 = $dbh->prepare($guaquery);
975 =head2 GetPendingIssues
977 ($count, $issues) = &GetPendingIssues($borrowernumber);
979 Looks up what the patron with the given borrowernumber has borrowed.
981 C<&GetPendingIssues> returns a two-element array. C<$issues> is a
982 reference-to-array, where each element is a reference-to-hash; the
983 keys are the fields from the C<issues>, C<biblio>, and C<items> tables
984 in the Koha database. C<$count> is the number of elements in
990 sub GetPendingIssues {
991 my ($borrowernumber) = @_;
992 my $dbh = C4::Context->dbh;
994 my $sth = $dbh->prepare(
995 "SELECT * FROM issues
996 LEFT JOIN items ON issues.itemnumber=items.itemnumber
997 LEFT JOIN biblio ON items.biblionumber=biblio.biblionumber
998 LEFT JOIN biblioitems ON items.biblioitemnumber=biblioitems.biblioitemnumber
1001 AND returndate IS NULL
1002 ORDER BY issues.issuedate"
1004 $sth->execute($borrowernumber);
1005 my $data = $sth->fetchall_arrayref({});
1006 my $today = POSIX::strftime("%Y%m%d", localtime);
1008 my $datedue = $_->{'date_due'};
1010 if ( $datedue < $today ) {
1011 $_->{'overdue'} = 1;
1015 return ( scalar(@$data), $data );
1020 ($count, $issues) = &GetAllIssues($borrowernumber, $sortkey, $limit);
1022 Looks up what the patron with the given borrowernumber has borrowed,
1023 and sorts the results.
1025 C<$sortkey> is the name of a field on which to sort the results. This
1026 should be the name of a field in the C<issues>, C<biblio>,
1027 C<biblioitems>, or C<items> table in the Koha database.
1029 C<$limit> is the maximum number of results to return.
1031 C<&GetAllIssues> returns a two-element array. C<$issues> is a
1032 reference-to-array, where each element is a reference-to-hash; the
1033 keys are the fields from the C<issues>, C<biblio>, C<biblioitems>, and
1034 C<items> tables of the Koha database. C<$count> is the number of
1035 elements in C<$issues>
1041 my ( $borrowernumber, $order, $limit ) = @_;
1043 #FIXME: sanity-check order and limit
1044 my $dbh = C4::Context->dbh;
1047 "Select *,items.timestamp AS itemstimestamp from
1049 LEFT JOIN items on items.itemnumber=issues.itemnumber
1050 LEFT JOIN biblio ON items.biblionumber=biblio.biblionumber
1051 LEFT JOIN biblioitems ON items.biblioitemnumber=biblioitems.biblioitemnumber
1052 where borrowernumber=?
1054 if ( $limit != 0 ) {
1055 $query .= " limit $limit";
1059 my $sth = $dbh->prepare($query);
1060 $sth->execute($borrowernumber);
1063 while ( my $data = $sth->fetchrow_hashref ) {
1064 $result[$i] = $data;
1069 # get all issued items for borrowernumber from oldissues table
1070 # large chunk of older issues data put into table oldissues
1071 # to speed up db calls for issuing items
1072 if ( C4::Context->preference("ReadingHistory") ) {
1073 my $query2 = "SELECT * FROM oldissues
1074 LEFT JOIN items ON items.itemnumber=oldissues.itemnumber
1075 LEFT JOIN biblio ON items.biblionumber=biblio.biblionumber
1076 LEFT JOIN biblioitems ON items.biblioitemnumber=biblioitems.biblioitemnumber
1077 WHERE borrowernumber=?
1079 if ( $limit != 0 ) {
1080 $limit = $limit - $count;
1081 $query2 .= " limit $limit";
1084 my $sth2 = $dbh->prepare($query2);
1085 $sth2->execute($borrowernumber);
1087 while ( my $data2 = $sth2->fetchrow_hashref ) {
1088 $result[$i] = $data2;
1095 return ( $i, \@result );
1099 =head2 GetMemberAccountRecords
1101 ($total, $acctlines, $count) = &GetMemberAccountRecords($borrowernumber);
1103 Looks up accounting data for the patron with the given borrowernumber.
1105 C<&GetMemberAccountRecords> returns a three-element array. C<$acctlines> is a
1106 reference-to-array, where each element is a reference-to-hash; the
1107 keys are the fields of the C<accountlines> table in the Koha database.
1108 C<$count> is the number of elements in C<$acctlines>. C<$total> is the
1109 total amount outstanding for all of the account lines.
1114 sub GetMemberAccountRecords {
1115 my ($borrowernumber,$date) = @_;
1116 my $dbh = C4::Context->dbh;
1122 WHERE borrowernumber=?);
1123 my @bind = ($borrowernumber);
1124 if ($date && $date ne ''){
1125 $strsth.=" AND date < ? ";
1128 $strsth.=" ORDER BY date desc,timestamp DESC";
1129 my $sth= $dbh->prepare( $strsth );
1130 $sth->execute( @bind );
1132 while ( my $data = $sth->fetchrow_hashref ) {
1133 $acctlines[$numlines] = $data;
1135 $total += $data->{'amountoutstanding'};
1138 return ( $total, \@acctlines,$numlines);
1141 =head2 GetBorNotifyAcctRecord
1143 ($count, $acctlines, $total) = &GetBorNotifyAcctRecord($params,$notifyid);
1145 Looks up accounting data for the patron with the given borrowernumber per file number.
1147 (FIXME - I'm not at all sure what this is about.)
1149 C<&GetBorNotifyAcctRecord> returns a three-element array. C<$acctlines> is a
1150 reference-to-array, where each element is a reference-to-hash; the
1151 keys are the fields of the C<accountlines> table in the Koha database.
1152 C<$count> is the number of elements in C<$acctlines>. C<$total> is the
1153 total amount outstanding for all of the account lines.
1157 sub GetBorNotifyAcctRecord {
1158 my ( $borrowernumber, $notifyid ) = @_;
1159 my $dbh = C4::Context->dbh;
1162 my $sth = $dbh->prepare(
1165 WHERE borrowernumber=?
1167 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')
1168 AND amountoutstanding != '0'
1169 ORDER BY notify_id,accounttype
1171 $sth->execute( $borrowernumber, $notifyid );
1173 while ( my $data = $sth->fetchrow_hashref ) {
1174 $acctlines[$numlines] = $data;
1176 $total += $data->{'amountoutstanding'};
1179 return ( $total, \@acctlines, $numlines );
1182 =head2 checkuniquemember (OUEST-PROVENCE)
1184 $result = &checkuniquemember($collectivity,$surname,$categorycode,$firstname,$dateofbirth);
1186 Checks that a member exists or not in the database.
1188 C<&result> is 1 (=exist) or 0 (=does not exist)
1189 C<&collectivity> is 1 (= we add a collectivity) or 0 (= we add a physical member)
1190 C<&surname> is the surname
1191 C<&categorycode> is from categorycode table
1192 C<&firstname> is the firstname (only if collectivity=0)
1193 C<&dateofbirth> is the date of birth (only if collectivity=0)
1197 sub checkuniquemember {
1198 my ( $collectivity, $surname, $firstname, $dateofbirth ) = @_;
1199 my $dbh = C4::Context->dbh;
1201 if ($collectivity) {
1203 # $request="select count(*) from borrowers where surname=? and categorycode=?";
1205 "select borrowernumber,categorycode from borrowers where surname=? ";
1209 # $request="select count(*) from borrowers where surname=? and categorycode=? and firstname=? and dateofbirth=?";
1211 "select borrowernumber,categorycode from borrowers where surname=? and firstname=? and dateofbirth=?";
1213 my $sth = $dbh->prepare($request);
1214 if ($collectivity) {
1215 $sth->execute( uc($surname) );
1218 $sth->execute( uc($surname), ucfirst($firstname), $dateofbirth );
1220 my @data = $sth->fetchrow;
1223 return $data[0], $data[1];
1233 sub checkcardnumber {
1234 my ($cardnumber,$borrowernumber) = @_;
1235 my $dbh = C4::Context->dbh;
1236 my $query = "SELECT * FROM borrowers WHERE cardnumber=?";
1237 $query .= " AND borrowernumber <> ?" if ($borrowernumber);
1238 my $sth = $dbh->prepare($query);
1239 if ($borrowernumber) {
1240 $sth->execute($cardnumber,$borrowernumber);
1242 $sth->execute($cardnumber);
1244 if (my $data= $sth->fetchrow_hashref()){
1254 =head2 getzipnamecity (OUEST-PROVENCE)
1256 take all info from table city for the fields city and zip
1257 check for the name and the zip code of the city selected
1261 sub getzipnamecity {
1263 my $dbh = C4::Context->dbh;
1266 "select city_name,city_zipcode from cities where cityid=? ");
1267 $sth->execute($cityid);
1268 my @data = $sth->fetchrow;
1269 return $data[0], $data[1];
1273 =head2 getdcity (OUEST-PROVENCE)
1275 recover cityid with city_name condition
1280 my ($city_name) = @_;
1281 my $dbh = C4::Context->dbh;
1282 my $sth = $dbh->prepare("select cityid from cities where city_name=? ");
1283 $sth->execute($city_name);
1284 my $data = $sth->fetchrow;
1289 =head2 GetExpiryDate
1291 $expirydate = GetExpiryDate($categorycode, $dateenrolled);
1292 process expiry date given a date and a categorycode
1296 my ( $categorycode, $dateenrolled ) = @_;
1297 my $dbh = C4::Context->dbh;
1300 "select enrolmentperiod from categories where categorycode=?");
1301 $sth->execute($categorycode);
1302 my ($enrolmentperiod) = $sth->fetchrow;
1303 $enrolmentperiod = 12 unless ($enrolmentperiod);
1304 my @date=split /-/,format_date_in_iso($dateenrolled);
1305 @date=Add_Delta_YM($date[0],$date[1],$date[2],0,$enrolmentperiod);
1306 return sprintf("%04d-%02d-%02d",$date[0],$date[1],$date[2]);
1309 =head2 checkuserpassword (OUEST-PROVENCE)
1311 check for the password and login are not used
1312 return the number of record
1313 0=> NOT USED 1=> USED
1317 sub checkuserpassword {
1318 my ( $borrowernumber, $userid, $password ) = @_;
1319 $password = md5_base64($password);
1320 my $dbh = C4::Context->dbh;
1323 "Select count(*) from borrowers where borrowernumber !=? and userid =? and password=? "
1325 $sth->execute( $borrowernumber, $userid, $password );
1326 my $number_rows = $sth->fetchrow;
1327 return $number_rows;
1331 =head2 GetborCatFromCatType
1333 ($codes_arrayref, $labels_hashref) = &GetborCatFromCatType();
1335 Looks up the different types of borrowers in the database. Returns two
1336 elements: a reference-to-array, which lists the borrower category
1337 codes, and a reference-to-hash, which maps the borrower category codes
1338 to category descriptions.
1343 sub GetborCatFromCatType {
1344 my ( $category_type, $action ) = @_;
1345 my $dbh = C4::Context->dbh;
1346 my $request = qq| SELECT categorycode,description
1349 ORDER BY categorycode|;
1350 my $sth = $dbh->prepare($request);
1352 $sth->execute($category_type);
1361 while ( my $data = $sth->fetchrow_hashref ) {
1362 push @codes, $data->{'categorycode'};
1363 $labels{ $data->{'categorycode'} } = $data->{'description'};
1366 return ( \@codes, \%labels );
1369 =head2 GetBorrowercategory
1371 $hashref = &GetBorrowercategory($categorycode);
1373 Given the borrower's category code, the function returns the corresponding
1374 data hashref for a comprehensive information display.
1378 sub GetBorrowercategory {
1380 my $dbh = C4::Context->dbh;
1383 "SELECT description,dateofbirthrequired,upperagelimit,category_type
1385 WHERE categorycode = ?"
1387 $sth->execute($catcode);
1389 $sth->fetchrow_hashref;
1392 } # sub getborrowercategory
1394 =head2 ethnicitycategories
1396 ($codes_arrayref, $labels_hashref) = ðnicitycategories();
1398 Looks up the different ethnic types in the database. Returns two
1399 elements: a reference-to-array, which lists the ethnicity codes, and a
1400 reference-to-hash, which maps the ethnicity codes to ethnicity
1407 sub ethnicitycategories {
1408 my $dbh = C4::Context->dbh;
1409 my $sth = $dbh->prepare("Select code,name from ethnicity order by name");
1413 while ( my $data = $sth->fetchrow_hashref ) {
1414 push @codes, $data->{'code'};
1415 $labels{ $data->{'code'} } = $data->{'name'};
1418 return ( \@codes, \%labels );
1423 $ethn_name = &fixEthnicity($ethn_code);
1425 Takes an ethnicity code (e.g., "european" or "pi") and returns the
1426 corresponding descriptive name from the C<ethnicity> table in the
1427 Koha database ("European" or "Pacific Islander").
1434 my $ethnicity = shift;
1435 return unless $ethnicity;
1436 my $dbh = C4::Context->dbh;
1437 my $sth = $dbh->prepare("Select name from ethnicity where code = ?");
1438 $sth->execute($ethnicity);
1439 my $data = $sth->fetchrow_hashref;
1441 return $data->{'name'};
1442 } # sub fixEthnicity
1446 $dateofbirth,$date = &GetAge($date);
1448 this function return the borrowers age with the value of dateofbirth
1454 my ( $date, $date_ref ) = @_;
1456 if ( not defined $date_ref ) {
1457 $date_ref = sprintf( '%04d-%02d-%02d', Today() );
1460 my ( $year1, $month1, $day1 ) = split /-/, $date;
1461 my ( $year2, $month2, $day2 ) = split /-/, $date_ref;
1463 my $age = $year2 - $year1;
1464 if ( $month1 . $day1 > $month2 . $day2 ) {
1471 =head2 get_institutions
1472 $insitutions = get_institutions();
1474 Just returns a list of all the borrowers of type I, borrownumber and name
1479 sub get_institutions {
1480 my $dbh = C4::Context->dbh();
1483 "SELECT borrowernumber,surname FROM borrowers WHERE categorycode=? ORDER BY surname"
1487 while ( my $data = $sth->fetchrow_hashref() ) {
1488 $orgs{ $data->{'borrowernumber'} } = $data;
1493 } # sub get_institutions
1495 =head2 add_member_orgs
1497 add_member_orgs($borrowernumber,$borrowernumbers);
1499 Takes a borrowernumber and a list of other borrowernumbers and inserts them into the borrowers_to_borrowers table
1504 sub add_member_orgs {
1505 my ( $borrowernumber, $otherborrowers ) = @_;
1506 my $dbh = C4::Context->dbh();
1508 "INSERT INTO borrowers_to_borrowers (borrower1,borrower2) VALUES (?,?)";
1509 my $sth = $dbh->prepare($query);
1510 foreach my $otherborrowernumber (@$otherborrowers) {
1511 $sth->execute( $borrowernumber, $otherborrowernumber );
1515 } # sub add_member_orgs
1517 =head2 GetCities (OUEST-PROVENCE)
1519 ($id_cityarrayref, $city_hashref) = &GetCities();
1521 Looks up the different city and zip in the database. Returns two
1522 elements: a reference-to-array, which lists the zip city
1523 codes, and a reference-to-hash, which maps the name of the city.
1524 WHERE =>OUEST PROVENCE OR EXTERIEUR
1530 #my ($type_city) = @_;
1531 my $dbh = C4::Context->dbh;
1532 my $query = qq|SELECT cityid,city_name
1534 ORDER BY city_name|;
1535 my $sth = $dbh->prepare($query);
1537 #$sth->execute($type_city);
1542 # insert empty value to create a empty choice in cgi popup
1544 while ( my $data = $sth->fetchrow_hashref ) {
1546 push @id, $data->{'cityid'};
1547 $city{ $data->{'cityid'} } = $data->{'city_name'};
1550 #test to know if the table contain some records if no the function return nothing
1558 return ( \@id, \%city );
1562 =head2 GetSortDetails (OUEST-PROVENCE)
1564 ($lib) = &GetSortDetails($category,$sortvalue);
1566 Returns the authorized value details
1567 C<&$lib>return value of authorized value details
1568 C<&$sortvalue>this is the value of authorized value
1569 C<&$category>this is the value of authorized value category
1573 sub GetSortDetails {
1574 my ( $category, $sortvalue ) = @_;
1575 my $dbh = C4::Context->dbh;
1576 my $query = qq|SELECT lib
1577 FROM authorised_values
1579 AND authorised_value=? |;
1580 my $sth = $dbh->prepare($query);
1581 $sth->execute( $category, $sortvalue );
1582 my $lib = $sth->fetchrow;
1586 =head2 DeleteBorrower
1588 () = &DeleteBorrower($member);
1590 delete all data fo borrowers and add record to deletedborrowers table
1591 C<&$member>this is the borrowernumber
1595 sub MoveMemberToDeleted {
1597 my $dbh = C4::Context->dbh;
1599 $query = qq|SELECT *
1601 WHERE borrowernumber=?|;
1602 my $sth = $dbh->prepare($query);
1603 $sth->execute($member);
1604 my @data = $sth->fetchrow_array;
1607 $dbh->prepare( "INSERT INTO deletedborrowers VALUES ("
1608 . ( "?," x ( scalar(@data) - 1 ) )
1610 $sth->execute(@data);
1616 DelMember($borrowernumber);
1618 This function remove directly a borrower whitout writing it on deleteborrower.
1619 + Deletes reserves for the borrower
1624 my $dbh = C4::Context->dbh;
1625 my $borrowernumber = shift;
1626 warn "in delmember with $borrowernumber";
1627 return unless $borrowernumber; # borrowernumber is mandatory.
1629 my $query = qq|DELETE
1631 WHERE borrowernumber=?|;
1632 my $sth = $dbh->prepare($query);
1633 $sth->execute($borrowernumber);
1638 WHERE borrowernumber = ?
1640 $sth = $dbh->prepare($query);
1641 $sth->execute($borrowernumber);
1643 &logaction(C4::Context->userenv->{'number'},"MEMBERS","DELETE",$borrowernumber,"")
1644 if C4::Context->preference("BorrowersLog");
1648 =head2 ExtendMemberSubscriptionTo (OUEST-PROVENCE)
1650 $date= ExtendMemberSubscriptionTo($borrowerid, $date);
1651 Extending the subscription to a given date or to the expiry date calculated on local date.
1655 sub ExtendMemberSubscriptionTo {
1656 my ( $borrowerid,$date) = @_;
1657 my $dbh = C4::Context->dbh;
1659 $date=POSIX::strftime("%Y-%m-%d",localtime(time));
1660 my $borrower = GetMember($borrowerid,'borrowernumber');
1661 $date = GetExpiryDate( $borrower->{'categorycode'}, $date );
1663 my $sth = $dbh->do(<<EOF);
1665 SET dateexpiry='$date'
1666 WHERE borrowernumber='$borrowerid'
1668 return $date if ($sth);
1672 =head2 GetRoadTypes (OUEST-PROVENCE)
1674 ($idroadtypearrayref, $roadttype_hashref) = &GetRoadTypes();
1676 Looks up the different road type . Returns two
1677 elements: a reference-to-array, which lists the id_roadtype
1678 codes, and a reference-to-hash, which maps the road type of the road .
1684 my $dbh = C4::Context->dbh;
1686 SELECT roadtypeid,road_type
1688 ORDER BY road_type|;
1689 my $sth = $dbh->prepare($query);
1694 # insert empty value to create a empty choice in cgi popup
1696 while ( my $data = $sth->fetchrow_hashref ) {
1698 push @id, $data->{'roadtypeid'};
1699 $roadtype{ $data->{'roadtypeid'} } = $data->{'road_type'};
1702 #test to know if the table contain some records if no the function return nothing
1710 return ( \@id, \%roadtype );
1716 =head2 GetTitles (OUEST-PROVENCE)
1718 ($borrowertitle)= &GetTitles();
1720 Looks up the different title . Returns array with all borrowers title
1725 my @borrowerTitle = split /,|\|/,C4::Context->preference('BorrowersTitles');
1726 unshift( @borrowerTitle, "" );
1727 return ( \@borrowerTitle);
1732 =head2 GetRoadTypeDetails (OUEST-PROVENCE)
1734 ($roadtype) = &GetRoadTypeDetails($roadtypeid);
1736 Returns the description of roadtype
1737 C<&$roadtype>return description of road type
1738 C<&$roadtypeid>this is the value of roadtype s
1742 sub GetRoadTypeDetails {
1743 my ($roadtypeid) = @_;
1744 my $dbh = C4::Context->dbh;
1748 WHERE roadtypeid=?|;
1749 my $sth = $dbh->prepare($query);
1750 $sth->execute($roadtypeid);
1751 my $roadtype = $sth->fetchrow;
1755 =head2 GetBorrowersWhoHaveNotBorrowedSince
1757 &GetBorrowersWhoHaveNotBorrowedSince($date)
1759 this function get all borrowers who haven't borrowed since the date given on input arg.
1763 sub GetBorrowersWhoHaveNotBorrowedSince {
1765 return unless $date; # date is mandatory.
1766 my $dbh = C4::Context->dbh;
1768 SELECT borrowers.borrowernumber,max(timestamp)
1770 LEFT JOIN issues ON borrowers.borrowernumber = issues.borrowernumber
1771 WHERE issues.borrowernumber IS NOT NULL
1772 GROUP BY borrowers.borrowernumber
1774 my $sth = $dbh->prepare($query);
1778 while ( my $data = $sth->fetchrow_hashref ) {
1779 push @results, $data;
1784 =head2 GetBorrowersWhoHaveNeverBorrowed
1786 $results = &GetBorrowersWhoHaveNeverBorrowed
1788 this function get all borrowers who have never borrowed.
1790 I<$result> is a ref to an array which all elements are a hasref.
1794 sub GetBorrowersWhoHaveNeverBorrowed {
1795 my $dbh = C4::Context->dbh;
1797 SELECT borrowers.borrowernumber,max(timestamp)
1799 LEFT JOIN issues ON borrowers.borrowernumber = issues.borrowernumber
1800 WHERE issues.borrowernumber IS NULL
1802 my $sth = $dbh->prepare($query);
1805 while ( my $data = $sth->fetchrow_hashref ) {
1806 push @results, $data;
1811 =head2 GetBorrowersWithIssuesHistoryOlderThan
1813 $results = &GetBorrowersWithIssuesHistoryOlderThan($date)
1815 this function get all borrowers who has an issue history older than I<$date> given on input arg.
1817 I<$result> is a ref to an array which all elements are a hashref.
1818 This hashref is containt the number of time this borrowers has borrowed before I<$date> and the borrowernumber.
1822 sub GetBorrowersWithIssuesHistoryOlderThan {
1823 my $dbh = C4::Context->dbh;
1825 return unless $date; # date is mandatory.
1827 SELECT count(borrowernumber) as n,borrowernumber
1829 WHERE returndate < ?
1830 AND borrowernumber IS NOT NULL
1831 GROUP BY borrowernumber
1833 my $sth = $dbh->prepare($query);
1834 $sth->execute($date);
1837 while ( my $data = $sth->fetchrow_hashref ) {
1838 push @results, $data;
1843 END { } # module clean-up code here (global destructor)