summaryrefslogtreecommitdiff
path: root/httemplate/misc/queue.cgi
blob: 5dee29b88741db78c2f3bca840f17ddf381cead0 (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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<% $cgi->redirect(popurl(2). "search/queue.html") %>
<%init>

die "access denied"
  unless $FS::CurrentUser::CurrentUser->access_right('Job queue');

$cgi->param('action') =~ /^(new|del|(retry|remove) selected)$/
  or die "Illegal action";
my $action = $1;

my $job;
if ( $action eq 'new' || $action eq 'del' ) {
  $cgi->param('jobnum') =~ /^(\d+)$/ or die "Illegal jobnum";
  my $jobnum = $1;
  $job = qsearchs('queue', { 'jobnum' => $1 })
    or die "unknown jobnum $jobnum - ".
           "it probably completed normally or was removed by another user";
}

if ( $action eq 'new' ) {
  my %hash = $job->hash;
  $hash{'status'} = 'new';
  $hash{'statustext'} = '';
  my $new = new FS::queue \%hash;
  my $error = $new->replace($job);
  die $error if $error;
} elsif ( $action eq 'del' ) {
  my $error = $job->delete;
  die $error if $error;
} elsif ( $action =~ /^(retry|remove) selected$/ ) {
  foreach my $jobnum (
    map { /^jobnum(\d+)$/; $1; } grep /^jobnum\d+$/, $cgi->param
  ) {
    my $job = qsearchs('queue', { 'jobnum' => $jobnum });
    if ( $action eq 'retry selected' && $job ) { #new
      my %hash = $job->hash;
      $hash{'status'} = 'new';
      $hash{'statustext'} = '';
      my $new = new FS::queue \%hash;
      my $error = $new->replace($job);
      die $error if $error;
    } elsif ( $action eq 'remove selected' && $job ) { #del
      my $error = $job->delete;
      die $error if $error;
    }
  }
}

</%init>