summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--FS/FS/Misc.pm4
-rw-r--r--FS/FS/msg_template.pm15
-rw-r--r--FS/FS/part_export/send_email.pm160
3 files changed, 171 insertions, 8 deletions
diff --git a/FS/FS/Misc.pm b/FS/FS/Misc.pm
index fe8ac60..6108f77 100644
--- a/FS/FS/Misc.pm
+++ b/FS/FS/Misc.pm
@@ -323,9 +323,9 @@ sub generate_email {
my $data;
if ( ref($args{'text_body'}) eq 'ARRAY' ) {
- $data = $args{'text_body'};
+ $data = join("\n", @{ $args{'text_body'} });
} else {
- $data = [ split(/\n/, $args{'text_body'}) ];
+ $data = $args{'text_body'};
}
$alternative->attach(
diff --git a/FS/FS/msg_template.pm b/FS/FS/msg_template.pm
index f0cda41..a35b2d1 100644
--- a/FS/FS/msg_template.pm
+++ b/FS/FS/msg_template.pm
@@ -178,7 +178,7 @@ rt_ticket export when exporting "replace" events.
=item to
Destination address. The default is to use the customer's
-invoicing_list addresses.
+invoicing_list addresses. Multiple addresses may be comma-separated.
=back
@@ -281,11 +281,14 @@ sub prepare {
# and email
###
- my @to = ($opt{'to'}) || $cust_main->invoicing_list_emailonly;
- #warn "prepared msg_template with no email destination (custnum ".
- # $cust_main->custnum.")\n"
- # if !@to;
- # warning is not appropriate now that we use these for tickets
+ my @to;
+ if ( exists($opt{'to'}) ) {
+ @to = split(/\s*,\s*/, $opt{'to'});
+ }
+ else {
+ @to = $cust_main->invoicing_list_emailonly;
+ }
+ # no warning when preparing with no destination
my $conf = new FS::Conf;
diff --git a/FS/FS/part_export/send_email.pm b/FS/FS/part_export/send_email.pm
new file mode 100644
index 0000000..05f6236
--- /dev/null
+++ b/FS/FS/part_export/send_email.pm
@@ -0,0 +1,160 @@
+package FS::part_export::send_email;
+
+use vars qw(@ISA %info);
+use Tie::IxHash;
+use FS::part_export;
+use FS::Record qw(qsearch qsearchs);
+use FS::Conf;
+use FS::msg_template;
+use FS::Misc qw(send_email);
+
+@ISA = qw(FS::part_export);
+
+my %templates;
+my %template_select = (
+ type => 'select',
+ freeform => 1,
+ option_label => sub {
+ $templates{$_[0]};
+ },
+ option_values => sub {
+ %templates = (0 => '',
+ map { $_->msgnum, $_->msgname }
+ qsearch({ table => 'msg_template',
+ hashref => {},
+ order_by => 'ORDER BY msgnum ASC'
+ })
+ );
+ sort keys (%templates);
+ },
+);
+
+tie my %options, 'Tie::IxHash', (
+ 'insert_template' => {
+ before => '
+<TR><TD COLSPAN=2>
+<TABLE>
+ <TR><TH></TH><TH>Template</TH></TR>
+ <TR><TD>New service</TD><TD>',
+ %template_select,
+ after => '</TD></TR>
+',
+ },
+ 'delete_template' => {
+ before => '
+ <TR><TD>Delete</TD><TD>',
+ %template_select,
+ after => '</TD></TR>
+',
+ },
+ 'replace_template' => {
+ before => '
+ <TR><TD>Modify</TD><TD>',
+ %template_select,
+ after => '</TD></TR>
+',
+ },
+ 'suspend_template' => {
+ before => '
+ <TR><TD>Suspend</TD><TD>',
+ %template_select,
+ after => '</TD></TR>
+',
+ },
+ 'unsuspend_template' => {
+ before => '
+ <TR><TD>Unsuspend</TD><TD>',
+ %template_select,
+ after => '</TD></TR>
+ </TABLE>
+</TD></TR>',
+ },
+ 'to_customer' => {
+ label => 'Send to customer',
+ type => 'checkbox',
+ },
+ 'to_address' => {
+ label => 'Send to other address: ',
+ type => 'text',
+ },
+);
+
+%info = (
+ 'svc' => [qw( svc_acct svc_broadband svc_phone svc_domain )],
+ 'desc' =>
+ 'Send an email message',
+ 'options' => \%options,
+ 'nodomain' => '',
+ 'notes' => '
+ Send an email message. The subject and body of the message
+ will be generated from a message template.'
+);
+
+sub _export {
+ my( $self, $action, $svc ) = (shift, shift, shift);
+ my $conf = new FS::Conf;
+
+ my $msgnum = $self->option($action.'_template');
+ return if !$msgnum;
+
+ my $msg_template = FS::msg_template->by_key($msgnum);
+ return "Template $msgnum not found\n" if !$msg_template;
+
+ my $cust_pkg = $svc->cust_svc->cust_pkg;
+ my $cust_main = $svc->cust_svc->cust_pkg->cust_main if $cust_pkg;
+ my $custnum = $cust_main->custnum if $cust_main;
+ my $svcnum = $svc->svcnum if $action ne 'delete';
+
+ my @to = split(',', $self->option('to_address') || '');
+ push @to, $cust_main->invoicing_list_emailonly
+ if $self->option('to_customer') and $cust_main;
+ if ( !@to ) {
+ warn 'No destination address for send_email export: custnum '.$cust_main->custnum;
+ # warn, don't die, but also avoid sending the template with _no_ 'to'=>
+ # param, which would send to the customer by default.
+ return;
+ }
+
+ if ( $action eq 'replace' ) {
+ my $old = shift;
+ return $msg_template->send(
+ 'cust_main' => $cust_main,
+ 'object' => [ $svc, $old ],
+ 'to' => join(',', @to),
+ );
+ }
+ else {
+ return $msg_template->send(
+ 'cust_main' => $cust_main,
+ 'object' => $svc,
+ 'to' => join(',', @to),
+ );
+ }
+}
+
+sub _export_insert {
+ my($self, $svc) = (shift, shift);
+ $self->_export('insert', $svc);
+}
+
+sub _export_replace {
+ my($self, $new, $old) = (shift, shift, shift);
+ $self->_export('replace', $new, $old);
+}
+
+sub _export_delete {
+ my($self, $svc) = (shift, shift);
+ $self->_export('delete', $svc);
+}
+
+sub _export_suspend {
+ my($self, $svc) = (shift, shift);
+ $self->_export('suspend', $svc);
+}
+
+sub _export_unsuspend {
+ my($self, $svc) = (shift, shift);
+ $self->_export('unsuspend', $svc);
+}
+
+1;