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