f53c35fca3e7c3bfdba9de28721c2202338ca2a7
[freeside.git] / httemplate / misc / xmlhttp-address_standardize.html
1 <% encode_json($return) %>
2 <%init>
3
4 local $SIG{__DIE__}; #disable Mason error trap
5
6 my $DEBUG = 0;
7
8 my $conf = new FS::Conf;
9
10 my $sub = $cgi->param('sub');
11
12 warn $cgi->param('arg') if $DEBUG;
13
14 my %old = %{ decode_json($cgi->param('arg')) }
15   or die "bad argument '".$cgi->param('arg')."'";
16
17 my %new;
18
19 foreach my $pre ( '', 'ship_' ) {
20   next unless ($pre || !$old{onlyship});
21
22   my $location = {
23     map { $_ => $old{$pre.$_} }
24       qw( company address1 address2 city state zip country )
25   };
26
27   my $cache = eval { FS::GeocodeCache->standardize($location) };
28   $cache->set_coord;
29   # don't do set_censustract here, though censustract may be set by now
30
31   foreach ( keys(%$cache) ) {
32     $new{$pre.$_} = $cache->get($_);
33   }
34 }
35
36 my $return = { old => \%old, new => \%new };
37 warn "result:\n".encode_json($return) if $DEBUG;
38 </%init>