f3fd0383ecfad8a5672c480c1c65dc6d579bd9c5
[freeside.git] / httemplate / misc / confirm-censustract.html
1 % if ( !$error and !$new_tract ) {
2 %   # then set_censustract returned nothing
3 %   # because it's not relevant for this address
4 %   # so output nothing (forces confirm_censustract() to continue)
5 % $m->clear_buffer;
6 % $m->abort;
7 % }
8 <CENTER><BR><B>
9 % if ( $error ) {
10 Census tract error
11 % }
12 % else {
13 Confirm census tract
14 % }
15 </B><BR>
16 <% $location{address1} |h %> <% $location{address2} |h %><BR>
17 <% $location{city} |h %>, <% $location{state} |h %> <% $location{zip} |h %><BR>
18 <BR>
19 % my $querystring = "census_year=$year&address=$location{address1}, $location{address2}, $location{city}, $location{state}";
20 <A HREF="<%$p%>misc/openmap.html?<% $querystring %>"
21    REL="opener"
22    TARGET="_blank"
23 >Map service module location</A><BR>
24 % $querystring = "census_year=$year&pre=$pre&zip_code=" . $cache->get('zip');
25 <A HREF="<%$p%>misc/openmap.html?<% $querystring %>"
26    REL="opener"
27    TARGET="_blank"
28 >Map zip code center</A><BR>
29 <BR>
30 <input type="hidden" id="new_tract" name="new_tract" value="<%$new_tract%>">
31 <TABLE>
32   <TR>
33     <TH style="width:50%">Entered census tract</TH>
34     <TH style="width:50%">Calculated census tract</TH>
35   </TR>
36   <TR>
37     <TD><% $old_tract %></TD>
38 % if ( $error ) {
39     <TD><div id='newcensustract'><FONT COLOR="#ff0000"><% $error %></FONT></div></TD>
40 % } else {
41     <TD><div id='newcensustract'><% $new_tract %></div></TD>
42 % }
43   </TR>
44   <TR>
45     <TD ALIGN="center">
46       <BUTTON TYPE="button"
47               onclick="set_censustract('<% $old_tract %>', '<% $year %>', '<% $pre %>')">
48       <IMG SRC="<%$p%>images/error.png" ALT=""> Use entered census tract
49       </BUTTON>
50     </TD>
51     <TD ALIGN="center">
52      <div id="setnewtractdiv"
53 % if ( $error ) { ## do not display this block if error finding track.
54       style="display:none"
55 % }
56      >
57       <BUTTON TYPE="button" id="setnewtract"
58               onclick="set_censustract(getElementById('new_tract').value, '<% $year %>', '<% $pre %>')">
59       <IMG SRC="<%$p%>images/tick.png" ALT=""> Use calculated census tract
60       </BUTTON>
61      </div>
62      <div id='cancelsubmissiontop'
63 % if ( !$error ) { ## do not display this block if there is no error finding a track.
64       style="display:none"
65 % }
66      >
67       <BUTTON TYPE="button" onclick="submit_abort()">
68         <IMG SRC="<%$p%>images/cross.png" ALT=""> Cancel submission
69       </BUTTON>
70      </div>
71     </TD>
72   </TR>
73   <TR>
74     <TD COLSPAN=2 ALIGN="center">
75      <div id='cancelsubmissionbottom'
76 % if ( $error ) { ## do not display this block if error finding track.
77       style="display:none"
78 % }
79      >
80       <BUTTON TYPE="button" onclick="submit_abort()">
81         <IMG SRC="<%$p%>images/cross.png" ALT=""> Cancel submission
82       </BUTTON>
83      </div>
84     </TD>
85   </TR>
86 </TABLE></CENTER>
87
88 <%init>
89
90 local $SIG{__DIE__}; #disable Mason error trap
91
92 my $DEBUG = 0;
93
94 my $conf = new FS::Conf;
95
96 warn $cgi->param('q') if $DEBUG;
97
98 my $q = decode_json($cgi->param('q'))
99   or die "bad argument '".$cgi->param('q')."'";
100
101 my $pre = $q->{prefix} || '';
102 my %location = (
103   map { $_ => $q->{$pre.$_} }
104     qw( company address1 address2 city state zip country latitude longitude )
105 );
106
107 my $old_tract = $q->{$pre.'censustract'};
108 my $cache = eval { FS::GeocodeCache->new(%location) };
109 $cache->set_censustract;
110 my $year = FS::Conf->new->config('census_legacy') || '2020';
111 my $new_tract = $cache->get('censustract');
112 my $error = $cache->get('censustract_error');
113
114 warn Dumper($cache) if $DEBUG;
115
116 </%init>