View | Details | Raw Unified | Return to bug 10861
Collapse All | Expand All

(-)a/C4/Members.pm (-13 / +18 lines)
Lines 1343-1368 sub checkcardnumber { Link Here
1343
1343
1344
    return 1 if $sth->fetchrow_hashref;
1344
    return 1 if $sth->fetchrow_hashref;
1345
1345
1346
    if ( my $length = C4::Context->preference('CardnumberLength') ) {
1346
    my ( $min_length, $max_length ) = get_cardnumber_length();
1347
    return 2
1348
        if length $cardnumber > $max_length
1349
        or length $cardnumber < $min_length;
1350
1351
    return 0;
1352
}
1353
1354
sub get_cardnumber_length {
1355
    my ( $min, $max ) = ( 0, 16 );
1356
    if ( my $cardnumber_length = C4::Context->preference('CardnumberLength') ) {
1347
        # Is integer and length match
1357
        # Is integer and length match
1348
        if (
1358
        if ( $cardnumber_length =~ m|^\d+$| ) {
1349
            $length =~ m|^\d+$|
1359
            $min = $max = $cardnumber_length;
1350
                and length $cardnumber == $length
1351
        ) {
1352
            return 0
1353
        }
1360
        }
1354
        # Else assuming it is a range
1361
        # Else assuming it is a range
1355
        else {
1362
        elsif ( $cardnumber_length =~ m|(\d+),(\d*)| ) {
1356
            my $qr = qr|^\d{$length}$|;
1363
            $min = $1;
1357
            return 0
1364
            $max = $2 || 16; # borrowers.cardnumber is a varchar(16)
1358
                if $cardnumber =~ $qr;
1359
        }
1365
        }
1360
        return 1
1366
1361
    }
1367
    }
1362
    return 0;
1368
    return ( $min, $max );
1363
}
1369
}
1364
1370
1365
1366
=head2 getzipnamecity (OUEST-PROVENCE)
1371
=head2 getzipnamecity (OUEST-PROVENCE)
1367
1372
1368
take all info from table city for the fields city and  zip
1373
take all info from table city for the fields city and  zip
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt (-6 / +5 lines)
Lines 152-159 Link Here
152
			[% IF ( ERROR_login_exist ) %]
152
			[% IF ( ERROR_login_exist ) %]
153
				<li id="ERROR_login_exist">Username/password already exists.</li>
153
				<li id="ERROR_login_exist">Username/password already exists.</li>
154
			[% END %]
154
			[% END %]
155
            [% IF ( ERROR_cardnumber ) %]
155
            [% IF ERROR_cardnumber_already_exists %]
156
                <li id="ERROR_cardnumber">Cardnumber already in use or not in a good format.</li>
156
                <li id="ERROR_cardnumber">Cardnumber already in use.</li>
157
            [% END %]
158
            [% IF ERROR_cardnumber_length %]
159
                <li id="ERROR_cardnumber">Cardnumber length is incorrect.</li>
157
            [% END %]
160
            [% END %]
158
			[% IF ( ERROR_age_limitations ) %]
161
			[% IF ( ERROR_age_limitations ) %]
159
				<li id="ERROR_age_limitations">Patron's age is incorrect for their category.  
162
				<li id="ERROR_age_limitations">Patron's age is incorrect for their category.  
Lines 860-870 Link Here
860
            <label for="cardnumber">
863
            <label for="cardnumber">
861
          [% END %]
864
          [% END %]
862
          Card number: </label>
865
          Card number: </label>
863
          [% IF minlength_cardnumber && maxlength_cardnumber %]
864
              <input type="text" id="cardnumber" name="cardnumber" size="20" value="[% cardnumber %]" pattern=".{[% minlength_cardnumber %],[% maxlength_cardnumber %]}" title="between [% minlength_cardnumber %] and [% maxlength_cardnumber %] characters" />
865
          [% ELSE %]
866
              <input type="text" id="cardnumber" name="cardnumber" size="20" value="[% cardnumber %]" />
866
              <input type="text" id="cardnumber" name="cardnumber" size="20" value="[% cardnumber %]" />
867
          [% END %]
868
          [% IF ( mandatorycardnumber ) %]<span class="required">Required</span>[% END %]
867
          [% IF ( mandatorycardnumber ) %]<span class="required">Required</span>[% END %]
869
        </li>
868
        </li>
870
      [% END %]
869
      [% END %]
