diff options
author | mark <mark> | 2010-03-09 21:57:52 +0000 |
---|---|---|
committer | mark <mark> | 2010-03-09 21:57:52 +0000 |
commit | 2dbf3fa84c7825aa02e168bc07a167ca9ad79620 (patch) | |
tree | 317bccc51f934e9b9425280c03e711168ab3c6e6 | |
parent | e84081ace9a19bd8007a74e8c062f4bc8d573e5d (diff) |
RT#7407, variable length prepaid card codes
-rw-r--r-- | FS/FS/prepay_credit.pm | 9 | ||||
-rw-r--r-- | httemplate/edit/prepay_credit.cgi | 5 | ||||
-rw-r--r-- | httemplate/edit/process/prepay_credit.cgi | 1 |
3 files changed, 10 insertions, 5 deletions
diff --git a/FS/FS/prepay_credit.pm b/FS/FS/prepay_credit.pm index 302ba37c7..e5773aebd 100644 --- a/FS/FS/prepay_credit.pm +++ b/FS/FS/prepay_credit.pm @@ -136,7 +136,7 @@ sub agent { =over 4 -=item generate NUM TYPE HASHREF +=item generate NUM TYPE LENGTH HASHREF Generates the specified number of prepaid cards. Returns an array reference of the newly generated card identifiers, or a scalar error message. @@ -145,11 +145,12 @@ the newly generated card identifiers, or a scalar error message. #false laziness w/agent::generate_reg_codes sub generate { - my( $num, $type, $hashref ) = @_; + my( $num, $type, $length, $hashref ) = @_; my @codeset = (); push @codeset, ( 'A'..'Z' ) if $type =~ /alpha/; push @codeset, ( '1'..'9' ) if $type =~ /numeric/; + $length ||= 8; local $SIG{HUP} = 'IGNORE'; local $SIG{INT} = 'IGNORE'; @@ -163,11 +164,11 @@ sub generate { my $dbh = dbh; my $condup = 0; #don't retry forever - + my @cards = (); for ( 1 ... $num ) { - my $identifier = join('', map($codeset[int(rand $#codeset)], (0..7) ) ); + my $identifier = join('', map($codeset[int(rand $#codeset)], (1..$length) ) ); redo if qsearchs('prepay_credit',{identifier=>$identifier}) && $condup++<23; $condup = 0; diff --git a/httemplate/edit/prepay_credit.cgi b/httemplate/edit/prepay_credit.cgi index ed404b7cd..f7a1b0801 100644 --- a/httemplate/edit/prepay_credit.cgi +++ b/httemplate/edit/prepay_credit.cgi @@ -7,13 +7,16 @@ Generate <INPUT TYPE="text" NAME="num" VALUE="<% $cgi->param('num') || '(quantity)' |h %>" SIZE=10 MAXLENGTH=10 onFocus="if ( this.value == '(quantity)' ) { this.value = ''; }"> +prepaid cards of + +<INPUT TYPE="text" NAME="length" SIZE=3 MAXLENGTH=2 VALUE=8> <SELECT NAME="type"> % foreach (qw(alpha alphanumeric numeric)) { <OPTION<% $cgi->param('type') eq $_ ? ' SELECTED' : '' %>><% $_ %> % } </SELECT> -prepaid cards +characters each <BR>for <SELECT NAME="agentnum"><OPTION>(any agent) % foreach my $opt_agent ( qsearch('agent', { 'disabled' => '' } ) ) { diff --git a/httemplate/edit/process/prepay_credit.cgi b/httemplate/edit/process/prepay_credit.cgi index 8f2eb2b25..a55522b86 100644 --- a/httemplate/edit/process/prepay_credit.cgi +++ b/httemplate/edit/process/prepay_credit.cgi @@ -56,6 +56,7 @@ $hashref->{totalbytes} = $cgi->param('totalbytes') * $cgi->param('totalmultiplie $error ||= FS::prepay_credit::generate( $num, scalar($cgi->param('type')), + $cgi->param('length'), $hashref ); |