@@ -, +, @@
- 1 new syspref CardnumberLength. 2 formats: a number or a range
(xx,yy).
- 1 new unit test file t/Members/checkcardnumber.t for the
---
C4/Members.pm | 43 +++++++++----
installer/data/mysql/updatedatabase.pl | 11 +++
.../prog/en/modules/admin/preferences/patrons.pref | 4 +
.../prog/en/modules/members/memberentrygen.tt | 34 ++++++----
.../prog/en/modules/tools/import_borrowers.tt | 6 ++
members/memberentry.pl | 20 ++++++-
t/Members/checkcardnumber.t | 66 ++++++++++++++++++++
tools/import_borrowers.pl | 13 ++++-
8 files changed, 167 insertions(+), 30 deletions(-)
create mode 100644 t/Members/checkcardnumber.t
--- a/C4/Members.pm
+++ a/C4/Members.pm
@@ -1329,25 +1329,40 @@ sub checkuniquemember {
}
sub checkcardnumber {
- my ($cardnumber,$borrowernumber) = @_;
+ my ( $cardnumber, $borrowernumber ) = @_;
+
# If cardnumber is null, we assume they're allowed.
- return 0 if !defined($cardnumber);
+ return 0 unless defined $cardnumber;
+
my $dbh = C4::Context->dbh;
my $query = "SELECT * FROM borrowers WHERE cardnumber=?";
$query .= " AND borrowernumber <> ?" if ($borrowernumber);
- my $sth = $dbh->prepare($query);
- if ($borrowernumber) {
- $sth->execute($cardnumber,$borrowernumber);
- } else {
- $sth->execute($cardnumber);
- }
- if (my $data= $sth->fetchrow_hashref()){
- return 1;
- }
- else {
- return 0;
+ my $sth = $dbh->prepare($query);
+ $sth->execute(
+ $cardnumber,
+ ( $borrowernumber ? $borrowernumber : () )
+ );
+
+ return 1 if $sth->fetchrow_hashref;
+
+ if ( my $length = C4::Context->preference('CardnumberLength') ) {
+ # Is integer and length match
+ if (
+ $length =~ m|^\d+$|
+ and length $cardnumber == $length
+ ) {
+ return 0
+ }
+ # Else assuming it is a range
+ else {
+ my $qr = qr|^\d{$length}$|;
+ return 0
+ if $cardnumber =~ $qr;
+ }
+ return 1
}
-}
+ return 0;
+}
=head2 getzipnamecity (OUEST-PROVENCE)
--- a/installer/data/mysql/updatedatabase.pl
+++ a/installer/data/mysql/updatedatabase.pl
@@ -7853,6 +7853,17 @@ if ( CheckVersion($DBversion) ) {
SetVersion ($DBversion);
}
+$DBversion = "3.15.00.XXX";
+if ( CheckVersion($DBversion) ) {
+ $dbh->do("
+ INSERT INTO systempreferences (variable,value,options,explanation,type)
+ VALUES('CardnumberLength', '', '', 'Set a length for card numbers.', 'Free');
+ ");
+ print "Upgrade to $DBversion done (Bug 10861: Add CardnumberLength syspref)\n";
+ SetVersion ($DBversion);
+}
+
+
=head1 FUNCTIONS
=head2 TableExists($table)
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref
+++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref
@@ -139,3 +139,7 @@ Patrons:
yes: Do
no: "Don't"
- enable the ability to upload and attach arbitrary files to a borrower record.
+ -
+ - Card numbers for patrons must be strictly equal to
+ - pref: CardnumberLength
+ - characters. The length can be a simple number or a range separated by a coma (xx,yy).
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt
+++ a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt
@@ -178,9 +178,9 @@
[% IF ( ERROR_login_exist ) %]
Username/password already exists.
[% END %]
- [% IF ( ERROR_cardnumber ) %]
- Cardnumber already in use.
- [% END %]
+ [% IF ( ERROR_cardnumber ) %]
+ Cardnumber already in use or not in a good format.
+ [% END %]
[% IF ( ERROR_age_limitations ) %]
Patron's age is incorrect for their category.
Ages allowed are [% age_low %]-[% age_high %].
@@ -878,17 +878,23 @@