fix direct use of customer_view_emails pref, RT#78617
[freeside.git] / httemplate / view / cust_main / notes / email.html
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}
9 </STYLE>
10 <DIV id="cust_msg">
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>
16   </A>
17 %   } else {
18 <% emt('[quant,_1,total message]', $total) %>
19 %   }
20 <BR>
21 <& /elements/table-grid.html &>
22   <TR>
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>
28   </TR>
29 %   my $i = 0;
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) : '' %>
36     </A></TD>
37     <TD CLASS="grid" STYLE="color: <% $typecolor->($row) %>"><% $link %>
38       <% ucfirst($row->msgtype) || $row->msgname %>
39     </A></TD>
40     <TD CLASS="grid"><% $link %>
41       <% join('<BR>', split(/,\s*/, $row->env_to)) %>
42     </A></TD>
43     <TD CLASS="grid" STYLE="color: <% $statuscolor->($row) %>">
44       <% $row->status %>
45     </TD>
46     <TD CLASS="grid">
47       <% $row->error |h %>
48     </TD>
49   </TR>
50 %     $i = 1 - $i;
51 %   }
52 </TABLE>
53 </DIV>
54 % }
55 <%init>
56 my %opt = @_;
57
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;
62
63 my $where = "WHERE cust_msg.custnum = $custnum";
64 my $maxrecords = 10;
65 if ( $curuser->option('customer_view_emails') =~ /^\s*(\d+)\s*$/ ) {
66   $maxrecords = $1;
67 }
68
69 my $order_by = '_date DESC';
70
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 LIMIT $maxrecords",
81 };
82 my $count_query = "SELECT COUNT(*) FROM cust_msg $where";
83
84 my @rows = qsearch($query);
85 my $total = FS::Record->scalar_sql($count_query);
86
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',
92     'width'       => 680,
93     'height'      => 550,
94   );
95 };
96
97 my %color = (
98   'failed'   => '#FF0000',
99   'sent'     => '#000000',
100
101   'invoice'  => '#00CC00',
102   'receipt'  => '#0000CC',
103   'admin'    => '#CC0000',
104   ''         => '#000000',
105 );
106 my $statuscolor = sub { $color{$_[0]->status} };
107 my $typecolor = sub { $color{$_[0]->msgtype} };
108
109 </%init>