<?php
$elem_ = '&nbsp;';
ob_start();
if($e_type_search == "checkbox") {
	$opt_class = "$e_name" . "_ck";
	$have_options = false;
	$elem = array();
	$elem['e_db'] = array();
	$options = trim($e_db);
	if($options != "") {
		$opts = unserialize(base64_decode($options));
		if(is_array($opts)) {
			$opts = array_map('stripslashes', $opts);
			$have_options = true;
		}
	}
	
	if($have_options) $elem['e_db'] = $opts;
	?>
	<select multiple size="1" name="<?=$e_name . '[]';?>" class="wb-selectbox show-menu-arrow form-control input-sm" id="<?php echo $e_id;?>" data-title="All">
		<?php
		$all_count = 0;
		ob_start();
		foreach ($elem['e_db'] as $val=>$label) {
			$opt_id = $e_name . '_' . $val;
			$opt_count = intval($wb_filters_names[$fe_uid]['e_db'][$val]['results']);
			
			$all_count += $opt_count;
			
			$selected = '';
			if(isset($wb_search_params['filter'][$e_name])) {
				if(is_array($wb_search_params['filter'][$e_name]) && in_array($val, $wb_search_params['filter'][$e_name]) ) {
                    $selected = 'selected="selected"';
                }
			}
			
			$disabled_elem = '';
			$disabled_class = '';
			
			if($opt_count == 0) {
				$disabled_elem = 'disabled="disabled"';
				$disabled_class = 'disabled';
				$selected = '';
			}
			
			?>

			<option <?=$disabled_class;?> value="<?=$val;?>" <?=$selected;?>>
				<?php
                echo $label;
				?>
			</option>
			<?php
		}
		$print_opts = ob_get_contents();
		ob_end_clean();
		
		
		$opt_id = $e_name . '_all';
				
		$selected = '';
		if(isset($wb_search_params['filter'][$e_name]) && $wb_search_params['filter'][$e_name] == "" ) {
            $selected = 'selected="selected"';
        }
		
		$disabled_elem = '';
		$disabled_class = '';
		
		if($e_type == "checkbox") {
			$all_count = intval($wb_filters_names[$fe_uid]['all']);
		}
		
		
		if($all_count == 0) {
			$disabled_elem = 'disabled="disabled"';
			$disabled_class = 'disabled';
			$selected = '';
		}
		?>
		<option <?=$disabled_class;?> value="" <?=$selected;?>>
			<?php
            echo 'All';
			?>
		</option>
		<?php
		echo $print_opts;
		?>
	</select>
	<?php
}

if($e_type == "yesno") {
	$have_options = false;
	$elem = array();
	$elem['e_db'] = array();
	$options = trim($e_db);
	if($options != "") {
		$opts = unserialize(base64_decode($options));
		if(is_array($opts)) {
			$opts = array_map('stripslashes', $opts);
			$have_options = true;
		}
	}
	
	
	if($have_options) $elem['e_db'] = $opts;
	?>
    <select name="<?php echo $e_name;?>" id="<?php echo $e_id;?>" class="wb-selectbox show-menu-arrow form-control input-sm"  data-show-tick="true"  data-title="Any">
		<?php
		
		$selected = '';
		foreach ($elem['e_db'] as $val=>$label) {
			$opt_id = $e_name . '_' . $val;
			$opt_count = 0;
			if(isset($wb_search_params['feature'][$fe_uid][$val])) {
				$opt_count = intval($wb_search_params['feature'][$fe_uid][$val]);
			}
			
			$selected = '';
			
			if(isset($wb_search_params['filter'][$e_name]) && in_array($val, $wb_search_params['filter'][$e_name]) ) $selected = 'selected="selected"';
			
			
			$disabled_elem = '';
			$disabled_class = '';
			
			if($opt_count == 0) {
				$disabled_elem = 'disabled="disabled"';
				$disabled_class = 'disabled';
				$selected = '';
			}
			
			?>
			<option <?=$disabled_class;?> value="<?=$val;?>" <?=$selected;?>>
				<?php
				echo $label;
				?>
			</option>
			<?php
			
			//echo '<li>';
			//echo '<input type="radio" name="', $e_name, '[]" value="', $val, '" ', $selected,' style="',$e_style,'" class="',$e_class,' wb-trigger wb-trigger-click"> ', $label;
			//echo '</li>';
		}
		?>
	</select>
	<?php
}

