4.x style
[freeside.git] / httemplate / elements / select-state.html
index f7ac2c7..8db157b 100644 (file)
@@ -2,7 +2,7 @@
 
 Example:
 
-  include( '/elements/select-state.html',
+  <& /elements/select-state.html,
     #recommended
     country    => $current_country,
     state      => $current_state,
@@ -14,32 +14,34 @@ Example:
     disable_empty => 1, #defaults to 1, disable the empty option
     empty_label   => 'all', #label for empty option
     disable_countyupdate => 0, #bool - disabled update of the select-state.html
-  );
+    style         => [ 'attribute:value', 'another:value' ],
+  &>
 
 </%doc>
 
 <SELECT NAME     = "<% $pre %>state"
         ID       = "<% $pre %>state"
         onChange = "<% $onchange %>"
+        <% $opt{'disabled'} %>
+        <% $style %>
 >
 
 % unless ( $opt{'disable_empty'} ) {
-  <OPTION VALUE=""<% $opt{state} eq '' ? ' SELECTED' : '' %>><% $opt{empty_label} %>
+  <OPTION VALUE=""<% $opt{state} eq '' ? ' SELECTED' : '' %>><% $opt{empty_label} %></OPTION>
 % }
 
 % foreach my $state ( keys %states ) { 
-
-  <OPTION VALUE="<% $state |h %>"<% $state eq $opt{'state'} ? ' SELECTED' : '' %>><% $states{$state} || '(n/a)' %>
-
+  <OPTION VALUE="<% $state |h %>"<% $state eq $opt{'state'} ? ' SELECTED' : '' %>><% $states{$state} || '(n/a)' |h %></OPTION>
 % } 
 
-
 </SELECT>
 
 <%init>
 
 my %opt = @_;
-foreach my $opt (qw( state country prefix onchange disabled empty_label )) {
+foreach my $opt (qw(
+  state country prefix onchange disabled empty_label svcpart
+)) {
   $opt{$opt} = '' unless exists($opt{$opt}) && defined($opt{$opt});
 }
 
@@ -51,7 +53,31 @@ 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;
+    }
+
+  }
+}
+
 </%init>