Merge branch 'master' of ssh://git.freeside.biz/home/git/freeside
[freeside.git] / httemplate / misc / confirm-address_standardize.html
1 <STYLE type="text/css">
2 th { line-height: 150%;
3   width: 45%;
4 }
5 .td_radio {
6   width: 5%;
7   vertical-align: middle;
8   text-align: center;
9 }
10 button {
11   width: 215px;
12 }
13 </STYLE>
14 <CENTER><BR><B>
15 % if ( $is_error ) {
16 Address standardization error
17 % }
18 % else {
19 Confirm address standardization
20 % }
21
22 </B><BR><BR>
23 <FORM ID="confirm_replace_form">
24 <TABLE WIDTH="100%">
25 % for my $pre (@prefixes) {
26 %   my $name = $pre eq 'bill_' ? 'billing' : 'service';
27 %   my $rows = 5;
28 %   if ( $new{$pre.'error'} ) {
29 %     # Standardization returned an error, so the user can either "continue
30 %     # without replacing" (replace = "") or "abort".
31   <TR>
32     <TD ROWSPAN=<% $rows %> CLASS="td_radio">
33 %       if ( $show_radio ) {
34         <INPUT TYPE="radio" NAME="<% $pre %>replace" VALUE="" CHECKED="Y">
35 %       } # else confirm_manual_address will be called
36     </TD>
37     <TH>Entered <%$name%> address
38     </TH>
39     <TH></TH>
40     <TD CLASS="td_radio"></TD>
41   </TR>
42   <TR>
43 %     if ( $old{$pre.'company'} ) {
44     <TD><% $old{$pre.'company'} |h %></TD>
45 %     }
46   </TR>
47   <TR>
48     <TD><% $old{$pre.'address1'} |h %></TD>
49     <TD ROWSPAN=3><FONT COLOR="#ff0000"><B><% $new{$pre.'error'} %></B></FONT></TD>
50   </TR>
51   <TR>
52     <TD><% $old{$pre.'address2'} |h %></TD>
53   </TR>
54   <TR>
55     <TD><% $old{$pre.'city'} |h %>, <% $old{$pre.'state'} |h %>  <% $old{$pre.'zip'} |h %></TD>
56   </TR>
57 %   } else { # not an error
58 %     $rows++ if !$new{$pre.'addr_clean'};
59   <TR>
60     <TD ROWSPAN=<% $rows %> CLASS="td_radio">
61 %     if ( $show_radio ) {
62       <INPUT TYPE="radio" NAME="<% $pre %>replace" VALUE="">
63 %     }
64     </TD>
65     <TH>Entered <%$name%> address</TH>
66     <TH>Standardized <%$name%> address</TH>
67     <TD ROWSPAN=<% $rows %> CLASS="td_radio">
68 %     if ( $show_radio ) {
69       <INPUT TYPE="radio" NAME="<% $pre %>replace" VALUE="Y" CHECKED="Y">
70 %     }
71     </TD>
72   </TR>
73 %   if ( !$new{$pre.'addr_clean'} ) { # we incremented $rows to fit this in
74   <TR>
75     <TD></TD>
76     <TH STYLE="font-size:smaller;color:#ff0000">(unverified)</TH>
77   </TR>
78 %   }
79   <TR>
80 %     if ( $old{$pre.'company'} ) {
81   <TR>
82     <TD><% $old{$pre.'company'} |h %></TD>
83     <TD><% $new{$pre.'company'} |h %></TD>
84   </TR>
85 %     }
86   <TR>
87     <TD><% $old{$pre.'address1'} |h %></TD>
88     <TD><% $new{$pre.'address1'} |h %></TD>
89   </TR>
90   <TR>
91     <TD><% $old{$pre.'address2'} |h %></TD>
92     <TD><% $new{$pre.'address2'} |h %></TD>
93   </TR>
94   <TR>
95     <TD><% $old{$pre.'city'} |h %>, <% $old{$pre.'state'} |h %>  <% $old{$pre.'zip'} |h %></TD>
96     <TD><% $new{$pre.'city'} |h %>, <% $new{$pre.'state'} |h %>  <% $new{$pre.'zip'} |h %></TD>
97   </TR>
98
99 %   } # if error
100 % } # for $pre
101
102 % # the prefix for the censustract
103 % my $pre = $old{billship} ?
104 %             ( $old{same} ? 'bill_'  : 'ship_' ) :
105 %             '';
106 % my $censustract = $new{$pre.'censustract'};
107 % if ( $censustract ) {
108   <TR>
109     <TD ROWSPAN=2 CLASS="td_radio">
110 %     if ( $show_radio ) {
111       <INPUT TYPE="radio" NAME="census_replace" VALUE="" <% $census_error ? 'CHECKED="Y"' : '' %>>
112 %     }
113     </TD>
114     <TH>Entered census tract</TH>
115     <TH>Calculated census tract</TH>
116     <TD ROWSPAN=2 CLASS="td_radio">
117 %     if ( $show_radio ) {
118       <INPUT TYPE="radio" NAME="census_replace" VALUE="Y" <% $census_error ? '' : 'CHECKED="Y"' %>>
119 %     }
120     </TD>
121   </TR>
122   <TR>
123     <TD><% $old{$pre.'censustract'} %></TD>
124     <TD>
125 %     if ( $census_error ) {
126       <FONT COLOR="#ff0000"><% $census_error %></FONT>
127 %     } else {
128       <% $censustract %>
129 %     }
130     </TD>
131   </TR>
132 % } #if censustract
133
134   <TR>
135 % if ( $show_radio ) {
136 %   # One button: "use selected address(es)".
137     <TD ALIGN="center" COLSPAN=4>
138       <BUTTON TYPE="button" onclick="replace_address();">
139       <IMG SRC="<%$p%>images/<% $is_error ? 'error.png' : 'tick.png' %>"
140            ALT="">
141              Use selected <%$addresses%>
142       </BUTTON>
143     </TD>
144 % } else {
145 %   # Two buttons: "use entered address", and "use selected address"
146 %   # and empty columns before and after
147     <TD> </TD>
148     <TD ALIGN="center">
149       <BUTTON TYPE="button" onclick="confirm_manual_address();">
150         <IMG SRC="<%$p%>images/error.png" ALT=""> Use entered <%$addresses%>
151       </BUTTON>
152     </TD>
153 %   # disable the button if standardization completely failed
154     <TD ALIGN="center">
155       <BUTTON TYPE="button" onclick="replace_address();" <% $failed ? 'DISABLED' : '' %>>
156         <IMG SRC="<%$p%>images/tick.png" ALT=""> Use standardized <%$addresses%>
157       </BUTTON>
158     </TD>
159     <TD> </TD>
160 % }
161   </TR>
162 % # always provide a cancel button
163   <TR>
164     <TD ALIGN="center" COLSPAN=4>
165       <BUTTON TYPE="button" onclick="submit_abort();">
166         <IMG SRC="<%$p%>images/cross.png" ALT=""> Cancel submission
167       </BUTTON>
168     </TD>
169   </TR>
170 </TABLE>
171 </FORM>
172 <%init>
173
174 # slightly weird interface...
175 my $q = decode_json($cgi->param('q'));
176 #warn Dumper($q);
177 my %old = %{ $q->{old} };
178 my %new = %{ $q->{new} };
179
180 my $addresses = $old{billship} ? 'addresses' : 'address';
181 my $show_radio = 0;
182 my $failed = 0; # true if standardization returned no addresses
183
184 my @prefixes = ('');
185
186 if ( $old{same} ) {
187
188   # Then there are bill and ship addresses and they're the same. Treat
189   # bill_error as a failure, and let the user accept or reject the whole
190   # standardization.
191
192   @prefixes = ('bill_');
193   $failed = 1 if $new{'bill_error'};
194
195 } elsif ( $old{billship} ) {
196
197   # There are separate bill and ship addresses. Treat error in both as a
198   # failure. Otherwise, at least one of them has a choice between entered
199   # and standardized address, so let the user choose.
200
201   @prefixes = ('bill_', 'ship_');
202   if ( $new{'bill_error'} and $new{'ship_error'} ) {
203     $failed = 1;
204   } else {
205     $show_radio = 1;
206   }
207
208 } else {
209
210   # There are no bill/ship addresses (this is used for package locations).
211   # Treat like the first case but without the bill_ prefix.
212   @prefixes = ('');
213   $failed = 1 if $new{'error'};
214
215 }
216
217 my $census_error = $new{'census_error'}; # seems to be unused
218 my $is_error = $census_error || grep { $new{$_.'error'} } @prefixes;
219
220 </%init>