event refactor, landing on HEAD!
[freeside.git] / httemplate / misc / process / cancel_pkg.html
1 <% header("Package $past{$method}") %>
2   <SCRIPT TYPE="text/javascript">
3     window.top.location.reload();
4   </SCRIPT>
5   </BODY>
6 </HTML>
7 <%once>
8
9 my %past = ( 'cancel'  => 'cancelled',
10              'expire'  => 'expired',
11              'suspend' => 'suspended',
12              'adjourn' => 'adjourned',
13            );
14
15 </%once>
16 <%init>
17
18 #untaint method
19 my $method = $cgi->param('method');
20 $method =~ /^(cancel|expire|suspend|adjourn)$/ || die "Illegal method";
21 $method = $1;
22
23 #untaint pkgnum
24 my $pkgnum = $cgi->param('pkgnum');
25 $pkgnum =~ /^(\d+)$/ || die "Illegal pkgnum";
26 $pkgnum = $1;
27
28 #untaint reasonnum
29 my $reasonnum = $cgi->param('reasonnum');
30 $reasonnum =~ /^(-?\d+)$/ || die "Illegal reasonnum";
31 $reasonnum = $1;
32
33 my $date = time;
34 if ($method eq 'expire' || $method eq 'adjourn'){
35   #untaint date
36   $date = $cgi->param('date');
37   str2time($cgi->param('date')) =~ /^(\d+)$/ || die "Illegal date";
38   $date = $1;
39 }
40
41 my $cust_pkg = qsearchs( 'cust_pkg', {'pkgnum'=>$pkgnum} );
42
43 #my $otaker = $FS::CurrentUser::CurrentUser->name;
44 #$otaker = $FS::CurrentUser::CurrentUser->username
45 #  if ($otaker eq "User, Legacy");
46
47 if ($reasonnum == -1) {
48   $reasonnum = {
49     'typenum' => scalar( $cgi->param('newreasonnumT') ),
50     'reason'  => scalar( $cgi->param('newreasonnum' ) ),
51   };
52 }
53
54 my $error;
55 if ($method eq 'expire' || $method eq 'adjourn'){
56   my %hash = $cust_pkg->hash;
57   $hash{$method} = $date;
58   my $new = new FS::cust_pkg \%hash;
59   $error = $new->replace($cust_pkg, 'reason' => $reasonnum);
60 } else {
61   $error = $cust_pkg->$method( 'reason' => $reasonnum );
62 }
63
64 if ($error) {
65   $cgi->param('error', $error);
66   print $cgi->redirect(popurl(2). "cancel_pkg.html?". $cgi->query_string );
67 }
68
69 </%init>