s(browse/queue.cgi)(search/queue.html)
[freeside.git] / httemplate / search / queue.html
1 <%
2
3 my $hashref = {};
4
5 my $conf = new FS::Conf;
6 my $dangerous = $conf->exists('queue_dangerous_controls');
7
8 my $noactions = 0;
9
10 my $count_query = 'SELECT COUNT(*) FROM queue'; # + $hashref
11
12 my $areboxes = 0;
13
14 %><%= include( 'elements/search.html',
15                  'title'       => 'Job Queue',
16                  'menubar'     => [ 'Main menu' => $p, ],
17                  'name'        => 'jobs',
18                  'query'       => { 'table'     => 'queue',
19                                     'hashref'   => $hashref,
20                                     'extra_sql' => 'ORDER BY jobnum',
21                                   },
22                  'count_query' => $count_query,
23                  'header' => [ '#',
24                                'Job',
25                                'Args',
26                                'Date',
27                                'Status',
28                                'Account', # unless $hashref->{'svcnum'}
29                                '', # checkbox column
30                              ],
31                  'fields' => [
32                                'jobnum',
33                                'job',
34                                sub {
35                                  my $queue = shift;
36                                  if (    $dangerous
37                                       || $queue->job !~ /^FS::part_export::/
38                                       || !$noactions
39                                     )
40                                  {
41                                    encode_entities( join(' ', $queue->args) );
42                                  } else {
43                                    '';
44                                  }
45                                },
46                                sub {
47                                  time2str( "%a %b %e %T %Y", shift->_date );
48                                },
49                                sub {
50                                  my $queue = shift;
51                                  my $jobnum = $queue->jobnum;
52                                  my $status = $queue->status;
53                                  $status .= ': '. $queue->statustext
54                                    if $queue->statustext;
55                                  my @queue_depend = $queue->queue_depend;
56                                  $status .= ' (waiting for '.
57                                             join(', ', map { $_->depend_jobnum }
58                                                            @queue_depend
59                                                 ). 
60                                             ')'
61                                    if @queue_depend;
62                                  my $changable = $dangerous
63                                                  || ( ! $noactions
64                                                       && $status =~ /^failed/
65                                                       || $status =~ /^locked/
66                                                     );
67                                  if ( $changable ) {
68                                    $status .=
69                                      qq! (&nbsp;<A HREF="$p/misc/queue.cgi?jobnum=$jobnum&action=new">retry</A>&nbsp;|!.
70                                      qq!&nbsp;<A HREF="$p/misc/queue.cgi?jobnum=$jobnum&action=del">remove</A>&nbsp;)!;
71                                  }
72                                  $status;
73                                },
74                                sub {
75                                  my $queue = shift;
76                                  # return '' if $hashref->{'svcnum'}
77                                  my $cust_svc = $queue->cust_svc;
78                                  my $account;
79                                  if ( $cust_svc ) {
80                                    my $table = $cust_svc->part_svc->svcdb;
81                                    my $label = ( $cust_svc->label )[1];
82                                    qq!<A HREF="../view/$table.cgi?!. $queue->svcnum.
83                                    qq!">$label</A>!;
84                                  } else {
85                                    '';
86                                  }
87                                },
88                                sub {
89                                  my $queue = shift;
90                                  my $jobnum = $queue->jobnum;
91                                  my $status = $queue->status;
92                                  my $changable = $dangerous
93                                                  || ( ! $noactions
94                                                       && $status eq 'failed'
95                                                       || $status eq 'locked'
96                                                     );
97                                  if ( $changable ) {
98                                    $areboxes = 1;
99                                    qq!<INPUT NAME="jobnum$jobnum" TYPE="checkbox" VALUE="1">!;
100                                  } else {
101                                    '';
102                                  }
103                                },
104                              ],
105                  #'links' =>  [
106                  #              '',
107                  #              '',
108                  #              '',
109                  #              '',
110                  #              '',
111                  #              '', #$acct_link,
112                  #              '',
113                  #            ],
114                  'html_foot' => sub {
115                                   if ( $areboxes ) {
116                                     '<BR><INPUT TYPE="submit" NAME="action" VALUE="retry selected">'.
117                                     '<INPUT TYPE="submit" NAME="action" VALUE="remove selected"><BR>';
118                                   } else {
119                                     '';
120                                   }
121                                 },
122              )
123
124 %>