summaryrefslogtreecommitdiff
path: root/httemplate/search/queue.html
blob: 141c535da13fd093aee7080483259c1da8cec2b2 (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<& elements/search.html,
                 'title'       => 'Job Queue',
                 'name'        => 'jobs',
		 'html_form'   => qq!<FORM NAME="jobForm" ACTION="$p/misc/queue.cgi" METHOD="POST">!,
                 'query'       => { 'table'     => 'queue',
                                    'hashref'   => $hashref,
                                    'order_by' => 'ORDER BY jobnum',
                                  },
                 'count_query' => $count_query,
                 'header' => [ '#',
                               'Job',
                               'Args',
                               'Date',
                               'Status',
                               'Account', # unless $hashref->{'svcnum'}
                               '', # checkbox column
                             ],
                 'fields' => [
                               'jobnum',
                               'job',
                               sub {
                                 my $queue = shift;
                                 if (    $dangerous
                                      || $queue->job !~ /^FS::part_export::/
                                      || !$noactions
                                    )
                                 {
                                   encode_entities( join(' ', $queue->args) );
                                 } else {
                                   '';
                                 }
                               },
                               sub {
                                 time2str( "%a %b %e %T %Y", shift->_date );
                               },
                               sub {
                                 my $queue = shift;
                                 my $jobnum = $queue->jobnum;
                                 my $status = $queue->status;
                                 $status .= ': '. $queue->statustext
                                   if $queue->statustext;
                                 my @queue_depend = $queue->queue_depend;
                                 $status .= ' (waiting for '.
                                            join(', ', map { $_->depend_jobnum }
                                                           @queue_depend
                                                ). 
                                            ')'
                                   if @queue_depend;
                                 my $changable = $dangerous
                                                 || ( ! $noactions
                                                      && $status =~ /^failed/
                                                      || $status =~ /^locked/
                                                      || $status =~ /^done/
                                                    );
                                 if ( $changable ) {
                                   $status .= qq! (!;
                                   $status .=
                                     qq! &nbsp;<A HREF="$p/misc/queue.cgi?jobnum=$jobnum&action=new">retry</A>&nbsp;|!
                                     unless $status =~ /^done/;
                                   $status .=
                                     qq!&nbsp;<A HREF="$p/misc/queue.cgi?jobnum=$jobnum&action=del">remove</A>&nbsp;)!;
                                 }
                                 $status;
                               },
                               sub {
                                 my $queue = shift;
                                 # return '' if $hashref->{'svcnum'}
                                 my $cust_svc = $queue->cust_svc;
                                 my $account;
                                 if ( $cust_svc ) {
                                   my $table = $cust_svc->part_svc->svcdb;
                                   my $label = ( $cust_svc->label )[1];
                                   qq!<A HREF="../view/$table.cgi?!. $queue->svcnum.
                                   qq!">$label</A>!;
                                 } else {
                                   '';
                                 }
                               },
                               sub {
                                 my $queue = shift;
                                 my $jobnum = $queue->jobnum;
                                 my $status = $queue->status;
                                 my $changable = $dangerous
                                                 || ( ! $noactions
                                                      && $status eq 'failed'
                                                      || $status eq 'locked'
                                                    );
                                 if ( $changable ) {
                                   $areboxes = 1;
                                   qq!<INPUT NAME="jobnum$jobnum" TYPE="checkbox" VALUE="1">!;
                                 } else {
                                   '';
                                 }
                               },
                             ],
                 #'links' =>  [
                 #              '',
                 #              '',
                 #              '',
                 #              '',
                 #              '',
                 #              '', #$acct_link,
                 #              '',
                 #            ],
                 'html_foot' => sub {
                                  if ( $areboxes ) {
                                    '<BR><INPUT TYPE="button" VALUE="select all" onClick="setAll(true)">'.
                                    '<INPUT TYPE="button" VALUE="unselect all" onClick="setAll(false)">'.
                                    '<BR><INPUT TYPE="submit" NAME="action" VALUE="retry selected">'.
                                    '<INPUT TYPE="submit" NAME="action" VALUE="remove selected"><BR>'.
                                    '<SCRIPT TYPE="text/javascript">'.
                                    '  function setAll(setTo) { '.
                                    '    theForm = document.jobForm;'.
                                    '    for (i=0,n=theForm.elements.length;i<n;i++)'.
                                    '      if (theForm.elements[i].name.indexOf("jobnum") != -1)'.
                                    '        theForm.elements[i].checked = setTo;'.
                                    '  }'.
                                    '</SCRIPT>';
                                  } else {
                                    '';
                                  }
                                },
             
&>
<%init>

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

my $hashref = {};

my $conf = new FS::Conf;
my $dangerous = $conf->exists('queue_dangerous_controls');

my $noactions = 0;

my $count_query = 'SELECT COUNT(*) FROM queue'; # + $hashref

my $areboxes = 0;

</%init>