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'),
44 % if ( $label_prefix eq '_location' ) {
47 <TD ALIGN="right" ><% $opt{'locationname_label'} || emt('Location ID') %></TD>
50 NAME = "<%$pre%>locationname"
51 ID = "<%$pre%>locationname"
52 VALUE = "<% $object->get('locationname') |h %>"
54 onChange = "<% $onchange %>"
62 <& hidden.html, field => $pre.'locationname', value => $object->get('locationname') &>
67 <<%$th%> STYLE="width:16ex" ALIGN="right"><%$r%><% $opt{'address1_label'} || emt('Address') %></<%$th%>>
70 NAME = "<%$pre%>address1"
71 ID = "<%$pre%>address1"
72 VALUE = "<% $object->get('address1') |h %>"
74 onChange = "<% $onchange %>"
81 % if ( ! $opt{'alt_format'} ) { #regular format
84 <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>
87 NAME = "<%$pre%>address2"
88 ID = "<%$pre%>address2"
89 VALUE = "<% $object->get('address2') |h %>"
91 onChange = "<% $onchange %>"
98 % } else { # alternate format
100 <& hidden.html, field => $pre.'address2', value => $object->get('address2') &>
103 <<%$th%> ALIGN="right">Unit type and #</<%$th%>>
106 % my $location_type = scalar($cgi->param('location_type'))
107 % || $object->get('location_type');
108 % #my $location_number = scalar($cgi->param('location_number'))
109 % # || $object->get($pre.'location_number');
111 % if ( $object->get($pre.'address2') && ! $location_type ) {
114 % if ( 1 ) { #ikano, switch on via config
115 % tie my %location_types, 'Tie::IxHash',
116 % FS::part_export::ikano->location_types;
117 <% include('/elements/select.html',
119 'field' => 'location_type',
120 'id' => 'location_type',
121 'disabled' => $disabled,
123 'options' => [ keys %location_types ],
124 'labels' => \%location_types,
125 'curr_value' => $location_type,
126 'onchange' => 'location_type_changed',
129 <SCRIPT TYPE="text/javascript">
130 function location_type_changed (what) {
131 if ( what.options[what.selectedIndex].value == '' ) {
132 what.form.location_number.disabled = true;
133 what.form.location_number.style.backgroundColor = '#dddddd';
135 what.form.location_number.disabled = false;
136 what.form.location_number.style.backgroundColor = '#ffffff';
142 NAME = "location_type"
144 VALUE = "<% $location_type |h %>"
152 NAME = "location_number"
153 ID = "location_number"
154 VALUE = "<% scalar($cgi->param('location_number')) || $object->get('location_number') |h %>"
156 <% $disabled || ($location_type ? '' : 'DISABLED') %>
160 % #XXX i don't work so well when the dropdown is changed :/ i probably need to be triggered by "default service address"
161 % $alt_err =~ s/(ship_)?address2/'<B>'.encode_entities($object->get($1.'address2')).'<\/B>'/e;
172 <<%$th%> ALIGN="right"><%$r%><% mt('City') |h %></<%$th%>>
173 <TD WIDTH="1"><% include('/elements/city.html', %select_hash, 'text_style' => \@style ) %></TD>
174 <<%$th%> ALIGN="right" WIDTH="1" ID="<%$pre%>countylabel" <%$county_style%>><%$r%>County</<%$th%>>
175 <TD WIDTH="1"><% include('/elements/select-county.html', %select_hash ) %></TD>
176 <<%$th%> ALIGN="right" WIDTH="1"><%$r%><% mt('State') |h %></<%$th%>>
178 <% include('/elements/select-state.html', %select_hash ) %>
180 <<%$th%> ALIGN="right" WIDTH="1"><%$r%><% mt('Zip') |h %></<%$th%>>
185 VALUE = "<% $object->get('zip') |h %>"
187 onChange = "<% $onchange %>"
195 <<%$th%> ALIGN="right"><%$r%><% mt('Country') |h %></<%$th%>>
196 <TD COLSPAN=6><% include('/elements/select-country.html', %select_hash ) %></TD>
199 % if ( $opt{enable_coords} ) {
201 <TD ALIGN="right"><% mt('Latitude') |h %></TD>
204 NAME = "<%$pre%>latitude"
205 ID = "<%$pre%>latitude"
206 VALUE = "<% $object->get('latitude') |h %>"
210 <% mt('Longitude') |h %>
212 NAME = "<%$pre%>longitude"
213 ID = "<%$pre%>longitude"
214 VALUE = "<% $object->get('longitude') |h %>"
221 % foreach (qw(latitude longitude)) {
222 <& hidden.html, field => $pre.$_, value => $object->get($_) &>
226 % foreach (qw(coord_auto geocode censustract censusyear)) {
227 <& hidden.html, field => $pre.$_, value => $object->get($_) &>
230 % if ( $opt{enable_censustract} ) {
232 <TD ALIGN="right">Census tract</TD>
234 <INPUT TYPE="text" SIZE=15
235 ID="<% $pre %>enter_censustract"
236 NAME="<% $pre %>enter_censustract"
237 VALUE="<% $object->censustract |h %>">
242 % if ( $opt{enable_district} and $conf->config('tax_district_method') ) {
244 <TD ALIGN="right">Tax district</TD>
246 <INPUT TYPE="text" SIZE=15
247 NAME="<%$pre%>district"
248 ID="<%$pre%>district"
249 VALUE="<% $object->district |h %>">
254 <& hidden.html, field => $pre.'district', value => $object->get('district') &>
257 %# For address standardization:
258 %# keep a clean copy of the address so we know if we need
260 % foreach (qw(address1 city state country zip latitude
261 % longitude censustract district addr_clean) ) {
262 <& hidden.html, field => 'old_'.$pre.$_, value => $object->get($_) &>
265 <& hidden.html, field => $pre.'cachenum', value => '' &>
266 <& hidden.html, field => $pre.'addr_clean', value => '' &>
268 <SCRIPT TYPE="text/javascript">
269 <&| /elements/onload.js &>
270 var clear_coords_ids = [
273 '<%$pre%>enter_censustract',
274 '<%$pre%>censustract',
277 function clear_coords() {
278 for (var i=0; i < clear_coords_ids.length; i++) {
279 var el = document.getElementById(clear_coords_ids[i]);
285 var clear_coords_on_change = [
293 for (var i=0; i < clear_coords_on_change.length; i++) {
294 var el = document.getElementById(clear_coords_on_change[i]);
295 if ( el.addEventListener ) {
296 el.addEventListener('change', clear_coords);
297 } else if ( el.attachEvent ) {
298 el.attachEvent('onchange', clear_coords);
301 function clear_censustract() {
302 // if the user manually edits the census tract, clear the 'hard' census
303 // tract field so that we can re-verify and present a confirmation popup
305 // get the ID of the hidden censustract field
306 var censustract_id = this.id.replace('enter_', '');
307 var el = document.getElementById(censustract_id);
312 var el = document.getElementById('<%$pre%>enter_censustract');
314 if ( el.addEventListener ) {
315 el.addEventListener('change', clear_censustract);
316 } else if ( el.attachEvent ) {
317 el.attachEvent('onchange', clear_censustract);
328 my $pre = $opt{'prefix'};
329 my $object = $opt{'object'};
330 my $onchange = $opt{'onchange'};
331 my $disabled = $opt{'disabled'};
333 my $r = $opt{'no_asterisks'} ? '' : qq!<font color="#ff0000">*</font> !;
335 my $conf = new FS::Conf;
336 my $countrydefault = $conf->config('countrydefault') || 'US';
337 my $statedefault = $conf->config('statedefault')
338 || ($countrydefault eq 'US' ? 'CA' : '');
339 my $label_prefix = $conf->config('cust_location-label_prefix');
341 $object ||= FS::cust_location->new({
342 'country' => $countrydefault,
343 'state' => $statedefault,
346 my $alt_err = ($opt{'alt_format'} && !$disabled) ? $object->alternize : '';
349 push @style, 'background-color: #dddddd' if $disabled;
351 my @address2_label_style = ();
352 push @address2_label_style, 'visibility:hidden'
354 || ! $conf->exists('cust_main-require_address2')
355 || ( !$pre && !$opt{'same_checked'} );
357 my @counties = counties( $object->get('state'),
358 $object->get('country'),
360 my @county_style = ();
361 push @county_style, 'display:none' # 'visibility:hidden'
362 unless scalar(@counties) > 1;
366 ? 'STYLE="'. join(';', @style). '"'
368 my $address2_label_style =
369 scalar(@address2_label_style)
370 ? 'STYLE="'. join(';', @address2_label_style). '"'
373 scalar(@county_style)
374 ? 'STYLE="'. join(';', @county_style). '"'
378 'city' => $object->get('city'),
379 'county' => $object->get('county'),
380 'state' => $object->get('state'),
381 'country' => $object->get('country'),
383 'onchange' => $onchange,
384 'disabled' => $disabled,
388 my $th = $opt{'no_bold'} ? 'TD' : 'TH';
390 my @location_kind_options = ( '', 'R', 'B' );
391 my $location_kind_labels = { '' => '', 'R' => 'Residential', 'B' => 'Business' };