allow country selection on credit card entry, RT#4997
[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              'address1_label' => 'Address', #label for address
15          )
16
17 </%doc>
18
19 <TR>
20   <TH ALIGN="right"><%$r%><% $opt{'address1_label'} || 'Address' %></TH>
21   <TD COLSPAN=7>
22     <INPUT TYPE     = "text"
23            NAME     = "<%$pre%>address1"
24            ID       = "<%$pre%>address1"
25            VALUE    = "<% $object->get($pre.'address1') |h %>"
26            SIZE     = 58
27            onChange = "<% $onchange %>"
28            <% $disabled %>
29            <% $style %>
30     >
31   </TD>
32 </TR>
33
34 <TR>
35   <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>
36   <TD COLSPAN=7>
37     <INPUT TYPE     = "text"
38            NAME     = "<%$pre%>address2"
39            ID       = "<%$pre%>address2"
40            VALUE    = "<% $object->get($pre.'address2') |h %>"
41            SIZE     = 58
42            onChange = "<% $onchange %>"
43            <% $disabled %>
44            <% $style %>
45     >
46   </TD>
47 </TR>
48
49 <TR>
50   <TH ALIGN="right"><%$r%>City</TH>
51   <TD>
52     <INPUT TYPE     = "text"
53            NAME     = "<%$pre%>city"
54            ID       = "<%$pre%>city"
55            VALUE    = "<% $object->get($pre.'city') |h %>"
56            onChange = "<% $onchange %>"
57            <% $disabled %>
58            <% $style %>
59     >
60  </TD>
61   <TH ALIGN="right" ID="<%$pre%>countylabel" <%$county_style%>><%$r%>County</TH>
62   <TD>
63     <% include('/elements/select-county.html', %select_hash ) %>
64   </TD>
65   <TH ALIGN="right"><%$r%>State</TH>
66   <TD>
67     <% include('/elements/select-state.html', %select_hash ) %>
68   </TD>
69   <TH><%$r%>Zip</TH>
70   <TD>
71     <INPUT TYPE     = "text"
72            NAME     = "<%$pre%>zip"
73            ID       = "<%$pre%>zip"
74            VALUE    = "<% $object->get($pre.'zip') |h %>"
75            SIZE     = 10
76            onChange = "<% $onchange %>"
77            <% $disabled %>
78            <% $style %>
79     >
80   </TD>
81 </TR>
82
83 <TR>
84   <TH ALIGN="right"><%$r%>Country</TH>
85   <TD COLSPAN=5><% include('/elements/select-country.html', %select_hash ) %></TD>
86 </TR>
87
88 % if ( !$pre ) { 
89   <INPUT TYPE="hidden" NAME="geocode" VALUE="<% $opt{geocode} %>">
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, '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   'county'   => $object->get($pre.'county'),
147   'state'    => $object->get($pre.'state'),
148   'country'  => $object->get($pre.'country'),
149   'prefix'   => $pre,
150   'onchange' => $onchange,
151   'disabled' => $disabled,
152   'style'    => \@style,
153 );
154
155 </%init>