0649261e7460917b8759d8f8268f68e5dece5010
[freeside.git] / httemplate / misc / process / cancel_pkg.html
1 <& /elements/header-popup.html, emt("Package $past_method") &>
2   <script src="<% $fsurl %>elements/js.cookie.js"></script>
3   <SCRIPT TYPE="text/javascript">
4     Cookies.set('freeside_status', <% mt("Package $past_method") |js_string %>,{
5                   expires: 0.0035
6     });
7     topreload();
8   </SCRIPT>
9   </BODY>
10 </HTML>
11 <%once>
12
13 my %past = ( 'cancel'   => 'cancelled',
14              'expire'   => 'expired',
15              'suspend'  => 'suspended',
16              'adjourn'  => 'adjourned',
17              'resume'   => 'scheduled to resume',
18              'uncancel' => 'un-cancelled',
19            );
20
21 #i'm sure this is false laziness with somewhere, at least w/misc/cancel_pkg.html
22 my %right = ( 'cancel'   => 'Cancel customer package immediately',
23               'expire'   => 'Cancel customer package later',
24               'suspend'  => 'Suspend customer package',
25               'adjourn'  => 'Suspend customer package later',
26               'resume'   => 'Unsuspend customer package', #later?
27               'uncancel' => 'Un-cancel customer package',
28             );
29
30 </%once>
31 <%init>
32
33 #untaint method
34 my $method = $cgi->param('method');
35 $method =~ /^(cancel|expire|suspend|adjourn|resume|uncancel)$/
36   or die "Illegal method";
37 $method = $1;
38 my $past_method = $past{$method};
39
40 my $curuser = $FS::CurrentUser::CurrentUser;
41
42 die "access denied"
43   unless $curuser->access_right($right{$method});
44
45 #untaint pkgnum
46 my $pkgnum = $cgi->param('pkgnum');
47 $pkgnum =~ /^(\d+)$/ or die "Illegal pkgnum";
48 $pkgnum = $1;
49
50 my $date = time;
51 if ($method eq 'expire' || $method eq 'adjourn' || $method eq 'resume') {
52   #untaint date
53   $date = $cgi->param('date'); #huh?
54   parse_datetime($cgi->param('date')) =~ /^(\d+)$/ or die "Illegal date";
55   $date = $1;
56   $method = 'cancel'    if $method eq 'expire';
57   $method = 'suspend'   if $method eq 'adjourn';
58   $method = 'unsuspend' if $method eq 'resume';
59 }
60
61 my $resume_date = '';
62 my $options = '';
63 if ( $method eq 'suspend' ) { #or 'adjourn'
64   $resume_date = parse_datetime($cgi->param('resume_date'))
65     if $cgi->param('resume_date');
66
67   $options = { map { $_ => scalar($cgi->param($_)) }
68                  qw( suspend_bill no_suspend_bill )
69              }
70     if $curuser->access_right('Customize billing during suspension');
71 }
72
73 my $cust_pkg = qsearchs( 'cust_pkg', {'pkgnum'=>$pkgnum} );
74
75 #untaint reasonnum, and set up new reason if appropriate
76 my ($reasonnum, $error);
77 if ($method ne 'unsuspend' and $method ne 'uncancel') {
78   ($reasonnum, $error) = $m->comp('elements/reason');
79   if (!$reasonnum) {
80     $error ||= 'Reason required';
81   }
82 }
83
84 #for uncancel
85 my $last_bill =
86   $cgi->param('last_bill') ? parse_datetime($cgi->param('last_bill')) : '';
87 my $bill =
88   $cgi->param('bill')      ? parse_datetime($cgi->param('bill'))      : '';
89
90 my $svc_fatal = ( $cgi->param('svc_not_fatal') ne 'Y' );
91
92 my $only_svcnum = ($method eq 'uncancel') ? [ $cgi->param('only_svcnum') ] : undef;
93
94 $error ||=  $cust_pkg->$method( 'reason'      => $reasonnum,
95                                 'date'        => $date,
96                                 'resume_date' => $resume_date,
97                                 'last_bill'   => $last_bill,
98                                 'bill'        => $bill,
99                                 'svc_fatal'   => $svc_fatal,
100                                 'options'     => $options,
101                                 'only_svcnum' => $only_svcnum,
102                               );
103
104 if ($error) {
105   $cgi->param('error', $error);
106   print $cgi->redirect(popurl(2). "cancel_pkg.html?". $cgi->query_string );
107 }
108
109 </%init>