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