default to a session cookie instead of setting an explicit timeout, weird timezone...
[freeside.git] / httemplate / misc / cust_main-cancel.cgi
1 <& /elements/popup-topreload.html, mt("Customer cancelled") &>
2 <%init>
3
4 die "access denied"
5   unless $FS::CurrentUser::CurrentUser->access_right('Cancel customer');
6
7 my $custnum;
8 my $ban = '';
9 my $expire = '';
10 if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
11   $custnum = $1;
12   $ban = $cgi->param('ban');
13   $expire = $cgi->param('expire');
14 } else {
15   my($query) = $cgi->keywords;
16   $query =~ /^(\d+)$/ || die "Illegal custnum";
17   $custnum = $1;
18 }
19
20
21 #untaint reasonnum / create new reason
22 my ($reasonnum, $error) = $m->comp('process/elements/reason');
23 if (!$reasonnum) {
24   $error ||= 'Reason required'
25 }
26
27 my $cust_main = qsearchs( {
28   'table'     => 'cust_main',
29   'hashref'   => { 'custnum' => $custnum },
30   'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
31 } );
32
33 if ( $error ) {
34   # do nothing
35 } elsif ( $cgi->param('now_or_later') ) {
36   $expire = parse_datetime($expire);
37   if($expire) {
38     #warn "setting expire dates on custnum#$custnum\n";
39     my @pkgs = $cust_main->ncancelled_pkgs;
40     my @errors = grep {$_} map { $_->cancel(
41       'reason'  => $reasonnum,
42       'date'    => $expire,
43     ) } @pkgs;
44     $error = join(' / ', @errors);
45   }
46   else {
47     $error = ("error parsing expire date: ".$cgi->param('expire'));
48   }
49 }
50 else {
51   warn "cancelling $cust_main";
52   my @error = $cust_main->cancel( #returns list of errors
53     'ban'    => $ban,
54     'reason' => $reasonnum,
55   );
56   $error = join(', ',@error);
57 }
58
59 if ( $error ) {
60   $cgi->param('error', $error);
61   print $cgi->redirect(popurl(1). "cancel_cust.html?". $cgi->query_string );
62 }
63
64 </%init>