401f52ebb485f8ba2ea6d940d96737566fd1d1db
[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 =
63   $FS::CurrentUser::CurrentUser->agentnums_sql( 'table' => 'cust_main' );
64
65 my @where = ( $agentnums_sql );
66
67 if ( $cgi->param('status') =~ /^(\w+)$/ ) {
68   push @where, "status = '$1'";
69 }
70 if ( $cgi->param('msgtype') =~ /^(\w+)$/ ) {
71   push @where, "msgtype = '$1'";
72 }
73 if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
74   push @where, "cust_msg.custnum = $1";
75 }
76 my ($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi, '');
77 push @where, "(_date >= $beginning AND _date <= $ending)";
78
79 my $order_by = '_date';
80 if ( $cgi->param('order_by') =~ /^(\w+)$/ ) {
81   $order_by = $1;
82 }
83
84 my $where = ' WHERE '. join(' AND ', @where);
85
86 my $join_cust_main = ' LEFT JOIN cust_main USING ( custnum ) ';
87
88 my $query = {
89   'table'     => 'cust_msg',
90   'select'    => join(', ',
91                    'cust_msg.*',
92                    'msg_template.msgname',
93                  ),
94   'addl_from' => ' LEFT JOIN msg_template USING ( msgnum ) '. $join_cust_main,
95   'hashref'   => {},
96   'extra_sql' => $where,
97   'order_by'  => "ORDER BY $order_by",
98 };
99 my $count_query = "SELECT COUNT(*) FROM cust_msg $join_cust_main $where";
100
101 my $sub_popup_link = sub {
102   my $custmsgnum = $_[0]->custmsgnum;
103   include('/elements/popup_link_onclick.html',
104     'action'      => $p. 'view/cust_msg.html?' . $custmsgnum,
105     'actionlabel' => 'Message detail',
106     'width'       => 680,
107     'height'      => 550,
108   );
109 };
110
111 my %color = (
112   'failed'   => 'FF0000',
113   'sent'     => '',
114
115   'invoice'  => '00CC00',
116   'receipt'  => '0000CC',
117   'admin'    => 'CC0000',
118   ''         => '000000',
119 );
120 my $statuscolor = sub { $color{$_[0]->status} };
121 my $typecolor = sub { $color{$_[0]->msgtype} };
122
123 my $html_init = qq!<FORM ACTION="$p/search/cust_msg.html" METHOD="GET">
124 <TABLE cellspacing="10">!.
125 '<TR><TD>From '.
126 include('/elements/input-date-field.html',
127   { 'name'  => 'beginning', 'value' => $cgi->param('beginning') }
128 ).
129 '</TD><TD> To '.
130 include('/elements/input-date-field.html',
131   { 'name'  => 'ending', 'value' => ($cgi->param('ending') || ''), 
132     'noinit' => 1, }
133 ).
134 '</TD><TD> Status '.
135 include('/elements/select.html',
136   'field' => 'status',
137   'curr_value' => $cgi->param('status') || '',
138   'options' => [ '', 'failed', 'sent', ],
139   'labels' => { ''        => '(any)', 
140                 'failed'  => 'failed',
141                 'sent'    => 'sent', },
142 ) .
143 '</TD><TD> Type '.
144 include('/elements/select.html',
145   'field' => 'msgtype',
146   'curr_value' => $cgi->param('msgtype') || '',
147   'options' => [ '', 'invoice', 'receipt', 'admin' ],
148   'labels'  => { ''         => '(any)',
149                  'invoice'  => 'Invoices',
150                  'receipt'  => 'Receipts',
151                  'admin'    => 'Admin notices',
152                },
153 ) .
154 '</TD>
155 <TD><INPUT type="submit" value="Search"></TD></TR>
156 </TABLE></FORM><BR>
157 <STYLE type="text/css">
158 a:link {text-decoration: none}
159 a:visited {text-decoration: none}
160 a:hover {text-decoration: underline}
161 </STYLE>';
162
163 </%init>