Will things ever be the same again?
[freeside.git] / httemplate / edit / process / prepay_credit.cgi
1 %
2 %my $hashref = {};
3 %
4 %my $agent = '';
5 %if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
6 %  $agent = qsearchs('agent', { 'agentnum' => $hashref->{agentnum}=$1 } );
7 %}
8 %
9 %my $error = '';
10 %
11 %my $num = 0;
12 %if ( $cgi->param('num') =~ /^\s*(\d+)\s*$/ ) {
13 %  $num = $1;
14 %} else {
15 %  $error = 'Illegal number of prepaid cards: '. $cgi->param('num');
16 %}
17 %
18 %$hashref->{amount} = $cgi->param('amount');
19 %$hashref->{seconds} = $cgi->param('seconds') * $cgi->param('multiplier');
20 %
21 %$error ||= FS::prepay_credit::generate( $num,
22 %                                        scalar($cgi->param('type')), 
23 %                                        $hashref
24 %                                      );
25 %
26 %unless ( ref($error) ) {
27 %  $cgi->param('error', $error );
28 %
29 <%
30   $cgi->redirect(popurl(3). "edit/prepay_credit.cgi?". $cgi->query_string )
31 %>
32 % } else { 
33
34
35 <% include("/elements/header.html", "$num prepaid cards generated".
36               ( $agent ? ' for '.$agent->agent : '' ),
37             menubar( 'Main menu' => popurl(3) )
38           )
39 %>
40
41 <FONT SIZE="+1">
42 % foreach my $card ( @$error ) { 
43
44   <code><% $card %></code>
45   -
46   <% $hashref->{amount} ? sprintf('$%.2f', $hashref->{amount} ) : '' %>
47   <% $hashref->{amount} && $hashref->{seconds} ? 'and' : '' %>
48   <% $hashref->{seconds} ? duration_exact($hashref->{seconds}) : '' %>
49   <br>
50 % } 
51
52
53 </FONT>
54
55 </BODY></HTML>
56 % } 
57