future package unsuspend date, #14144
[freeside.git] / httemplate / misc / process / cancel_pkg.html
1 <% header(emt("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              'resume'  => 'scheduled to resume',
14            );
15
16 #i'm sure this is false laziness with somewhere, at least w/misc/cancel_pkg.html
17 my %right = ( 'cancel'  => 'Cancel customer package immediately',
18               'expire'  => 'Cancel customer package later',
19               'suspend' => 'Suspend customer package',
20               'adjourn' => 'Suspend customer package later',
21               'resume'  => 'Unsuspend customer package', #later?
22             );
23
24 </%once>
25 <%init>
26
27 #untaint method
28 my $method = $cgi->param('method');
29 $method =~ /^(cancel|expire|suspend|adjourn|resume)$/ or die "Illegal method";
30 $method = $1;
31 my $past_method = $past{$method};
32
33 die "access denied"
34   unless $FS::CurrentUser::CurrentUser->access_right($right{$method});
35
36 #untaint pkgnum
37 my $pkgnum = $cgi->param('pkgnum');
38 $pkgnum =~ /^(\d+)$/ or die "Illegal pkgnum";
39 $pkgnum = $1;
40
41 my $date = time;
42 if ($method eq 'expire' || $method eq 'adjourn' || $method eq 'resume'){
43   #untaint date
44   $date = $cgi->param('date'); #huh?
45   parse_datetime($cgi->param('date')) =~ /^(\d+)$/ or die "Illegal date";
46   $date = $1;
47   $method = 'cancel'    if $method eq 'expire';
48   $method = 'suspend'   if $method eq 'adjourn';
49   $method = 'unsuspend' if $method eq 'resume';
50 }
51
52 my $resume_date;
53 if ( $method eq 'suspend' ) { #or 'adjourn'
54   $resume_date = parse_datetime($cgi->param('resume_date'))
55     if $cgi->param('resume_date');
56 }
57
58 my $cust_pkg = qsearchs( 'cust_pkg', {'pkgnum'=>$pkgnum} );
59
60 #untaint reasonnum
61 my $reasonnum = $cgi->param('reasonnum');
62 if ( $method ne 'unsuspend' ) { #i.e. 'resume'
63   $reasonnum =~ /^(-?\d+)$/ or die "Illegal reasonnum";
64   $reasonnum = $1;
65
66   if ($reasonnum == -1) {
67     $reasonnum = {
68       'typenum' => scalar( $cgi->param('newreasonnumT') ),
69       'reason'  => scalar( $cgi->param('newreasonnum' ) ),
70     };
71   }
72 }
73
74 my $error = $cust_pkg->$method( 'reason'      => $reasonnum,
75                                 'date'        => $date,
76                                 'resume_date' => $resume_date );
77
78 if ($error) {
79   $cgi->param('error', $error);
80   print $cgi->redirect(popurl(2). "cancel_pkg.html?". $cgi->query_string );
81 }
82
83 </%init>