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

(-)a/C4/Members.pm (-5 / +7 lines)
Lines 1352-1367 sub checkcardnumber { Link Here
1352
}
1352
}
1353
1353
1354
sub get_cardnumber_length {
1354
sub get_cardnumber_length {
1355
    my ( $min, $max ) = ( 0, 16 );
1355
    my ( $min, $max ) = ( 1, 16 ); # borrowers.cardnumber is a varchar(16)
1356
    if ( my $cardnumber_length = C4::Context->preference('CardnumberLength') ) {
1356
    if ( my $cardnumber_length = C4::Context->preference('CardnumberLength') ) {
1357
        # Is integer and length match
1357
        # Is integer and length match
1358
        if ( $cardnumber_length =~ m|^\d+$| ) {
1358
        if ( $cardnumber_length =~ m|^\d+$| ) {
1359
            $min = $max = $cardnumber_length;
1359
            $min = $max = $cardnumber_length
1360
                if $cardnumber_length >= $min
1361
                    and $cardnumber_length <= $max;
1360
        }
1362
        }
1361
        # Else assuming it is a range
1363
        # Else assuming it is a range
1362
        elsif ( $cardnumber_length =~ m|(\d+),(\d*)| ) {
1364
        elsif ( $cardnumber_length =~ m|(\d*),(\d*)| ) {
1363
            $min = $1;
1365
            $min = $1 if $1 and $min < $1;
1364
            $max = $2 || 16; # borrowers.cardnumber is a varchar(16)
1366
            $max = $2 if $2 and $max > $2;
1365
        }
1367
        }
1366
1368
1367
    }
1369
    }
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt (-1 / +7 lines)
Lines 863-869 Link Here
863
            <label for="cardnumber">
863
            <label for="cardnumber">
864
          [% END %]
864
          [% END %]
865
          Card number: </label>
865
          Card number: </label>
866
              <input type="text" id="cardnumber" name="cardnumber" size="20" value="[% cardnumber %]" />
866
          [% IF minlength_cardnumber == maxlength_cardnumber %]
867
              <input type="text" id="cardnumber" name="cardnumber" size="20" value="[% cardnumber %]" pattern=".{[% minlength_cardnumber %]}" title="Exactly [% minlength_cardnumber %] characters" />
868
          [% ELSIF minlength_cardnumber && maxlength_cardnumber %]
869
              <input type="text" id="cardnumber" name="cardnumber" size="20" value="[% cardnumber %]" pattern=".{[% minlength_cardnumber %],[% maxlength_cardnumber %]}" title="between [% minlength_cardnumber %] and [% maxlength_cardnumber %] characters" />
870
          [% ELSE %]
871
               <input type="text" id="cardnumber" name="cardnumber" size="20" value="[% cardnumber %]" />
872
          [% END %]
867
          [% IF ( mandatorycardnumber ) %]<span class="required">Required</span>[% END %]
873
          [% IF ( mandatorycardnumber ) %]<span class="required">Required</span>[% END %]
868
        </li>
874
        </li>
869
      [% END %]
875
      [% END %]
(-)a/t/Members/cardnumber.t (-3 / +11 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 =>18;
4
use Test::More tests => 22;
5
5
6
use Test::MockModule;
6
use Test::MockModule;
7
use DBD::Mock;
7
use DBD::Mock;
Lines 61-68 is( C4::Members::checkcardnumber( q{1234567} ), 2, "1234567 is shorter than $pre Link Here
61
$dbh->{mock_add_resultset} = $rs;
61
$dbh->{mock_add_resultset} = $rs;
62
is( C4::Members::checkcardnumber( q{1234567890123456} ), 0, "1234567890123456 matches $pref");
62
is( C4::Members::checkcardnumber( q{1234567890123456} ), 0, "1234567890123456 matches $pref");
63
$dbh->{mock_add_resultset} = $rs;
63
$dbh->{mock_add_resultset} = $rs;
64
is( C4::Members::checkcardnumber( q{1234567890} ), 0, "12345678 matches $pref");
64
is( C4::Members::checkcardnumber( q{1234567890} ), 0, "1234567890 matches $pref");
65
65
66
$pref = q|,8|; # max 8 chars
67
set_pref( $module_context, $pref );
68
is_deeply( [ C4::Members::get_cardnumber_length() ], [ 1, 8 ], ',8 => min=1 and max=8');
69
$dbh->{mock_add_resultset} = $rs;
70
is( C4::Members::checkcardnumber( q{1234567} ), 0, "1234567 matches $pref");
71
$dbh->{mock_add_resultset} = $rs;
72
is( C4::Members::checkcardnumber( q{1234567890123456} ), 2, "1234567890123456 is longer than $pref");
73
$dbh->{mock_add_resultset} = $rs;
74
is( C4::Members::checkcardnumber( q{1234567890} ), 2, "1234567890 is longer than $pref");
66
75
67
76
68
sub set_pref {
77
sub set_pref {
69
- 

Return to bug 10861