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