=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.
#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';
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;
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' => '' } ) ) {