international self-service payments, RT#1592
[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     = 54
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     = 54
42            onChange = "<% $onchange %>"
43            <% $disabled %>
44            <% $style %>
45     >
46   </TD>
47 </TR>
48
49 <TR>
50   <TH ALIGN="right"><%$r%>City</TH>
51   <TD WIDTH="1">
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><% include('/elements/select-county.html', %select_hash ) %></TD>
63   <TH ALIGN="right" WIDTH="1"><%$r%>State</TH>
64   <TD WIDTH="1">
65     <% include('/elements/select-state.html', %select_hash ) %>
66   </TD>
67   <TH><%$r%>Zip</TH>
68   <TD>
69     <INPUT TYPE     = "text"
70            NAME     = "<%$pre%>zip"
71            ID       = "<%$pre%>zip"
72            VALUE    = "<% $object->get($pre.'zip') |h %>"
73            SIZE     = 10
74            onChange = "<% $onchange %>"
75            <% $disabled %>
76            <% $style %>
77     >
78   </TD>
79 </TR>
80
81 <TR>
82   <TH ALIGN="right"><%$r%>Country</TH>
83   <TD COLSPAN=6><% include('/elements/select-country.html', %select_hash ) %></TD>
84 </TR>
85
86 % if ( !$pre ) { 
87   <INPUT TYPE="hidden" NAME="geocode" VALUE="<% $opt{geocode} %>">
88 % } 
89
90 <%init>
91
92 my %opt = @_;
93
94 my $pre      = $opt{'prefix'};
95 my $object   = $opt{'object'};
96 my $onchange = $opt{'onchange'};
97 my $disabled = $opt{'disabled'};
98
99 my $conf = new FS::Conf;
100
101 my $r = $opt{'no_asterisks'} ? '' : qq!<font color="#ff0000">*</font>&nbsp;!;
102
103 #false laziness with ship state
104 my $countrydefault = $conf->config('countrydefault') || 'US';
105 $object->set($pre.'country', $countrydefault )
106   unless $object->get($pre.'country');
107
108 my $statedefault = $conf->config('statedefault')
109                    || ($countrydefault eq 'US' ? 'CA' : '');
110 $object->set($pre.'state', $statedefault )
111   unless $object->get($pre.'state')
112          || $object->get($pre.'country') ne $countrydefault;
113
114 my @style = ();
115 push @style, 'background-color: #dddddd"' if $disabled;
116
117 my @address2_label_style = ();
118 push @address2_label_style, 'visibility:hidden'
119   if $disabled
120   || ! $conf->exists('cust_main-require_address2')
121   || ( !$pre && !$opt{'same_checked'} );
122
123 my @counties = counties( $object->get($pre.'state'),
124                          $object->get($pre.'country'),
125                        );
126 my @county_style = ();
127 push @county_style, 'display:none' # 'visibility:hidden'
128   unless scalar(@counties) > 1;
129
130 my $style =
131   scalar(@style)
132     ? 'STYLE="'. join(';', @style). '"'
133     : '';
134 my $address2_label_style =
135   scalar(@address2_label_style)
136     ? 'STYLE="'. join(';', @address2_label_style). '"'
137     : '';
138 my $county_style = 
139   scalar(@county_style)
140     ? 'STYLE="'. join(';', @county_style). '"'
141     : '';
142
143 my %select_hash = (
144   'county'   => $object->get($pre.'county'),
145   'state'    => $object->get($pre.'state'),
146   'country'  => $object->get($pre.'country'),
147   'prefix'   => $pre,
148   'onchange' => $onchange,
149   'disabled' => $disabled,
150   'style'    => \@style,
151 );
152
153 </%init>