summaryrefslogtreecommitdiff
path: root/httemplate/misc/cust_attachment.cgi
blob: d1ec777d8e860caafab0423c62bfb8dd1793a11f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<% '',$cgi->redirect(popurl(2). "browse/cust_attachment.html?$browse_opts") %>
<%init>

$cgi->param('action') =~ /^(Delete|Undelete|Purge) selected$/
  or die "Illegal action";
my $action = $1;

my $browse_opts = join(';', map { $_.'='.$cgi->param($_) } 
    qw( orderby show_deleted )
    );

die "access denied"
  unless $FS::CurrentUser::CurrentUser->access_right("$action attachment");

foreach my $attachnum (
    map { /^attachnum(\d+)$/; $1; } grep /^attachnum\d+$/, $cgi->param
  ) {
  my $attach = qsearchs('cust_attachment', { 'attachnum' => $attachnum });
  my $error;
  if ( $action eq 'Delete' and !$attach->disabled ) {
    $attach->disabled(time);
    $error = $attach->replace;
  }
  elsif ( $action eq 'Undelete' and $attach->disabled ) {
    $attach->disabled('');
    $error = $attach->replace;
  }
  elsif ( $action eq 'Purge' and $attach->disabled ) {
    $error = $attach->delete;
  }
  die $error if $error;
}

</%init>