1 <% include('/elements/header.html', $title) %>
3 <FORM NAME="OneTrueForm" ACTION="email-customers.html" METHOD="POST">
4 <INPUT TYPE="hidden" NAME="table" VALUE="<% $table %>">
5 %# Mixing search params with from address, subject, etc. required special-case
6 %# handling of those, risked name conflicts, and caused massive problems with
7 %# multi-valued search params. We are no longer in search context, so we
8 %# pack the search into a Storable string for later use.
9 <INPUT TYPE="hidden" NAME="search" VALUE="<% encode_base64(nfreeze(\%search)) %>">
11 % if ( $cgi->param('action') eq 'send' ) {
13 <FONT SIZE="+2">Sending notice</FONT>
15 <% include('/elements/progress-init.html',
17 [ qw( search table from subject html_body text_body msgnum ) ],
18 'process/email-customers.html',
19 { 'message' => "Notice sent" }, #would be nice to show #, but..
23 % } elsif ( $cgi->param('action') eq 'preview' ) {
25 <FONT SIZE="+2">Preview notice</FONT>
29 % if ( $cgi->param('action') ) {
31 <TABLE BGCOLOR="#cccccc" CELLSPACING=0>
32 <INPUT TYPE="hidden" NAME="msgnum" VALUE="<% $cgi->param('msgnum') %>">
34 % if ( $msg_template ) {
35 <% include('/elements/tr-fixed.html',
36 'label' => 'Template:',
37 'value' => $msg_template->msgname,
42 <% include('/elements/tr-fixed.html',
45 'value' => scalar( $from ),
49 <% include('/elements/tr-fixed.html',
51 'label' => 'Subject:',
52 'value' => scalar( $subject ),
56 <INPUT TYPE="hidden" NAME="html_body" VALUE="<% $html_body |h %>">
58 <TD ALIGN="right" VALIGN="top">Message (HTML display): </TD>
59 <TD CLASS="background" ALIGN="left"><% $html_body %></TD>
62 % my $text_body = HTML::FormatText->new(leftmargin=>0)->format(
63 % HTML::TreeBuilder->new_from_content(
67 <INPUT TYPE="hidden" NAME="text_body" VALUE="<% $text_body |h %>">
69 <TD ALIGN="right" VALIGN="top">Message (Text display): </TD>
70 <TD CLASS="background" STYLE="background-color:white" ALIGN="left"><PRE><% $text_body %></PRE></TD>
75 % if ( $cgi->param('action') eq 'preview' ) {
78 function areyousure(href) {
79 return confirm("Send this notice to <% ($num_cust > 1) ? "$num_cust customers" : '1 customer' %> ?");
84 <INPUT TYPE="hidden" NAME="action" VALUE="send">
85 <INPUT TYPE="submit" VALUE="Send notice" onClick="return areyousure()">
91 <SCRIPT TYPE="text/javascript">
92 function toggle(obj) {
93 document.getElementById('table_no_template').style.display = (obj.value == 0) ? '' : 'none';
98 <% include('/elements/select-table.html',
99 'label' => 'Template:',
100 'table' => 'msg_template',
101 'name_col' => 'msgname',
102 'empty_label' => '(none)',
103 'onchange' => 'toggle(this)',
106 <TABLE BGCOLOR="#cccccc" CELLSPACING=0 WIDTH="100%" id="table_no_template">
107 <& /elements/tr-td-label.html, 'label' => 'From:' &>
108 <TD><& /elements/input-text.html,
109 'field' => 'from_name',
110 'value' => $conf->config('company_name'), #?
113 <& /elements/input-text.html,
114 'field' => 'from_addr',
115 'type' => 'email', # HTML5, woot
116 'value' => $conf->config('invoice_from'),
120 <% include('/elements/tr-input-text.html',
121 'field' => 'subject',
122 'label' => 'Subject:',
128 <TD ALIGN="right" VALIGN="top" STYLE="padding-top:3px">Message: </TD>
129 <TD><& /elements/htmlarea.html,
130 'field' => 'html_body',
140 <INPUT TYPE="hidden" NAME="action" VALUE="preview">
141 <INPUT TYPE="submit" VALUE="Preview notice">
147 % if ( $cgi->param('action') eq 'send' ) {
148 <SCRIPT TYPE="text/javascript">
153 <% include('/elements/footer.html') %>
158 unless $FS::CurrentUser::CurrentUser->access_right('Bulk send customer notices');
160 my $conf = FS::Conf->new;
161 my $table = $cgi->param('table') or die "'table' required";
163 if ( $cgi->param('search') ) {
164 %search = %{ thaw(decode_base64($cgi->param('search'))) };
167 %search = $cgi->Vars;
168 delete $search{$_} for qw( action table from subject html_body text_body );
169 # FS::$table->search is expected to know which parameters might be
170 # multi-valued, and to accept scalar values for them also. No good
171 # solution to this since CGI can't tell whether a parameter _might_
172 # have had multiple values, only whether it does.
173 @search{keys %search} = map { /\0/ ? [ split /\0/, $_ ] : $_ } values %search;
176 my $title = 'Send customer notices';
180 if ( $cgi->param('from') ) {
181 $from = $cgi->param('from');
182 } elsif ( $cgi->param('from_name') ) {
183 $from = ($cgi->param('from_name') . ' <' . $cgi->param('from_addr') . '>');
184 } elsif ( $cgi->param('from_addr') ) {
185 $from = $cgi->param('from_addr');
188 my $subject = $cgi->param('subject') || '';
189 my $html_body = $cgi->param('html_body') || '';
191 my $msg_template = '';
193 if ( $cgi->param('action') eq 'preview' ) {
194 my $sql_query = "FS::$table"->search(\%search);
195 my $count_query = delete($sql_query->{'count_query'});
196 my $count_sth = dbh->prepare($count_query)
197 or die "Error preparing $count_query: ". dbh->errstr;
199 or die "Error executing $count_query: ". $count_sth->errstr;
200 my $count_arrayref = $count_sth->fetchrow_arrayref;
201 $num_cust = $count_arrayref->[0];
203 if ( $cgi->param('msgnum') ) {
204 $msg_template = qsearchs('msg_template',
205 { msgnum => $cgi->param('msgnum') } )
206 or die "template not found: ".$cgi->param('msgnum');
207 $sql_query->{'extra_sql'} .= ' LIMIT 1';
208 $sql_query->{'select'} = "$table.*";
209 $sql_query->{'order_by'} = '';
210 my $object = qsearchs($sql_query);
211 my $cust = $object->cust_main;
212 my %message = $msg_template->prepare(
213 'cust_main' => $cust,
216 ($from, $subject, $html_body) = @message{'from', 'subject', 'html_body'};