fix selfservice balance display
[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 my $options = '';
54 if ( $method eq 'suspend' ) { #or 'adjourn'
55   $resume_date = parse_datetime($cgi->param('resume_date'))
56     if $cgi->param('resume_date');
57
58   $options = { map scalar($cgi->param($_)),
59                  suspend_bill no_suspend_bill
60              };
61 }
62
63 my $cust_pkg = qsearchs( 'cust_pkg', {'pkgnum'=>$pkgnum} );
64
65 #untaint reasonnum
66 my $reasonnum = $cgi->param('reasonnum');
67 if ( $method ne 'unsuspend' ) { #i.e. 'resume'
68   $reasonnum =~ /^(-?\d+)$/ or die "Illegal reasonnum";
69   $reasonnum = $1;
70
71   if ($reasonnum == -1) {
72     $reasonnum = {
73       'typenum' => scalar( $cgi->param('newreasonnumT') ),
74       'reason'  => scalar( $cgi->param('newreasonnum' ) ),
75     };
76   }
77 }
78
79 my $error = $cust_pkg->$method( 'reason'      => $reasonnum,
80                                 'date'        => $date,
81                                 'resume_date' => $resume_date,
82                                 'options'     => $options,
83                               );
84
85 if ($error) {
86   $cgi->param('error', $error);
87   print $cgi->redirect(popurl(2). "cancel_pkg.html?". $cgi->query_string );
88 }
89
90 </%init>