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