move header() to include(/elements/header.html) so it can be changed in one place...
[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   $cgi->redirect(popurl(3). "edit/prepay_credit.cgi?". $cgi->query_string )
30 %><% } else { %>
31
32 <%= include("/elements/header.html", "$num prepaid cards generated".
33               ( $agent ? ' for '.$agent->agent : '' ),
34             menubar( 'Main menu' => popurl(3) )
35           )
36 %>
37
38 <FONT SIZE="+1">
39 <% foreach my $card ( @$error ) { %>
40   <code><%= $card %></code>
41   -
42   <%= $hashref->{amount} ? sprintf('$%.2f', $hashref->{amount} ) : '' %>
43   <%= $hashref->{amount} && $hashref->{seconds} ? 'and' : '' %>
44   <%= $hashref->{seconds} ? duration_exact($hashref->{seconds}) : '' %>
45   <br>
46 <% } %>
47
48 </FONT>
49
50 </BODY></HTML>
51 <% } %>