[freeside-commits] branch FREESIDE_4_BRANCH updated. 314a04d3626bb2faaa5d3d4f0191d305a71d8ede

Ivan Kohler ivan at freeside.biz
Wed Apr 27 13:50:40 PDT 2022


The branch, FREESIDE_4_BRANCH has been updated
       via  314a04d3626bb2faaa5d3d4f0191d305a71d8ede (commit)
      from  0c1bbe3f62b483feb841b8b958dc468e1c457c45 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 314a04d3626bb2faaa5d3d4f0191d305a71d8ede
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Wed Apr 27 13:50:39 2022 -0700

    restore correct workflow when no census match is found: offer map-based picker, RT#86245, RT#76968

diff --git a/FS/FS/Misc/Geo.pm b/FS/FS/Misc/Geo.pm
index 3beffc8a9..6f923f595 100644
--- a/FS/FS/Misc/Geo.pm
+++ b/FS/FS/Misc/Geo.pm
@@ -166,9 +166,11 @@ sub get_censustract_uscensus {
 
   warn Dumper($content) if $DEBUG;
 
-  if ( $content->{result}->{addressMatches} ) {
+  my $addressMatches_ref = $content->{result}->{addressMatches};
 
-    my $tract = $content->{result}->{addressMatches}[0]->{geographies}->{'Census Blocks'}[0]->{GEOID};
+  if ( $addressMatches_ref && scalar @{$addressMatches_ref} ) {
+
+    my $tract = $addressMatches_ref->[0]->{geographies}->{'Census Blocks'}[0]->{GEOID};
     return $tract;
 
   } else {
diff --git a/httemplate/misc/confirm-censustract.html b/httemplate/misc/confirm-censustract.html
index 8535c1495..f3fd0383e 100644
--- a/httemplate/misc/confirm-censustract.html
+++ b/httemplate/misc/confirm-censustract.html
@@ -18,10 +18,14 @@ Confirm census tract
 <BR>
 % my $querystring = "census_year=$year&address=$location{address1}, $location{address2}, $location{city}, $location{state}";
 <A HREF="<%$p%>misc/openmap.html?<% $querystring %>"
-   TARGET="_blank">Map service module location</A><BR>
+   REL="opener"
+   TARGET="_blank"
+>Map service module location</A><BR>
 % $querystring = "census_year=$year&pre=$pre&zip_code=" . $cache->get('zip');
 <A HREF="<%$p%>misc/openmap.html?<% $querystring %>"
-   TARGET="_blank">Map zip code center</A><BR>
+   REL="opener"
+   TARGET="_blank"
+>Map zip code center</A><BR>
 <BR>
 <input type="hidden" id="new_tract" name="new_tract" value="<%$new_tract%>">
 <TABLE>
diff --git a/httemplate/misc/openmap.html b/httemplate/misc/openmap.html
index 88f64c1ff..a9a70337f 100644
--- a/httemplate/misc/openmap.html
+++ b/httemplate/misc/openmap.html
@@ -44,8 +44,7 @@
       function getCensusTract(lat, lon) {
        var url = 'xmlhttp-censustract.html?lat=' + lat + '&lon=' + lon + '&census_year=<%$census_year%>';
        $.getJSON(url,function(data){
-         var tract = (data.Block.FIPS.substr(0, 11) / 100).toFixed(2);
-         document.getElementById("mycensustract").innerHTML = tract;
+         document.getElementById("mycensustract").innerHTML = data.Block.FIPS;
        });
       }
 
@@ -81,4 +80,4 @@ my $zip_code    = $cgi->param('zip_code');
 my $address     = $cgi->param('address');
 my $loc = $zip_code ? $zip_code : $address;
 
-</%init>
\ No newline at end of file
+</%init>
diff --git a/httemplate/misc/xmlhttp-censustract.html b/httemplate/misc/xmlhttp-censustract.html
index 985fb90e5..855e172e2 100644
--- a/httemplate/misc/xmlhttp-censustract.html
+++ b/httemplate/misc/xmlhttp-censustract.html
@@ -5,12 +5,19 @@ my $DEBUG = 0;
 
 my $conf = new FS::Conf;
 
-my $return = {};
-
 ## new api link, see doc https://geo.fcc.gov/api/census/
 my $url = "https://geo.fcc.gov/api/census/block/find?format=json&censusYear=" . $cgi->param('census_year') . "&latitude=" . $cgi->param('lat') . "&longitude=" . $cgi->param('lon');
 
-use LWP::Simple;
-my $return = get $url;
+my $ua = new LWP::UserAgent;
+$ua->agent('Freeside/'. $FS::VERSION); #libwww* elicits "403 Forbidden"
+my $res = $ua->get($url);
+
+my $return = '';
+if ( $res->is_success ) {
+  $return = $res->decoded_content;
+} else {
+  #better error handling?  well, hopefully the site is reliable enough
+  warn 'Error from geo.fcc.gov: '. $res->status_line. "\n";
+}
 
-</%init>
\ No newline at end of file
+</%init>

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/Misc/Geo.pm                        |  6 ++++--
 httemplate/misc/confirm-censustract.html |  8 ++++++--
 httemplate/misc/openmap.html             |  5 ++---
 httemplate/misc/xmlhttp-censustract.html | 17 ++++++++++++-----
 4 files changed, 24 insertions(+), 12 deletions(-)




More information about the freeside-commits mailing list