prevent reload loops on process pages, #71249
[freeside.git] / httemplate / misc / cust_main-suspend.cgi
1 <& /elements/header-popup.html, mt("Customer suspended") &>
2   <SCRIPT TYPE="text/javascript">
3     topreload();
4   </SCRIPT>
5   </BODY>
6 </HTML>
7 <%init>
8
9 #false laziness w/cust_main-cancel.cgi
10
11 die "access denied"
12   unless $FS::CurrentUser::CurrentUser->access_right('Suspend customer');
13
14 my $custnum;
15 my $adjourn = '';
16 if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
17   $custnum = $1;
18   $adjourn = $cgi->param('adjourn');
19 } else {
20   my($query) = $cgi->keywords;
21   $query =~ /^(\d+)$/ || die "Illegal custnum";
22   $custnum = $1;
23 }
24
25 #untaint reasonnum / create new reason
26 my ($reasonnum, $error) = $m->comp('process/elements/reason');
27 if (!$reasonnum) {
28   $error ||= 'Reason required';
29 }
30
31 my $cust_main = qsearchs( {
32   'table'     => 'cust_main',
33   'hashref'   => { 'custnum' => $custnum },
34   'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
35 } );
36
37 if ( $error ) {
38   # do nothing
39 } elsif ( $cgi->param('now_or_later') ) {
40   $adjourn = parse_datetime($adjourn);
41   if($adjourn) {
42     #warn "setting adjourn dates on custnum#$custnum\n";
43     my @pkgs = $cust_main->unsuspended_pkgs;
44     my @errors = grep {$_} map { $_->suspend(
45       'reason'  => $reasonnum,
46       'date'    => $adjourn,
47     ) } @pkgs;
48     $error = join(' / ', @errors);
49   } else {
50     $error = ("error parsing adjourn date: ".$cgi->param('adjourn'));
51   }
52 } else {
53   warn "suspending $cust_main";
54   $error = $cust_main->suspend(
55     'reason' => $reasonnum,
56   );
57 }
58
59 if ( $error ) {
60   $cgi->param('error', $error);
61   print $cgi->redirect(popurl(1). "suspend_cust.html?". $cgi->query_string );
62 }
63
64 </%init>