X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Felements%2Fselect-state.html;h=8db157b9295426cbe39a87597163e6a0a0af1044;hb=dac9051f94d03903c00a46117f6edf8315ec57dc;hp=4f1c056b51f8fa043d1202cecc28cf1c8b9f0591;hpb=9c7dee35f91a386fcce14cb6c3e9d23ba3eee8af;p=freeside.git diff --git a/httemplate/elements/select-state.html b/httemplate/elements/select-state.html index 4f1c056b5..8db157b92 100644 --- a/httemplate/elements/select-state.html +++ b/httemplate/elements/select-state.html @@ -1,24 +1,83 @@ - + <% $style %> +> + +% unless ( $opt{'disable_empty'} ) { + +% } +% foreach my $state ( keys %states ) { + +% } <%init> + my %opt = @_; -foreach my $opt (qw( county state country prefix onchange disabled empty )) { - $opt{$_} = '' unless exists($opt{$_}) && defined($opt{$_}); +foreach my $opt (qw( + state country prefix onchange disabled empty_label svcpart +)) { + $opt{$opt} = '' unless exists($opt{$opt}) && defined($opt{$opt}); } +$opt{'disable_empty'} = 1 unless exists($opt{'disable_empty'}); + +my $pre = $opt{'prefix'}; + +my $onchange = + ( $opt{'disable_countyupdate'} ? '' : $pre.'state_changed(this); ' ). + $opt{'onchange'}; + +$opt{'style'} ||= []; +my $style = + scalar(@{$opt{style}}) + ? 'STYLE="'. join(';', @{$opt{style}}). '"' + : ''; + tie my %states, 'Tie::IxHash', states_hash( $opt{'country'} ); + +if ( $opt{'svcpart'} ) { + + my $part_svc = qsearchs('part_svc', { 'svcpart' => $opt{'svcpart'} } ); + if ( $part_svc && $part_svc->exporttype eq 'internal_diddb' ) { + + my $sth = dbh->prepare( + 'SELECT DISTINCT state FROM phone_avail WHERE svcnum IS NULL' + ) or die dbh->errstr; + $sth->execute or die $sth->errstr; + my %avail_states = map { $_->[0] => 1 } @{ $sth->fetchall_arrayref }; + + if ( %avail_states ) { + delete $states{$_} foreach grep ! $avail_states{$_}, keys %states; + } + + } +} +