(-)a/members/memberentry.pl (-20 / +15 lines)
Lines 274-282 if ($op eq 'save' || $op eq 'insert'){ Link Here
274
    # If the cardnumber is blank, treat it as null.
274
    # If the cardnumber is blank, treat it as null.
275
    $newdata{'cardnumber'} = undef if $newdata{'cardnumber'} =~ /^\s*$/;
275
    $newdata{'cardnumber'} = undef if $newdata{'cardnumber'} =~ /^\s*$/;
276
276
277
    if (checkcardnumber($newdata{cardnumber},$newdata{borrowernumber})){ 
277
    if (my $error_code = checkcardnumber($newdata{cardnumber},$newdata{borrowernumber})){
278
        push @errors, 'ERROR_cardnumber';
278
        push @errors, $error_code == 1
279
    } 
279
            ? 'ERROR_cardnumber_already_exists'
280
            : $error_code == 2
281
                ? 'ERROR_cardnumber_length'
282
                : ()
283
    }
284
280
    if ($newdata{dateofbirth} && $dateofbirthmandatory) {
285
    if ($newdata{dateofbirth} && $dateofbirthmandatory) {
281
        my $age = GetAge($newdata{dateofbirth});
286
        my $age = GetAge($newdata{dateofbirth});
282
        my $borrowercategory=GetBorrowercategory($newdata{'categorycode'});   
287
        my $borrowercategory=GetBorrowercategory($newdata{'categorycode'});   
Lines 727-749 if(defined($data{'contacttitle'})){ Link Here
727
  $template->param("contacttitle_" . $data{'contacttitle'} => "SELECTED");
732
  $template->param("contacttitle_" . $data{'contacttitle'} => "SELECTED");
728
}
733
}
729
734
730
if ( my $cardnumber_length = C4::Context->preference('CardnumberLength') ) {
735
731
    my ( $min, $max );
736
my ( $min, $max ) = C4::Members::get_cardnumber_length();
732
    # Is integer and length match
737
if ( defined $min ) {
733
    if ( $cardnumber_length =~ m|^\d+$| ) {
738
    $template->param(
734
        $min = $max = $cardnumber_length;
739
        minlength_cardnumber => $min,
735
    }
740
        maxlength_cardnumber => $max
736
    # Else assuming it is a range
741
    );
737
    elsif ( $cardnumber_length =~ m|(\d+),(\d*)| ) {
738
        $min = $1;
739
        $max = $2 || 16; # borrowers.cardnumber is a varchar(16)
740
    }
741
    if ( defined $min ) {
742
        $template->param(
743
            minlength_cardnumber => $min,
744
            maxlength_cardnumber => $max
745
        );
746
    }
747
}
742
}
748
743
749
output_html_with_http_headers $input, $cookie, $template->output;
744
output_html_with_http_headers $input, $cookie, $template->output;
(-)a/t/Members/checkcardnumber.t (-11 / +15 lines)
Lines 1-7 Link Here
1
#!/usr/bin/env perl
1
#!/usr/bin/env perl
2
2
3
use Modern::Perl;
3
use Modern::Perl;
4
use Test::More tests =>14;
4
use Test::More tests =>18;
5
5
6
use Test::MockModule;
6
use Test::MockModule;
7
use DBD::Mock;
7
use DBD::Mock;
Lines 23-65 my $rs = []; Link Here
23
23
24
my $pref = "10";
24
my $pref = "10";
25
set_pref( $module_context, $pref );
25
set_pref( $module_context, $pref );
26
26
is_deeply( [ C4::Members::get_cardnumber_length() ], [ 10, 10 ], '10 => min=10 and max=10');
27
$dbh->{mock_add_resultset} = $rs;
27
$dbh->{mock_add_resultset} = $rs;
28
is( C4::Members::checkcardnumber( q{123456789} ), 1, "123456789 is shorter than $pref");
28
is( C4::Members::checkcardnumber( q{123456789} ), 2, "123456789 is shorter than $pref");
29
$dbh->{mock_add_resultset} = $rs;
29
$dbh->{mock_add_resultset} = $rs;
30
is( C4::Members::checkcardnumber( q{12345678901234567890} ), 1, "12345678901234567890 is longer than $pref");
30
is( C4::Members::checkcardnumber( q{1234567890123456} ), 2, "1234567890123456 is longer than $pref");
31
$dbh->{mock_add_resultset} = $rs;
31
$dbh->{mock_add_resultset} = $rs;
32
is( C4::Members::checkcardnumber( q{1234567890} ), 0, "1234567890 is equal to $pref");
32
is( C4::Members::checkcardnumber( q{1234567890} ), 0, "1234567890 is equal to $pref");
33
33
34
$pref = q|10,10|; # Same as before !
34
$pref = q|10,10|; # Same as before !
35
set_pref( $module_context, $pref );
35
set_pref( $module_context, $pref );
36
is_deeply( [ C4::Members::get_cardnumber_length() ], [ 10, 10 ], '10,10 => min=10 and max=10');
36
$dbh->{mock_add_resultset} = $rs;
37
$dbh->{mock_add_resultset} = $rs;
37
is( C4::Members::checkcardnumber( q{123456789} ), 1, "123456789 is shorter than $pref");
38
is( C4::Members::checkcardnumber( q{123456789} ), 2, "123456789 is shorter than $pref");
38
$dbh->{mock_add_resultset} = $rs;
39
$dbh->{mock_add_resultset} = $rs;
39
is( C4::Members::checkcardnumber( q{12345678901234567890} ), 1, "12345678901234567890 is longer than $pref");
40
is( C4::Members::checkcardnumber( q{1234567890123456} ), 2, "1234567890123456 is longer than $pref");
40
$dbh->{mock_add_resultset} = $rs;
41
$dbh->{mock_add_resultset} = $rs;
41
is( C4::Members::checkcardnumber( q{1234567890} ), 0, "1234567890 is equal to $pref");
42
is( C4::Members::checkcardnumber( q{1234567890} ), 0, "1234567890 is equal to $pref");
42
43
43
$pref = q|8,10|; # between 8 and 10 chars
44
$pref = q|8,10|; # between 8 and 10 chars
44
set_pref( $module_context, $pref );
45
set_pref( $module_context, $pref );
46
is_deeply( [ C4::Members::get_cardnumber_length() ], [ 8, 10 ], '8,10 => min=8 and max=10');
45
$dbh->{mock_add_resultset} = $rs;
47
$dbh->{mock_add_resultset} = $rs;
46
is( C4::Members::checkcardnumber( q{12345678} ), 0, "12345678 matches $pref");
48
is( C4::Members::checkcardnumber( q{12345678} ), 0, "12345678 matches $pref");
47
$dbh->{mock_add_resultset} = $rs;
49
$dbh->{mock_add_resultset} = $rs;
48
is( C4::Members::checkcardnumber( q{12345678901234567890} ), 1, "12345678901234567890 is longer than $pref");
50
is( C4::Members::checkcardnumber( q{1234567890123456} ), 2, "1234567890123456 is longer than $pref");
49
$dbh->{mock_add_resultset} = $rs;
51
$dbh->{mock_add_resultset} = $rs;
50
is( C4::Members::checkcardnumber( q{1234567} ), 1, "1234567 is shorter than $pref");
52
is( C4::Members::checkcardnumber( q{1234567} ), 2, "1234567 is shorter than $pref");
51
$dbh->{mock_add_resultset} = $rs;
53
$dbh->{mock_add_resultset} = $rs;
52
is( C4::Members::checkcardnumber( q{1234567890} ), 0, "1234567890 matches $pref");
54
is( C4::Members::checkcardnumber( q{1234567890} ), 0, "1234567890 matches $pref");
53
55
54
$pref = q|8,|; # At least 8 chars
56
$pref = q|8,|; # At least 8 chars
55
set_pref( $module_context, $pref );
57
set_pref( $module_context, $pref );
58
is_deeply( [ C4::Members::get_cardnumber_length() ], [ 8, 16 ], '8, => min=8 and max=16');
56
$dbh->{mock_add_resultset} = $rs;
59
$dbh->{mock_add_resultset} = $rs;
57
is( C4::Members::checkcardnumber( q{1234567} ), 1, "1234567 is shorter than $pref");
60
is( C4::Members::checkcardnumber( q{1234567} ), 2, "1234567 is shorter than $pref");
58
$dbh->{mock_add_resultset} = $rs;
61
$dbh->{mock_add_resultset} = $rs;
59
is( C4::Members::checkcardnumber( q{12345678901234567890} ), 0, "12345678901234567890 matches $pref");
62
is( C4::Members::checkcardnumber( q{1234567890123456} ), 0, "1234567890123456 matches $pref");
60
$dbh->{mock_add_resultset} = $rs;
63
$dbh->{mock_add_resultset} = $rs;
61
is( C4::Members::checkcardnumber( q{1234567890} ), 0, "12345678 matches $pref");
64
is( C4::Members::checkcardnumber( q{1234567890} ), 0, "12345678 matches $pref");
62
65
66
67
63
sub set_pref {
68
sub set_pref {
64
    my ( $module, $value ) = @_;
69
    my ( $module, $value ) = @_;
65
    $module->mock('preference', sub { return $value } );
70
    $module->mock('preference', sub { return $value } );
66
- 

Return to bug 10861