events should attach reasons
[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 %  #untaint new reason
40 %  my $nr = $cgi->param('newreasonnum');
41 %  $nr =~ /^([\w\s]+)$/ || die "Illegal new reason";
42 %  $nr = $1;
43 %
44 %  #untaint new reason type
45 %  my $nrtype = $cgi->param('newreasonnumT');
46 %  $nrtype =~ /^(\d+)$/ || die "Illegal new reason type";
47 %  $nrtype = $1;
48 %
49 %  my $reason = new FS::reason({ 'reason_type' => $nrtype,
50 %                                'reason'      => $nr,
51 %                              });
52 %  $error = $reason->insert;
53 %  $reasonnum = $reason->reasonnum
54 %    unless $error;
55 %}
56 %
57 %unless ($error) {
58 %  if ($method eq 'expire'){
59 %    my %hash = $cust_pkg->hash;
60 %    $hash{'expire'}=$date;
61 %    my $new = new FS::cust_pkg (\%hash);
62 %    $error = $new->replace($cust_pkg, 'reason' => $reasonnum);
63 %  }else{
64 %    $error = $cust_pkg->$method( 'reason' => $reasonnum );
65 %  }
66 %}
67 %
68 %if ($error) {
69 %  $cgi->param('error', $error);
70 %  $dbh->rollback if $oldAutoCommit;
71 %  print $cgi->redirect(popurl(2). "cancel_pkg.html?". $cgi->query_string );
72 %}
73 %
74 %$dbh->commit or die $dbh->errstr if $oldAutoCommit;
75 %
76 % my %past = ( 'cancel'  => 'cancelled',
77 %              'expire'  => 'expired',
78 %              'suspend' => 'suspended',
79 %            );
80 <% header("Package $past{$method}") %>
81   <SCRIPT TYPE="text/javascript">
82     window.top.location.reload();
83   </SCRIPT>
84   </BODY></HTML>
85