1 <& elements/search.html,
3 'name_singular' => 'message',
5 'count_query' => $count_query,
15 my $date = $_[0]->_date;
16 $date ? time2str('%Y-%m-%d %T',$_[0]->_date) : ''
19 ucfirst($_[0]->msgtype) || $_[0]->msgname
23 map { encode_entities($_->format) }
24 Email::Address->parse($_[0]->env_to)
28 sub { encode_entities($_[0]->error) },
30 'sort_fields' => [ '_date',
51 'html_init' => $html_init,
52 'really_disable_download' => 1,
53 'order_by' => '_date DESC',
58 unless $FS::CurrentUser::CurrentUser->access_right('View email logs');
60 my $conf = new FS::Conf;
62 my $title = 'Outgoing Message Log';
64 #here is the agent virtualization
66 $FS::CurrentUser::CurrentUser->agentnums_sql( 'table' => 'cust_main' );
68 my @where = ( $agentnums_sql );
70 if ( $cgi->param('status') =~ /^(\w+)$/ ) {
71 push @where, "status = '$1'";
73 if ( $cgi->param('msgtype') =~ /^(\w+)$/ ) {
74 push @where, "msgtype = '$1'";
76 if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
77 push @where, "custnum = $1";
79 my ($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi, '');
80 push @where, "(_date >= $beginning AND _date <= $ending)";
82 my $order_by = '_date';
83 if ( $cgi->param('order_by') =~ /^(\w+)$/ ) {
87 my $where = ' WHERE '. join(' AND ', @where);
89 my $join_cust_main = ' LEFT JOIN cust_main USING ( custnum ) ';
92 'table' => 'cust_msg',
93 'select' => join(', ',
95 'msg_template.msgname',
97 'addl_from' => ' LEFT JOIN msg_template USING ( msgnum ) '. $join_cust_main,
99 'extra_sql' => $where,
100 'order_by' => "ORDER BY $order_by",
102 my $count_query = "SELECT COUNT(*) FROM cust_msg $join_cust_main $where";
104 my $sub_popup_link = sub {
105 my $custmsgnum = $_[0]->custmsgnum;
106 include('/elements/popup_link_onclick.html',
107 'action' => $p. 'view/cust_msg.html?' . $custmsgnum,
108 'actionlabel' => 'Message detail',
115 'failed' => 'FF0000',
118 'invoice' => '00CC00',
119 'receipt' => '0000CC',
123 my $statuscolor = sub { $color{$_[0]->status} };
124 my $typecolor = sub { $color{$_[0]->msgtype} };
126 my $html_init = qq!<FORM ACTION="$p/search/cust_msg.html" METHOD="GET">
127 <TABLE cellspacing="10">!.
129 include('/elements/input-date-field.html',
130 { 'name' => 'beginning', 'value' => scalar($cgi->param('beginning')) }
133 include('/elements/input-date-field.html',
134 { 'name' => 'ending', 'value' => (scalar($cgi->param('ending')) || ''),
138 include('/elements/select.html',
140 'curr_value' => scalar($cgi->param('status')) || '',
141 'options' => [ '', 'failed', 'sent', ],
142 'labels' => { '' => '(any)',
143 'failed' => 'failed',
147 include('/elements/select.html',
148 'field' => 'msgtype',
149 'curr_value' => scalar($cgi->param('msgtype')) || '',
150 'options' => [ '', 'invoice', 'receipt', 'admin', 'report' ],
151 'labels' => { '' => '(any)',
152 'invoice' => 'Invoices',
153 'receipt' => 'Receipts',
154 'admin' => 'Admin notices',
155 'report' => 'Reports',
159 <TD><INPUT type="submit" value="Search"></TD></TR>
161 <STYLE type="text/css">
162 a:link {text-decoration: none}
163 a:visited {text-decoration: none}
164 a:hover {text-decoration: underline}