From fd8a7c99f3b78c233ec44d1b3f15e558e48e092a Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 17 Jun 2008 03:36:10 +0000 Subject: finish adding a feature to easily list all email addresses for an agent & send them email --- httemplate/elements/htmlarea.html | 36 +++++++ httemplate/misc/email-customers.html | 145 +++++++++++++++++++++++++++ httemplate/misc/process/email-customers.html | 9 ++ httemplate/search/cust_main.html | 25 ++++- 4 files changed, 210 insertions(+), 5 deletions(-) create mode 100644 httemplate/elements/htmlarea.html create mode 100644 httemplate/misc/email-customers.html create mode 100644 httemplate/misc/process/email-customers.html (limited to 'httemplate') diff --git a/httemplate/elements/htmlarea.html b/httemplate/elements/htmlarea.html new file mode 100644 index 000000000..f27c4b5e6 --- /dev/null +++ b/httemplate/elements/htmlarea.html @@ -0,0 +1,36 @@ +<%doc> + +Example: + + include('/elements/htmlarea.html', + 'field' => 'fieldname', + 'curr_value' => $curr_value, + 'height' => 800, + ); + + + +% #init + + +% #editor + + +<%init> + +my %opt = @_; + + diff --git a/httemplate/misc/email-customers.html b/httemplate/misc/email-customers.html new file mode 100644 index 000000000..0d3d622c3 --- /dev/null +++ b/httemplate/misc/email-customers.html @@ -0,0 +1,145 @@ +<% include('/elements/header.html', $title) %> + +
+% foreach my $key ( keys %search ) { +% my @values = ref($search{$key}) ? @{$search{$key}} : ( $search{$key} ); +% foreach my $value ( @values ) { + +% } +% } + +% if ( $cgi->param('magic') eq 'send' ) { + + Sending notice + + <% 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' ) { + + Preview notice + +% } + +% if ( $cgi->param('magic') ) { + + + + <% 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') ), + ) + %> + + + + + + + +% my $text_body = HTML::FormatText->new(leftmargin=>0)->format( +% HTML::TreeBuilder->new_from_content( +% $cgi->param('html_body') +% ) +% ); + + + + + + +
Message (HTML display): <% $cgi->param('html_body') %>
Message (Text display):
<% $text_body %>
+ +% if ( $cgi->param('magic') eq 'preview' ) { + + + +
+ + + +% } + +% } else { + + + + <% include('/elements/tr-input-text.html', + 'field' => 'from', + 'label' => 'From:', + ) + %> + + <% include('/elements/tr-input-text.html', + 'field' => 'subject', + 'label' => 'Subject:', + ) + %> + + + + + + +
Message: <% include('/elements/htmlarea.html', 'field'=>'html_body') %>
+ +%#Substitution vars: + +

+ + + +% } + +
+ +% if ( $cgi->param('magic') eq 'send' ) { + +% } + +<% 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]; +} + + diff --git a/httemplate/misc/process/email-customers.html b/httemplate/misc/process/email-customers.html new file mode 100644 index 000000000..d254cfecb --- /dev/null +++ b/httemplate/misc/process/email-customers.html @@ -0,0 +1,9 @@ +<% $server->process %> +<%init> + +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('Bulk send customer notices'); + +my $server = new FS::UI::Web::JSRPC 'FS::cust_main::process_email_search_sql', $cgi; + + diff --git a/httemplate/search/cust_main.html b/httemplate/search/cust_main.html index a2ecd047c..cd5e51f25 100755 --- a/httemplate/search/cust_main.html +++ b/httemplate/search/cust_main.html @@ -1,5 +1,6 @@ <% include( 'elements/search.html', 'title' => 'Customer Search Results', + 'menubar' => $menubar, 'name' => 'customers', 'query' => $sql_query, 'count_query' => $count_query, @@ -30,11 +31,6 @@ ], ) %> -<%once> - -my $link = [ "${p}view/cust_main.cgi?", 'custnum' ]; - - <%init> die "access denied" @@ -89,4 +85,23 @@ my $count_query = delete($sql_query->{'count_query'}); my @extra_headers = @{ delete($sql_query->{'extra_headers'}) }; my @extra_fields = @{ delete($sql_query->{'extra_fields'}) }; +my $link = [ "${p}view/cust_main.cgi?", 'custnum' ]; + +### +# email links +### + +my $menubar = []; + +if ( $FS::CurrentUser::CurrentUser->access_right('Bulk send customer notices') ) { + + my $uri = new URI::URL; + $uri->query_form( \%search_hash ); + my $query = $uri->query; + + push @$menubar, 'Email a notice to these customers' => + "${p}misc/email-customers.html?$query", + +} + -- cgit v1.2.1