diff options
| -rw-r--r-- | FS/FS/prepay_credit.pm | 10 | ||||
| -rw-r--r-- | httemplate/edit/process/prepay_credit.cgi | 67 | 
2 files changed, 40 insertions, 37 deletions
| diff --git a/FS/FS/prepay_credit.pm b/FS/FS/prepay_credit.pm index bf85dfaa6..302ba37c7 100644 --- a/FS/FS/prepay_credit.pm +++ b/FS/FS/prepay_credit.pm @@ -162,10 +162,18 @@ sub generate {    local $FS::UID::AutoCommit = 0;    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) ) ); + +    redo if qsearchs('prepay_credit',{identifier=>$identifier}) && $condup++<23; +    $condup = 0; +      my $prepay_credit = new FS::prepay_credit { -      'identifier' => join('', map($codeset[int(rand $#codeset)], (0..7) ) ), +      'identifier' => $identifier,        %$hashref,      };      my $error = $prepay_credit->check || $prepay_credit->insert; diff --git a/httemplate/edit/process/prepay_credit.cgi b/httemplate/edit/process/prepay_credit.cgi index 24ce25608..8f2eb2b25 100644 --- a/httemplate/edit/process/prepay_credit.cgi +++ b/httemplate/edit/process/prepay_credit.cgi @@ -1,41 +1,9 @@ -% -%my $hashref = {}; -% -%my $agent = ''; -%if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) { -%  $agent = qsearchs('agent', { 'agentnum' => $hashref->{agentnum}=$1 } ); -%} -% -%my $error = ''; -% -%my $num = 0; -%if ( $cgi->param('num') =~ /^\s*(\d+)\s*$/ ) { -%  $num = $1; -%} else { -%  $error = 'Illegal number of prepaid cards: '. $cgi->param('num'); -%} -% -%$hashref->{amount}    = $cgi->param('amount'); -%$hashref->{seconds}   = $cgi->param('seconds') * $cgi->param('multiplier'); -%$hashref->{upbytes}   = $cgi->param('upbytes') * $cgi->param('upmultiplier'); -%$hashref->{downbytes} = $cgi->param('downbytes') * $cgi->param('downmultiplier'); -%$hashref->{totalbytes} = $cgi->param('totalbytes') * $cgi->param('totalmultiplier'); -% -%$error ||= FS::prepay_credit::generate( $num, -%                                        scalar($cgi->param('type')),  -%                                        $hashref -%                                      ); -%  %unless ( ref($error) ) {  %  $cgi->param('error', $error ); -% -<% -  $cgi->redirect(popurl(3). "edit/prepay_credit.cgi?". $cgi->query_string ) -%> +<% $cgi->redirect(popurl(3). "edit/prepay_credit.cgi?". $cgi->query_string ) %>  % } else {  - -<% include("/elements/header.html", "$num prepaid cards generated". +<% include('/elements/header.html', "$num prepaid cards generated".                ( $agent ? ' for '.$agent->agent : '' )            )  %> @@ -54,14 +22,41 @@    <br>  % }  -  </FONT> -</BODY></HTML> +<% include('/elements/footer.html') %> +  % }   <%init>  die "access denied"    unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); +my $hashref = {}; + +my $agent = ''; +if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) { +  $agent = qsearchs('agent', { 'agentnum' => $hashref->{agentnum}=$1 } ); +} + +my $error = ''; + +my $num = 0; +if ( $cgi->param('num') =~ /^\s*(\d+)\s*$/ ) { +  $num = $1; +} else { +  $error = 'Illegal number of prepaid cards: '. $cgi->param('num'); +} + +$hashref->{amount}    = $cgi->param('amount'); +$hashref->{seconds}   = $cgi->param('seconds') * $cgi->param('multiplier'); +$hashref->{upbytes}   = $cgi->param('upbytes') * $cgi->param('upmultiplier'); +$hashref->{downbytes} = $cgi->param('downbytes') * $cgi->param('downmultiplier'); +$hashref->{totalbytes} = $cgi->param('totalbytes') * $cgi->param('totalmultiplier'); + +$error ||= FS::prepay_credit::generate( $num, +                                        scalar($cgi->param('type')),  +                                        $hashref +                                      ); +  </%init> | 
