diff options
author | Ivan Kohler <ivan@freeside.biz> | 2018-02-09 19:10:00 -0800 |
---|---|---|
committer | Ivan Kohler <ivan@freeside.biz> | 2018-02-09 19:10:00 -0800 |
commit | d45dd4a826f314fb5459747590d3e11cd80c211f (patch) | |
tree | c1dd2edd4bc42b12cc9a995e95dd7fb630da925e /httemplate/misc | |
parent | 4b67c9f8cfc9f944b7758e7e69ac1f9f188ffa47 (diff) | |
parent | 15d596e3090f3bde642917b56563736cd1ee2e90 (diff) |
Merge branch 'master' of git.freeside.biz:/home/git/freeside
Diffstat (limited to 'httemplate/misc')
-rw-r--r-- | httemplate/misc/cust_main-import_charges.cgi | 8 | ||||
-rw-r--r-- | httemplate/misc/email-customers.html | 113 |
2 files changed, 99 insertions, 22 deletions
diff --git a/httemplate/misc/cust_main-import_charges.cgi b/httemplate/misc/cust_main-import_charges.cgi index 4eacce13a..215cc4c9d 100644 --- a/httemplate/misc/cust_main-import_charges.cgi +++ b/httemplate/misc/cust_main-import_charges.cgi @@ -28,9 +28,9 @@ Import a CSV file containing customer charges. <TH ALIGN="right">Format</TH> <TD> <SELECT NAME="format"> - <OPTION VALUE="simple">Simple - <OPTION VALUE="ooma">Ooma -<!-- <OPTION VALUE="extended" SELECTED>Extended --> +% foreach my $format ( keys %formats ) { + <OPTION VALUE="<% $format %>"><% $formats{$format} %></OPTION> +% } </SELECT> </TD> </TR> @@ -94,6 +94,8 @@ Field information: die "access denied" unless $FS::CurrentUser::CurrentUser->access_right('Import'); + tie my %formats, 'Tie::IxHash', FS::cust_main::Import_Charges->import_formats; + my $custbatch = time2str('webimport-%Y/%m/%d-%T'. "-$$-". rand() * 2**32, time); </%init> diff --git a/httemplate/misc/email-customers.html b/httemplate/misc/email-customers.html index fe637abe1..f52c6b36a 100644 --- a/httemplate/misc/email-customers.html +++ b/httemplate/misc/email-customers.html @@ -171,16 +171,18 @@ Template: <TD>Send to contacts:</TD> <TD> <div id="contactclassesdiv"> - <& /elements/checkboxes.html, - 'style' => 'display: inline; vertical-align: top', - 'disable_links' => 1, - 'names_list' => \@contact_checkboxes, - 'element_name_prefix' => 'contact_class_', - 'checked_callback' => sub { - my($cgi, $name) = @_; - $name eq 'invoice' #others default to unchecked - }, - &> + <& /elements/checkboxes.html, + 'style' => 'display: inline; vertical-align: top', + 'disable_links' => 1, + 'names_list' => \@optin_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 $dest_ischecked{$name}; + }, + &> </div> % if ($send_to_domain) { <div> @@ -197,6 +199,27 @@ Template: </div> % } </TD> +% if (@active_classes) { +</tr> +<tr> +<TD>Contact Type:</TD> +<TD> + <div id="contactclassesdiv"> + <& /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}; + }, + &> + </div> +</TD> +% } </TR> </TABLE> <BR> @@ -340,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) @@ -389,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, @@ -422,24 +462,59 @@ if ( !$cgi->param('preview') ) { push @contact_classnum, $1; if ( $1 eq 'invoice' ) { push @contact_classname, 'Invoice recipients'; + } elsif ( $1 eq 'message' ) { + push @contact_classname, 'Message recipients'; } else { my $contact_class = FS::contact_class->by_key($1); - push @contact_classname, encode_entities($contact_class->classname); + push @contact_classname, encode_entities( + $contact_class ? $contact_class->classname : '(none)' + ); } } } } } -my @contact_checkboxes = ( - [ 'invoice' => { label => 'Invoice recipients' } ] -); +# 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 => ''} ); + +my %classnum_ischecked; +my %dest_ischecked; -foreach my $class (qsearch('contact_class', { disabled => '' })) { - push @contact_checkboxes, [ - $class->classnum, - { label => $class->classname } - ]; +$CGI::LIST_CONTEXT_WARN = 0; +if ( my @in_classnums = $cgi->param('classnums') ) { + # Set checked boxes from form input + for my $v (@in_classnums) { + + if ( $v =~ /^\d+$/ ) { + $classnum_ischecked{$v} = 1 + } elsif ( $v =~ /^(invoice|message)$/ ) { + $dest_ischecked{$v} = 1; + } + + } +} else { + # Checked boxes default values + $classnum_ischecked{$_->classnum} = 1 for @active_classes; + $classnum_ischecked{0} = 1; } +# At least one destination is required +$dest_ischecked{message} = 1 unless %dest_ischecked; + +my @optin_checkboxes = ( + [ 'message' => { label => 'Message recipients' } ], + [ 'invoice' => { label => 'Invoice recipients' } ], +); +my @classnum_checkboxes = ( + [ '0' => { label => '(None)' }], + map { [ $_->classnum => {label => $_->classname} ] } @active_classes, +); + </%init> |