add location to svc_phone, RT#7047
[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 <TR>
21   <<%$th%> ALIGN="right"><%$r%><% $opt{'address1_label'} || 'Address' %></<%$th%>>
22   <TD COLSPAN=7>
23     <INPUT TYPE     = "text"
24            NAME     = "<%$pre%>address1"
25            ID       = "<%$pre%>address1"
26            VALUE    = "<% $object->get($pre.'address1') |h %>"
27            SIZE     = 54
28            onChange = "<% $onchange %>"
29            <% $disabled %>
30            <% $style %>
31     >
32   </TD>
33 </TR>
34
35 <TR>
36   <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>
37   <TD COLSPAN=7>
38     <INPUT TYPE     = "text"
39            NAME     = "<%$pre%>address2"
40            ID       = "<%$pre%>address2"
41            VALUE    = "<% $object->get($pre.'address2') |h %>"
42            SIZE     = 54
43            onChange = "<% $onchange %>"
44            <% $disabled %>
45            <% $style %>
46     >
47   </TD>
48 </TR>
49
50 <TR>
51   <<%$th%> ALIGN="right"><%$r%>City</<%$th%>>
52   <TD WIDTH="1"><% include('/elements/city.html', %select_hash) %></TD>
53   <<%$th%> ALIGN="right" ID="<%$pre%>countylabel" <%$county_style%>><%$r%>County</<%$th%>>
54   <TD><% include('/elements/select-county.html', %select_hash ) %></TD>
55   <<%$th%> ALIGN="right" WIDTH="1"><%$r%>State</<%$th%>>
56   <TD WIDTH="1">
57     <% include('/elements/select-state.html', %select_hash ) %>
58   </TD>
59   <<%$th%>><%$r%>Zip</<%$th%>>
60   <TD>
61     <INPUT TYPE     = "text"
62            NAME     = "<%$pre%>zip"
63            ID       = "<%$pre%>zip"
64            VALUE    = "<% $object->get($pre.'zip') |h %>"
65            SIZE     = 10
66            onChange = "<% $onchange %>"
67            <% $disabled %>
68            <% $style %>
69     >
70   </TD>
71 </TR>
72
73 <TR>
74   <<%$th%> ALIGN="right"><%$r%>Country</<%$th%>>
75   <TD COLSPAN=6><% include('/elements/select-country.html', %select_hash ) %></TD>
76 </TR>
77
78 % if ( !$pre ) { 
79   <INPUT TYPE="hidden" NAME="geocode" VALUE="<% $opt{geocode} %>">
80 % } else {
81 %   if ( $pre eq 'ship_' && $conf->exists('cust_main-require_censustract') ) {
82       <TR><<%$th%> ALIGN="right">Census tract<BR>(automatic)</<%$th%>>
83         <TD>
84           <INPUT TYPE="text" NAME="censustract" VALUE="<% $opt{censustract} %>">
85         </TD>
86       </TR>
87 %   } else {
88       <INPUT TYPE="hidden" NAME="censustract" VALUE="<% $opt{censustract} %>">
89 %   } 
90 % } 
91
92 <%init>
93
94 my %opt = @_;
95
96 my $pre      = $opt{'prefix'};
97 my $object   = $opt{'object'};
98 my $onchange = $opt{'onchange'};
99 my $disabled = $opt{'disabled'};
100
101 my $conf = new FS::Conf;
102
103 my $r = $opt{'no_asterisks'} ? '' : qq!<font color="#ff0000">*</font>&nbsp;!;
104
105 #false laziness with ship state
106 my $countrydefault = $conf->config('countrydefault') || 'US';
107 $object->set($pre.'country', $countrydefault )
108   unless $object->get($pre.'country');
109
110 my $statedefault = $conf->config('statedefault')
111                    || ($countrydefault eq 'US' ? 'CA' : '');
112 $object->set($pre.'state', $statedefault )
113   unless $object->get($pre.'state')
114          || $object->get($pre.'country') ne $countrydefault;
115
116 my @style = ();
117 push @style, 'background-color: #dddddd' if $disabled;
118
119 my @address2_label_style = ();
120 push @address2_label_style, 'visibility:hidden'
121   if $disabled
122   || ! $conf->exists('cust_main-require_address2')
123   || ( !$pre && !$opt{'same_checked'} );
124
125 my @counties = counties( $object->get($pre.'state'),
126                          $object->get($pre.'country'),
127                        );
128 my @county_style = ();
129 push @county_style, 'display:none' # 'visibility:hidden'
130   unless scalar(@counties) > 1;
131
132 my $style =
133   scalar(@style)
134     ? 'STYLE="'. join(';', @style). '"'
135     : '';
136 my $address2_label_style =
137   scalar(@address2_label_style)
138     ? 'STYLE="'. join(';', @address2_label_style). '"'
139     : '';
140 my $county_style = 
141   scalar(@county_style)
142     ? 'STYLE="'. join(';', @county_style). '"'
143     : '';
144
145 my %select_hash = (
146   'city'     => $object->get($pre.'city'),
147   'county'   => $object->get($pre.'county'),
148   'state'    => $object->get($pre.'state'),
149   'country'  => $object->get($pre.'country'),
150   'prefix'   => $pre,
151   'onchange' => $onchange,
152   'disabled' => $disabled,
153   'style'    => \@style,
154 );
155
156 my $th = $opt{'no_bold'} ? 'TD' : 'TH';
157
158 </%init>