1 <% include('/elements/header.html', $title) %>
3 <FORM NAME="OneTrueForm" ACTION="email-customers.html" METHOD="POST">
4 % foreach my $key ( keys %search ) {
5 % my @values = ref($search{$key}) ? @{$search{$key}} : ( $search{$key} );
6 % foreach my $value ( @values ) {
7 <INPUT TYPE="hidden" NAME="<% $key |h %>" VALUE="<% $value |h %>">
11 % if ( $cgi->param('magic') eq 'send' ) {
13 <FONT SIZE="+2">Sending notice</FONT>
15 <% include('/elements/progress-init.html',
17 [ keys(%search), qw( from subject html_body text_body ) ],
18 'process/email-customers.html',
19 { 'message' => "Notice sent" }, #would be nice to show #, but..
23 % } elsif ( $cgi->param('magic') eq 'preview' ) {
25 <FONT SIZE="+2">Preview notice</FONT>
29 % if ( $cgi->param('magic') ) {
31 <TABLE BGCOLOR="#cccccc" CELLSPACING=0>
33 <% include('/elements/tr-fixed.html',
36 'value' => scalar( $cgi->param('from') ),
40 <% include('/elements/tr-fixed.html',
42 'label' => 'Subject:',
43 'value' => scalar( $cgi->param('subject') ),
47 <INPUT TYPE="hidden" NAME="html_body" VALUE="<% $cgi->param('html_body') |h %>">
49 <TD ALIGN="right" VALIGN="top">Message (HTML display): </TD>
50 <TD BGCOLOR="#e8e8e8" ALIGN="left"><% $cgi->param('html_body') %></TD>
53 % my $text_body = HTML::FormatText->new(leftmargin=>0)->format(
54 % HTML::TreeBuilder->new_from_content(
55 % $cgi->param('html_body')
58 <INPUT TYPE="hidden" NAME="text_body" VALUE="<% $text_body |h %>">
60 <TD ALIGN="right" VALIGN="top">Message (Text display): </TD>
61 <TD BGCOLOR="#e8e8e8" ALIGN="left"><PRE><% $text_body %></PRE></TD>
66 % if ( $cgi->param('magic') eq 'preview' ) {
69 function areyousure(href) {
70 return confirm("Send this notice to <% $num_cust %> customers?");
75 <INPUT TYPE="hidden" NAME="magic" VALUE="send">
76 <INPUT TYPE="submit" VALUE="Send notice" onClick="return areyousure()">
82 <TABLE BGCOLOR="#cccccc" CELLSPACING=0 WIDTH="100%">
84 <% include('/elements/tr-input-text.html',
90 <% include('/elements/tr-input-text.html',
92 'label' => 'Subject:',
97 <TD ALIGN="right" VALIGN="top">Message: </TD>
98 <TD><% include('/elements/htmlarea.html', 'field'=>'html_body') %></TD>
106 <INPUT TYPE="hidden" NAME="magic" VALUE="preview">
107 <INPUT TYPE="submit" VALUE="Preview notice">
113 % if ( $cgi->param('magic') eq 'send' ) {
114 <SCRIPT TYPE="text/javascript">
119 <% include('/elements/footer.html') %>
124 unless $FS::CurrentUser::CurrentUser->access_right('Bulk send customer notices');
126 my %search = $cgi->Vars;
127 delete $search{$_} for qw( magic from subject html_body text_body );
128 $search{$_} = [ split(/\0/, $search{$_}) ]
129 foreach grep $search{$_} =~ /\0/, keys %search;
131 my $title = 'Bulk send customer notices';
134 if ( $cgi->param('magic') eq 'preview' ) {
135 my $sql_query = FS::cust_main->search_sql(\%search);
136 my $count_query = delete($sql_query->{'count_query'});
137 my $count_sth = dbh->prepare($count_query)
138 or die "Error preparing $count_query: ". dbh->errstr;
140 or die "Error executing $count_query: ". $count_sth->errstr;
141 my $count_arrayref = $count_sth->fetchrow_arrayref;
142 $num_cust = $count_arrayref->[0];