merging RT 4.0.6
[freeside.git] / httemplate / misc / cust_main-suspend.cgi
1 <& /elements/header-popup.html, mt("Customer suspended") &>
2   <SCRIPT TYPE="text/javascript">
3     window.top.location.reload();
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 #false laziness w/process/cancel_pkg.html
26
27 #untaint reasonnum
28 my $reasonnum = $cgi->param('reasonnum');
29 $reasonnum =~ /^(-?\d+)$/ || die "Illegal reasonnum";
30 $reasonnum = $1;
31
32 if ($reasonnum == -1) {
33   $reasonnum = {
34     'typenum' => scalar( $cgi->param('newreasonnumT') ),
35     'reason'  => scalar( $cgi->param('newreasonnum' ) ),
36   };
37 }
38
39 #eslaf
40
41 my $cust_main = qsearchs( {
42   'table'     => 'cust_main',
43   'hashref'   => { 'custnum' => $custnum },
44   'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
45 } );
46
47 my @errors;
48 if($cgi->param('now_or_later')) {
49   $adjourn = parse_datetime($adjourn);
50   if($adjourn) {
51     #warn "setting adjourn dates on custnum#$custnum\n";
52     my @pkgs = $cust_main->unsuspended_pkgs;
53     @errors = grep {$_} map { $_->suspend(
54       'reason'  => $reasonnum,
55       'date'    => $adjourn,
56     ) } @pkgs;
57   }
58   else {
59     @errors = ("error parsing adjourn date: ".$cgi->param('adjourn'));
60   }
61 }
62 else {
63   warn "suspending $cust_main";
64   @errors = $cust_main->suspend(
65     'reason' => $reasonnum,
66   );
67 }
68 my $error = join(' / ', @errors) if scalar(@errors);
69
70 if ( $error ) {
71   $cgi->param('error', $error);
72   print $cgi->redirect(popurl(1). "suspend_cust.html?". $cgi->query_string );
73 }
74
75 </%init>