implement package changes w/location change, RT#4499
[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              'no_asterisks' => 0, #set true to disable the red asterisks next
13                                   #to required fields
14          )
15
16 </%doc>
17
18 <TR>
19   <TH ALIGN="right"><%$r%>Address</TH>
20   <TD COLSPAN=7>
21     <INPUT TYPE     = "text"
22            NAME     = "<%$pre%>address1"
23            ID       = "<%$pre%>address1"
24            VALUE    = "<% $object->get($pre.'address1') |h %>"
25            SIZE     = 58
26            onChange = "<% $onchange %>"
27            <% $disabled %>
28            <% $style %>
29     >
30   </TD>
31 </TR>
32
33 <TR>
34   <TD ALIGN="right"><FONT ID="<% $pre %>address2_required" color="#ff0000" STYLE="<% $address2_label_style %>">*</FONT>&nbsp;<FONT ID="<% $pre %>address2_label" STYLE="<% $address2_label_style %>"><B>Unit&nbsp;#</B></FONT></TD>
35   <TD COLSPAN=7>
36     <INPUT TYPE     = "text"
37            NAME     = "<%$pre%>address2"
38            ID       = "<%$pre%>address2"
39            VALUE    = "<% $object->get($pre.'address2') |h %>"
40            SIZE     = 58
41            onChange = "<% $onchange %>"
42            <% $disabled %>
43            <% $style %>
44     >
45   </TD>
46 </TR>
47
48 <TR>
49   <TH ALIGN="right"><%$r%>City</TH>
50   <TD>
51     <INPUT TYPE     = "text"
52            NAME     = "<%$pre%>city"
53            ID       = "<%$pre%>city"
54            VALUE    = "<% $object->get($pre.'city') |h %>"
55            onChange = "<% $onchange %>"
56            <% $disabled %>
57            <% $style %>
58     >
59  </TD>
60   <TH ALIGN="right" ID="<%$pre%>countylabel" <%$county_style%>><%$r%>County</TH>
61   <TD>
62     <% include('/elements/select-county.html', %select_hash ) %>
63   </TD>
64   <TH ALIGN="right"><%$r%>State</TH>
65   <TD>
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=5><% include('/elements/select-country.html', %select_hash ) %></TD>
85 </TR>
86
87 % if ( !$pre ) { 
88   <INPUT TYPE="hidden" NAME="geocode" VALUE="<% $opt{geocode} %>">
89 % } 
90
91 <%init>
92
93 my %opt = @_;
94
95 my $pre      = $opt{'prefix'};
96 my $object   = $opt{'object'};
97 my $onchange = $opt{'onchange'};
98 my $disabled = $opt{'disabled'};
99
100 my $conf = new FS::Conf;
101
102 my $r = $opt{'no_asterisks'} ? '' : qq!<font color="#ff0000">*</font>&nbsp;!;
103
104 #false laziness with ship state
105 my $countrydefault = $conf->config('countrydefault') || 'US';
106 $object->set($pre.'country', $countrydefault )
107   unless $object->get($pre.'country');
108
109 my $statedefault = $conf->config('statedefault')
110                    || ($countrydefault eq 'US' ? 'CA' : '');
111 $object->set($pre.'state', $statedefault )
112   unless $object->get($pre.'state')
113          || $object->get($pre.'country') ne $countrydefault;
114
115 my @style = ();
116 push @style, 'background-color: #dddddd"' if $disabled;
117
118 my @address2_label_style = ();
119 push @address2_label_style, 'visibility:hidden'
120   if $disabled
121   || ! $conf->exists('cust_main-require_address2')
122   || ( !$pre && !$opt{'same_checked'} );
123
124 my @counties = counties( $object->get($pre.'state'),
125                          $object->get($pre.'country'),
126                        );
127 my @county_style = ();
128 push @county_style, 'visibility:hidden'
129   unless scalar(@counties) > 1;
130
131 my $style =
132   scalar(@style)
133     ? 'STYLE="'. join(';', @style). '"'
134     : '';
135 my $address2_label_style =
136   scalar(@address2_label_style)
137     ? 'STYLE="'. join(';', @address2_label_style). '"'
138     : '';
139 my $county_style = 
140   scalar(@county_style)
141     ? 'STYLE="'. join(';', @county_style). '"'
142     : '';
143
144 my %select_hash = (
145   'county'   => $object->get($pre.'county'),
146   'state'    => $object->get($pre.'state'),
147   'country'  => $object->get($pre.'country'),
148   'prefix'   => $pre,
149   'onchange' => $onchange,
150   'disabled' => $disabled,
151   'style'    => \@style,
152 );
153
154 </%init>