RT# 73421 Fixed E-Mail pipeline to obey contact opt-in flags
[freeside.git] / httemplate / view / cust_main / contacts_new.html
index a851d99..fe412cc 100644 (file)
@@ -1,33 +1,71 @@
+% if ( $display and @cust_contacts ) {
 <BR>
 <FONT CLASS="fsinnerbox-title">Contacts</FONT>
-<A HREF="<%$p%>edit/cust_main-contacts.html?<% $cust_main->custnum %>">Edit contacts</A>
-<TABLE CLASS="fsinnerbox">
-%   foreach my $contact ( @contacts ) {
-%     #XXX maybe this should be a table with alternating colors instead
+
+<& /elements/table-grid.html &>
+<THEAD>
+% my $th = '<TH CLASS="grid" ALIGN="left">';
+<TR>
+  <%$th%>Type</TH>
+  <%$th%>Contact</TH>
+  <%$th%>Email</TH>
+  <%$th%>Send invoices</TH>
+  <%$th%>Send messages</TH>
+  <%$th%>Self-service</TH>
+% foreach my $phone_type (@phone_type) {
+    <%$th%><% $phone_type->typename |h %></TH>
+% }
+  <%$th%>Comment</TH>
+</TR>
+</THEAD>
+
+%   my $bgcolor1 = '#ffffff';
+%   my $bgcolor2 = '#eeeeee';
+%   my $bgcolor = $bgcolor2;
+%   foreach my $cust_contact ( @cust_contacts ) {
+%     my $contact = $cust_contact->contact;
+%     my $td = qq(<TD CLASS="grid" BGCOLOR="$bgcolor">);
+
       <TR>
-        <TD ALIGN="right"><% $contact->contact_classname %> Contact</TD>
-        <TD BGCOLOR="#FFFFFF"><% $contact->line %></TD>
+        <%$td%><% $cust_contact->contact_classname |h %></TD>
+        <%$td%><% $contact->line |h %></TD>
 
 %       my @contact_email = $contact->contact_email;
-%       if (@contact_email) {
-          <TD ALIGN="right">&nbsp;&nbsp;&nbsp;Email</TD>
-          <TD BGCOLOR="#FFFFFF"><% join(', ', map $_->emailaddress, @contact_email) %></TD>
-%       }
+        <%$td%><% join(', ', map $_->emailaddress, @contact_email) %></TD>
+        <%$td%><% $cust_contact->invoice_dest eq 'Y' ? 'Yes' : 'No' %></TD>
+        <%$td%><% $cust_contact->message_dest eq 'Y' ? 'Yes' : 'No' %></TD>
+        <%$td%>
+%         if ( $cust_contact->selfservice_access ) {
+            Enabled
+%#            <FONT SIZE="-1"><A HREF="XXX">disable</A>
+%#                            <A HREF="XXX">re-email</A></FONT>
+%         } else {
+            Disabled
+%#            <FONT SIZE="-1"><A HREF="XXX">enable</A></FONT>
+%        }
+       </TD>
 
 %       foreach my $phone_type (@phone_type) {
 %         my $contact_phone =
 %           qsearchs('contact_phone', {
 %                      'contactnum'   => $contact->contactnum,
 %                      'phonetypenum' => $phone_type->phonetypenum,
-%                   })
-%           or next;
-          <TD ALIGN="right">&nbsp;&nbsp;&nbsp;<% $phone_type->typename %> phone</TD>
-          <TD BGCOLOR="#FFFFFF"><% $contact_phone->phonenum_pretty |h %></TD>
+%                   });
+          <%$td%><% $contact_phone ? $contact_phone->phonenum_pretty : '' |h %></TD>
 %       }
 
+        <%$td%><% $cust_contact->comment |h %></TD>
+
       </TR>
+
+%     if ( $bgcolor eq $bgcolor1 ) {
+%        $bgcolor = $bgcolor2;
+%      } else {
+%        $bgcolor = $bgcolor1;
+%      }
 %   }
 </TABLE>
+%}
 <%once>
 
 my @phone_type = qsearch({table=>'phone_type', order_by=>'weight'});
@@ -38,6 +76,10 @@ my @phone_type = qsearch({table=>'phone_type', order_by=>'weight'});
 my( $cust_main ) = @_;
 #my $conf = new FS::Conf;
 
-my @contacts = $cust_main->cust_contact;
+my @cust_contacts = $cust_main->cust_contact;
+
+# residential customers have a default "invisible" contact, but if they
+# somehow get more than one contact, show them
+my $display = scalar(@cust_contacts) > 1;
 
 </%init>