suspension and cancellation 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 %  my $cust_pkg_reason = new FS::cust_pkg_reason({ 'pkgnum'      => $pkgnum,
59 %                                                  'reasonnum'   => $reasonnum,
60 %                                                  'otaker'      => $otaker,
61 %                                                  'date'        => $date,
62 %                                                 });
63 %  $error = $cust_pkg_reason->insert;
64 %}
65 %
66 %unless ($error) {
67 %  if ($method eq 'expire'){
68 %    my %hash = $cust_pkg->hash;
69 %    $hash{'expire'}=$date;
70 %    my $new = new FS::cust_pkg (\%hash);
71 %    $error = $new->replace($cust_pkg);
72 %  }else{
73 %    $error = $cust_pkg->$method
74 %  }
75 %}
76 %
77 %if ($error) {
78 %  $cgi->param('error', $error);
79 %  $dbh->rollback if $oldAutoCommit;
80 %  print $cgi->redirect(popurl(2). "cancel_pkg.html?". $cgi->query_string );
81 %}
82 %
83 %$dbh->commit or die $dbh->errstr if $oldAutoCommit;
84 %
85 % my %past = ( 'cancel'  => 'cancelled',
86 %              'expire'  => 'expired',
87 %              'suspend' => 'suspended',
88 %            );
89 <% header("Package $past{$method}") %>
90   <SCRIPT TYPE="text/javascript">
91     window.top.location.reload();
92   </SCRIPT>
93   </BODY></HTML>
94