if($e_type_search == "radio") {
	
	//echo '<pre>', var_export($wb_search_params['feature'][$fe_uid], true), '</pre>';
	
	$have_options = false;
	$elem = array();
	$elem['e_db'] = array();
	$options = trim($e_db);
	if($options != "") {
		$opts = unserialize(base64_decode($options));
		if(is_array($opts)) {
			$opts = array_map('stripslashes', $opts);
			$have_options = true;
		}
	}
	
	if($have_options) $elem['e_db'] = $opts;
	?>
	<select name="<?=$e_name;?>" class="wb-selectbox show-menu-arrow form-control input-sm" id="<?php echo $e_id;?>" data-show-tick="true" data-title="All">
		<?php
		
			
		$selected = '';
		foreach ($elem['e_db'] as $val=>$label) {
			$opt_id = $e_name . '_' . $val;
			$opt_count = 0;
			if(isset($wb_filters_names[$fe_uid]['e_db'][$val]['results']))  {
				$opt_count = intval($wb_filters_names[$fe_uid]['e_db'][$val]['results']);
			}
			//echo print_r($wb_search_params);
			
			
			if(isset($wb_search_params['feature'][$fe_uid][$val])) {
				//$opt_count = intval($wb_search_params['feature'][$fe_uid][$val]);
				$opt_count = intval($wb_filters_names[$fe_uid]['e_db'][$val]['results']);
			}
			$selected = '';
			if(isset($wb_search_params['filter'][$e_name]) && in_array($val, $wb_search_params['filter'][$e_name]) ) {
                $selected = 'selected="selected"';
            }
			
			$disabled_elem = '';
			$disabled_class = '';
			
			if($opt_count == 0) {
				$disabled_elem = 'disabled="disabled"';
				$disabled_class = 'disabled';
				$selected = '';
			}
			
			?>
			<option <?=$disabled_class;?> value="<?=$val;?>" <?=$selected;?>>
				<?php
				echo $label;
				?>
			</option>
			<?php
			
			//echo '<li>';
			//echo '<input type="radio" name="', $e_name, '[]" value="', $val, '" ', $selected,' style="',$e_style,'" class="',$e_class,' wb-trigger wb-trigger-click"> ', $label;
			//echo '</li>';
		}
		?>
	</select>
	<?php
}

if($e_type == "select") {
	$have_options = false;
	$elem = array();
	$elem['e_db'] = array();
	$options = trim($e_db);
	if($options != "") {
		$opts = unserialize(base64_decode($options));
		if(is_array($opts)) {
			$opts = array_map('stripslashes', $opts);
			$have_options = true;
		}
	}
	
	if($have_options) $elem['e_db'] = $opts;
	?>
	<select name="<?php echo $e_name;?>" id="<?php echo $e_id;?>" class="wb-selectbox show-menu-arrow form-control input-sm <?php echo $e_class;?>"  data-show-tick="true"  data-title="All">
		<?php
		echo '<option value="" selected="selected"> ', $e_def, '</option>';
		foreach ($elem['e_db'] as $val=>$label) {
			

			
			$selected = '';
			if(isset($fvalues[$fe_uid]) && in_array($val, $fvalues[$fe_uid])) $selected = 'selected="selected"';
			echo '<option value="', $val, '" ', $selected,'> ', $label, '</option>';
		}
		?>
	</select>
	<?php
}


$elem_ = ob_get_contents();
ob_end_clean();
echo $elem_;