5 include( '/elements/location.html',
6 'object' => $cust_location
7 'prefix' => $pre, # prefixed to form field names
8 'onchange' => $javascript,
9 'geocode' => $geocode, #passed through
10 'censustract' => $censustract, #passed through
11 'no_asterisks' => 0, #set true to disable the red asterisks next
13 'address1_label' => 'Address', #label for address
14 'enable_coords' => 1, #show latitude/longitude fields
15 'enable_district' => 1, #show tax district field
16 'enable_censustract' => 1, #show censustract field
22 % if ( $opt{'alt_format'} ) {
25 <<%$th%> ALIGN="right">Location kind</<%$th%>>
27 <% include('/elements/select.html',
29 'field' => 'location_kind',
30 'id' => 'location_kind',
31 'disabled' => $disabled,
33 'options' => \@location_kind_options,
34 'labels' => $location_kind_labels,
35 'curr_value' => scalar($cgi->param('location_kind'))
36 || $object->get('location_kind'),
45 <<%$th%> STYLE="width:16ex" ALIGN="right"><%$r%><% $opt{'address1_label'} || emt('Address') %></<%$th%>>
48 NAME = "<%$pre%>address1"
49 ID = "<%$pre%>address1"
50 VALUE = "<% $object->get('address1') |h %>"
52 onChange = "<% $onchange %>"
59 % if ( ! $opt{'alt_format'} ) { #regular format
62 <TD ALIGN="right"><FONT ID="<% $pre %>address2_required" color="#ff0000" <% $address2_label_style %>>*</FONT> <FONT ID="<% $pre %>address2_label" <% $address2_label_style %>><B>Unit #</B></FONT></TD>
65 NAME = "<%$pre%>address2"
66 ID = "<%$pre%>address2"
67 VALUE = "<% $object->get('address2') |h %>"
69 onChange = "<% $onchange %>"
76 % } else { # alternate format
78 <INPUT TYPE = "hidden"
79 NAME = "<%$pre%>address2"
80 VALUE = "<% $object->get('address2') |h %>"
84 <<%$th%> ALIGN="right">Unit type and #</<%$th%>>
87 % my $location_type = scalar($cgi->param('location_type'))
88 % || $object->get('location_type');
89 % #my $location_number = scalar($cgi->param('location_number'))
90 % # || $object->get($pre.'location_number');
92 % if ( $object->get($pre.'address2') && ! $location_type ) {
95 % if ( 1 ) { #ikano, switch on via config
96 % tie my %location_types, 'Tie::IxHash',
97 % FS::part_export::ikano->location_types;
98 <% include('/elements/select.html',
100 'field' => 'location_type',
101 'id' => 'location_type',
102 'disabled' => $disabled,
104 'options' => [ keys %location_types ],
105 'labels' => \%location_types,
106 'curr_value' => $location_type,
107 'onchange' => 'location_type_changed',
110 <SCRIPT TYPE="text/javascript">
111 function location_type_changed (what) {
112 if ( what.options[what.selectedIndex].value == '' ) {
113 what.form.location_number.disabled = true;
114 what.form.location_number.style.backgroundColor = '#dddddd';
116 what.form.location_number.disabled = false;
117 what.form.location_number.style.backgroundColor = '#ffffff';
123 NAME = "location_type"
125 VALUE = "<% $location_type |h %>"
133 NAME = "location_number"
134 ID = "location_number"
135 VALUE = "<% scalar($cgi->param('location_number')) || $object->get('location_number') |h %>"
137 <% $disabled || ($location_type ? '' : 'DISABLED') %>
141 % #XXX i don't work so well when the dropdown is changed :/ i probably need to be triggered by "default service address"
142 % $alt_err =~ s/(ship_)?address2/'<B>'.encode_entities($object->get($1.'address2')).'<\/B>'/e;
153 <<%$th%> ALIGN="right"><%$r%><% mt('City') |h %></<%$th%>>
154 <TD WIDTH="1"><% include('/elements/city.html', %select_hash, 'text_style' => \@style ) %></TD>
155 <<%$th%> ALIGN="right" WIDTH="1" ID="<%$pre%>countylabel" <%$county_style%>><%$r%>County</<%$th%>>
156 <TD WIDTH="1"><% include('/elements/select-county.html', %select_hash ) %></TD>
157 <<%$th%> ALIGN="right" WIDTH="1"><%$r%><% mt('State') |h %></<%$th%>>
159 <% include('/elements/select-state.html', %select_hash ) %>
161 <<%$th%> ALIGN="right" WIDTH="1"><%$r%><% mt('Zip') |h %></<%$th%>>
166 VALUE = "<% $object->get('zip') |h %>"
168 onChange = "<% $onchange %>"
176 <<%$th%> ALIGN="right"><%$r%><% mt('Country') |h %></<%$th%>>
177 <TD COLSPAN=6><% include('/elements/select-country.html', %select_hash ) %></TD>
180 % if ( $opt{enable_coords} ) {
182 <TD ALIGN="right"><% mt('Latitude') |h %></TD>
185 NAME = "<%$pre%>latitude"
186 ID = "<%$pre%>latitude"
187 VALUE = "<% $object->get('latitude') |h %>"
191 <% mt('Longitude') |h %>
193 NAME = "<%$pre%>longitude"
194 ID = "<%$pre%>longitude"
195 VALUE = "<% $object->get('longitude') |h %>"
202 % foreach (qw(latitude longitude)) {
203 <INPUT TYPE="hidden" NAME="<% $_ %>" ID="<% $_ %>" VALUE="<% $object->get($_) |h%>">
206 <INPUT TYPE="hidden" NAME="<%$pre%>coord_auto" VALUE="<% $object->coord_auto %>">
208 <INPUT TYPE="hidden" NAME="<%$pre%>geocode" VALUE="<% $object->geocode %>">
209 <INPUT TYPE="hidden" NAME="<%$pre%>censustract" VALUE="<% $object->censustract %>">
210 <INPUT TYPE="hidden" NAME="<%$pre%>censusyear" VALUE="<% $object->censusyear %>">
211 % if ( $opt{enable_censustract} ) {
213 <TD ALIGN="right">Census tract</TD>
215 <INPUT TYPE="text" SIZE=15
216 NAME="enter_censustract"
217 VALUE="<% $object->censustract |h %>">
222 % if ( $opt{enable_district} and $conf->config('tax_district_method') ) {
224 <TD ALIGN="right">Tax district</TD>
226 <INPUT TYPE="text" SIZE=15
227 NAME="<%$pre%>district"
228 ID="<%$pre%>district"
229 VALUE="<% $object->district |h %>">
234 <INPUT TYPE="hidden" ID="<%$pre%>" NAME="<%$pre%>district" VALUE="<% $object->district %>">
237 %# For address standardization:
238 %# keep a clean copy of the address so we know if we need
240 % foreach (qw(address1 city state country zip latitude
241 % longitude censustract district addr_clean) ) {
242 <INPUT TYPE="hidden" NAME="old_<%$pre.$_%>" ID="old_<%$pre.$_%>" VALUE="<% $object->get($_) |h%>">
245 <INPUT TYPE="hidden" NAME="<%$pre%>cachenum" VALUE="">
246 <INPUT TYPE="hidden" NAME="<%$pre%>addr_clean" VALUE="">
248 <SCRIPT TYPE="text/javascript">
249 <&| /elements/onload.js &>
250 var clear_coords_ids = [
256 function clear_coords() {
257 for (var i=0; i < clear_coords_ids.length; i++) {
258 var el = document.getElementById(clear_coords_ids[i]);
264 var clear_coords_on_change = [
272 for (var i=0; i < clear_coords_on_change.length; i++) {
273 var el = document.getElementById(clear_coords_on_change[i]);
274 if ( el.addEventListener ) {
275 el.addEventListener('change', clear_coords);
276 } else if ( el.attachEvent ) {
277 el.attachEvent('onchange', clear_coords);
287 my $pre = $opt{'prefix'};
288 my $object = $opt{'object'};
289 my $onchange = $opt{'onchange'};
290 my $disabled = $opt{'disabled'};
292 my $conf = new FS::Conf;
294 my $r = $opt{'no_asterisks'} ? '' : qq!<font color="#ff0000">*</font> !;
296 my $countrydefault = $conf->config('countrydefault') || 'US';
297 my $statedefault = $conf->config('statedefault')
298 || ($countrydefault eq 'US' ? 'CA' : '');
299 $object ||= FS::cust_location->new({
300 'country' => $countrydefault,
301 'state' => $statedefault,
304 my $alt_err = ($opt{'alt_format'} && !$disabled) ? $object->alternize : '';
307 push @style, 'background-color: #dddddd' if $disabled;
309 my @address2_label_style = ();
310 push @address2_label_style, 'visibility:hidden'
312 || ! $conf->exists('cust_main-require_address2')
313 || ( !$pre && !$opt{'same_checked'} );
315 my @counties = counties( $object->get('state'),
316 $object->get('country'),
318 my @county_style = ();
319 push @county_style, 'display:none' # 'visibility:hidden'
320 unless scalar(@counties) > 1;
324 ? 'STYLE="'. join(';', @style). '"'
326 my $address2_label_style =
327 scalar(@address2_label_style)
328 ? 'STYLE="'. join(';', @address2_label_style). '"'
331 scalar(@county_style)
332 ? 'STYLE="'. join(';', @county_style). '"'
336 'city' => $object->get('city'),
337 'county' => $object->get('county'),
338 'state' => $object->get('state'),
339 'country' => $object->get('country'),
341 'onchange' => $onchange,
342 'disabled' => $disabled,
346 my $th = $opt{'no_bold'} ? 'TD' : 'TH';
348 my @location_kind_options = ( '', 'R', 'B' );
349 my $location_kind_labels = { '' => '', 'R' => 'Residential', 'B' => 'Business' };