summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorivan <ivan>2008-12-28 18:48:51 +0000
committerivan <ivan>2008-12-28 18:48:51 +0000
commitd8cb6cd67cc574c90dbbfbd8db2da6711c516d65 (patch)
treea1635fa18b7ccca84e53599fc2bb05233c08317c
parenta96ddd777a87c2f74a9cf408b44d0f6e7347b5f3 (diff)
fix browse results for selecting counties (resulting from separating tax classes), also add dropdowns to browse by state and county, RT#4496
-rwxr-xr-xhttemplate/browse/cust_main_county.cgi101
-rw-r--r--httemplate/edit/cust_main/billing.html4
-rw-r--r--httemplate/edit/cust_main/contact.html20
-rw-r--r--httemplate/edit/cust_main/select-country.html76
-rw-r--r--httemplate/edit/cust_main/select-county.html113
-rw-r--r--httemplate/edit/cust_main/select-state.html4
-rw-r--r--httemplate/elements/select-country.html120
-rw-r--r--httemplate/elements/select-county.html152
-rw-r--r--httemplate/elements/select-did.html5
-rw-r--r--httemplate/elements/select-state.html45
-rw-r--r--httemplate/misc/payment.cgi311
11 files changed, 567 insertions, 384 deletions
diff --git a/httemplate/browse/cust_main_county.cgi b/httemplate/browse/cust_main_county.cgi
index 1e969aa8f..c4d1d1882 100755
--- a/httemplate/browse/cust_main_county.cgi
+++ b/httemplate/browse/cust_main_county.cgi
@@ -32,18 +32,6 @@
my $conf = new FS::Conf;
my $money_char = $conf->config('money_char') || '$';
-my @manual_countries = ( 'US', 'CA', 'AU', 'NZ', 'GB' ); #some manual ordering
-my @all_countries = ( @manual_countries,
- grep { my $c = $_; ! grep { $c eq $_ } @manual_countries }
- map { $_->country }
- qsearch({
- 'select' => 'country',
- 'table' => 'cust_main_county',
- 'hashref' => {},
- 'extra_sql' => 'GROUP BY country',
- })
- );
-
my $exempt_sub = sub {
my $cust_main_county = shift;
@@ -153,16 +141,20 @@ if ( $cgi->param('country') =~ /^(\w\w)$/ ) {
$cgi->delete('country');
my $state = '';
-if ( $cgi->param('state') =~ /^([\w \-\'\[\]]+)$/ ) {
+if ( $country && $cgi->param('state') =~ /^([\w \-\'\[\]]+)$/ ) {
$state = $1;
$title = "$state, $title";
}
$cgi->delete('state');
my $county = '';
-if ( $cgi->param('county') =~ /^([\w \-\'\[\]]+)$/ ) {
+if ( $country && $state && $cgi->param('county') =~ /^([\w \-\'\[\]]+)$/ ) {
$county = $1;
- $title = "$county county, $title";
+ if ( $county eq '__NONE__' ) {
+ $title = "No county, $title";
+ } else {
+ $title = "$county county, $title";
+ }
}
$cgi->delete('county');
@@ -181,9 +173,11 @@ if ( $country || $taxclass ) {
$cgi->param('dummy', 1);
-my $country_filter_change =
- "window.location = '".
- $cgi->self_url. ";country=' + this.options[this.selectedIndex].value;";
+my $filter_change =
+ "window.location = '". $cgi->self_url.
+ ";country=' + document.getElementById('country').options[document.getElementById('country').selectedIndex].value + ".
+ "';state=' + document.getElementById('state').options[document.getElementById('state').selectedIndex].value +".
+ "';county=' + document.getElementById('county').options[document.getElementById('county').selectedIndex].value;";
#restore this so pagination works
$cgi->param('country', $country) if $country;
@@ -192,15 +186,57 @@ $cgi->param('county', $county ) if $county;
$cgi->param('taxclass', $county ) if $taxclass;
my $html_posttotal =
- '(show country: '.
- qq(<SELECT NAME="country" onChange="$country_filter_change">).
- qq(<OPTION VALUE="">(all)\n).
- join("\n", map qq[<OPTION VALUE="$_"].
- ( $_ eq $country ? 'SELECTED' : '' ).
- '>'. code2country($_). " ($_)",
- @all_countries
- ).
- '</SELECT>)';
+ '( show country: '.
+ include('/elements/select-country.html',
+ 'country' => $country,
+ 'onchange' => $filter_change,
+ 'empty_label' => '(all)',
+ 'disable_empty' => 0,
+ 'disable_stateupdate' => 1,
+ );
+
+my %states_hash = $country ? states_hash($country) : ();
+if ( scalar(keys(%states_hash)) > 1 ) {
+ $html_posttotal .=
+ ' show state: '.
+ include('/elements/select-state.html',
+ 'country' => $country,
+ 'state' => $state,
+ 'onchange' => $filter_change,
+ 'empty_label' => '(all)',
+ 'disable_empty' => 0,
+ 'disable_countyupdate' => 1,
+ );
+} else {
+ $html_posttotal .=
+ '<SELECT NAME="state" ID="state" STYLE="display:none">'.
+ ' <OPTION VALUE="" SELECTED>'.
+ '</SELECT>';
+}
+
+my @counties = ( $country && $state ) ? counties($state, $country) : ();
+if ( scalar(@counties) > 1 ) {
+ $html_posttotal .=
+ ' show county: '.
+ include('/elements/select-county.html',
+ 'country' => $country,
+ 'state' => $state,
+ 'county' => $county,
+ 'onchange' => $filter_change,
+ 'empty_label' => '(all)',
+ 'empty_data_label' => '(none)',
+ 'empty_data_value' => '__NONE__',
+ 'disable_empty' => 0,
+ 'disable_countyupdate' => 1,
+ );
+} else {
+ $html_posttotal .=
+ '<SELECT NAME="county" ID="county" STYLE="display:none">'.
+ ' <OPTION VALUE="" SELECTED>'.
+ '</SELECT>';
+}
+
+$html_posttotal .= ' )';
my $bulk_popup_link =
include( '/elements/popup_link_onclick.html',
@@ -281,11 +317,16 @@ if ( $country ) {
}
if ( $state ) {
$hashref->{'state'} = $state;
- $count_query .= ' AND state = '. dbh->quote($state);
+ $count_query .= ' AND state = '. dbh->quote($state);
}
if ( $county ) {
- $hashref->{'country'} = $country;
- $count_query .= ' AND county = '. dbh->quote($county);
+ if ( $county eq '__NONE__' ) {
+ $hashref->{'county'} = '';
+ $count_query .= " AND ( county = '' OR county IS NULL ) ";
+ } else {
+ $hashref->{'county'} = $county;
+ $count_query .= ' AND county = '. dbh->quote($county);
+ }
}
if ( $taxclass ) {
$hashref->{'taxclass'} = $taxclass;
diff --git a/httemplate/edit/cust_main/billing.html b/httemplate/edit/cust_main/billing.html
index d4c503412..8724db9dc 100644
--- a/httemplate/edit/cust_main/billing.html
+++ b/httemplate/edit/cust_main/billing.html
@@ -199,11 +199,11 @@
% ( $conf->exists('show_bankstate') ?
% qq!<TR><TD ALIGN="right" WIDTH="200">$paystate_label</TD>!.
% qq!<TD COLSPAN="3" WIDTH="408">!.
-% include('select-state.html',
+% include('/elements/select-state.html',
% 'empty' => '(choose)',
% 'state' => $cust_main->paystate,
% 'country' => $cust_main->country,
-% 'prefix' => 'pay',
+% 'prefix' => 'pay',
% ). "</TD></TR>"
% : '<INPUT TYPE="hidden" NAME="paystate" VALUE="'.
% $cust_main->paystate. '">'
diff --git a/httemplate/edit/cust_main/contact.html b/httemplate/edit/cust_main/contact.html
index 2d37dc895..d93d41728 100644
--- a/httemplate/edit/cust_main/contact.html
+++ b/httemplate/edit/cust_main/contact.html
@@ -54,11 +54,11 @@
</TD>
<TH ALIGN="right" ID="<%$pre%>countylabel" <%$county_style%>><%$r%>County</TH>
<TD>
- <% include('select-county.html', %select_hash ) %>
+ <% include('/elements/select-county.html', %select_hash ) %>
</TD>
<TH ALIGN="right"><%$r%>State</TH>
<TD>
- <% include('select-state.html', %select_hash ) %>
+ <% include('/elements/select-state.html', %select_hash ) %>
</TD>
<TH><%$r%>Zip</TH>
<TD>
@@ -68,7 +68,7 @@
<TR>
<TH ALIGN="right"><%$r%>Country</TH>
- <TD COLSPAN=5><% include('select-country.html', %select_hash ) %></TD>
+ <TD COLSPAN=5><% include('/elements/select-country.html', %select_hash ) %></TD>
% if ( !$pre ) {
<TD><INPUT TYPE="hidden" NAME="geocode" VALUE="<% $opt{geocode} %>"></TD>
% }
@@ -102,11 +102,15 @@
<TD ALIGN="right"><% $stateid_label %></TD>
<TD><INPUT TYPE="text" NAME="stateid" VALUE="<% $opt{stateid} %>" SIZE=12 onChange="<% $onchange %>" <%$disabled%>></TD>
<TD ALIGN="right"><% $stateid_state_label %></TD>
- <TD><% include('select-state.html', 'state' => $cust_main->stateid_state,
- 'country' => $cust_main->country,
- 'prefix' => 'stateid_',
- 'onchange' => $onchange,
- 'disabled' => $disabled) %></TD>
+ <TD><% include('/elements/select-state.html',
+ 'state' => $cust_main->stateid_state,
+ 'country' => $cust_main->country,
+ 'prefix' => 'stateid_',
+ 'onchange' => $onchange,
+ 'disabled' => $disabled,
+ )
+ %>
+ </TD>
</TR>
% } elsif ( !$pre ) {
diff --git a/httemplate/edit/cust_main/select-country.html b/httemplate/edit/cust_main/select-country.html
deleted file mode 100644
index 137f61975..000000000
--- a/httemplate/edit/cust_main/select-country.html
+++ /dev/null
@@ -1,76 +0,0 @@
-
-<% include('/elements/xmlhttp.html',
- 'url' => $p.'misc/states.cgi',
- 'subs' => [ $opt{'prefix'}. 'get_states' ],
- )
-%>
-
-<SCRIPT TYPE="text/javascript">
-
- function opt(what,value,text) {
- var optionName = new Option(text, value, false, false);
- var length = what.length;
- what.options[length] = optionName;
- }
-
- function <% $opt{'prefix'} %>country_changed(what, callback) {
-
- country = what.options[what.selectedIndex].value;
-
- function <% $opt{'prefix'} %>update_states(states) {
-
- // blank the current state list
- for ( var i = what.form.<% $opt{'prefix'} %>state.length; i >= 0; i-- )
- what.form.<% $opt{'prefix'} %>state.options[i] = null;
-
- // add the new states
- var statesArray = eval('(' + states + ')' );
- for ( var s = 0; s < statesArray.length; s=s+2 ) {
- var stateLabel = statesArray[s+1];
- if ( stateLabel == "" )
- stateLabel = '(n/a)';
- opt(what.form.<% $opt{'prefix'} %>state, statesArray[s], stateLabel);
- }
-
- //run the callback
- if ( callback != null )
- callback();
- }
-
- // go get the new states
- <% $opt{'prefix'} %>get_states( country, <% $opt{'prefix'} %>update_states );
-
- }
-
-</SCRIPT>
-
-<SELECT NAME="<% $opt{'prefix'} %>country" onChange="<% $opt{'prefix'} %>country_changed(this); <% $opt{'onchange'} %>" <% $opt{'disabled'} %>>
-
-% foreach my $country (
-% sort { ($b eq $countrydefault) <=> ($a eq $countrydefault)
-% or code2country($a) cmp code2country($b) }
-% map { $_->country }
-% qsearch({
-% 'select' => 'country',
-% 'table' => 'cust_main_county',
-% 'hashref' => {},
-% 'extra_sql' => 'GROUP BY country',
-% })
-% ) {
-
- <OPTION VALUE="<% $country %>"<% $country eq $opt{'country'} ? ' SELECTED' : '' %>><% code2country($country). " ($country)" %>
-
-% }
-
-</SELECT>
-
-<%init>
-my %opt = @_;
-foreach my $opt (qw( county state country prefix onchange disabled )) {
- $opt{$_} = '' unless exists($opt{$_}) && defined($opt{$_});
-}
-
-my $conf = new FS::Conf;
-my $countrydefault = $conf->config('countrydefault') || 'US';
-</%init>
-
diff --git a/httemplate/edit/cust_main/select-county.html b/httemplate/edit/cust_main/select-county.html
deleted file mode 100644
index 0dc826896..000000000
--- a/httemplate/edit/cust_main/select-county.html
+++ /dev/null
@@ -1,113 +0,0 @@
-% if ( $countyflag ) {
-
- <% include('/elements/xmlhttp.html',
- 'url' => $p.'misc/counties.cgi',
- 'subs' => [ $opt{'prefix'}. 'get_counties' ],
- )
- %>
-
- <SCRIPT TYPE="text/javascript">
-
- function opt(what,value,text) {
- var optionName = new Option(text, value, false, false);
- var length = what.length;
- what.options[length] = optionName;
- }
-
- function <% $opt{'prefix'} %>state_changed(what, callback) {
-
- state = what.options[what.selectedIndex].value;
- country = what.form.<% $opt{'prefix'} %>country.options[what.form.<% $opt{'prefix'} %>country.selectedIndex].value;
-
- function <% $opt{'prefix'} %>update_counties(counties) {
-
- // blank the current county list
- for ( var i = what.form.<% $opt{'prefix'} %>county.length; i >= 0; i-- )
- what.form.<% $opt{'prefix'} %>county.options[i] = null;
-
- // add the new counties
- var countiesArray = eval('(' + counties + ')' );
- for ( var s = 0; s < countiesArray.length; s++ ) {
- var countyLabel = countiesArray[s];
- if ( countyLabel == "" )
- countyLabel = '(n/a)';
- opt(what.form.<% $opt{'prefix'} %>county, countiesArray[s], countyLabel);
- }
-
- var countyFormLabel = document.getElementById('<% $opt{'prefix'} %>countylabel');
-
- if ( countiesArray.length > 1 ) {
- what.form.<% $opt{'prefix'} %>county.style.display = '';
- countyFormLabel.style.visibility = 'visible';
- } else {
- what.form.<% $opt{'prefix'} %>county.style.display = 'none';
- countyFormLabel.style.visibility = 'hidden';
- }
-
- //run the callback
- if ( callback != null )
- callback();
- }
-
- // go get the new counties
- <% $opt{'prefix'} %>get_counties( state, country, <% $opt{'prefix'} %>update_counties );
-
- }
-
- </SCRIPT>
-
- <SELECT NAME="<% $opt{'prefix'} %>county" onChange="<% $opt{'onchange'} %>" <% $opt{'disabled'} %>>
-
-% foreach my $county ( @counties ) {
-
- <OPTION VALUE="<% $county %>"<% $county eq $opt{'county'} ? ' SELECTED' : '' %>><% $county %>
-
-% }
-
- </SELECT>
-
-% } else {
-
-
- <SCRIPT TYPE="text/javascript">
- function <% $opt{'prefix'} %>state_changed(what) {
- }
- </SCRIPT>
-
- <INPUT TYPE="hidden" NAME="<% $opt{'prefix'} %>county" VALUE="<% $opt{'county'} %>">
-
-% }
-
-<%init>
-
-my %opt = @_;
-foreach my $opt (qw( county state country prefix onchange disabled )) {
- $opt{$_} = '' unless exists($opt{$_}) && defined($opt{$_});
-}
-
-my @counties = ();
-if ( $countyflag ) {
-
- @counties = counties( $opt{'state'}, $opt{'country'} );
-
- # this is very hacky
- unless ( scalar(@counties) > 1 ) {
- if ( $opt{'disabled'} =~ /STYLE=/i ) {
- $opt{'disabled'} =~ s/STYLE="([^"]+)"/STYLE="$1; display:none"/i;
- } else {
- $opt{'disabled'} .= ' STYLE="display:none"';
- }
- }
-
-}
-
-</%init>
-<%once>
-
-my $sql = "SELECT COUNT(*) FROM cust_main_county".
- " WHERE county IS NOT NULL AND county != ''";
-my $sth = dbh->prepare($sql) or die dbh->errstr;
-$sth->execute or die $sth->errstr;
-my $countyflag = $sth->fetchrow_arrayref->[0];
-
-</%once>
diff --git a/httemplate/edit/cust_main/select-state.html b/httemplate/edit/cust_main/select-state.html
deleted file mode 100644
index ce08443e4..000000000
--- a/httemplate/edit/cust_main/select-state.html
+++ /dev/null
@@ -1,4 +0,0 @@
-<% include('/elements/select-state.html', @_) %>
-<%init>
-warn "cust_main/select-state.html depreated; use /elements/select-state.html instead";
-</%init>
diff --git a/httemplate/elements/select-country.html b/httemplate/elements/select-country.html
new file mode 100644
index 000000000..c4368c271
--- /dev/null
+++ b/httemplate/elements/select-country.html
@@ -0,0 +1,120 @@
+<%doc>
+
+Example:
+
+ include( '/elements/select-country.html',
+ #recommended
+ country => $current_country,
+
+ #optional
+ prefix => $optional_unique_prefix,
+ onchange => $javascript,
+ disabled => 0, #bool
+ disable_empty => 1, #defaults to 1, disable the empty option
+ empty_label => 'all', #label for empty option
+ disable_stateupdate => 0, #bool - disabled update of the select-state.html
+
+ );
+
+</%doc>
+% unless ( $opt{'disable_stateupdate'} ) {
+
+ <% include('/elements/xmlhttp.html',
+ 'url' => $p.'misc/states.cgi',
+ 'subs' => [ $pre. 'get_states' ],
+ )
+ %>
+
+ <SCRIPT TYPE="text/javascript">
+
+ function opt(what,value,text) {
+ var optionName = new Option(text, value, false, false);
+ var length = what.length;
+ what.options[length] = optionName;
+ }
+
+ function <% $pre %>country_changed(what, callback) {
+
+ country = what.options[what.selectedIndex].value;
+
+ function <% $pre %>update_states(states) {
+
+ // blank the current state list
+ for ( var i = what.form.<% $pre %>state.length; i >= 0; i-- )
+ what.form.<% $pre %>state.options[i] = null;
+
+ // add the new states
+ var statesArray = eval('(' + states + ')' );
+ for ( var s = 0; s < statesArray.length; s=s+2 ) {
+ var stateLabel = statesArray[s+1];
+ if ( stateLabel == "" )
+ stateLabel = '(n/a)';
+ opt(what.form.<% $pre %>state, statesArray[s], stateLabel);
+ }
+
+ //run the callback
+ if ( callback != null )
+ callback();
+ }
+
+ // go get the new states
+ <% $pre %>get_states( country, <% $pre %>update_states );
+
+ }
+
+ </SCRIPT>
+
+% }
+
+<SELECT NAME = "<% $pre %>country"
+ ID = "<% $pre %>country"
+ onChange = "<% $onchange %>"
+ <% $opt{'disabled'} %>
+>
+
+% unless ( $opt{'disable_empty'} ) {
+ <OPTION VALUE=""><% $opt{'empty_label'} || '(all)' %>
+% }
+
+% foreach my $country ( @all_countries ) {
+
+ <OPTION VALUE="<% $country |h %>"
+ <% $country eq $opt{'country'} ? ' SELECTED' : '' %>
+ ><% code2country($country). " ($country)" %>
+
+% }
+
+</SELECT>
+
+<%init>
+
+my %opt = @_;
+foreach my $opt (qw( country prefix onchange disabled disable_stateupdate )) {
+ $opt{$opt} = '' unless exists($opt{$opt}) && defined($opt{$opt});
+}
+
+$opt{'disable_empty'} = 1 unless exists($opt{'disable_empty'});
+
+my $pre = $opt{'prefix'};
+
+my $onchange =
+ ( $opt{'disable_stateupdate'} ? '' : $pre.'country_changed(this); ' ).
+ $opt{'onchange'};
+
+my $conf = new FS::Conf;
+my $default = $conf->config('countrydefault') || 'US';
+
+my @all_countries = (
+ sort { ($b eq $default) <=> ($a eq $default)
+ or code2country($a) cmp code2country($b)
+ }
+ map { $_->country }
+ qsearch({
+ 'select' => 'country',
+ 'table' => 'cust_main_county',
+ 'hashref' => {},
+ 'extra_sql' => 'GROUP BY country',
+ })
+ );
+
+</%init>
diff --git a/httemplate/elements/select-county.html b/httemplate/elements/select-county.html
new file mode 100644
index 000000000..8ef34dbe6
--- /dev/null
+++ b/httemplate/elements/select-county.html
@@ -0,0 +1,152 @@
+<%doc>
+
+Example:
+
+ include( '/elements/select-county.html',
+ #recommended
+ country => $current_country,
+ state => $current_state,
+ county => $current_county,
+
+ #optional
+ prefix => $optional_unique_prefix,
+ onchange => $javascript,
+ disabled => 0, #bool
+ disable_empty => 1, #defaults to 1, disable the empty option
+ empty_label => 'all', #label for empty option
+ );
+
+</%doc>
+% if ( $countyflag ) {
+
+ <% include('/elements/xmlhttp.html',
+ 'url' => $p.'misc/counties.cgi',
+ 'subs' => [ $pre. 'get_counties' ],
+ )
+ %>
+
+ <SCRIPT TYPE="text/javascript">
+
+ function opt(what,value,text) {
+ var optionName = new Option(text, value, false, false);
+ var length = what.length;
+ what.options[length] = optionName;
+ }
+
+ function <% $pre %>state_changed(what, callback) {
+
+ state = what.options[what.selectedIndex].value;
+ country = what.form.<% $pre %>country.options[what.form.<% $pre %>country.selectedIndex].value;
+
+ function <% $pre %>update_counties(counties) {
+
+ // blank the current county list
+ for ( var i = what.form.<% $pre %>county.length; i >= 0; i-- )
+ what.form.<% $pre %>county.options[i] = null;
+
+ // add the new counties
+ var countiesArray = eval('(' + counties + ')' );
+ for ( var s = 0; s < countiesArray.length; s++ ) {
+ var countyLabel = countiesArray[s];
+ if ( countyLabel == "" )
+ countyLabel = '(n/a)';
+ opt(what.form.<% $pre %>county, countiesArray[s], countyLabel);
+ }
+
+ var countyFormLabel = document.getElementById('<% $pre %>countylabel');
+
+ if ( countiesArray.length > 1 ) {
+ what.form.<% $pre %>county.style.display = '';
+ countyFormLabel.style.visibility = 'visible';
+ } else {
+ what.form.<% $pre %>county.style.display = 'none';
+ countyFormLabel.style.visibility = 'hidden';
+ }
+
+ //run the callback
+ if ( callback != null )
+ callback();
+ }
+
+ // go get the new counties
+ <% $pre %>get_counties( state, country, <% $pre %>update_counties );
+
+ }
+
+ </SCRIPT>
+
+ <SELECT NAME = "<% $pre %>county"
+ ID = "<% $pre %>county"
+ onChange= "<% $opt{'onchange'} %>"
+ <% $opt{'disabled'} %>
+ >
+
+% unless ( $opt{'disable_empty'} ) {
+ <OPTION VALUE="" <% $opt{county} eq '' ? 'SELECTED' : '' %>><% $opt{empty_label} %>
+% }
+
+% foreach my $county ( @counties ) {
+
+ <OPTION VALUE="<% $county |h %>"
+ <% $county eq $opt{'county'} ? 'SELECTED' : '' %>
+ ><% $county eq $opt{'empty_data_value'} ? $opt{'empty_data_label'} : $county %>
+
+% }
+
+ </SELECT>
+
+% } else {
+
+ <SCRIPT TYPE="text/javascript">
+ function <% $pre %>state_changed(what) {
+ }
+ </SCRIPT>
+
+ <SELECT NAME = "<% $pre %>county"
+ ID = "<% $pre %>county"
+ STYLE = "display:none"
+ >
+ <OPTION SELECTED VALUE="<% $opt{'county'} |h %>">
+ </SELECT>
+
+% }
+
+<%init>
+
+my %opt = @_;
+foreach my $opt (qw( county state country prefix onchange disabled
+ empty_value )) {
+ $opt{$opt} = '' unless exists($opt{$opt}) && defined($opt{$opt});
+}
+
+$opt{'disable_empty'} = 1 unless exists($opt{'disable_empty'});
+
+my $pre = $opt{'prefix'};
+
+my @counties = ();
+if ( $countyflag ) {
+
+ @counties = map { length($_) ? $_ : $opt{'empty_data_value'} }
+ counties( $opt{'state'}, $opt{'country'} );
+
+ # this is very hacky
+ unless ( scalar(@counties) > 1 ) {
+ if ( $opt{'disabled'} =~ /STYLE=/i ) {
+ $opt{'disabled'} =~ s/STYLE="([^"]+)"/STYLE="$1; display:none"/i;
+ } else {
+ $opt{'disabled'} .= ' STYLE="display:none"';
+ }
+ }
+
+}
+
+</%init>
+<%once>
+
+my $sql = "SELECT COUNT(*) FROM cust_main_county".
+ " WHERE county IS NOT NULL AND county != ''";
+my $sth = dbh->prepare($sql) or die dbh->errstr;
+$sth->execute or die $sth->errstr;
+my $countyflag = $sth->fetchrow_arrayref->[0];
+
+</%once>
diff --git a/httemplate/elements/select-did.html b/httemplate/elements/select-did.html
index a8ef09d61..069516476 100644
--- a/httemplate/elements/select-did.html
+++ b/httemplate/elements/select-did.html
@@ -18,8 +18,9 @@ Example:
<TR>
<TD>
<% include('/elements/select-state.html',
- 'country' => $country,
- 'empty' => 'Select state',
+ 'country' => $country,
+ 'disable_empty' => 0,
+ 'empty_label' => 'Select state',
)
%>
</TD>
diff --git a/httemplate/elements/select-state.html b/httemplate/elements/select-state.html
index 4f1c056b5..f7ac2c7bf 100644
--- a/httemplate/elements/select-state.html
+++ b/httemplate/elements/select-state.html
@@ -1,12 +1,35 @@
-<SELECT NAME="<% $opt{'prefix'} %>state" onChange="<% $opt{'prefix'} %>state_changed(this); <% $opt{'onchange'} %>" <% $opt{'disabled'} %>>
+<%doc>
-% if ($opt{empty}) {
- <OPTION VALUE=""<% $opt{state} eq '' ? ' SELECTED' : '' %>><% $opt{empty} %>
+Example:
+
+ include( '/elements/select-state.html',
+ #recommended
+ country => $current_country,
+ state => $current_state,
+
+ #optional
+ prefix => $optional_unique_prefix,
+ onchange => $javascript,
+ disabled => 0, #bool
+ disable_empty => 1, #defaults to 1, disable the empty option
+ empty_label => 'all', #label for empty option
+ disable_countyupdate => 0, #bool - disabled update of the select-state.html
+ );
+
+</%doc>
+
+<SELECT NAME = "<% $pre %>state"
+ ID = "<% $pre %>state"
+ onChange = "<% $onchange %>"
+>
+
+% unless ( $opt{'disable_empty'} ) {
+ <OPTION VALUE=""<% $opt{state} eq '' ? ' SELECTED' : '' %>><% $opt{empty_label} %>
% }
% foreach my $state ( keys %states ) {
- <OPTION VALUE="<% $state %>"<% $state eq $opt{'state'} ? ' SELECTED' : '' %>><% $states{$state} || '(n/a)' %>
+ <OPTION VALUE="<% $state |h %>"<% $state eq $opt{'state'} ? ' SELECTED' : '' %>><% $states{$state} || '(n/a)' %>
% }
@@ -14,11 +37,21 @@
</SELECT>
<%init>
+
my %opt = @_;
-foreach my $opt (qw( county state country prefix onchange disabled empty )) {
- $opt{$_} = '' unless exists($opt{$_}) && defined($opt{$_});
+foreach my $opt (qw( state country prefix onchange disabled empty_label )) {
+ $opt{$opt} = '' unless exists($opt{$opt}) && defined($opt{$opt});
}
+$opt{'disable_empty'} = 1 unless exists($opt{'disable_empty'});
+
+my $pre = $opt{'prefix'};
+
+my $onchange =
+ ( $opt{'disable_countyupdate'} ? '' : $pre.'state_changed(this); ' ).
+ $opt{'onchange'};
+
tie my %states, 'Tie::IxHash', states_hash( $opt{'country'} );
+
</%init>
diff --git a/httemplate/misc/payment.cgi b/httemplate/misc/payment.cgi
index 9aaa45904..004700488 100644
--- a/httemplate/misc/payment.cgi
+++ b/httemplate/misc/payment.cgi
@@ -19,165 +19,190 @@
</TD></TR></TABLE>
</TD>
</TR>
+
% if ( $payby eq 'CARD' ) {
-% my( $payinfo, $paycvv, $month, $year ) = ( '', '', '', '' );
-% my $payname = $cust_main->first. ' '. $cust_main->getfield('last');
-% my $address1 = $cust_main->address1;
-% my $address2 = $cust_main->address2;
-% my $city = $cust_main->city;
-% my $state = $cust_main->state;
-% my $zip = $cust_main->zip;
-% if ( $cust_main->payby =~ /^(CARD|DCRD)$/ ) {
-% $payinfo = $cust_main->paymask;
-% $paycvv = $cust_main->paycvv;
-% ( $month, $year ) = $cust_main->paydate_monthyear;
-% $payname = $cust_main->payname if $cust_main->payname;
-% }
%
-
- <TR>
- <TD ALIGN="right">Card&nbsp;number</TD>
- <TD>
- <TABLE>
- <TR>
- <TD>
- <INPUT TYPE="text" NAME="payinfo" SIZE=20 MAXLENGTH=19 VALUE="<%$payinfo%>"> </TD>
- <TD>Exp.</TD>
- <TD>
- <SELECT NAME="month">
+% my( $payinfo, $paycvv, $month, $year ) = ( '', '', '', '' );
+% my $payname = $cust_main->first. ' '. $cust_main->getfield('last');
+% my $address1 = $cust_main->address1;
+% my $address2 = $cust_main->address2;
+% my $city = $cust_main->city;
+% my $state = $cust_main->state;
+% my $zip = $cust_main->zip;
+% if ( $cust_main->payby =~ /^(CARD|DCRD)$/ ) {
+% $payinfo = $cust_main->paymask;
+% $paycvv = $cust_main->paycvv;
+% ( $month, $year ) = $cust_main->paydate_monthyear;
+% $payname = $cust_main->payname if $cust_main->payname;
+% }
+
+ <TR>
+ <TD ALIGN="right">Card&nbsp;number</TD>
+ <TD>
+ <TABLE>
+ <TR>
+ <TD>
+ <INPUT TYPE="text" NAME="payinfo" SIZE=20 MAXLENGTH=19 VALUE="<%$payinfo%>"> </TD>
+ <TD>Exp.</TD>
+ <TD>
+ <SELECT NAME="month">
% for ( ( map "0$_", 1 .. 9 ), 10 .. 12 ) {
- <OPTION<% $_ == $month ? ' SELECTED' : '' %>><% $_ %>
+ <OPTION<% $_ == $month ? ' SELECTED' : '' %>><% $_ %>
% }
- </SELECT>
- </TD>
- <TD> / </TD>
- <TD>
- <SELECT NAME="year">
+ </SELECT>
+ </TD>
+ <TD> / </TD>
+ <TD>
+ <SELECT NAME="year">
% my @a = localtime; for ( $a[5]+1900 .. $a[5]+1915 ) {
- <OPTION<% $_ == $year ? ' SELECTED' : '' %>><% $_ %>
+ <OPTION<% $_ == $year ? ' SELECTED' : '' %>><% $_ %>
% }
- </SELECT>
- </TD>
- </TR>
- </TABLE>
- </TD>
- </TR>
- <TR>
- <TD ALIGN="right">CVV2</TD>
- <TD><INPUT TYPE="text" NAME="paycvv" VALUE="<% $paycvv %>" SIZE=4 MAXLENGTH=4>
- (<A HREF="javascript:void(0);" onClick="overlib( OLiframeContent('../docs/cvv2.html', 480, 352, 'cvv2_popup' ), CAPTION, 'CVV2 Help', STICKY, AUTOSTATUSCAP, CLOSECLICK, DRAGGABLE ); return false;">help</A>)
- </TD>
- </TR>
- <TR>
- <TD ALIGN="right">Exact&nbsp;name&nbsp;on&nbsp;card</TD>
- <TD><INPUT TYPE="text" SIZE=32 MAXLENGTH=80 NAME="payname" VALUE="<%$payname%>"></TD>
- </TR><TR>
- <TD ALIGN="right">Card&nbsp;billing&nbsp;address</TD>
- <TD>
- <INPUT TYPE="text" SIZE=40 MAXLENGTH=80 NAME="address1" VALUE="<%$address1%>">
- </TD>
- </TR><TR>
- <TD ALIGN="right">Address&nbsp;line&nbsp;2</TD>
- <TD>
- <INPUT TYPE="text" SIZE=40 MAXLENGTH=80 NAME="address2" VALUE="<%$address2%>">
- </TD>
- </TR><TR>
- <TD ALIGN="right">City</TD>
- <TD>
- <TABLE>
- <TR>
- <TD>
- <INPUT TYPE="text" NAME="city" SIZE="12" MAXLENGTH=80 VALUE="<%$city%>">
- </TD>
- <TD>State</TD>
- <TD>
- <SELECT NAME="state">
+ </SELECT>
+ </TD>
+ </TR>
+ </TABLE>
+ </TD>
+ </TR>
+ <TR>
+ <TD ALIGN="right">CVV2</TD>
+ <TD><INPUT TYPE="text" NAME="paycvv" VALUE="<% $paycvv %>" SIZE=4 MAXLENGTH=4>
+ (<A HREF="javascript:void(0);" onClick="overlib( OLiframeContent('../docs/cvv2.html', 480, 352, 'cvv2_popup' ), CAPTION, 'CVV2 Help', STICKY, AUTOSTATUSCAP, CLOSECLICK, DRAGGABLE ); return false;">help</A>)
+ </TD>
+ </TR>
+ <TR>
+ <TD ALIGN="right">Exact&nbsp;name&nbsp;on&nbsp;card</TD>
+ <TD><INPUT TYPE="text" SIZE=32 MAXLENGTH=80 NAME="payname" VALUE="<%$payname%>"></TD>
+ </TR><TR>
+ <TD ALIGN="right">Card&nbsp;billing&nbsp;address</TD>
+ <TD>
+ <INPUT TYPE="text" SIZE=40 MAXLENGTH=80 NAME="address1" VALUE="<%$address1%>">
+ </TD>
+ </TR><TR>
+ <TD ALIGN="right">Address&nbsp;line&nbsp;2</TD>
+ <TD>
+ <INPUT TYPE="text" SIZE=40 MAXLENGTH=80 NAME="address2" VALUE="<%$address2%>">
+ </TD>
+ </TR><TR>
+ <TD ALIGN="right">City</TD>
+ <TD>
+ <TABLE>
+ <TR>
+ <TD>
+ <INPUT TYPE="text" NAME="city" SIZE="12" MAXLENGTH=80 VALUE="<%$city%>">
+ </TD>
+ <TD>State</TD>
+ <TD>
+ <SELECT NAME="state">
% for ( @states ) {
- <OPTION<% $_ eq $state ? ' SELECTED' : '' %>><% $_ %>
+ <OPTION<% $_ eq $state ? ' SELECTED' : '' %>><% $_ %>
% }
- </SELECT>
- </TD>
- <TD>Zip</TD>
- <TD>
- <INPUT TYPE="text" NAME="zip" SIZE=11 MAXLENGTH=10 VALUE="<%$zip%>">
- </TD>
- </TR>
- </TABLE>
- </TD>
- </TR>
+ </SELECT>
+ </TD>
+ <TD>Zip</TD>
+ <TD>
+ <INPUT TYPE="text" NAME="zip" SIZE=11 MAXLENGTH=10 VALUE="<%$zip%>">
+ </TD>
+ </TR>
+ </TABLE>
+ </TD>
+ </TR>
+
% } elsif ( $payby eq 'CHEK' ) {
-% my( $payinfo1, $payinfo2, $payname, $ss, $paytype, $paystate,
-% $stateid, $stateid_state )
-% = ( '', '', '', '', '', '', '', '' );
-% if ( $cust_main->payby =~ /^(CHEK|DCHK)$/ ) {
-% $cust_main->paymask =~ /^([\dx]+)\@([\dx]+)$/i
-% or die "unparsable payinfo ". $cust_main->payinfo;
-% ($payinfo1, $payinfo2) = ($1, $2);
-% $payname = $cust_main->payname;
-% $ss = $cust_main->ss;
-% $paytype = $cust_main->getfield('paytype');
-% $paystate = $cust_main->getfield('paystate');
-% $stateid = $cust_main->getfield('stateid');
-% $stateid_state = $cust_main->getfield('stateid_state');
-% }
%
-
- <INPUT TYPE="hidden" NAME="month" VALUE="12">
- <INPUT TYPE="hidden" NAME="year" VALUE="2037">
- <TR>
- <TD ALIGN="right">Account&nbsp;number</TD>
- <TD><INPUT TYPE="text" SIZE=10 NAME="payinfo1" VALUE="<%$payinfo1%>"></TD>
- <TD ALIGN="right">Type</TD>
- <TD><SELECT NAME="paytype"><% join('', map { qq!<OPTION VALUE="$_" !.($paytype eq $_ ? 'SELECTED' : '').">$_</OPTION>" } @FS::cust_main::paytypes) %></SELECT></TD>
- </TR>
- <TR>
- <TD ALIGN="right">ABA/Routing&nbsp;number</TD>
- <TD>
- <INPUT TYPE="text" SIZE=10 MAXLENGTH=9 NAME="payinfo2" VALUE="<%$payinfo2%>">
- (<A HREF="javascript:void(0);" onClick="overlib( OLiframeContent('../docs/ach.html', 380, 240, 'ach_popup' ), CAPTION, 'ACH Help', STICKY, AUTOSTATUSCAP, CLOSECLICK, DRAGGABLE ); return false;">help</A>)
- </TD>
- </TR>
- <TR>
- <TD ALIGN="right">Bank&nbsp;name</TD>
- <TD><INPUT TYPE="text" NAME="payname" VALUE="<%$payname%>"></TD>
- </TR>
- <TR>
- <TD ALIGN="right">Bank&nbsp;state</TD>
- <TD><% include('../edit/cust_main/select-state.html', #meh
- 'empty' => '(choose)',
- 'state' => $paystate,
- 'country' => $cust_main->country,
- 'prefix' => 'pay',
- ) %></TD>
- </TR>
- <TR>
- <TD ALIGN="right">
- Account&nbsp;holder<BR>
- Social&nbsp;security&nbsp;or&nbsp;tax&nbsp;ID&nbsp;#
- </TD>
- <TD><INPUT TYPE="text" NAME="ss" VALUE="<%$ss%>"></TD>
- </TR>
- <TR>
- <TD ALIGN="right">
- Account&nbsp;holder<BR>
- Driver&rsquo;s&nbsp;license&nbsp;or&nbsp;state&nbsp;ID&nbsp;#
- </TD>
- <TD><INPUT TYPE="text" NAME="stateid" VALUE="<%$stateid%>"></TD>
- <TD ALIGN="right">State</TD>
- <TD><% include('../edit/cust_main/select-state.html', #meh
- 'empty' => '(choose)',
- 'state' => $stateid_state,
- 'country' => $cust_main->country,
- 'prefix' => 'stateid_',
- ) %></TD>
- </TR>
-% }
+% my( $payinfo1, $payinfo2, $payname, $ss, $paytype, $paystate,
+% $stateid, $stateid_state )
+% = ( '', '', '', '', '', '', '', '' );
+% if ( $cust_main->payby =~ /^(CHEK|DCHK)$/ ) {
+% $cust_main->paymask =~ /^([\dx]+)\@([\dx]+)$/i
+% or die "unparsable payinfo ". $cust_main->payinfo;
+% ($payinfo1, $payinfo2) = ($1, $2);
+% $payname = $cust_main->payname;
+% $ss = $cust_main->ss;
+% $paytype = $cust_main->getfield('paytype');
+% $paystate = $cust_main->getfield('paystate');
+% $stateid = $cust_main->getfield('stateid');
+% $stateid_state = $cust_main->getfield('stateid_state');
+% }
+
+ <INPUT TYPE="hidden" NAME="month" VALUE="12">
+ <INPUT TYPE="hidden" NAME="year" VALUE="2037">
+ <TR>
+ <TD ALIGN="right">Account&nbsp;number</TD>
+ <TD><INPUT TYPE="text" SIZE=10 NAME="payinfo1" VALUE="<%$payinfo1%>"></TD>
+ <TD ALIGN="right">Type</TD>
+ <TD><SELECT NAME="paytype"><% join('', map { qq!<OPTION VALUE="$_" !.($paytype eq $_ ? 'SELECTED' : '').">$_</OPTION>" } @FS::cust_main::paytypes) %></SELECT></TD>
+ </TR>
+ <TR>
+ <TD ALIGN="right">ABA/Routing&nbsp;number</TD>
+ <TD>
+ <INPUT TYPE="text" SIZE=10 MAXLENGTH=9 NAME="payinfo2" VALUE="<%$payinfo2%>">
+ (<A HREF="javascript:void(0);" onClick="overlib( OLiframeContent('../docs/ach.html', 380, 240, 'ach_popup' ), CAPTION, 'ACH Help', STICKY, AUTOSTATUSCAP, CLOSECLICK, DRAGGABLE ); return false;">help</A>)
+ </TD>
+ </TR>
+ <TR>
+ <TD ALIGN="right">Bank&nbsp;name</TD>
+ <TD><INPUT TYPE="text" NAME="payname" VALUE="<%$payname%>"></TD>
+ </TR>
+
+% if ( $conf->exists('show_bankstate') ) {
+ <TR>
+ <TD ALIGN="right">Bank&nbsp;state</TD>
+ <TD><% include('/elements/select-state.html',
+ 'disable_empty' => 0,
+ 'empty_label' => '(choose)',
+ 'state' => $paystate,
+ 'country' => $cust_main->country,
+ 'prefix' => 'pay',
+ )
+ %>
+ </TD>
+ </TR>
+% } else {
+ <INPUT TYPE="hidden" NAME="paystate" VALUE="<% $paystate %>">
+% }
+
+% if ( $conf->exists('show_ss') ) {
+ <TR>
+ <TD ALIGN="right">
+ Account&nbsp;holder<BR>
+ Social&nbsp;security&nbsp;or&nbsp;tax&nbsp;ID&nbsp;#
+ </TD>
+ <TD><INPUT TYPE="text" NAME="ss" VALUE="<% $ss %>"></TD>
+ </TR>
+% } else {
+ <INPUT TYPE="hidden" NAME="ss" VALUE="<% $ss %>"></TD>
+% }
+
+% if ( $conf->exists('show_stateid') ) {
+ <TR>
+ <TD ALIGN="right">
+ Account&nbsp;holder<BR>
+ Driver&rsquo;s&nbsp;license&nbsp;or&nbsp;state&nbsp;ID&nbsp;#
+ </TD>
+ <TD><INPUT TYPE="text" NAME="stateid" VALUE="<% $stateid %>"></TD>
+ <TD ALIGN="right">State</TD>
+ <TD><% include('/elements/select-state.html',
+ 'disable_empty' => 0,
+ 'empty_label' => '(choose)',
+ 'state' => $stateid_state,
+ 'country' => $cust_main->country,
+ 'prefix' => 'stateid_',
+ )
+ %>
+ </TD>
+ </TR>
+% } else {
+ <INPUT TYPE="hidden" NAME="stateid" VALUE="<% $stateid %>">
+ <INPUT TYPE="hidden" NAME="stateid_state" VALUE="<% $stateid_state %>">
+% }
+
+% } #end CARD/CHEK-specific section
<TR>