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>
33 % if ( $msg_template ) {
34 <% include('/elements/tr-fixed.html',
35 'label' => 'Template:',
36 'value' => $msg_template->msgname,
41 <% include('/elements/tr-fixed.html',
44 'value' => scalar( $from ),
48 <% include('/elements/tr-fixed.html',
50 'label' => 'Subject:',
51 'value' => scalar( $subject ),
55 <INPUT TYPE="hidden" NAME="html_body" VALUE="<% $html_body |h %>">
57 <TD ALIGN="right" VALIGN="top">Message (HTML display): </TD>
58 <TD CLASS="background" ALIGN="left"><% $html_body %></TD>
61 % my $text_body = HTML::FormatText->new(leftmargin=>0)->format(
62 % HTML::TreeBuilder->new_from_content(
66 <INPUT TYPE="hidden" NAME="text_body" VALUE="<% $text_body |h %>">
68 <TD ALIGN="right" VALIGN="top">Message (Text display): </TD>
69 <TD CLASS="background" STYLE="background-color:white" ALIGN="left"><PRE><% $text_body %></PRE></TD>
74 % if ( $cgi->param('action') eq 'preview' ) {
77 function areyousure(href) {
78 return confirm("Send this notice to <% $num_cust %> customers?");
83 <INPUT TYPE="hidden" NAME="action" VALUE="send">
84 <INPUT TYPE="submit" VALUE="Send notice" onClick="return areyousure()">
90 <SCRIPT TYPE="text/javascript">
91 function toggle(obj) {
92 document.getElementById('table_no_template').style.display = (obj.value == 0) ? '' : 'none';
97 <% include('/elements/select-table.html',
98 'label' => 'Template:',
99 'table' => 'msg_template',
100 'name_col' => 'msgname',
101 'empty_label' => '(none)',
102 'onchange' => 'toggle(this)',
105 <TABLE BGCOLOR="#cccccc" CELLSPACING=0 WIDTH="100%" id="table_no_template">
106 <% include('/elements/tr-input-text.html',
112 <% include('/elements/tr-input-text.html',
113 'field' => 'subject',
114 'label' => 'Subject:',
119 <TD ALIGN="right" VALIGN="top">Message: </TD>
120 <TD><% include('/elements/htmlarea.html', 'field'=>'html_body') %></TD>
127 <INPUT TYPE="hidden" NAME="action" VALUE="preview">
128 <INPUT TYPE="submit" VALUE="Preview notice">
134 % if ( $cgi->param('action') eq 'send' ) {
135 <SCRIPT TYPE="text/javascript">
140 <% include('/elements/footer.html') %>
145 unless $FS::CurrentUser::CurrentUser->access_right('Bulk send customer notices');
147 my $table = $cgi->param('table') or die "'table' required";
149 if ( $cgi->param('search') ) {
150 %search = %{ thaw(decode_base64($cgi->param('search'))) };
153 %search = $cgi->Vars;
154 delete $search{$_} for qw( action table from subject html_body text_body );
155 # FS::$table->search is expected to know which parameters might be
156 # multi-valued, and to accept scalar values for them also. No good
157 # solution to this since CGI can't tell whether a parameter _might_
158 # have had multiple values, only whether it does.
159 @search{keys %search} = map { /\0/ ? [ split /\0/, $_ ] : $_ } values %search;
162 my $title = 'Send bulk customer notices';
165 my $from = $cgi->param('from') || '';
166 my $subject = $cgi->param('subject') || '';
167 my $html_body = $cgi->param('html_body') || '';
169 my $msg_template = '';
171 if ( $cgi->param('action') eq 'preview' ) {
172 my $sql_query = "FS::$table"->search(\%search);
173 my $count_query = delete($sql_query->{'count_query'});
174 my $count_sth = dbh->prepare($count_query)
175 or die "Error preparing $count_query: ". dbh->errstr;
177 or die "Error executing $count_query: ". $count_sth->errstr;
178 my $count_arrayref = $count_sth->fetchrow_arrayref;
179 $num_cust = $count_arrayref->[0];
181 if ( $cgi->param('msgnum') ) {
182 $msg_template = qsearchs('msg_template',
183 { msgnum => $cgi->param('msgnum') } )
184 or die "template not found: ".$cgi->param('msgnum');
185 $sql_query->{'extra_sql'} .= ' LIMIT 1';
186 $sql_query->{'order_by'} = '';
187 my $cust = qsearchs($sql_query)->cust_main;
188 my %message = $msg_template->prepare( 'cust_main' => $cust );
189 ($from, $subject, $html_body) = @message{'from', 'subject', 'html_body'};