default to a session cookie instead of setting an explicit timeout, weird timezone...
[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 $address1 = $location{address1};
20 % $address1 =~ s/(apt|ste|suite|unit)[\s\d]\w*\s*$//i;
21 % my $querystring = "census_year=$year&address=$address1, $location{address2}, $location{city}, $location{state}";
22 <A HREF="<%$p%>misc/openmap.html?<% $querystring %>"
23    REL="opener"
24    TARGET="_blank"
25 >Map service location</A><BR>
26 % $querystring = "census_year=$year&pre=$pre&zip_code=" . $cache->get('zip');
27 <A HREF="<%$p%>misc/openmap.html?<% $querystring %>"
28    REL="opener"
29    TARGET="_blank"
30 >Map zip code center</A><BR>
31 <BR>
32 <input type="hidden" id="new_tract" name="new_tract" value="<%$new_tract%>">
33 <TABLE>
34   <TR>
35     <TH style="width:50%">Entered census tract</TH>
36     <TH style="width:50%">Calculated census tract</TH>
37   </TR>
38   <TR>
39     <TD><% $old_tract %></TD>
40 % if ( $error ) {
41     <TD><div id='newcensustract'><FONT COLOR="#ff0000"><% $error %></FONT></div></TD>
42 % } else {
43     <TD><div id='newcensustract'><% $new_tract %></div></TD>
44 % }
45   </TR>
46   <TR>
47     <TD ALIGN="center">
48       <BUTTON TYPE="button"
49               onclick="set_censustract('<% $old_tract %>', '<% $year %>', '<% $pre %>')">
50       <IMG SRC="<%$p%>images/error.png" ALT=""> Use entered census tract
51       </BUTTON>
52     </TD>
53     <TD ALIGN="center">
54      <div id="setnewtractdiv"
55 % if ( $error ) { ## do not display this block if error finding track.
56       style="display:none"
57 % }
58      >
59       <BUTTON TYPE="button" id="setnewtract"
60               onclick="set_censustract(getElementById('new_tract').value, '<% $year %>', '<% $pre %>')">
61       <IMG SRC="<%$p%>images/tick.png" ALT=""> Use calculated census tract
62       </BUTTON>
63      </div>
64      <div id='cancelsubmissiontop'
65 % if ( !$error ) { ## do not display this block if there is no error finding a track.
66       style="display:none"
67 % }
68      >
69       <BUTTON TYPE="button" onclick="submit_abort()">
70         <IMG SRC="<%$p%>images/cross.png" ALT=""> Cancel submission
71       </BUTTON>
72      </div>
73     </TD>
74   </TR>
75   <TR>
76     <TD COLSPAN=2 ALIGN="center">
77      <div id='cancelsubmissionbottom'
78 % if ( $error ) { ## do not display this block if error finding track.
79       style="display:none"
80 % }
81      >
82       <BUTTON TYPE="button" onclick="submit_abort()">
83         <IMG SRC="<%$p%>images/cross.png" ALT=""> Cancel submission
84       </BUTTON>
85      </div>
86     </TD>
87   </TR>
88 </TABLE></CENTER>
89
90 <%init>
91
92 local $SIG{__DIE__}; #disable Mason error trap
93
94 my $DEBUG = 0;
95
96 my $conf = new FS::Conf;
97
98 warn $cgi->param('q') if $DEBUG;
99
100 my $q = decode_json($cgi->param('q'))
101   or die "bad argument '".$cgi->param('q')."'";
102
103 my $pre = $q->{prefix} || '';
104 my %location = (
105   map { $_ => $q->{$pre.$_} }
106     qw( company address1 address2 city state zip country latitude longitude )
107 );
108
109 my $old_tract = $q->{$pre.'censustract'};
110 my $cache = eval { FS::GeocodeCache->new(%location) };
111 $cache->set_censustract;
112 my $year = FS::Conf->new->config('census_legacy') || '2020';
113 my $new_tract = $cache->get('censustract');
114 my $error = $cache->get('censustract_error');
115
116 warn Dumper($cache) if $DEBUG;
117
118 </%init>