<?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;
	?>
	<div class="wb-search-checkbox-group form-group" id="<?php echo $e_id;?>">
		<?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;
			
			$checked = '';
			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]) ) $checked = 'checked="checked"';
			}
			
			$disabled_elem = '';
			$disabled_class = '';
			
			if($opt_count == 0) {
				$disabled_elem = 'disabled="disabled"';
				$disabled_class = 'disabled';
				$checked = '';
			}
			
			?>

			<div class="wb-search-chkset checkbox <?=$disabled_class;?>">
				<?php
                echo '<label id="label_', $opt_id,'" for="', $opt_id,'" class="wb-label ',$disabled_class ,'">';
				echo '<input type="checkbox" ',$disabled_elem, ' name="', $e_name, '[]" id="', $opt_id, '" value="', $val, '" ', $checked,' style="',$e_style,'" rel="',$e_name . '_all" class="',$opt_class . ' ' . $e_class,' wb-trigger wb-trigger-click"> ';
                echo $label ,' <span id="label_', $opt_id,'_count">(',$opt_count ,')</span>';
				echo '</label>';
				?>
			</div>
			<?php
		}
		$print_opts = ob_get_contents();
		ob_end_clean();
		
		
		$opt_id = $e_name . '_all';
				
		$checked = '';
		if(isset($wb_search_params['filter'][$e_name]) && $wb_search_params['filter'][$e_name] == "" ) $checked = 'checked="checked"';
		
		$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';
			$checked = '';
		}
		?>
		<div class="wb-search-chkset wb-search-chkset-all checkbox <?=$disabled_class;?>">
			<?php
            echo '<label id="label_', $opt_id,'" for="', $opt_id,'" class="wb-label ',$disabled_class ,'">';
			echo '<input type="checkbox" ',$disabled_elem, ' name="', $e_name, '" id="', $opt_id, '" value="" ', $checked,' style="',$e_style,'" rel="',$opt_class ,'" class="',$opt_class . ' ' . $e_class,' wb-trigger wb-trigger-click wb-all"/> ';
			
			echo 'All <span id="label_', $opt_id,'_count">(',$all_count ,')</span>';
			echo '</label>';
			?>
		</div>
		<?php
		echo $print_opts;
		?>
	</div>
	<?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;
	?>
	<div class="wb-search-yesno-group form-group" id="<?php echo $e_id;?>">
		<?php
		
		$checked = '';
		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]);
			}
			
			$checked = '';
			
			if(isset($wb_search_params['filter'][$e_name]) && in_array($val, $wb_search_params['filter'][$e_name]) ) $checked = 'checked="checked"';
			
			
			$disabled_elem = '';
			$disabled_class = '';
			
			if($opt_count == 0) {
				$disabled_elem = 'disabled="disabled"';
				$disabled_class = 'disabled';
				$checked = '';
			}
			
			?>
			<div class="wb-search-chkset radio <?=$disabled_class;?>">
				<?php
                echo '<label id="label_', $opt_id,'" for="', $opt_id,'" class="wb-label ',$disabled_class ,'">';
				echo '<input type="radio" ',$disabled_elem, ' name="', $e_name, '[]" id="', $opt_id, '" value="', $val, '" ', $checked,' style="',$e_style,'" class="',$e_class,' wb-trigger wb-trigger-click"/> ';
				echo $label ,' <span id="label_', $opt_id,'_count">(',$opt_count ,')</span>
				</label>';
				?>
			</div>
			<?php
			
			//echo '<li>';
			//echo '<input type="radio" name="', $e_name, '[]" value="', $val, '" ', $checked,' style="',$e_style,'" class="',$e_class,' wb-trigger wb-trigger-click"> ', $label;
			//echo '</li>';
		}
		?>
	</div>
	<?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;
	?>
	<div class="wb-search-radio-group form-group" id="<?php echo $e_id;?>">
		<?php
		
			
		$checked = '';
		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']);
			}
			$checked = '';
			if(isset($wb_search_params['filter'][$e_name]) && in_array($val, $wb_search_params['filter'][$e_name]) ) $checked = 'checked="checked"';
			
			$disabled_elem = '';
			$disabled_class = '';
			
			if($opt_count == 0) {
				$disabled_elem = 'disabled="disabled"';
				$disabled_class = 'wb-disabled';
				$checked = '';
			}
			
			?>
			<div class="wb-search-chkset radio <?=$disabled_class;?>">
				<?php
                echo '<label id="label_', $opt_id,'" for="', $opt_id,'" class="wb-label ',$disabled_class ,'">';
				echo '<input type="radio" ',$disabled_elem, ' name="', $e_name, '[]" id="', $opt_id, '" value="', $val, '" ', $checked,' style="',$e_style,'" class="',$e_class,' wb-trigger wb-trigger-click"/> ';
				
				echo $label ,' <span id="label_', $opt_id,'_count">(',$opt_count ,')</span>
				</label>';
				?>
			</div>
			<?php
			
			//echo '<li>';
			//echo '<input type="radio" name="', $e_name, '[]" value="', $val, '" ', $checked,' style="',$e_style,'" class="',$e_class,' wb-trigger wb-trigger-click"> ', $label;
			//echo '</li>';
		}
		?>
	</div>
	<?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="form-control input-sm <?php echo $e_class;?> wb-trigger wb-trigger-change" style="<?php echo $e_style;?>">
		<?php
		echo '<option value="" selected="selected"> ', $e_def, '</option>';
		foreach ($elem['e_db'] as $val=>$label) {
			
			if(isset($wb_search_params['feature'][$fe_uid][$val])) {
				$label .= ' (' . intval($wb_search_params['feature'][$fe_uid][$val]) . ')';
			}
			else {
				$label .= ' (0)';
			}
			
			$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_;
?>