5 include( '/elements/select-country.html',
7 country => $current_country,
10 prefix => $optional_unique_prefix,
11 onchange => $javascript,
13 disable_empty => 1, #defaults to 1, disable the empty option
14 empty_label => 'all', #label for empty option
15 disable_stateupdate => 0, #bool - disabled update of the select-state.html
16 style => [ 'attribute:value', 'another:value' ],
20 % unless ( $opt{'disable_stateupdate'} ) {
22 <% include('/elements/xmlhttp.html',
23 'url' => $p.'misc/states.cgi',
24 'subs' => [ $pre. 'get_states' ],
28 <SCRIPT TYPE="text/javascript">
30 function opt(what,value,text) {
31 var optionName = new Option(text, value, false, false);
32 var length = what.length;
33 what.options[length] = optionName;
36 function <% $pre %>country_changed(what, callback) {
38 country = what.options[what.selectedIndex].value;
40 function <% $pre %>update_states(states) {
42 // blank the current state list
43 for ( var i = what.form.<% $pre %>state.length; i >= 0; i-- )
44 what.form.<% $pre %>state.options[i] = null;
47 var statesArray = eval('(' + states + ')' );
48 for ( var s = 0; s < statesArray.length; s=s+2 ) {
49 var stateLabel = statesArray[s+1];
50 if ( stateLabel == "" )
52 opt(what.form.<% $pre %>state, statesArray[s], stateLabel);
56 if ( callback != null ) {
59 <% $pre %>state_changed(what.form.<% $pre %>state);
63 // go get the new states
64 <% $pre %>get_states( country, <% $pre %>update_states );
72 <SELECT NAME = "<% $pre %>country"
73 ID = "<% $pre %>country"
74 onChange = "<% $onchange %>"
75 <% $opt{'disabled'} %>
79 % unless ( $opt{'disable_empty'} ) {
80 <OPTION VALUE=""><% $opt{'empty_label'} || '(all)' %>
83 % foreach my $country ( @all_countries ) {
85 <OPTION VALUE="<% $country |h %>"
86 <% $country eq $opt{'country'} ? ' SELECTED' : '' %>
87 ><% code2country($country). " ($country)" %>
96 foreach my $opt (qw( country prefix onchange disabled disable_stateupdate )) {
97 $opt{$opt} = '' unless exists($opt{$opt}) && defined($opt{$opt});
100 $opt{'disable_empty'} = 1 unless exists($opt{'disable_empty'});
102 my $pre = $opt{'prefix'};
105 ( $opt{'disable_stateupdate'} ? '' : $pre.'country_changed(this); ' ).
108 $opt{'style'} ||= [];
110 scalar(@{$opt{style}})
111 ? 'STYLE="'. join(';', @{$opt{style}}). '"'
114 my $conf = new FS::Conf;
115 my $default = $conf->config('countrydefault') || 'US';
117 my @all_countries = (
118 sort { ($b eq $default) <=> ($a eq $default)
119 or code2country($a) cmp code2country($b)
123 'select' => 'country',
124 'table' => 'cust_main_county',
126 'extra_sql' => 'GROUP BY country',