summaryrefslogtreecommitdiff
path: root/httemplate/misc/confirm-censustract.html
blob: b491d49541b32591c142ed067857239fb23000fc (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
% if ( !$error and !$new_tract ) {
%   # then set_censustract returned nothing
%   # because it's not relevant for this address
%   # so output nothing (forces confirm_censustract() to continue)
% $m->clear_buffer;
% $m->abort;
% }
<CENTER><BR><B>
% if ( $error ) {
Census tract error
% }
% else {
Confirm census tract
% }
</B><BR>
<% $location{address1} |h %> <% $location{address2} |h %><BR>
<% $location{city} |h %>, <% $location{state} |h %> <% $location{zip} |h %><BR>
<BR>
% my $querystring = "census_year=$year&address=$location{address1}, $location{address2}, $location{city}, $location{state}, $location{zip}";
<A HREF="<%$p%>misc/openmap.html?<% $querystring %>"
   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>
<BR>
<input type="hidden" id="new_tract" name="new_tract" value="<%$new_tract%>">
<TABLE>
  <TR>
    <TH style="width:50%">Entered census tract</TH>
    <TH style="width:50%">Calculated census tract</TH>
  </TR>
  <TR>
    <TD><% $old_tract %></TD>
% if ( $error ) {
    <TD><div id='newcensustract'><FONT COLOR="#ff0000"><% $error %></FONT></div></TD>
% } else {
    <TD><div id='newcensustract'><% $new_tract %></div></TD>
% }
  </TR>
  <TR>
    <TD ALIGN="center">
      <BUTTON TYPE="button"
              onclick="set_censustract('<% $old_tract %>', '<% $year %>', '<% $pre %>')">
      <IMG SRC="<%$p%>images/error.png" ALT=""> Use entered census tract
      </BUTTON>
    </TD>
    <TD ALIGN="center">
     <div id="setnewtractdiv"
% if ( $error ) { ## do not display this block if error finding track.
      style="display:none"
% }
     >
      <BUTTON TYPE="button" id="setnewtract"
              onclick="set_censustract(getElementById('new_tract').value, '<% $year %>', '<% $pre %>')">
      <IMG SRC="<%$p%>images/tick.png" ALT=""> Use calculated census tract
      </BUTTON>
     </div>
     <div id='cancelsubmissiontop'
% if ( !$error ) { ## do not display this block if there is no error finding a track.
      style="display:none"
% }
     >
      <BUTTON TYPE="button" onclick="submit_abort()">
        <IMG SRC="<%$p%>images/cross.png" ALT=""> Cancel submission
      </BUTTON>
     </div>
    </TD>
  </TR>
  <TR>
    <TD COLSPAN=2 ALIGN="center">
     <div id='cancelsubmissionbottom'
% if ( $error ) { ## do not display this block if error finding track.
      style="display:none"
% }
     >
      <BUTTON TYPE="button" onclick="submit_abort()">
        <IMG SRC="<%$p%>images/cross.png" ALT=""> Cancel submission
      </BUTTON>
     </div>
    </TD>
  </TR>
</TABLE></CENTER>

<%init>

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

my $DEBUG = 0;

my $conf = new FS::Conf;

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

my $q = decode_json($cgi->param('q'))
  or die "bad argument '".$cgi->param('q')."'";

my $pre = $q->{prefix} || '';
my %location = (
  map { $_ => $q->{$pre.$_} }
    qw( company address1 address2 city state zip country latitude longitude )
);

my $old_tract = $q->{$pre.'censustract'};
my $cache = eval { FS::GeocodeCache->new(%location) };
$cache->set_censustract;
my $year = FS::Conf->new->config('census_year');
my $new_tract = $cache->get('censustract');
my $error = $cache->get('censustract_error');

warn Dumper($cache) if $DEBUG;

</%init>