Lines 33-38
use C4::Accounts;
Link Here
|
33 |
use C4::Biblio; |
33 |
use C4::Biblio; |
34 |
use C4::SQLHelper qw(InsertInTable UpdateInTable SearchInTable); |
34 |
use C4::SQLHelper qw(InsertInTable UpdateInTable SearchInTable); |
35 |
use C4::Members::Attributes qw(SearchIdMatchingAttribute); |
35 |
use C4::Members::Attributes qw(SearchIdMatchingAttribute); |
|
|
36 |
use C4::Branch qw(GetBranchDetail); |
36 |
|
37 |
|
37 |
our ($VERSION,@ISA,@EXPORT,@EXPORT_OK,$debug); |
38 |
our ($VERSION,@ISA,@EXPORT,@EXPORT_OK,$debug); |
38 |
|
39 |
|
Lines 168-177
sub _express_member_find {
Link Here
|
168 |
# so we can check an exact match first, if that works return, otherwise do the rest |
169 |
# so we can check an exact match first, if that works return, otherwise do the rest |
169 |
my $dbh = C4::Context->dbh; |
170 |
my $dbh = C4::Context->dbh; |
170 |
my $query = "SELECT borrowernumber FROM borrowers WHERE cardnumber = ?"; |
171 |
my $query = "SELECT borrowernumber FROM borrowers WHERE cardnumber = ?"; |
171 |
if ( my $borrowernumber = $dbh->selectrow_array($query, undef, $filter) ) { |
172 |
my $cardnum = _prefix_cardnum($filter); |
|
|
173 |
if ( my $borrowernumber = $dbh->selectrow_array($query, undef, $cardnum) ) { |
172 |
return( {"borrowernumber"=>$borrowernumber} ); |
174 |
return( {"borrowernumber"=>$borrowernumber} ); |
173 |
} |
175 |
} |
174 |
|
|
|
175 |
my ($search_on_fields, $searchtype); |
176 |
my ($search_on_fields, $searchtype); |
176 |
if ( length($filter) == 1 ) { |
177 |
if ( length($filter) == 1 ) { |
177 |
$search_on_fields = [ qw(surname) ]; |
178 |
$search_on_fields = [ qw(surname) ]; |
Lines 710-715
sub ModMember {
Link Here
|
710 |
$data{password} = md5_base64($data{password}); |
711 |
$data{password} = md5_base64($data{password}); |
711 |
} |
712 |
} |
712 |
} |
713 |
} |
|
|
714 |
|
715 |
# modify cardnumber with prefix, if needed. |
716 |
if(C4::Context->preference('patronbarcodelength') && exists($data{'cardnumber'})){ |
717 |
$data{'cardnumber'} = _prefix_cardnum($data{'cardnumber'}); |
718 |
} |
719 |
|
713 |
my $execute_success=UpdateInTable("borrowers",\%data); |
720 |
my $execute_success=UpdateInTable("borrowers",\%data); |
714 |
if ($execute_success) { # only proceed if the update was a success |
721 |
if ($execute_success) { # only proceed if the update was a success |
715 |
# ok if its an adult (type) it may have borrowers that depend on it as a guarantor |
722 |
# ok if its an adult (type) it may have borrowers that depend on it as a guarantor |
Lines 745-750
sub AddMember {
Link Here
|
745 |
$data{'userid'} = Generate_Userid($data{'borrowernumber'}, $data{'firstname'}, $data{'surname'}) if $data{'userid'} eq ''; |
752 |
$data{'userid'} = Generate_Userid($data{'borrowernumber'}, $data{'firstname'}, $data{'surname'}) if $data{'userid'} eq ''; |
746 |
# create a disabled account if no password provided |
753 |
# create a disabled account if no password provided |
747 |
$data{'password'} = ($data{'password'})? md5_base64($data{'password'}) : '!'; |
754 |
$data{'password'} = ($data{'password'})? md5_base64($data{'password'}) : '!'; |
|
|
755 |
$data{'cardnumber'} = _prefix_cardnum($data{'cardnumber'}) if(C4::Context->preference('patronbarcodelength')); |
756 |
|
748 |
$data{'borrowernumber'}=InsertInTable("borrowers",\%data); |
757 |
$data{'borrowernumber'}=InsertInTable("borrowers",\%data); |
749 |
# mysql_insertid is probably bad. not necessarily accurate and mysql-specific at best. |
758 |
# mysql_insertid is probably bad. not necessarily accurate and mysql-specific at best. |
750 |
logaction("MEMBERS", "CREATE", $data{'borrowernumber'}, "") if C4::Context->preference("BorrowersLog"); |
759 |
logaction("MEMBERS", "CREATE", $data{'borrowernumber'}, "") if C4::Context->preference("BorrowersLog"); |
Lines 838-845
mode, to avoid database corruption.
Link Here
|
838 |
use vars qw( @weightings ); |
847 |
use vars qw( @weightings ); |
839 |
my @weightings = ( 8, 4, 6, 3, 5, 2, 1 ); |
848 |
my @weightings = ( 8, 4, 6, 3, 5, 2, 1 ); |
840 |
|
849 |
|
841 |
sub fixup_cardnumber ($) { |
850 |
sub fixup_cardnumber { |
842 |
my ($cardnumber) = @_; |
851 |
my ($cardnumber,$branch) = @_; |
843 |
my $autonumber_members = C4::Context->boolean_preference('autoMemberNum') || 0; |
852 |
my $autonumber_members = C4::Context->boolean_preference('autoMemberNum') || 0; |
844 |
|
853 |
|
845 |
# Find out whether member numbers should be generated |
854 |
# Find out whether member numbers should be generated |
Lines 887-903
sub fixup_cardnumber ($) {
Link Here
|
887 |
|
896 |
|
888 |
return "V$cardnumber$rem"; |
897 |
return "V$cardnumber$rem"; |
889 |
} else { |
898 |
} else { |
|
|
899 |
my $cardlength = C4::Context->preference('patronbarcodelength'); |
900 |
if (defined($cardnumber) && (length($cardnumber) == $cardlength) && $cardnumber =~ m/^$branch->{'patronbarcodeprefix'}/ ) { |
901 |
return $cardnumber; |
902 |
} |
890 |
|
903 |
|
891 |
# MODIFIED BY JF: mysql4.1 allows casting as an integer, which is probably |
904 |
# increment operator without cast(int) should be safe, and should properly increment |
892 |
# better. I'll leave the original in in case it needs to be changed for you |
905 |
# whether the string is numeric or not. |
893 |
# my $sth=$dbh->prepare("select max(borrowers.cardnumber) from borrowers"); |
906 |
# FIXME : This needs to be pulled out into an ajax function, since the interface allows on-the-fly changing of patron home library. |
894 |
my $sth = $dbh->prepare( |
907 |
# |
895 |
"select max(cast(cardnumber as signed)) from borrowers" |
908 |
my $query = "select max(borrowers.cardnumber) from borrowers "; |
896 |
); |
909 |
my @bind; |
897 |
$sth->execute; |
910 |
my $firstnumber = 0; |
898 |
my ($result) = $sth->fetchrow; |
911 |
if($branch->{'patronbarcodeprefix'} && $cardlength) { |
899 |
return $result + 1; |
912 |
my $cardnum_search = $branch->{'patronbarcodeprefix'} . '%'; |
900 |
} |
913 |
$query .= " WHERE cardnumber LIKE ?"; |
|
|
914 |
$query .= " AND length(cardnumber) = ?"; |
915 |
@bind = ($cardnum_search,$cardlength ) ; |
916 |
} |
917 |
my $sth= $dbh->prepare($query); |
918 |
$sth->execute(@bind); |
919 |
my ($result) = $sth->fetchrow; |
920 |
$sth->finish; |
921 |
if($result) { |
922 |
my $cnt = 0; |
923 |
$result =~ s/^$branch->{'patronbarcodeprefix'}//; |
924 |
while ( $result =~ /([a-zA-Z]*[0-9]*)\z/ ) { # use perl's magical stringcrement behavior (++). |
925 |
my $incrementable = $1; |
926 |
$incrementable++; |
927 |
if ( length($incrementable) > length($1) ) { # carry a digit to next incrementable fragment |
928 |
$cardnumber = substr($incrementable,1) . $cardnumber; |
929 |
$result = $`; |
930 |
} else { |
931 |
$cardnumber = $branch->{'patronbarcodeprefix'} . $` . $incrementable . $cardnumber ; |
932 |
last; |
933 |
} |
934 |
last if(++$cnt>10); |
935 |
} |
936 |
} else { |
937 |
$cardnumber = ++$firstnumber ; |
938 |
} |
939 |
} |
901 |
return $cardnumber; # just here as a fallback/reminder |
940 |
return $cardnumber; # just here as a fallback/reminder |
902 |
} |
941 |
} |
903 |
|
942 |
|
Lines 2229-2234
sub DeleteMessage {
Link Here
|
2229 |
logaction("MEMBERS", "DELCIRCMESSAGE", $message->{'borrowernumber'}, $message->{'message'}) if C4::Context->preference("BorrowersLog"); |
2268 |
logaction("MEMBERS", "DELCIRCMESSAGE", $message->{'borrowernumber'}, $message->{'message'}) if C4::Context->preference("BorrowersLog"); |
2230 |
} |
2269 |
} |
2231 |
|
2270 |
|
|
|
2271 |
=head2 _prefix_cardnum |
2272 |
|
2273 |
=over 4 |
2274 |
|
2275 |
$cardnum = _prefix_cardnum($cardnum,$branchcode); |
2276 |
|
2277 |
If a system-wide barcode length is defined, and a prefix defined for the passed branch or the user's branch, |
2278 |
modify the barcode by prefixing and padding. |
2279 |
|
2280 |
=back |
2281 |
=cut |
2282 |
|
2283 |
sub _prefix_cardnum{ |
2284 |
my ($cardnum,$branchcode) = @_; |
2285 |
|
2286 |
if(C4::Context->preference('patronbarcodelength') && (length($cardnum) < C4::Context->preference('patronbarcodelength'))) { |
2287 |
#if we have a system-wide cardnum length and a branch prefix, prepend the prefix. |
2288 |
if( ! $branchcode && defined(C4::Context->userenv) ) { |
2289 |
$branchcode = C4::Context->userenv->{'branch'}; |
2290 |
} |
2291 |
return $cardnum unless $branchcode; |
2292 |
my $branch = GetBranchDetail( $branchcode ); |
2293 |
return $cardnum unless( defined($branch) && defined($branch->{'patronbarcodeprefix'}) ); |
2294 |
my $prefix = $branch->{'patronbarcodeprefix'} ; |
2295 |
my $padding = C4::Context->preference('patronbarcodelength') - length($prefix) - length($cardnum) ; |
2296 |
$cardnum = $prefix . '0' x $padding . $cardnum if($padding >= 0) ; |
2297 |
} |
2298 |
return $cardnum; |
2299 |
} |
2300 |
|
2232 |
END { } # module clean-up code here (global destructor) |
2301 |
END { } # module clean-up code here (global destructor) |
2233 |
|
2302 |
|
2234 |
1; |
2303 |
1; |