summaryrefslogtreecommitdiff
path: root/httemplate/misc/email-customers.html
blob: 0d3d622c312d78372e4cde467754b83cee21ce26 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<% include('/elements/header.html', $title) %>

<FORM NAME="OneTrueForm" ACTION="email-customers.html" METHOD="POST">
% foreach my $key ( keys %search ) {
%   my @values = ref($search{$key}) ? @{$search{$key}} : ( $search{$key} );
%   foreach my $value ( @values ) {
      <INPUT TYPE="hidden" NAME="<% $key |h %>" VALUE="<% $value |h %>">
%   }
% }

% if ( $cgi->param('magic') eq 'send' ) {

    <FONT SIZE="+2">Sending notice</FONT>

    <% include('/elements/progress-init.html',
                 'OneTrueForm',
                 [ keys(%search), qw( from subject html_body text_body ) ],
                 'process/email-customers.html',
                 { 'message' => "Notice sent" }, #would be nice to show #, but..
              )
    %>

% } elsif ( $cgi->param('magic') eq 'preview' ) {

    <FONT SIZE="+2">Preview notice</FONT>

% }

% if ( $cgi->param('magic') ) {

    <TABLE BGCOLOR="#cccccc" CELLSPACING=0>

      <% include('/elements/tr-fixed.html',
                   'field'      => 'from',
                   'label'      => 'From:',
                   'value' => scalar( $cgi->param('from') ),
                )
      %>

      <% include('/elements/tr-fixed.html',
                   'field'      => 'subject',
                   'label'      => 'Subject:',
                   'value' => scalar( $cgi->param('subject') ),
                )
      %>

      <INPUT TYPE="hidden" NAME="html_body" VALUE="<% $cgi->param('html_body') |h %>">
      <TR>
        <TD ALIGN="right" VALIGN="top">Message (HTML display): </TD>
        <TD BGCOLOR="#e8e8e8" ALIGN="left"><% $cgi->param('html_body') %></TD>
      </TR>

%     my $text_body = HTML::FormatText->new(leftmargin=>0)->format(
%                       HTML::TreeBuilder->new_from_content(
%                         $cgi->param('html_body')
%                       )
%                     );
      <INPUT TYPE="hidden" NAME="text_body" VALUE="<% $text_body |h %>">
      <TR>
        <TD ALIGN="right" VALIGN="top">Message (Text display): </TD>
        <TD BGCOLOR="#e8e8e8" ALIGN="left"><PRE><% $text_body %></PRE></TD>
      </TR>

    </TABLE>

% if ( $cgi->param('magic') eq 'preview' ) {

      <SCRIPT>
        function areyousure(href) {
          return confirm("Send this notice to <% $num_cust %> customers?");
        }
      </SCRIPT>

      <BR>
      <INPUT TYPE="hidden" NAME="magic" VALUE="send">
      <INPUT TYPE="submit" VALUE="Send notice" onClick="return areyousure()">
    
%   }

% } else {

  <TABLE BGCOLOR="#cccccc" CELLSPACING=0 WIDTH="100%">

    <% include('/elements/tr-input-text.html',
                 'field' => 'from',
                 'label' => 'From:',
              )
    %>

    <% include('/elements/tr-input-text.html',
                 'field' => 'subject',
                 'label' => 'Subject:',
              )
    %>

    <TR>
      <TD ALIGN="right" VALIGN="top">Message: </TD>
      <TD><% include('/elements/htmlarea.html', 'field'=>'html_body') %></TD>
    </TR>

  </TABLE>

%#Substitution vars:

    <BR><BR>
    <INPUT TYPE="hidden" NAME="magic" VALUE="preview">
    <INPUT TYPE="submit" VALUE="Preview notice">

% }

</FORM>

% if ( $cgi->param('magic') eq 'send' ) {
    <SCRIPT TYPE="text/javascript">
      process();
    </SCRIPT>
% }

<% include('/elements/footer.html') %>

<%init>

die "access denied"
  unless $FS::CurrentUser::CurrentUser->access_right('Bulk send customer notices');

my %search = $cgi->Vars;
delete $search{$_} for qw( magic from subject html_body text_body );
$search{$_} = [ split(/\0/, $search{$_}) ]
  foreach grep $search{$_} =~ /\0/, keys %search;

my $title = 'Bulk send customer notices';

my $num_cust;
if ( $cgi->param('magic') eq 'preview' ) {
  my $sql_query = FS::cust_main->search_sql(\%search);
  my $count_query = delete($sql_query->{'count_query'});
  my $count_sth = dbh->prepare($count_query)
    or die "Error preparing $count_query: ". dbh->errstr;
  $count_sth->execute
    or die "Error executing $count_query: ". $count_sth->errstr;
  my $count_arrayref = $count_sth->fetchrow_arrayref;
  $num_cust = $count_arrayref->[0];
}

</%init>