summaryrefslogtreecommitdiff
path: root/httemplate/misc/confirm-address_standardize.html
blob: 8bd43ca547e8bdba38bf620f07461cc6dac911f1 (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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
<STYLE type="text/css">
th { line-height: 150%;
  width: 45%;
}
.td_radio {
  width: 5%;
  vertical-align: middle;
  text-align: center;
}
button {
  width: 215px;
}
</STYLE>
<CENTER><BR><B>
% if ( $is_error ) {
Address standardization error
% }
% else {
Confirm address standardization
% }

</B><BR><BR>
<FORM ID="confirm_replace_form">
<TABLE WIDTH="100%">
% for my $pre (@prefixes) {
%   my $name = $pre eq 'bill_' ? 'billing' : 'service';
%   my $rows = 5;
%   if ( $new{$pre.'error'} ) {
%     # Standardization returned an error, so the user can either "continue
%     # without replacing" (replace = "") or "abort".
  <TR>
    <TD ROWSPAN=<% $rows %> CLASS="td_radio">
%       if ( $show_radio ) {
        <INPUT TYPE="radio" NAME="<% $pre %>replace" VALUE="" CHECKED="Y">
%       } # else confirm_manual_address will be called
    </TD>
    <TH>Entered <%$name%> address
    </TH>
    <TH></TH>
    <TD CLASS="td_radio"></TD>
  </TR>
  <TR>
%     if ( $old{$pre.'company'} ) {
    <TD><% $old{$pre.'company'} |h %></TD>
%     }
  </TR>
  <TR>
    <TD><% $old{$pre.'address1'} |h %></TD>
    <TD ROWSPAN=3><FONT COLOR="#ff0000"><B><% $new{$pre.'error'} %></B></FONT></TD>
  </TR>
  <TR>
    <TD><% $old{$pre.'address2'} |h %></TD>
  </TR>
  <TR>
    <TD><% $old{$pre.'city'} |h %>, <% $old{$pre.'state'} |h %>  <% $old{$pre.'zip'} |h %></TD>
  </TR>
%   } else { # not an error
%     $rows++ if !$new{$pre.'addr_clean'};
  <TR>
    <TD ROWSPAN=<% $rows %> CLASS="td_radio">
%     if ( $show_radio ) {
      <INPUT TYPE="radio" NAME="<% $pre %>replace" VALUE="">
%     }
    </TD>
    <TH>Entered <%$name%> address</TH>
    <TH>Standardized <%$name%> address</TH>
    <TD ROWSPAN=<% $rows %> CLASS="td_radio">
%     if ( $show_radio ) {
      <INPUT TYPE="radio" NAME="<% $pre %>replace" VALUE="Y" CHECKED="Y">
%     }
    </TD>
  </TR>
%   if ( !$new{$pre.'addr_clean'} ) { # we incremented $rows to fit this in
  <TR>
    <TD></TD>
    <TH STYLE="font-size:smaller;color:#ff0000">(unverified)</TH>
  </TR>
%   }
  <TR>
%     if ( $old{$pre.'company'} ) {
  <TR>
    <TD><% $old{$pre.'company'} |h %></TD>
    <TD><% $new{$pre.'company'} |h %></TD>
  </TR>
%     }
  <TR>
    <TD><% $old{$pre.'address1'} |h %></TD>
    <TD><% $new{$pre.'address1'} |h %></TD>
  </TR>
  <TR>
    <TD><% $old{$pre.'address2'} |h %></TD>
    <TD><% $new{$pre.'address2'} |h %></TD>
  </TR>
  <TR>
    <TD><% $old{$pre.'city'} |h %>, <% $old{$pre.'state'} |h %>  <% $old{$pre.'zip'} |h %></TD>
    <TD><% $new{$pre.'city'} |h %>, <% $new{$pre.'state'} |h %>  <% $new{$pre.'zip'} |h %></TD>
  </TR>

%   } # if error
% } # for $pre

% # the prefix for the censustract
% my $pre = $old{billship} ?
%             ( $old{same} ? 'bill_'  : 'ship_' ) :
%             '';
% my $censustract = $new{$pre.'censustract'};
% if ( $censustract ) {
  <TR>
    <TD ROWSPAN=2 CLASS="td_radio">
%     if ( $show_radio ) {
      <INPUT TYPE="radio" NAME="census_replace" VALUE="" <% $census_error ? 'CHECKED="Y"' : '' %>>
%     }
    </TD>
    <TH>Entered census tract</TH>
    <TH>Calculated census tract</TH>
    <TD ROWSPAN=2 CLASS="td_radio">
%     if ( $show_radio ) {
      <INPUT TYPE="radio" NAME="census_replace" VALUE="Y" <% $census_error ? '' : 'CHECKED="Y"' %>>
%     }
    </TD>
  </TR>
  <TR>
    <TD><% $old{$pre.'censustract'} %></TD>
    <TD>
%     if ( $census_error ) {
      <FONT COLOR="#ff0000"><% $census_error %></FONT>
%     } else {
      <% $censustract %>
%     }
    </TD>
  </TR>
% } #if censustract

  <TR>
% if ( $show_radio ) {
%   # One button: "use selected address(es)".
    <TD ALIGN="center" COLSPAN=4>
      <BUTTON TYPE="button" onclick="replace_address();">
      <IMG SRC="<%$p%>images/<% $is_error ? 'error.png' : 'tick.png' %>"
           ALT="">
             Use selected <%$addresses%>
      </BUTTON>
    </TD>
% } else {
%   # Two buttons: "use entered address", and "use selected address"
%   # and empty columns before and after
    <TD> </TD>
    <TD ALIGN="center">
      <BUTTON TYPE="button" onclick="confirm_manual_address();">
        <IMG SRC="<%$p%>images/error.png" ALT=""> Use entered <%$addresses%>
      </BUTTON>
    </TD>
%   # disable the button if standardization completely failed
    <TD ALIGN="center">
      <BUTTON TYPE="button" onclick="replace_address();" <% $failed ? 'DISABLED' : '' %>>
        <IMG SRC="<%$p%>images/tick.png" ALT=""> Use standardized <%$addresses%>
      </BUTTON>
    </TD>
    <TD> </TD>
% }
  </TR>
% # always provide a cancel button
  <TR>
    <TD ALIGN="center" COLSPAN=4>
      <BUTTON TYPE="button" onclick="submit_abort();">
        <IMG SRC="<%$p%>images/cross.png" ALT=""> Cancel submission
      </BUTTON>
    </TD>
  </TR>
</TABLE>
</FORM>
<%init>

# slightly weird interface...
my $q = decode_json($cgi->param('q'));
#warn Dumper($q);
my %old = %{ $q->{old} };
my %new = %{ $q->{new} };

my $addresses = $old{billship} ? 'addresses' : 'address';
my $show_radio = 0;
my $failed = 0; # true if standardization returned no addresses

my @prefixes = ('');

if ( $old{same} ) {

  # Then there are bill and ship addresses and they're the same. Treat
  # bill_error as a failure, and let the user accept or reject the whole
  # standardization.

  @prefixes = ('bill_');
  $failed = 1 if $new{'bill_error'};

} elsif ( $old{billship} ) {

  # There are separate bill and ship addresses. Treat error in both as a
  # failure. Otherwise, at least one of them has a choice between entered
  # and standardized address, so let the user choose.

  @prefixes = ('bill_', 'ship_');
  if ( $new{'bill_error'} and $new{'ship_error'} ) {
    $failed = 1;
  } else {
    $show_radio = 1;
  }

} else {

  # There are no bill/ship addresses (this is used for package locations).
  # Treat like the first case but without the bill_ prefix.
  @prefixes = ('');
  $failed = 1 if $new{'error'};

}

my $census_error = $new{'census_error'}; # seems to be unused
my $is_error = $census_error || grep { $new{$_.'error'} } @prefixes;

</%init>