add per-customer "Invoice reports" link, RT#13802
[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 customers of all agents');
45
46 my $conf = new FS::Conf;
47
48 my $title = 'Outgoing Message Log';
49
50 my @where;
51 if ( $cgi->param('status') =~ /^(\w+)$/ ) {
52   push @where, "status = '$1'";
53 }
54 my ($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi, '');
55 push @where, "(_date >= $beginning AND _date <= $ending)";
56
57 my $order_by = '_date';
58 if ( $cgi->param('order_by') =~ /^(\w+)$/ ) {
59   $order_by = $1;
60 }
61
62 my $where = '';
63 $where = ' WHERE '.join(' AND ', @where) if @where;
64 my $query = {
65   'table'     => 'cust_msg',
66   'select'    => join(', ',
67                    'cust_msg.*',
68                    'msg_template.msgname',
69                  ),
70   'addl_from' => ' LEFT JOIN msg_template USING ( msgnum )',
71   'hashref'   => {},
72   'extra_sql' => $where,
73   'order_by'  => "ORDER BY $order_by",
74 };
75 my $count_query = 'SELECT COUNT(*) FROM cust_msg'.$where;
76
77 my $sub_popup_link = sub {
78   my $custmsgnum = $_[0]->custmsgnum;
79   include('/elements/popup_link_onclick.html',
80     'action'      => $p. 'view/cust_msg.html?' . $custmsgnum,
81     'actionlabel' => 'Message detail',
82     'width'       => 600,
83     'height'      => 500,
84   );
85 };
86
87 my %color = (
88   'failed'   => 'FF0000',
89   'sent'     => '',
90 );
91 my $statuscolor = sub { $color{$_[0]->status} };
92
93 my $html_init = qq!<FORM ACTION="$p/search/cust_msg.html" METHOD="GET">
94 <TABLE cellspacing="10">!.
95 '<TR><TD>From '.
96 include('/elements/input-date-field.html',
97   { 'name'  => 'beginning', 'value' => $cgi->param('beginning') }
98 ).
99 '</TD><TD> To '.
100 include('/elements/input-date-field.html',
101   { 'name'  => 'ending', 'value' => ($cgi->param('ending') || ''), 
102     'noinit' => 1, }
103 ).
104 '</TD><TD> Status '.
105 include('/elements/select.html',
106   'field' => 'status',
107   'curr_value' => $cgi->param('status') || '',
108   'options' => [ '', 'failed', 'sent', ],
109   'labels' => { ''        => '(any)', 
110                 'failed'  => 'failed',
111                 'sent'    => 'sent', },
112 ) .
113 '</TD>
114 <TD><INPUT type="submit" value="Search"></TD></TR>
115 </TABLE></FORM><BR>
116 <STYLE type="text/css">
117 a:link {text-decoration: none}
118 a:visited {text-decoration: none}
119 a:hover {text-decoration: underline}
120 </STYLE>';
121
122 </%init>