summaryrefslogtreecommitdiff
path: root/httemplate/misc/xmlhttp-address_standardize.html
blob: c2d6d7a80d552ace2f0b6a9a50f1055db29f702d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<% encode_json($return) %>
<%init>

local $SIG{__DIE__}; #disable Mason error trap

my $DEBUG = 0;

my $conf = new FS::Conf;

my $sub = $cgi->param('sub');

warn $cgi->param('arg') if $DEBUG;

my %old = %{ decode_json($cgi->param('arg')) }
  or die "bad argument '".$cgi->param('arg')."'";

my %new;

foreach my $pre ( '', 'ship_' ) {
  next unless ($pre || !$old{onlyship});

  my $location = {
    map { $_ => $old{$pre.$_} }
      qw( company address1 address2 city state zip country )
  };

  my $cache = eval { FS::GeocodeCache->standardize($location) };
  $cache->set_censustract if $pre;
  $cache->set_coord;

  foreach ( keys(%$cache) ) {
    $new{$pre.$_} = $cache->get($_);
  }
}

my $return = { old => \%old, new => \%new };
warn "result:\n".encode_json($return) if $DEBUG;
</%init>