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";
64 my $maxrecords = $curuser->option('customer_view_emails') || 10;
66 my $order_by = '_date DESC';
69 'table' => 'cust_msg',
70 'select' => join(', ',
72 'msg_template.msgname',
74 'addl_from' => ' LEFT JOIN msg_template USING ( msgnum ) ',
76 'extra_sql' => $where,
77 'order_by' => "ORDER BY $order_by LIMIT $maxrecords",
79 my $count_query = "SELECT COUNT(*) FROM cust_msg $where";
81 my @rows = qsearch($query);
82 my $total = FS::Record->scalar_sql($count_query);
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',
95 'failed' => '#FF0000',
98 'invoice' => '#00CC00',
99 'receipt' => '#0000CC',
100 'admin' => '#CC0000',
103 my $statuscolor = sub { $color{$_[0]->status} };
104 my $typecolor = sub { $color{$_[0]->msgtype} };