1 % if ( scalar(@rows) ) {
2 <STYLE type="text/css">
3 #cust_msg td.grid a:link {text-decoration: none}
4 #cust_msg td.grid a:visited {text-decoration: none}
5 #cust_msg td.grid a:hover {text-decoration: underline}
6 #cust_msg th {background-color: #cccccc}
7 .row0 {background-color: #eeeeee}
8 .row1 {background-color: #ffffff}
11 <FONT SIZE="+1"> <% emt('Email sent to this customer') %> </FONT><BR>
12 % if ($maxrecords < $total) {
13 <% emt('Showing [_1] most recent of [quant,_2,total message]', $maxrecords, $total) %>
14 <A HREF="<%$p%>search/cust_msg.html?custnum=<%$custnum%>">
15 <i>(<% emt('view all') %>)</i>
18 <% emt('[quant,_1,total message]', $total) %>
21 <& /elements/table-grid.html &>
23 <TH CLASS="grid"><% emt('Date') %></TH>
24 <TH CLASS="grid"><% emt('Type') %></TH>
25 <TH CLASS="grid"><% emt('Destination') %></TH>
26 <TH CLASS="grid"><% emt('Subject') %></TH>
27 <TH CLASS="grid"></TH>
30 % foreach my $row (@rows) {
31 % my $onclick = $sub_popup_link->($row);
32 % my $link = qq!<A onclick="$onclick">!;
33 <TR CLASS="row<%$i%>">
34 <TD CLASS="grid"><% $link %>
35 <% $row->_date ? time2str('%Y-%m-%d %T', $row->_date) : '' %>
37 <TD CLASS="grid" STYLE="color: <% $typecolor->($row) %>"><% $link %>
38 <% ucfirst($row->msgtype) || $row->msgname %>
40 <TD CLASS="grid"><% $link %>
41 <% join('<BR>', split(/,\s*/, $row->env_to)) %>
43 <TD CLASS="grid" STYLE="color: <% $statuscolor->($row) %>">
58 my $curuser = $FS::CurrentUser::CurrentUser;
59 my $cust_main = $opt{'cust_main'}
60 or die "cust_main required";
61 my $custnum = $cust_main->custnum;
63 my $where = "WHERE cust_msg.custnum = $custnum";
65 if ( $curuser->option('customer_view_emails') =~ /^\s*(\d+)\s*$/ ) {
69 my $order_by = '_date DESC';
72 'table' => 'cust_msg',
73 'select' => join(', ',
75 'msg_template.msgname',
77 'addl_from' => ' LEFT JOIN msg_template USING ( msgnum ) ',
79 'extra_sql' => $where,
80 'order_by' => "ORDER BY $order_by LIMIT $maxrecords",
82 my $count_query = "SELECT COUNT(*) FROM cust_msg $where";
84 my @rows = qsearch($query);
85 my $total = FS::Record->scalar_sql($count_query);
87 my $sub_popup_link = sub {
88 my $custmsgnum = $_[0]->custmsgnum;
89 include('/elements/popup_link_onclick.html',
90 'action' => $p. 'view/cust_msg.html?' . $custmsgnum,
91 'actionlabel' => 'Message detail',
98 'failed' => '#FF0000',
101 'invoice' => '#00CC00',
102 'receipt' => '#0000CC',
103 'admin' => '#CC0000',
106 my $statuscolor = sub { $color{$_[0]->status} };
107 my $typecolor = sub { $color{$_[0]->msgtype} };