X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=httemplate%2Fmisc%2Femail-customers.html;h=4520c75145b0a346196d7e5d13de2087f63f3518;hp=dc53f6d5527f1d057bf0f469710265f595657c5c;hb=e803d5f00368e951f7a4b82d5d390b53c4a6c827;hpb=280c44682a79e586af941e869e7a78ca8f367cf2 diff --git a/httemplate/misc/email-customers.html b/httemplate/misc/email-customers.html index dc53f6d55..4520c7514 100644 --- a/httemplate/misc/email-customers.html +++ b/httemplate/misc/email-customers.html @@ -174,7 +174,7 @@ Template: <& /elements/checkboxes.html, 'style' => 'display: inline; vertical-align: top', 'disable_links' => 1, - 'names_list' => \@contact_checkboxes, + 'names_list' => \@optin_checkboxes, 'element_name_prefix' => 'contact_class_', 'checked_callback' => sub { # Called for each checkbox @@ -199,6 +199,27 @@ Template: % } +% if (@active_classes) { + + +Contact Type: + +
+ <& /elements/checkboxes.html, + 'style' => 'display: inline; vertical-align: top', + 'disable_links' => 1, + 'names_list' => \@classnum_checkboxes, + 'element_name_prefix' => 'contact_class_', + 'checked_callback' => sub { + # Called for each checkbox + # Return true to default as checked, false as unchecked + my($cgi, $name) = @_; + exists $classnum_ischecked{$name}; + }, + &> +
+ +% }
@@ -342,6 +363,21 @@ if ( !$cgi->param('preview') ) { } else { + my @checked_email_dest; + my @checked_contact_type; + for ($cgi->param) { + if (/^contact_class_(.+)$/) { + my $f = $1; + if ($f eq 'invoice' || $f eq 'message') { + push @checked_email_dest, $f; + } elsif ( $f =~ /^\d+$/ ) { + push @checked_contact_type, $f; + } + } + } + $search{with_email_dest} = \@checked_email_dest if @checked_email_dest; + $search{with_contact_type} = \@checked_contact_type if @checked_contact_type; + my $sql_query = "FS::$table"->search(\%search); my $count_query = delete($sql_query->{'count_query'}); my $count_sth = dbh->prepare($count_query) @@ -391,6 +427,8 @@ if ( !$cgi->param('preview') ) { $sql_query->{'select'} = "$table.*"; $sql_query->{'order_by'} = ''; my $object = qsearchs($sql_query); + # Could use better error handling here... + die "No customers match the search criteria" unless ref $object; $cust = $object->cust_main; my %msgopts = ( 'cust_main' => $cust, @@ -435,16 +473,35 @@ if ( !$cgi->param('preview') ) { } } -my @contact_checkboxes = ( +# Build data structures for "Opt In" and "Contact Type" checkboxes +# +# By default, message recipients will be selected, this is a message. +# By default, all Contact Types will be selected, but this may be +# overridden by passing 'classnums' get/post values. If no contact +# types have been defined, the option will not be presented. + +my @active_classes = qsearch(contact_class => {disabled => ''} ); + +$CGI::LIST_CONTEXT_WARN = 0; +my @classnums = grep{ /^\d+$/ } $cgi->param('classnums'); + +my %classnum_ischecked; +if (@classnums) { + # values passed to form + $classnum_ischecked{$_} = 1 for @classnums; +} else { + # default values + $classnum_ischecked{$_->classnum} = 1 for @active_classes; + $classnum_ischecked{0} = 1; +} + +my @optin_checkboxes = ( [ 'message' => { label => 'Message recipients' } ], [ 'invoice' => { label => 'Invoice recipients' } ], ); - -foreach my $class (qsearch('contact_class', { disabled => '' })) { - push @contact_checkboxes, [ - $class->classnum, - { label => $class->classname } - ]; -} +my @classnum_checkboxes = ( + [ '0' => { label => '(None)' }], + map { [ $_->classnum => {label => $_->classname} ] } @active_classes, +);