better error message if you don't enter a reason. FS::reason::check can untaint...
[freeside.git] / httemplate / misc / process / cancel_pkg.html
1 %
2 %
3 %#untaint method
4 %my $method = $cgi->param('method');
5 %$method =~ /^(cancel|expire|suspend)$/ || die "Illegal method";
6 %$method = $1;
7
8 %#untaint pkgnum
9 %my $pkgnum = $cgi->param('pkgnum');
10 %$pkgnum =~ /^(\d+)$/ || die "Illegal pkgnum";
11 %$pkgnum = $1;
12 %
13 %#untaint reasonnum
14 %my $reasonnum = $cgi->param('reasonnum');
15 %$reasonnum =~ /^(-?\d+)$/ || die "Illegal reasonnum";
16 %$reasonnum = $1;
17 %
18 %my $date = time;
19 %if ($method eq 'expire'){
20 %  #untaint date
21 %  $date = $cgi->param('date');
22 %  str2time($cgi->param('date')) =~ /^(\d+)$/ || die "Illegal date";
23 %  $date = $1;
24 %}
25 %
26 %my $cust_pkg = qsearchs( 'cust_pkg', {'pkgnum'=>$pkgnum} );
27 %
28 %
29 %my $oldAutoCommit = $FS::UID::AutoCommit;
30 %local $FS::UID::AutoCommit = 0;
31 %my $dbh = dbh;
32 %
33 %my $otaker = $FS::CurrentUser::CurrentUser->name;
34 %$otaker = $FS::CurrentUser::CurrentUser->username
35 %  if ($otaker eq "User, Legacy");
36 %
37 %my $error = '';
38 %if ($reasonnum == -1) {
39 %
40 %  $error = 'Enter a new reason (or select an existing oen)'
41 %    unless $cgi->param('newreasonnum') !~ /^\s*$/;
42 %
43 %  my $reason = new FS::reason({ 'reason_type' => $cgi->param('newreasonnumT'),
44 %                                'reason'      => $cgi->param('newreasonnum'),
45 %                              });
46 %  $error ||= $reason->insert;
47 %  $reasonnum = $reason->reasonnum
48 %    unless $error;
49 %}
50 %
51 %unless ($error) {
52 %  if ($method eq 'expire'){
53 %    my %hash = $cust_pkg->hash;
54 %    $hash{'expire'}=$date;
55 %    my $new = new FS::cust_pkg (\%hash);
56 %    $error = $new->replace($cust_pkg, 'reason' => $reasonnum);
57 %  }else{
58 %    $error = $cust_pkg->$method( 'reason' => $reasonnum );
59 %  }
60 %}
61 %
62 %if ($error) {
63 %  $cgi->param('error', $error);
64 %  $dbh->rollback if $oldAutoCommit;
65 %  print $cgi->redirect(popurl(2). "cancel_pkg.html?". $cgi->query_string );
66 %}
67 %
68 %$dbh->commit or die $dbh->errstr if $oldAutoCommit;
69 %
70 % my %past = ( 'cancel'  => 'cancelled',
71 %              'expire'  => 'expired',
72 %              'suspend' => 'suspended',
73 %            );
74 <% header("Package $past{$method}") %>
75   <SCRIPT TYPE="text/javascript">
76     window.top.location.reload();
77   </SCRIPT>
78   </BODY></HTML>
79