qualification address handling changes, RT#7111
[freeside.git] / httemplate / elements / location.html
1 <%doc>
2
3 Example:
4
5   include( '/elements/location.html',
6              'object'         => $cust_main,  # or $cust_location
7              'prefix'         => $pre,        #only for cust_main objects
8              'onchange'       => $javascript,
9              'disabled'       => $disabled,
10              'same_checked'   => $same_checked,
11              'geocode'        => $geocode, #passed through
12              'censustract'    => $censustract, #passed through
13              'no_asterisks'   => 0, #set true to disable the red asterisks next
14                                     #to required fields
15              'address1_label' => 'Address', #label for address
16          )
17
18 </%doc>
19
20 % if ( $opt{'alt_format'} ) {
21
22 <TR>
23     <<%$th%> ALIGN="right">Location type</<%$th%>>
24     <TD>
25     <% include('/elements/select.html',
26                  'cgi'        => $cgi,
27                  'field'      => 'location_kind',
28                  'disabled'   => $disabled,
29                  'style'      => $style, 
30                  'options'    => \@location_kind_options,
31                  'labels'     => $location_kind_labels,
32                  'curr_value' => scalar($cgi->param('location_kind'))
33                                    || $object->get($pre.'location_kind'),
34               )
35     %>
36     </TD>
37   </TR>
38
39 % } 
40
41 <TR>
42   <<%$th%> ALIGN="right"><%$r%><% $opt{'address1_label'} || 'Address' %></<%$th%>>
43   <TD COLSPAN=7>
44     <INPUT TYPE     = "text"
45            NAME     = "<%$pre%>address1"
46            ID       = "<%$pre%>address1"
47            VALUE    = "<% $object->get($pre.'address1') |h %>"
48            SIZE     = 54
49            onChange = "<% $onchange %>"
50            <% $disabled %>
51            <% $style %>
52     >
53   </TD>
54 </TR>
55
56 % if ( ! $opt{'alt_format'} ) { #regular format
57
58 <TR>
59       <TD ALIGN="right"><FONT ID="<% $pre %>address2_required" color="#ff0000" <% $address2_label_style %>>*</FONT>&nbsp;<FONT ID="<% $pre %>address2_label" <% $address2_label_style %>><B>Unit&nbsp;#</B></FONT></TD>
60       <TD COLSPAN=7>
61         <INPUT TYPE     = "text"
62                NAME     = "<%$pre%>address2"
63                ID       = "<%$pre%>address2"
64                VALUE    = "<% $object->get($pre.'address2') |h %>"
65                SIZE     = 54
66                onChange = "<% $onchange %>"
67                <% $disabled %>
68                <% $style %>
69         >
70       </TD>
71 </TR>
72
73 % } else { # alternate format
74
75       <INPUT TYPE  = "hidden"
76              NAME  = "<%$pre%>address2"
77              VALUE = "<% $object->get($pre.'address2') |h %>"
78       >
79
80 <TR>
81     <<%$th%> ALIGN="right">Unit Type and #</<%$th%>>
82     <TD COLSPAN=7>
83
84 %     my $location_type = scalar($cgi->param('location_type'))
85 %                           || $object->get($pre.'location_type');
86 %     #my $location_number = scalar($cgi->param('location_number'))
87 %     #                        || $object->get($pre.'location_number');
88 %
89 %   if ( $object->get($pre.'address2') && ! $location_type ) {
90 %   }
91 %
92 %     if ( 1 ) { #ikano, switch on via config
93 %       tie my %location_types, 'Tie::IxHash',
94 %         FS::part_export::ikano->location_types;
95         <% include('/elements/select.html',
96                      'cgi'        => $cgi,
97                      'field'      => 'location_type',
98                      'disabled'   => $disabled,
99                      'style'      => $style,
100                      'options'    => [ keys %location_types ],
101                      'labels'     => \%location_types,
102                      'curr_value' => $location_type,
103                      'onchange'   => 'location_type_changed',
104                   )
105         %>
106         <SCRIPT TYPE="text/javascript">
107           function location_type_changed (what) {
108             if ( what.options[what.selectedIndex].value == '' ) {
109               what.form.location_number.disabled = true;
110               what.form.location_number.style.backgroundColor = '#dddddd';
111             } else {
112               what.form.location_number.disabled = false;
113               what.form.location_number.style.backgroundColor = '#ffffff';
114             }
115           }
116         </SCRIPT>
117 %     } else {
118         <INPUT TYPE  = "text" 
119                NAME  = "location_type" 
120                ID    = "location_type"
121                VALUE = "<% $location_type |h %>"
122                SIZE  = "10"
123                <% $disabled %>
124                <% $style %>
125         >
126 %     }
127
128     <INPUT TYPE="text" 
129                NAME="location_number"
130                ID="location_number"
131                VALUE="<% scalar($cgi->param('location_number')) || $object->get($pre.'location_number') |h %>"
132                SIZE="5"
133                <% $disabled || ($location_type ? '' : 'DISABLED') %>
134                <% $style %>
135         >
136
137 %   if ( $object->get($pre.'address2') ) {
138
139 %     #XXX try to parse first
140 %     if ( 0 ) {
141 %     } else {
142         Can't parse unit type and number from <B><% $object->get($pre.'address2') |h %></B>
143 %    }
144
145 % }
146
147     </TD>
148
149 </TR>
150
151 % } 
152
153
154 <TR>
155   <<%$th%> ALIGN="right"><%$r%>City</<%$th%>>
156   <TD WIDTH="1"><% include('/elements/city.html', %select_hash) %></TD>
157   <<%$th%> ALIGN="right" ID="<%$pre%>countylabel" <%$county_style%>><%$r%>County</<%$th%>>
158   <TD><% include('/elements/select-county.html', %select_hash ) %></TD>
159   <<%$th%> ALIGN="right" WIDTH="1"><%$r%>State</<%$th%>>
160   <TD WIDTH="1">
161     <% include('/elements/select-state.html', %select_hash ) %>
162   </TD>
163   <<%$th%>><%$r%>Zip</<%$th%>>
164   <TD>
165     <INPUT TYPE     = "text"
166            NAME     = "<%$pre%>zip"
167            ID       = "<%$pre%>zip"
168            VALUE    = "<% $object->get($pre.'zip') |h %>"
169            SIZE     = 10
170            onChange = "<% $onchange %>"
171            <% $disabled %>
172            <% $style %>
173     >
174   </TD>
175 </TR>
176
177 <TR>
178   <<%$th%> ALIGN="right"><%$r%>Country</<%$th%>>
179   <TD COLSPAN=6><% include('/elements/select-country.html', %select_hash ) %></TD>
180 </TR>
181
182 % if ( !$pre ) { 
183   <INPUT TYPE="hidden" NAME="geocode" VALUE="<% $opt{geocode} %>">
184 % } else {
185 %   if ( $pre eq 'ship_' && $conf->exists('cust_main-require_censustract') ) {
186       <TR><<%$th%> ALIGN="right">Census tract<BR>(automatic)</<%$th%>>
187         <TD>
188           <INPUT TYPE="text" NAME="censustract" VALUE="<% $opt{censustract} %>">
189         </TD>
190       </TR>
191 %   } else {
192       <INPUT TYPE="hidden" NAME="censustract" VALUE="<% $opt{censustract} %>">
193 %   } 
194 % } 
195
196 <%init>
197
198 my %opt = @_;
199
200 my $pre      = $opt{'prefix'};
201 my $object   = $opt{'object'};
202 my $onchange = $opt{'onchange'};
203 my $disabled = $opt{'disabled'};
204
205 my $conf = new FS::Conf;
206
207 my $r = $opt{'no_asterisks'} ? '' : qq!<font color="#ff0000">*</font>&nbsp;!;
208
209 #false laziness with ship state
210 my $countrydefault = $conf->config('countrydefault') || 'US';
211 $object->set($pre.'country', $countrydefault )
212   unless $object->get($pre.'country');
213
214 my $statedefault = $conf->config('statedefault')
215                    || ($countrydefault eq 'US' ? 'CA' : '');
216 $object->set($pre.'state', $statedefault )
217   unless $object->get($pre.'state')
218          || $object->get($pre.'country') ne $countrydefault;
219
220 my @style = ();
221 push @style, 'background-color: #dddddd' if $disabled;
222
223 my @address2_label_style = ();
224 push @address2_label_style, 'visibility:hidden'
225   if $disabled
226   || ! $conf->exists('cust_main-require_address2')
227   || ( !$pre && !$opt{'same_checked'} );
228
229 my @counties = counties( $object->get($pre.'state'),
230                          $object->get($pre.'country'),
231                        );
232 my @county_style = ();
233 push @county_style, 'display:none' # 'visibility:hidden'
234   unless scalar(@counties) > 1;
235
236 my $style =
237   scalar(@style)
238     ? 'STYLE="'. join(';', @style). '"'
239     : '';
240 my $address2_label_style =
241   scalar(@address2_label_style)
242     ? 'STYLE="'. join(';', @address2_label_style). '"'
243     : '';
244 my $county_style = 
245   scalar(@county_style)
246     ? 'STYLE="'. join(';', @county_style). '"'
247     : '';
248
249 my %select_hash = (
250   'city'     => $object->get($pre.'city'),
251   'county'   => $object->get($pre.'county'),
252   'state'    => $object->get($pre.'state'),
253   'country'  => $object->get($pre.'country'),
254   'prefix'   => $pre,
255   'onchange' => $onchange,
256   'disabled' => $disabled,
257   'style'    => \@style,
258 );
259
260 my $th = $opt{'no_bold'} ? 'TD' : 'TH';
261
262 my @location_kind_options = ( '', 'R', 'B' );
263 my $location_kind_labels = { '' => '', 'R' => 'Residential', 'B' => 'Business' };
264
265 </%init>