merging RT 4.0.6
[freeside.git] / httemplate / elements / location.html
1 <%doc>
2
3 Example:
4
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
12                                     #to required fields
13              'address1_label' => 'Address', #label for address
14              'enable_district' => 1, #show tax district field
15              'enable_censustract' => 1, #show censustract field
16          )
17
18 </%doc>
19
20 % if ( $opt{'alt_format'} ) {
21
22 <TR>
23     <<%$th%> ALIGN="right">Location&nbsp;kind</<%$th%>>
24     <TD>
25     <% include('/elements/select.html',
26                  'cgi'        => $cgi,
27                  'field'      => 'location_kind',
28                  'id'         => 'location_kind',
29                  'disabled'   => $disabled,
30                  #'style'      => \@style,
31                  'options'    => \@location_kind_options,
32                  'labels'     => $location_kind_labels,
33                  'curr_value' => scalar($cgi->param('location_kind'))
34                                    || $object->get($pre.'location_kind'),
35               )
36     %>
37     </TD>
38   </TR>
39
40 % } 
41
42 <TR>
43   <<%$th%> STYLE="width:16ex" ALIGN="right"><%$r%><% $opt{'address1_label'} || emt('Address') %></<%$th%>>
44   <TD COLSPAN=7>
45     <INPUT TYPE     = "text"
46            NAME     = "<%$pre%>address1"
47            ID       = "<%$pre%>address1"
48            VALUE    = "<% $object->get('address1') |h %>"
49            SIZE     = 54
50            onChange = "<% $onchange %>"
51            <% $disabled %>
52            <% $style %>
53     >
54   </TD>
55 </TR>
56
57 % if ( ! $opt{'alt_format'} ) { #regular format
58
59 <TR>
60       <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>
61       <TD COLSPAN=7>
62         <INPUT TYPE     = "text"
63                NAME     = "<%$pre%>address2"
64                ID       = "<%$pre%>address2"
65                VALUE    = "<% $object->get('address2') |h %>"
66                SIZE     = 54
67                onChange = "<% $onchange %>"
68                <% $disabled %>
69                <% $style %>
70         >
71       </TD>
72 </TR>
73
74 % } else { # alternate format
75
76       <INPUT TYPE  = "hidden"
77              NAME  = "<%$pre%>address2"
78              VALUE = "<% $object->get('address2') |h %>"
79       >
80
81 <TR>
82     <<%$th%> ALIGN="right">Unit&nbsp;type&nbsp;and&nbsp;#</<%$th%>>
83     <TD COLSPAN=7>
84
85 %     my $location_type = scalar($cgi->param('location_type'))
86 %                           || $object->get('location_type');
87 %     #my $location_number = scalar($cgi->param('location_number'))
88 %     #                        || $object->get($pre.'location_number');
89 %
90 %   if ( $object->get($pre.'address2') && ! $location_type ) {
91 %   }
92 %
93 %     if ( 1 ) { #ikano, switch on via config
94 %       tie my %location_types, 'Tie::IxHash',
95 %         FS::part_export::ikano->location_types;
96         <% include('/elements/select.html',
97                      'cgi'        => $cgi,
98                      'field'      => 'location_type',
99                      'id'         => 'location_type',
100                      'disabled'   => $disabled,
101                      #'style'      => \@style,
102                      'options'    => [ keys %location_types ],
103                      'labels'     => \%location_types,
104                      'curr_value' => $location_type,
105                      'onchange'   => 'location_type_changed',
106                   )
107         %>
108         <SCRIPT TYPE="text/javascript">
109           function location_type_changed (what) {
110             if ( what.options[what.selectedIndex].value == '' ) {
111               what.form.location_number.disabled = true;
112               what.form.location_number.style.backgroundColor = '#dddddd';
113             } else {
114               what.form.location_number.disabled = false;
115               what.form.location_number.style.backgroundColor = '#ffffff';
116             }
117           }
118         </SCRIPT>
119 %     } else {
120         <INPUT TYPE  = "text" 
121                NAME  = "location_type" 
122                ID    = "location_type"
123                VALUE = "<% $location_type |h %>"
124                SIZE  = "10"
125                <% $disabled %>
126                <% $style %>
127         >
128 %     }
129
130     <INPUT TYPE="text" 
131                NAME  = "location_number"
132                ID    = "location_number"
133                VALUE = "<% scalar($cgi->param('location_number')) || $object->get('location_number') |h %>"
134                SIZE  = "5"
135                <% $disabled || ($location_type ? '' : 'DISABLED') %>
136                <% $style %>
137         >
138
139 %    #XXX i don't work so well when the dropdown is changed :/  i probably need to be triggered by "default service address"
140 %    $alt_err =~ s/(ship_)?address2/'<B>'.encode_entities($object->get($1.'address2')).'<\/B>'/e;
141      <% $alt_err %>
142
143     </TD>
144
145 </TR>
146
147 % } 
148
149
150 <TR>
151   <<%$th%> ALIGN="right"><%$r%><% mt('City') |h %></<%$th%>>
152   <TD WIDTH="1"><% include('/elements/city.html', %select_hash, 'text_style' => \@style ) %></TD>
153   <<%$th%> ALIGN="right" WIDTH="1" ID="<%$pre%>countylabel" <%$county_style%>><%$r%>County</<%$th%>>
154   <TD WIDTH="1"><% include('/elements/select-county.html', %select_hash ) %></TD>
155   <<%$th%> ALIGN="right" WIDTH="1"><%$r%><% mt('State') |h %></<%$th%>>
156   <TD WIDTH="1">
157     <% include('/elements/select-state.html', %select_hash ) %>
158   </TD>
159   <<%$th%> ALIGN="right" WIDTH="1"><%$r%><% mt('Zip') |h %></<%$th%>>
160   <TD>
161     <INPUT TYPE     = "text"
162            NAME     = "<%$pre%>zip"
163            ID       = "<%$pre%>zip"
164            VALUE    = "<% $object->get('zip') |h %>"
165            SIZE     = 10
166            onChange = "<% $onchange %>"
167            <% $disabled %>
168            <% $style %>
169     >
170   </TD>
171 </TR>
172
173 <TR>
174   <<%$th%> ALIGN="right"><%$r%><% mt('Country') |h %></<%$th%>>
175   <TD COLSPAN=6><% include('/elements/select-country.html', %select_hash ) %></TD>
176 </TR>
177
178 <TR>
179   <TD ALIGN="right"><% mt('Latitude') |h %></TH>
180   <TD COLSPAN=7>
181     <INPUT TYPE  = "text"
182            NAME  = "<%$pre%>latitude"
183            ID    = "<%$pre%>latitude"
184            VALUE = "<% $object->get('latitude') |h %>"
185            <% $disabled %>
186            <% $style %>
187     >
188     <% mt('Longitude') |h %>
189     <INPUT TYPE  = "text"
190            NAME  = "<%$pre%>longitude"
191            ID    = "<%$pre%>longitude"
192            VALUE = "<% $object->get('longitude') |h %>"
193            <% $disabled %>
194            <% $style %>
195     >
196   </TD>
197 </TR>
198 <INPUT TYPE="hidden" NAME="<%$pre%>coord_auto" VALUE="<% $object->coord_auto %>">
199
200 <INPUT TYPE="hidden" NAME="<%$pre%>geocode" VALUE="<% $object->geocode %>">
201 <INPUT TYPE="hidden" NAME="<%$pre%>censusyear" VALUE="<% $object->censusyear %>">
202 <TR>
203 % if ( $opt{enable_censustract} ) {
204   <TD ALIGN="right">Census&nbsp;tract</TD>
205   <TD COLSPAN=8>
206     <INPUT TYPE="text" SIZE=15
207            NAME="<%$pre%>censustract" 
208            VALUE="<% $object->censustract %>">
209     <% '(automatic)' %>
210   </TD>
211 % } else {
212   <INPUT TYPE="hidden" NAME="<%$pre%>censustract" VALUE="<% $object->censustract %>">
213 % } 
214 </TR>
215 % if ( $conf->config('tax_district_method') ) {
216   <TR>
217 %   if ( $opt{enable_district} ) {
218     <TD ALIGN="right">Tax&nbsp;district</TD>
219     <TD COLSPAN=8>
220       <INPUT TYPE="text" SIZE=15
221              NAME="<%$pre%>district" 
222              VALUE="<% $object->district %>">
223     <% '(automatic)' %>
224     </TD>
225 %   } else {
226     <INPUT TYPE="hidden" NAME="<%$pre%>district" VALUE="<% $object->district %>">
227 %   }
228   </TR>
229 % }
230
231 <%init>
232
233 my %opt = @_;
234
235 my $pre      = $opt{'prefix'};
236 my $object   = $opt{'object'};
237 my $onchange = $opt{'onchange'};
238 my $disabled = $opt{'disabled'};
239
240 my $conf = new FS::Conf;
241
242 my $r = $opt{'no_asterisks'} ? '' : qq!<font color="#ff0000">*</font>&nbsp;!;
243
244 my $countrydefault = $conf->config('countrydefault') || 'US';
245 my $statedefault = $conf->config('statedefault') 
246                    || ($countrydefault eq 'US' ? 'CA' : '');
247 $object ||= FS::cust_location->new({
248   'country' => $countrydefault,
249   'state'   => $statedefault,
250 });
251
252 my $alt_err = ($opt{'alt_format'} && !$disabled) ? $object->alternize : '';
253
254 my @style = ();
255 push @style, 'background-color: #dddddd' if $disabled;
256
257 my @address2_label_style = ();
258 push @address2_label_style, 'visibility:hidden'
259   if $disabled
260   || ! $conf->exists('cust_main-require_address2')
261   || ( !$pre && !$opt{'same_checked'} );
262
263 my @counties = counties( $object->get('state'),
264                          $object->get('country'),
265                        );
266 my @county_style = ();
267 push @county_style, 'display:none' # 'visibility:hidden'
268   unless scalar(@counties) > 1;
269
270 my $style =
271   scalar(@style)
272     ? 'STYLE="'. join(';', @style). '"'
273     : '';
274 my $address2_label_style =
275   scalar(@address2_label_style)
276     ? 'STYLE="'. join(';', @address2_label_style). '"'
277     : '';
278 my $county_style = 
279   scalar(@county_style)
280     ? 'STYLE="'. join(';', @county_style). '"'
281     : '';
282
283 my %select_hash = (
284   'city'     => $object->get('city'),
285   'county'   => $object->get('county'),
286   'state'    => $object->get('state'),
287   'country'  => $object->get('country'),
288   'prefix'   => $pre,
289   'onchange' => $onchange,
290   'disabled' => $disabled,
291   #'style'    => \@style,
292 );
293
294 my $th = $opt{'no_bold'} ? 'TD' : 'TH';
295
296 my @location_kind_options = ( '', 'R', 'B' );
297 my $location_kind_labels = { '' => '', 'R' => 'Residential', 'B' => 'Business' };
298
299 </%init>