fix "texas tax" in 1.9
[freeside.git] / httemplate / edit / cust_main / select-county.html
1 % if ( $countyflag ) { 
2
3   <% include('/elements/xmlhttp.html',
4                 'url'  => $p.'misc/counties.cgi',
5                 'subs' => [ $opt{'prefix'}. 'get_counties' ],
6              )
7   %>
8   
9   <SCRIPT TYPE="text/javascript">
10   
11     function opt(what,value,text) {
12       var optionName = new Option(text, value, false, false);
13       var length = what.length;
14       what.options[length] = optionName;
15     }
16   
17     function <% $opt{'prefix'} %>state_changed(what, callback) {
18
19       state = what.options[what.selectedIndex].value;
20       country = what.form.<% $opt{'prefix'} %>country.options[what.form.<% $opt{'prefix'} %>country.selectedIndex].value;
21   
22       function <% $opt{'prefix'} %>update_counties(counties) {
23
24         // blank the current county list
25         for ( var i = what.form.<% $opt{'prefix'} %>county.length; i >= 0; i-- )
26             what.form.<% $opt{'prefix'} %>county.options[i] = null;
27   
28         // add the new counties
29         var countiesArray = eval('(' + counties + ')' );
30         for ( var s = 0; s < countiesArray.length; s++ ) {
31             var countyLabel = countiesArray[s];
32             if ( countyLabel == "" )
33                 countyLabel = '(n/a)';
34             opt(what.form.<% $opt{'prefix'} %>county, countiesArray[s], countyLabel);
35         }
36
37         var countyFormLabel = document.getElementById('<% $opt{'prefix'} %>countylabel');
38
39         if ( countiesArray.length > 1 ) { 
40           what.form.<% $opt{'prefix'} %>county.style.display = '';
41           countyFormLabel.style.visibility = 'visible';
42         } else {
43           what.form.<% $opt{'prefix'} %>county.style.display = 'none';
44           countyFormLabel.style.visibility = 'hidden';
45         }
46
47         //run the callback
48         if ( callback != null ) 
49           callback();
50       }
51   
52       // go get the new counties
53       <% $opt{'prefix'} %>get_counties( state, country, <% $opt{'prefix'} %>update_counties );
54   
55     }
56   
57   </SCRIPT>
58
59   <SELECT NAME="<% $opt{'prefix'} %>county" onChange="<% $opt{'onchange'} %>" <% $opt{'disabled'} %>>
60
61 % foreach my $county ( @counties ) {
62
63     <OPTION VALUE="<% $county %>"<% $county eq $opt{'county'} ? ' SELECTED' : '' %>><% $county %>
64
65 % } 
66
67   </SELECT>
68
69 % } else { 
70
71
72   <SCRIPT TYPE="text/javascript">
73     function <% $opt{'prefix'} %>state_changed(what) {
74     }
75   </SCRIPT>
76
77   <INPUT TYPE="hidden" NAME="<% $opt{'prefix'} %>county" VALUE="<% $opt{'county'} %>">
78
79 % } 
80
81 <%init>
82
83 my %opt = @_;
84 foreach my $opt (qw( county state country prefix onchange disabled )) {
85   $opt{$_} = '' unless exists($opt{$_}) && defined($opt{$_});
86 }
87
88 my @counties = ();
89 if ( $countyflag ) {
90
91   @counties = counties( $opt{'state'}, $opt{'country'} );
92
93   # this is very hacky
94   unless ( scalar(@counties) > 1 ) {
95     if ( $opt{'disabled'} =~ /STYLE=/i ) {
96       $opt{'disabled'} =~ s/STYLE="([^"]+)"/STYLE="$1; display:none"/i;
97     } else {
98       $opt{'disabled'} .= ' STYLE="display:none"';
99     }
100   }
101
102 }
103
104 </%init>
105 <%once>
106
107 my $sql = "SELECT COUNT(*) FROM cust_main_county".
108           " WHERE county IS NOT NULL AND county != ''";
109 my $sth = dbh->prepare($sql) or die dbh->errstr;
110 $sth->execute or die $sth->errstr;
111 my $countyflag = $sth->fetchrow_arrayref->[0];
112
113 </%once>