This commit was generated by cvs2svn to compensate for changes in r8593,
[freeside.git] / httemplate / misc / email-customers.html
1 <% include('/elements/header.html', $title) %>
2
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 %>" VALUE="<% $value %>">
8 %   }
9 % }
10
11 % if ( $cgi->param('magic') eq 'send' ) {
12
13     <FONT SIZE="+2">Sending notice</FONT>
14
15     <% include('/elements/progress-init.html',
16                  'OneTrueForm',
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..
20               )
21     %>
22
23 % } elsif ( $cgi->param('magic') eq 'preview' ) {
24
25     <FONT SIZE="+2">Preview notice</FONT>
26
27 % }
28
29 % if ( $cgi->param('magic') ) {
30
31     <TABLE BGCOLOR="#cccccc" CELLSPACING=0>
32
33       <% include('/elements/tr-fixed.html',
34                    'field'      => 'from',
35                    'label'      => 'From:',
36                    'value' => scalar( $cgi->param('from') ),
37                 )
38       %>
39
40       <% include('/elements/tr-fixed.html',
41                    'field'      => 'subject',
42                    'label'      => 'Subject:',
43                    'value' => scalar( $cgi->param('subject') ),
44                 )
45       %>
46
47       <INPUT TYPE="hidden" NAME="html_body" VALUE="<% $cgi->param('html_body') |h %>">
48       <TR>
49         <TD ALIGN="right" VALIGN="top">Message (HTML display): </TD>
50         <TD BGCOLOR="#e8e8e8" ALIGN="left"><% $cgi->param('html_body') %></TD>
51       </TR>
52
53 %     my $text_body = HTML::FormatText->new(leftmargin=>0)->format(
54 %                       HTML::TreeBuilder->new_from_content(
55 %                         $cgi->param('html_body')
56 %                       )
57 %                     );
58       <INPUT TYPE="hidden" NAME="text_body" VALUE="<% $text_body |h %>">
59       <TR>
60         <TD ALIGN="right" VALIGN="top">Message (Text display): </TD>
61         <TD BGCOLOR="#e8e8e8" ALIGN="left"><PRE><% $text_body %></PRE></TD>
62       </TR>
63
64     </TABLE>
65
66 % if ( $cgi->param('magic') eq 'preview' ) {
67
68       <SCRIPT>
69         function areyousure(href) {
70           return confirm("Send this notice to <% $num_cust %> customers?");
71         }
72       </SCRIPT>
73
74       <BR>
75       <INPUT TYPE="hidden" NAME="magic" VALUE="send">
76       <INPUT TYPE="submit" VALUE="Send notice" onClick="return areyousure()">
77     
78 %   }
79
80 % } else {
81
82   <TABLE BGCOLOR="#cccccc" CELLSPACING=0 WIDTH="100%">
83
84     <% include('/elements/tr-input-text.html',
85                  'field' => 'from',
86                  'label' => 'From:',
87               )
88     %>
89
90     <% include('/elements/tr-input-text.html',
91                  'field' => 'subject',
92                  'label' => 'Subject:',
93               )
94     %>
95
96     <TR>
97       <TD ALIGN="right" VALIGN="top">Message: </TD>
98       <TD><% include('/elements/htmlarea.html', 'field'=>'html_body') %></TD>
99     </TR>
100
101   </TABLE>
102
103 %#Substitution vars:
104
105     <BR><BR>
106     <INPUT TYPE="hidden" NAME="magic" VALUE="preview">
107     <INPUT TYPE="submit" VALUE="Preview notice">
108
109 % }
110
111 </FORM>
112
113 % if ( $cgi->param('magic') eq 'send' ) {
114     <SCRIPT TYPE="text/javascript">
115       process();
116     </SCRIPT>
117 % }
118
119 <% include('/elements/footer.html') %>
120
121 <%init>
122
123 die "access denied"
124   unless $FS::CurrentUser::CurrentUser->access_right('Bulk send customer notices');
125
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 { $_ eq 'payby' || $search{$_} =~ /\0/ } keys %search;
130
131 my $title = 'Bulk send customer notices';
132
133 my $num_cust;
134 if ( $cgi->param('magic') eq 'preview' ) {
135   my $sql_query = FS::cust_main->search(\%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;
139   $count_sth->execute
140     or die "Error executing $count_query: ". $count_sth->errstr;
141   my $count_arrayref = $count_sth->fetchrow_arrayref;
142   $num_cust = $count_arrayref->[0];
143 }
144
145 </%init>