From 785af7310daa4633359755add9474e81f108d022 Mon Sep 17 00:00:00 2001 From: Robin Sheat Date: Tue, 21 Jun 2011 07:54:55 -0400 Subject: [PATCH] Bug 6521 - allow blank cardnumbers to not trigger "already in use" Now a blank cardnumber will get stored as a null in the database, which is a value that allows duplicates. As such, if cardnumbers aren't mandatory, then you can actually save a user with it being blank. Signed-off-by: Nicole C. Engard Signed-off-by: Chris Cormack --- C4/Members.pm | 3 +++ members/memberentry.pl | 28 +++++++++++++++------------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/C4/Members.pm b/C4/Members.pm index e03b40b545..c6c6985129 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -900,6 +900,7 @@ sub fixup_cardnumber ($) { # if ($cardnumber !~ /\S/ && $autonumber_members) { ($autonumber_members) or return $cardnumber; + defined($cardnumber) or return $cardnumber; my $checkdigit = C4::Context->preference('checkdigit'); my $dbh = C4::Context->dbh; if ( $checkdigit and $checkdigit eq 'katipo' ) { @@ -1261,6 +1262,8 @@ sub checkuniquemember { sub checkcardnumber { my ($cardnumber,$borrowernumber) = @_; + # If cardnumber is null, we assume they're allowed. + return 0 if !defined($cardnumber); my $dbh = C4::Context->dbh; my $query = "SELECT * FROM borrowers WHERE cardnumber=?"; $query .= " AND borrowernumber <> ?" if ($borrowernumber); diff --git a/members/memberentry.pl b/members/memberentry.pl index 61c3c2ca20..be34cc41b0 100755 --- a/members/memberentry.pl +++ b/members/memberentry.pl @@ -236,19 +236,22 @@ if ( (defined $newdata{'userid'}) && ($newdata{'userid'} eq '')){ $debug and warn join "\t", map {"$_: $newdata{$_}"} qw(dateofbirth dateenrolled dateexpiry); my $extended_patron_attributes = (); if ($op eq 'save' || $op eq 'insert'){ - if (checkcardnumber($newdata{cardnumber},$newdata{borrowernumber})){ - push @errors, 'ERROR_cardnumber'; - } - my $dateofbirthmandatory = (scalar grep {$_ eq "dateofbirth"} @field_check) ? 1 : 0; - if ($newdata{dateofbirth} && $dateofbirthmandatory) { - my $age = GetAge($newdata{dateofbirth}); - my $borrowercategory=GetBorrowercategory($newdata{'categorycode'}); - my ($low,$high) = ($borrowercategory->{'dateofbirthrequired'}, $borrowercategory->{'upperagelimit'}); - if (($high && ($age > $high)) or ($age < $low)) { - push @errors, 'ERROR_age_limitations'; - $template->param('ERROR_age_limitations' => "$low to $high"); + # If the cardnumber is blank, treat it as null. + $newdata{'cardnumber'} = undef if $newdata{'cardnumber'} =~ /^\s*$/; + + if (checkcardnumber($newdata{cardnumber},$newdata{borrowernumber})){ + push @errors, 'ERROR_cardnumber'; + } + my $dateofbirthmandatory = (scalar grep {$_ eq "dateofbirth"} @field_check) ? 1 : 0; + if ($newdata{dateofbirth} && $dateofbirthmandatory) { + my $age = GetAge($newdata{dateofbirth}); + my $borrowercategory=GetBorrowercategory($newdata{'categorycode'}); + my ($low,$high) = ($borrowercategory->{'dateofbirthrequired'}, $borrowercategory->{'upperagelimit'}); + if (($high && ($age > $high)) or ($age < $low)) { + push @errors, 'ERROR_age_limitations'; + $template->param('ERROR_age_limitations' => "$low to $high"); + } } - } if($newdata{surname} && C4::Context->preference('uppercasesurnames')) { $newdata{'surname'} = uc($newdata{'surname'}); @@ -396,7 +399,6 @@ if ( $op eq "duplicate" ) { $template->param( step_1 => 1, step_2 => 1, step_3 => 1, step_4 => 1, step_5 => 1, step_6 => 1 ) unless $step; } -# my $cardnumber=$data{'cardnumber'}; $data{'cardnumber'}=fixup_cardnumber($data{'cardnumber'}) if $op eq 'add'; if(!defined($data{'sex'})){ $template->param( none => 1); -- 2.39.5