RT# 82949 - changes section name from fees to pricing, better opiton
[freeside.git] / httemplate / search / cust_msg.html
1 <& elements/search.html,
2        'title'         => $title,
3        'name_singular' => 'message',
4        'query'         => $query,
5        'count_query'   => $count_query,
6        'header'        => [ 
7                             'Date',
8                             'Type',
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                             sub {
19                               ucfirst($_[0]->msgtype) || $_[0]->msgname
20                             },
21                             sub {
22                               join('<BR>',
23                                 map { encode_entities($_->format) }
24                                 Email::Address->parse($_[0]->env_to)
25                               )
26                             },
27                             'status',
28                             sub { encode_entities($_[0]->error) },
29                          ],
30        'sort_fields'   => [ '_date',
31                             'msgtype',
32                             'env_to',
33                             'status',
34                             'error',
35                           ],
36        'align'         => 'rllcl',
37        'links'         => [],
38        'link_onclicks' => [ 
39                             $sub_popup_link,
40                             $sub_popup_link,
41                             $sub_popup_link,
42                             '',
43                             '',
44                           ],
45        'color'         => [ '',
46                             $typecolor,
47                             '',
48                             $statuscolor,
49                             $statuscolor,
50                           ],
51        'html_init'     => $html_init,
52        'really_disable_download' => 1,
53        'order_by'      => '_date DESC',
54 &>
55 <%init>
56 #hmm...
57 die "access denied"
58   unless $FS::CurrentUser::CurrentUser->access_right('View email logs');
59
60 my $conf = new FS::Conf;
61
62 my $title = 'Outgoing Message Log';
63
64 #here is the agent virtualization
65 my $agentnums_sql = $FS::CurrentUser::CurrentUser->agentnums_sql(
66   'table' => 'cust_main',
67   'null_right' => [ 'View system logs', 'Configuration' ],
68 );
69
70 my @where = ( $agentnums_sql );
71
72 if ( $cgi->param('status') =~ /^(\w+)$/ ) {
73   push @where, "status = '$1'";
74 }
75 if ( $cgi->param('msgtype') =~ /^(\w+)$/ ) {
76   push @where, "msgtype = '$1'";
77 }
78 if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
79   push @where, "cust_msg.custnum = $1";
80 }
81 my ($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi, '');
82 push @where, "(_date >= $beginning AND _date <= $ending)";
83
84 my $order_by = '_date';
85 if ( $cgi->param('order_by') =~ /^(\w+)$/ ) {
86   $order_by = $1;
87 }
88
89 my $where = ' WHERE '. join(' AND ', @where);
90
91 my $join_cust_main = ' LEFT JOIN cust_main USING ( custnum ) ';
92
93 my $query = {
94   'table'     => 'cust_msg',
95   'select'    => join(', ',
96                    'cust_msg.*',
97                    'msg_template.msgname',
98                  ),
99   'addl_from' => ' LEFT JOIN msg_template USING ( msgnum ) '. $join_cust_main,
100   'hashref'   => {},
101   'extra_sql' => $where,
102   'order_by'  => "ORDER BY $order_by",
103 };
104 my $count_query = "SELECT COUNT(*) FROM cust_msg $join_cust_main $where";
105
106 my $sub_popup_link = sub {
107   my $custmsgnum = $_[0]->custmsgnum;
108   include('/elements/popup_link_onclick.html',
109     'action'      => $p. 'view/cust_msg.html?' . $custmsgnum,
110     'actionlabel' => 'Message detail',
111     'width'       => 680,
112     'height'      => 550,
113   );
114 };
115
116 my %color = (
117   'failed'   => 'FF0000',
118   'sent'     => '',
119
120   'invoice'  => '00CC00',
121   'receipt'  => '0000CC',
122   'admin'    => 'CC0000',
123   ''         => '000000',
124 );
125 my $statuscolor = sub { $color{$_[0]->status} };
126 my $typecolor = sub { $color{$_[0]->msgtype} };
127
128 my $html_init = qq!<FORM ACTION="$p/search/cust_msg.html" METHOD="GET">
129 <TABLE cellspacing="10">!.
130 '<TR><TD>From '.
131 include('/elements/input-date-field.html',
132   { 'name'  => 'beginning', 'value' => scalar($cgi->param('beginning')) }
133 ).
134 '</TD><TD> To '.
135 include('/elements/input-date-field.html',
136   { 'name'  => 'ending', 'value' => (scalar($cgi->param('ending')) || ''), 
137     'noinit' => 1, }
138 ).
139 '</TD><TD> Status '.
140 include('/elements/select.html',
141   'field' => 'status',
142   'curr_value' => scalar($cgi->param('status')) || '',
143   'options' => [ '', 'failed', 'sent', ],
144   'labels' => { ''        => '(any)', 
145                 'failed'  => 'failed',
146                 'sent'    => 'sent', },
147 ) .
148 '</TD><TD> Type '.
149 include('/elements/select.html',
150   'field' => 'msgtype',
151   'curr_value' => scalar($cgi->param('msgtype')) || '',
152   'options' => [ '', 'invoice', 'receipt', 'admin', 'report' ],
153   'labels'  => { ''         => '(any)',
154                  'invoice'  => 'Invoices',
155                  'receipt'  => 'Receipts',
156                  'admin'    => 'Admin notices',
157                  'report'   => 'Reports',
158                },
159 ) .
160 '</TD>
161 <TD><INPUT type="submit" value="Search"></TD></TR>
162 </TABLE></FORM><BR>
163 <STYLE type="text/css">
164 a:link {text-decoration: none}
165 a:visited {text-decoration: none}
166 a:hover {text-decoration: underline}
167 </STYLE>';
168
169 </%init>