From 868ef784aa38d4eafb6065cf39d8f4261e14f959 Mon Sep 17 00:00:00 2001 From: Christopher Burger Date: Tue, 11 Dec 2018 18:45:36 -0500 Subject: [PATCH] RT# 74693 - Added city select when using tax classes --- httemplate/elements/select-city.html | 176 +++++++++++++++++++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100644 httemplate/elements/select-city.html diff --git a/httemplate/elements/select-city.html b/httemplate/elements/select-city.html new file mode 100644 index 000000000..09e28dd48 --- /dev/null +++ b/httemplate/elements/select-city.html @@ -0,0 +1,176 @@ +<%doc> + +Example: + + <& /elements/select-city.html, + #recommended + country => $current_country, + state => $current_state, + county => $current_county, + city => $current_city, + + #optional + prefix => $optional_unique_prefix, + onchange => $javascript, + disabled => 0, #bool + disable_empty => 1, #defaults to 1, set to 0 to disable the empty option + empty_label => 'all', #label for empty option + style => [ 'attribute:value', 'another:value' ], + &> + + +% if ( $cityflag ) { + + <% include('/elements/xmlhttp.html', + 'url' => $p.'misc/cities.cgi', + 'subs' => [ $pre. 'get_cities' ], + ) + %> + + + + + +% } else { + + + + + +% } + +<%init> + +my %opt = @_; +foreach my $opt (qw( city 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 $onchange = $opt{'onchange'}; + +my $city_style = $opt{'style'} ? [ @{ $opt{'style'} } ] : []; + +my @cities = (); +if ( $cityflag ) { + + @cities = map { length($_) ? $_ : $opt{'empty_data_value'} } + cities( $opt{'county'}, $opt{'state'}, $opt{'country'} ); + + push @$city_style, 'display:none' + unless scalar(@cities) > 1; + +} + +my $style = + scalar(@$city_style) + ? 'STYLE="'. join(';', @$city_style). '"' + : ''; + + +<%once> + +my $sql = "SELECT COUNT(*) FROM cust_main_county". + " WHERE city IS NOT NULL AND city != ''"; +my $sth = dbh->prepare($sql) or die dbh->errstr; +$sth->execute or die $sth->errstr; +my $cityflag = $sth->fetchrow_arrayref->[0]; + + \ No newline at end of file -- 2.11.0