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