Merge branch 'master' of git.freeside.biz:/home/git/freeside
[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              'uncancel' => 'un-cancelled',
15            );
16
17 #i'm sure this is false laziness with somewhere, at least w/misc/cancel_pkg.html
18 my %right = ( 'cancel'   => 'Cancel customer package immediately',
19               'expire'   => 'Cancel customer package later',
20               'suspend'  => 'Suspend customer package',
21               'adjourn'  => 'Suspend customer package later',
22               'resume'   => 'Unsuspend customer package', #later?
23               'uncancel' => 'Un-cancel customer package',
24             );
25
26 </%once>
27 <%init>
28
29 #untaint method
30 my $method = $cgi->param('method');
31 $method =~ /^(cancel|expire|suspend|adjourn|resume|uncancel)$/
32   or die "Illegal method";
33 $method = $1;
34 my $past_method = $past{$method};
35
36 die "access denied"
37   unless $FS::CurrentUser::CurrentUser->access_right($right{$method});
38
39 #untaint pkgnum
40 my $pkgnum = $cgi->param('pkgnum');
41 $pkgnum =~ /^(\d+)$/ or die "Illegal pkgnum";
42 $pkgnum = $1;
43
44 my $date = time;
45 if ($method eq 'expire' || $method eq 'adjourn' || $method eq 'resume') {
46   #untaint date
47   $date = $cgi->param('date'); #huh?
48   parse_datetime($cgi->param('date')) =~ /^(\d+)$/ or die "Illegal date";
49   $date = $1;
50   $method = 'cancel'    if $method eq 'expire';
51   $method = 'suspend'   if $method eq 'adjourn';
52   $method = 'unsuspend' if $method eq 'resume';
53 }
54
55 my $resume_date = '';
56 my $options = '';
57 if ( $method eq 'suspend' ) { #or 'adjourn'
58   $resume_date = parse_datetime($cgi->param('resume_date'))
59     if $cgi->param('resume_date');
60
61   $options = { map scalar($cgi->param($_)),
62                  suspend_bill no_suspend_bill
63              };
64 }
65
66 my $cust_pkg = qsearchs( 'cust_pkg', {'pkgnum'=>$pkgnum} );
67
68 #untaint reasonnum
69 my $reasonnum = $cgi->param('reasonnum');
70 if ( $method !~ /^(unsuspend|uncancel)$/ ) {
71   $reasonnum =~ /^(-?\d+)$/ or die "Illegal reasonnum";
72   $reasonnum = $1;
73
74   if ($reasonnum == -1) {
75     $reasonnum = {
76       'typenum' => scalar( $cgi->param('newreasonnumT') ),
77       'reason'  => scalar( $cgi->param('newreasonnum' ) ),
78     };
79   }
80 }
81
82 #for uncancel
83 my $last_bill =
84   $cgi->param('last_bill') ? parse_datetime($cgi->param('last_bill')) : '';
85 my $bill =
86   $cgi->param('bill')      ? parse_datetime($cgi->param('bill'))      : '';
87
88 my $svc_fatal = ( $cgi->param('svc_not_fatal') ne 'Y' );
89
90 my $error = $cust_pkg->$method( 'reason'      => $reasonnum,
91                                 'date'        => $date,
92                                 'resume_date' => $resume_date,
93                                 'last_bill'   => $last_bill,
94                                 'bill'        => $bill,
95                                 'svc_fatal'   => $svc_fatal,
96                                 'options'     => $options,
97                               );
98
99 if ($error) {
100   $cgi->param('error', $error);
101   print $cgi->redirect(popurl(2). "cancel_pkg.html?". $cgi->query_string );
102 }
103
104 </%init>