summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormark <mark>2011-07-01 05:33:55 +0000
committermark <mark>2011-07-01 05:33:55 +0000
commit4b80fe118da16b21603fcdbd090bc03d8fbf0578 (patch)
treefe5960c7c4ad7514dc46bd37e8e09cb86f266845
parent2c69cd41531a493c45ea72da3aa379fcc9f70aa9 (diff)
send email from customer view, #13444
-rw-r--r--FS/FS/Misc.pm58
-rw-r--r--FS/FS/cust_main/Search.pm27
-rw-r--r--FS/FS/cust_main_Mixin.pm10
-rw-r--r--FS/FS/msg_template.pm26
-rw-r--r--httemplate/misc/email-customers.html17
-rw-r--r--httemplate/search/cust_msg.html10
-rwxr-xr-xhttemplate/view/cust_main.cgi11
7 files changed, 94 insertions, 65 deletions
diff --git a/FS/FS/Misc.pm b/FS/FS/Misc.pm
index d5f02de..3b0de3d 100644
--- a/FS/FS/Misc.pm
+++ b/FS/FS/Misc.pm
@@ -89,10 +89,14 @@ encoding which, if specified, overrides the default "7bit".
(optional) type parameter for multipart/related messages
-=item cust_msg
+=item custnum
-(optional) L<FS::cust_msg> object. If provided, it will be updated
-with the message envelope information, contents, and server response.
+(optional) L<FS::cust_main> key; if passed, the message will be logged
+(if logging is enabled) with this custnum.
+
+=item msgnum
+
+(optional) L<FS::msg_template> key, for logging.
=back
@@ -255,18 +259,20 @@ sub send_email {
}
# Logging
- my $cust_msg = $options{'cust_msg'};
- if ( $cust_msg ) {
- $cust_msg->env_from($options{from});
- $cust_msg->env_to(join(",", @to));
- $cust_msg->header($message->header_as_string);
- $cust_msg->body($message->body_as_string);
- $cust_msg->_date($time);
- $cust_msg->error($error);
- $cust_msg->status( $error ? 'failed' : 'sent' );
- $cust_msg->replace;
- };
- return $error;
+ if ( $conf->exists('log_sent_mail') and $options{'custnum'} ) {
+ my $cust_msg = FS::cust_msg->new({
+ 'env_from' => $options{'from'},
+ 'env_to' => join(', ', @to),
+ 'header' => $message->header_as_string,
+ 'body' => $message->body_as_string,
+ '_date' => $time,
+ 'error' => $error,
+ 'custnum' => $options{'custnum'},
+ 'msgnum' => $options{'msgnum'},
+ 'status' => ($error ? 'failed' : 'sent'),
+ });
+ $cust_msg->insert; # ignore errors
+ }
}
@@ -302,9 +308,9 @@ Will be placed inside an HTML <BODY> tag.
Email body (Text alternative). Arrayref of lines, or scalar.
-=item cust_msg (optional)
+=item custnum, msgnum (optional)
-An L<FS::cust_msg> object. Will be passed through to send_email.
+Customer and template numbers, passed through to send_email for logging.
=back
@@ -322,21 +328,9 @@ sub generate_email {
my $me = '[FS::Misc::generate_email]';
- my %return = (
- 'from' => $args{'from'},
- 'to' => $args{'to'},
- 'bcc' => $args{'bcc'},
- 'subject' => $args{'subject'},
- 'cust_msg'=> $args{'cust_msg'},
- );
-
- #if (ref($args{'to'}) eq 'ARRAY') {
- # $return{'to'} = $args{'to'};
- #} else {
- # $return{'to'} = [ grep { $_ !~ /^(POST|FAX)$/ }
- # $self->cust_main->invoicing_list
- # ];
- #}
+ my @fields = qw(from to bcc subject custnum msgnum);
+ my %return;
+ @return{@fields} = @args{@fields};
warn "$me creating HTML/text multipart message"
if $DEBUG;
diff --git a/FS/FS/cust_main/Search.pm b/FS/FS/cust_main/Search.pm
index 06a4522..5636fc6 100644
--- a/FS/FS/cust_main/Search.pm
+++ b/FS/FS/cust_main/Search.pm
@@ -471,6 +471,33 @@ sub search {
my @where = ();
my $orderby;
+ # initialize these to prevent warnings
+ $params = {
+ 'custnum' => '',
+ 'agentnum' => '',
+ 'usernum' => '',
+ 'status' => '',
+ 'address' => '',
+ 'paydate_year' => '',
+ 'invoice_terms' => '',
+ 'custbatch' => '',
+ %$params
+ };
+
+ ##
+ # explicit custnum(s)
+ ##
+
+ if ( $params->{'custnum'} ) {
+ my @custnums = ref($params->{'custnum'}) ?
+ @{ $params->{'custnum'} } :
+ $params->{'custnum'};
+ push @where,
+ 'cust_main.custnum IN (' .
+ join(',', map { $_ =~ /^(\d+)$/ ? $1 : () } @custnums ) .
+ ')' if scalar(@custnums) > 0;
+ }
+
##
# parse agent
##
diff --git a/FS/FS/cust_main_Mixin.pm b/FS/FS/cust_main_Mixin.pm
index 8c8553c..e8e243f 100644
--- a/FS/FS/cust_main_Mixin.pm
+++ b/FS/FS/cust_main_Mixin.pm
@@ -408,9 +408,6 @@ sub email_search_result {
or die "msgnum $msgnum not found\n";
}
- $param->{'payby'} = [ split(/\0/, $param->{'payby'}) ]
- unless ref($param->{'payby'});
-
my $sql_query = $class->search($param->{'search'});
my $count_query = delete($sql_query->{'count_query'});
@@ -463,15 +460,16 @@ sub email_search_result {
@message = $msg_template->prepare( 'cust_main' => $cust_main );
}
else {
- my $to = $cust_main->invoicing_list_emailonly_scalar;
- next if !$to;
+ my @to = $cust_main->invoicing_list_emailonly;
+ next if !@to;
@message = (
'from' => $from,
- 'to' => $to,
+ 'to' => \@to,
'subject' => $subject,
'html_body' => $html_body,
'text_body' => $text_body,
+ 'custnum' => $cust_main->custnum,
);
} #if $msg_template
diff --git a/FS/FS/msg_template.pm b/FS/FS/msg_template.pm
index 4a1e345..e90cffd 100644
--- a/FS/FS/msg_template.pm
+++ b/FS/FS/msg_template.pm
@@ -193,11 +193,6 @@ The I<from_addr> field in the template takes precedence over this.
Destination address. The default is to use the customer's
invoicing_list addresses. Multiple addresses may be comma-separated.
-=item preview
-
-Set to true when preparing a message for previewing, rather than to actually
-send it. This turns off logging.
-
=back
=cut
@@ -318,16 +313,16 @@ sub prepare {
$from_addr ||= scalar( $conf->config('invoice_from',
$cust_main->agentnum) );
}
- my @cust_msg = ();
- if ( $conf->exists('log_sent_mail') and !$opt{'preview'} ) {
- my $cust_msg = FS::cust_msg->new({
- 'custnum' => $cust_main->custnum,
- 'msgnum' => $self->msgnum,
- 'status' => 'prepared',
- });
- $cust_msg->insert;
- @cust_msg = ('cust_msg' => $cust_msg);
- }
+# my @cust_msg = ();
+# if ( $conf->exists('log_sent_mail') and !$opt{'preview'} ) {
+# my $cust_msg = FS::cust_msg->new({
+# 'custnum' => $cust_main->custnum,
+# 'msgnum' => $self->msgnum,
+# 'status' => 'prepared',
+# });
+# $cust_msg->insert;
+# @cust_msg = ('cust_msg' => $cust_msg);
+# }
(
'custnum' => $cust_main->custnum,
@@ -339,7 +334,6 @@ sub prepare {
'html_body' => $body,
'text_body' => HTML::FormatText->new(leftmargin => 0, rightmargin => 70
)->format( HTML::TreeBuilder->new_from_content($body) ),
- @cust_msg,
);
}
diff --git a/httemplate/misc/email-customers.html b/httemplate/misc/email-customers.html
index 97ad8d8..d981aea 100644
--- a/httemplate/misc/email-customers.html
+++ b/httemplate/misc/email-customers.html
@@ -76,7 +76,7 @@
<SCRIPT>
function areyousure(href) {
- return confirm("Send this notice to <% $num_cust %> customers?");
+ return confirm("Send this notice to <% ($num_cust > 1) ? "$num_cust customers" : '1 customer' %> ?");
}
</SCRIPT>
@@ -107,18 +107,22 @@ Template:
<% include('/elements/tr-input-text.html',
'field' => 'from',
'label' => 'From:',
+ 'size' => 50,
)
%>
<% include('/elements/tr-input-text.html',
'field' => 'subject',
'label' => 'Subject:',
+ 'size' => 50,
)
%>
<TR>
- <TD ALIGN="right" VALIGN="top">Message: </TD>
- <TD><% include('/elements/htmlarea.html', 'field'=>'html_body') %></TD>
+ <TD ALIGN="right" VALIGN="top" STYLE="padding-top:3px">Message: </TD>
+ <TD><& '/elements/htmlarea.html',
+ 'field' => 'html_body',
+ 'width' => 600 &></TD>
</TR>
</TABLE>
@@ -160,7 +164,7 @@ else {
@search{keys %search} = map { /\0/ ? [ split /\0/, $_ ] : $_ } values %search;
}
-my $title = 'Send bulk customer notices';
+my $title = 'Send customer notices';
my $num_cust;
my $from = $cgi->param('from') || '';
@@ -185,8 +189,9 @@ if ( $cgi->param('action') eq 'preview' ) {
or die "template not found: ".$cgi->param('msgnum');
$sql_query->{'extra_sql'} .= ' LIMIT 1';
$sql_query->{'order_by'} = '';
- my $cust = qsearchs($sql_query)->cust_main;
- my %message = $msg_template->prepare( 'cust_main' => $cust, 'preview' => 1 );
+ my $object = qsearchs($sql_query);
+ my $cust = $object->cust_main;
+ my %message = $msg_template->prepare( 'cust_main' => $cust );
($from, $subject, $html_body) = @message{'from', 'subject', 'html_body'};
}
}
diff --git a/httemplate/search/cust_msg.html b/httemplate/search/cust_msg.html
index 7932ab3..64fae30 100644
--- a/httemplate/search/cust_msg.html
+++ b/httemplate/search/cust_msg.html
@@ -16,7 +16,9 @@
$date ? time2str('%Y-%m-%d %T',$_[0]->_date) : ''
},
'msgname',
- 'env_to',
+ sub {
+ join('<BR>', split(/,\s*/, $_[0]->env_to) )
+ },
'status',
sub { encode_entities($_[0]->error) },
],
@@ -83,7 +85,6 @@ my $sub_popup_link = sub {
};
my %color = (
- 'prepared' => '0000FF',
'failed' => 'FF0000',
'sent' => '',
);
@@ -104,11 +105,10 @@ include('/elements/input-date-field.html',
include('/elements/select.html',
'field' => 'status',
'curr_value' => $cgi->param('status') || '',
- 'options' => [ '', 'failed', 'sent', 'prepared' ],
+ 'options' => [ '', 'failed', 'sent', ],
'labels' => { '' => '(any)',
'failed' => 'failed',
- 'sent' => 'sent',
- 'prepared'=> 'prepared' },
+ 'sent' => 'sent', },
) .
'</TD>
<TD><INPUT type="submit" value="Search"></TD></TR>
diff --git a/httemplate/view/cust_main.cgi b/httemplate/view/cust_main.cgi
index a6c917f..dcadf99 100755
--- a/httemplate/view/cust_main.cgi
+++ b/httemplate/view/cust_main.cgi
@@ -97,6 +97,17 @@ function areyousure(href, message) {
% $br=1;
<A HREF="<% $p %>search/cust_event.html?custnum=<% $custnum %>"><% mt('View billing events for this customer') |h %></A>
% }
+%
+% my $email_link = ($cust_main->invoicing_list_emailonly) &&
+% include('/elements/email-link.html',
+% 'table' => 'cust_main',
+% 'search_hash' => { 'custnum' => $custnum },
+% 'label' => 'Email a notice to this customer',
+% );
+% if ( $email_link and $br ) {
+ |
+% }
+<% $email_link || '' %>
% if ( $conf->config('cust_main-external_links') ) {
<% $br++ ? ' | ' : '' %>