Add "View email logs" ACL - "View customers of all agents" was definitely not the...
[freeside.git] / httemplate / search / cust_msg.html
1 <& 'elements/search.html',
2        'title' => $title,
3        'name'  => 'messages',
4        'query' => $query,
5        'count_query' => $count_query,
6        'header' => [ 
7                      'Date',
8                      'Template',
9                      'Destination',
10                      'Status',
11                      '', #error
12                   ],
13        'fields' => [ 
14                      sub { 
15                        my $date = $_[0]->_date;
16                        $date ? time2str('%Y-%m-%d %T',$_[0]->_date) : '' 
17                      },
18                      'msgname',
19                      sub {
20                        join('<BR>', split(/,\s*/, $_[0]->env_to) )
21                      },
22                      'status',
23                      sub { encode_entities($_[0]->error) },
24                   ],
25        'align' => 'rllcl',
26        'links' => [ ],
27        'link_onclicks' => [ 
28                     $sub_popup_link,
29                     $sub_popup_link,
30                     $sub_popup_link,
31                     '',
32                     '',
33                   ],
34        'color' => [ ('') x 3, 
35                      $statuscolor,
36                      $statuscolor,
37                   ],
38        'html_init' => $html_init,
39        'really_disable_download' => 1,
40 &>
41 <%init>
42 #hmm...
43 die "access denied"
44   unless $FS::CurrentUser::CurrentUser->access_right('View email logs')
45       || $FS::CurrentUser::CurrentUser->access_right('Configuration');
46
47 my $conf = new FS::Conf;
48
49 my $title = 'Outgoing Message Log';
50
51 my @where;
52 if ( $cgi->param('status') =~ /^(\w+)$/ ) {
53   push @where, "status = '$1'";
54 }
55 my ($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi, '');
56 push @where, "(_date >= $beginning AND _date <= $ending)";
57
58 my $order_by = '_date';
59 if ( $cgi->param('order_by') =~ /^(\w+)$/ ) {
60   $order_by = $1;
61 }
62
63 my $where = '';
64 $where = ' WHERE '.join(' AND ', @where) if @where;
65 my $query = {
66   'table'     => 'cust_msg',
67   'select'    => join(', ',
68                    'cust_msg.*',
69                    'msg_template.msgname',
70                  ),
71   'addl_from' => ' LEFT JOIN msg_template USING ( msgnum )',
72   'hashref'   => {},
73   'extra_sql' => $where,
74   'order_by'  => "ORDER BY $order_by",
75 };
76 my $count_query = 'SELECT COUNT(*) FROM cust_msg'.$where;
77
78 my $sub_popup_link = sub {
79   my $custmsgnum = $_[0]->custmsgnum;
80   include('/elements/popup_link_onclick.html',
81     'action'      => $p. 'view/cust_msg.html?' . $custmsgnum,
82     'actionlabel' => 'Message detail',
83     'width'       => 600,
84     'height'      => 500,
85   );
86 };
87
88 my %color = (
89   'failed'   => 'FF0000',
90   'sent'     => '',
91 );
92 my $statuscolor = sub { $color{$_[0]->status} };
93
94 my $html_init = qq!<FORM ACTION="$p/search/cust_msg.html" METHOD="GET">
95 <TABLE cellspacing="10">!.
96 '<TR><TD>From '.
97 include('/elements/input-date-field.html',
98   { 'name'  => 'beginning', 'value' => $cgi->param('beginning') }
99 ).
100 '</TD><TD> To '.
101 include('/elements/input-date-field.html',
102   { 'name'  => 'ending', 'value' => ($cgi->param('ending') || ''), 
103     'noinit' => 1, }
104 ).
105 '</TD><TD> Status '.
106 include('/elements/select.html',
107   'field' => 'status',
108   'curr_value' => $cgi->param('status') || '',
109   'options' => [ '', 'failed', 'sent', ],
110   'labels' => { ''        => '(any)', 
111                 'failed'  => 'failed',
112                 'sent'    => 'sent', },
113 ) .
114 '</TD>
115 <TD><INPUT type="submit" value="Search"></TD></TR>
116 </TABLE></FORM><BR>
117 <STYLE type="text/css">
118 a:link {text-decoration: none}
119 a:visited {text-decoration: none}
120 a:hover {text-decoration: underline}
121 </STYLE>';
122
123 </%init>