| 1 |
<?php |
| 2 |
/** |
| 3 |
* The template for Search field LOCATION. |
| 4 |
* |
| 5 |
* This is the template that field layout for search form |
| 6 |
* |
| 7 |
*/ |
| 8 |
|
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
exit; // Exit if accessed directly. |
| 11 |
} |
| 12 |
?> |
| 13 |
<?php |
| 14 |
|
| 15 |
$field_key = 'search_location'; |
| 16 |
$field_attr_id = 'wdk_search_'.wmvc_show_data('idfield', $field_data); |
| 17 |
$placeholder = wmvc_show_data('field_label', $field_data); |
| 18 |
$field_value = ''; |
| 19 |
$filter_ids = array(); |
| 20 |
if(isset($predefinedfields_query) && !empty($predefinedfields_query[$field_key])) { |
| 21 |
$field_value = intval($predefinedfields_query[$field_key]); |
| 22 |
} |
| 23 |
|
| 24 |
if(isset($_GET['location_root'])) { |
| 25 |
$predefinedfields_query['custom_location_root'] = sanitize_text_field($_GET['location_root']); |
| 26 |
} |
| 27 |
|
| 28 |
if(isset($predefinedfields_query) && !empty($predefinedfields_query['custom_location_root'])) { |
| 29 |
$custom_field_value = intval($predefinedfields_query['custom_location_root']); |
| 30 |
global $Winter_MVC_WDK; |
| 31 |
$Winter_MVC_WDK->load_helper('listing'); |
| 32 |
$Winter_MVC_WDK->model('location_m'); |
| 33 |
$location = $Winter_MVC_WDK->location_m->get($custom_field_value, TRUE); |
| 34 |
|
| 35 |
/* if root search childs */ |
| 36 |
if(isset($_GET['location_root']) || empty(wmvc_show_data('parent_id', $location, false, TRUE, TRUE))) { |
| 37 |
$filter_ids = wdk_location_get_all_childs($custom_field_value); |
| 38 |
if(!empty($filter_ids)) { |
| 39 |
if(in_array($field_value, $filter_ids) === FALSE) { |
| 40 |
$field_value = $custom_field_value; |
| 41 |
} |
| 42 |
} else { |
| 43 |
$filter_ids[] = $custom_field_value; |
| 44 |
} |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
if(isset($_GET[$field_key])) { |
| 49 |
$field_value = ($_GET[$field_key]); |
| 50 |
} else { |
| 51 |
if(function_exists('run_wdk_geo') && (get_option('wdk_geo_autodetect_by_ip_enable') && !get_option('wdk_geo_autodetect_by_google_js_enable'))) { |
| 52 |
$field_value = wdk_geo_get_location_id(); |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
wdk_search_fields_toggle(); |
| 57 |
|
| 58 |
$hide_fields = ''; |
| 59 |
if(wmvc_show_data('search_type_tree_hide', $field_data)) { |
| 60 |
$hide_fields = wmvc_show_data('search_type_tree_hide', $field_data); |
| 61 |
} |
| 62 |
|
| 63 |
?> |
| 64 |
|
| 65 |
<?php if(isset($custom_field_value)):?> |
| 66 |
<input type="hidden" name="search_location[]" value="<?php echo esc_attr($custom_field_value);?>"> |
| 67 |
<?php endif;?> |
| 68 |
|
| 69 |
<?php if(wdk_get_option('wdk_multi_locations_search_field_type') == 'wdk_treefield_dropdown'):?> |
| 70 |
<?php |
| 71 |
global $Winter_MVC_WDK; |
| 72 |
$Winter_MVC_WDK->load_helper('listing'); |
| 73 |
$Winter_MVC_WDK->model('location_m'); |
| 74 |
|
| 75 |
$locations = array(); |
| 76 |
if(!empty($field_value)) { |
| 77 |
$locations[] = $field_value; |
| 78 |
$location = $Winter_MVC_WDK->location_m->get($field_value, TRUE); |
| 79 |
|
| 80 |
while(!empty($location->parent_id)) { |
| 81 |
$location = $Winter_MVC_WDK->location_m->get($location->parent_id, TRUE); |
| 82 |
$locations[] = $location->idlocation; |
| 83 |
} |
| 84 |
krsort($locations); |
| 85 |
} else { |
| 86 |
$locations[] = 0; |
| 87 |
} |
| 88 |
|
| 89 |
wp_enqueue_style('wdk-treefield-dropdown'); |
| 90 |
wp_enqueue_script('wdk-treefield-dropdown'); |
| 91 |
wp_enqueue_style( 'dashicons' ); |
| 92 |
|
| 93 |
$level_max = $Winter_MVC_WDK->location_m->get_max_level(); |
| 94 |
|
| 95 |
$placeholder = [ |
| 96 |
0 => esc_html__('Select Country','wpdirectorykit'), |
| 97 |
1 => esc_html__('Select City','wpdirectorykit'), |
| 98 |
2 => esc_html__('Select Neighborhood','wpdirectorykit'), |
| 99 |
3 => esc_html__('Select Sub Area','wpdirectorykit'), |
| 100 |
4 => esc_html__('Select Sub Area','wpdirectorykit'), |
| 101 |
5 => esc_html__('Select Sub Area','wpdirectorykit'), |
| 102 |
]; |
| 103 |
|
| 104 |
|
| 105 |
?> |
| 106 |
|
| 107 |
<input name="<?php echo esc_attr($field_key); ?>" type="hidden" value="<?php echo esc_attr($field_value); ?>" class="wdk_field_id_location"> |
| 108 |
<?php |
| 109 |
$level = 0; |
| 110 |
foreach ($locations as $location) { |
| 111 |
$current = $Winter_MVC_WDK->location_m->get($location, TRUE); |
| 112 |
|
| 113 |
$list = $Winter_MVC_WDK->location_m->get_by(array('parent_id = '.$current->parent_id => NULL)); |
| 114 |
|
| 115 |
|
| 116 |
if(isset($placeholder[$level])) { |
| 117 |
$values_list = array(''=> $placeholder[$level]); |
| 118 |
} else { |
| 119 |
$values_list = array(''=> esc_html__('Select Sub Categories','wpdirectorykit')); |
| 120 |
} |
| 121 |
|
| 122 |
foreach ($list as $list_value) { |
| 123 |
$values_list[$list_value->idlocation] = $list_value->location_title; |
| 124 |
} |
| 125 |
?> |
| 126 |
|
| 127 |
<div data-level="<?php echo esc_attr($level);?>" data-field="<?php echo esc_attr($field_key); ?>" class="wdk-field wdk-col wdk_treefield_dropdown <?php echo esc_attr(wmvc_show_data('field_type', $field_data)); ?> <?php echo esc_attr(wmvc_show_data('class', $field_data)); ?>"> |
| 128 |
<label class="wdk-field-label"><?php echo esc_html(wmvc_show_data('field_label', $field_data)); ?></label> |
| 129 |
<div class="wdk-field-group"> |
| 130 |
<?php echo wmvc_select_option('location_'.$level, $values_list, $location, 'class="wdk-control"');?> |
| 131 |
</div> |
| 132 |
</div> |
| 133 |
|
| 134 |
<?php |
| 135 |
$level++; |
| 136 |
} |
| 137 |
|
| 138 |
if($level<$level_max ) { |
| 139 |
for (; $level<$level_max;) { |
| 140 |
|
| 141 |
if(isset($placeholder[$level])) { |
| 142 |
$values_list = array(''=> $placeholder[$level]); |
| 143 |
} else { |
| 144 |
$values_list = array(''=> esc_html__('Select Sub Categories','wpdirectorykit')); |
| 145 |
} |
| 146 |
|
| 147 |
?> |
| 148 |
|
| 149 |
<div data-level="<?php echo esc_attr($level);?>" data-field="<?php echo esc_attr($field_key); ?>" class="wdk-field wdk-col wdk_treefield_dropdown <?php echo esc_attr(wmvc_show_data('field_type', $field_data)); ?> <?php echo esc_attr(wmvc_show_data('class', $field_data)); ?>"> |
| 150 |
<label class="wdk-field-label"><?php echo esc_html(wmvc_show_data('field_label', $field_data)); ?></label> |
| 151 |
<div class="wdk-field-group"> |
| 152 |
<?php echo wmvc_select_option('location_'.$level, $values_list, NULL, 'class="wdk-control"');?> |
| 153 |
</div> |
| 154 |
</div> |
| 155 |
|
| 156 |
<?php |
| 157 |
$level++; |
| 158 |
} |
| 159 |
} |
| 160 |
?> |
| 161 |
<?php else:?> |
| 162 |
|
| 163 |
<div class="wdk-field wdk-col <?php echo esc_attr(wmvc_show_data('field_type', $field_data)); ?> <?php echo esc_attr(wmvc_show_data('class', $field_data)); ?>"> |
| 164 |
<label class="wdk-field-label"><?php echo esc_html(wmvc_show_data('field_label', $field_data)); ?></label> |
| 165 |
<div class="wdk-field-group"> |
| 166 |
<?php if(wdk_get_option('wdk_multi_locations_search_field_type') == 'select2'):?> |
| 167 |
<?php echo wdk_treefield_select_ajax ($field_key.'[]', 'location_m', $field_value, 'location_title','idlocation', '', __('All Locations', 'wpdirectorykit'), $filter_ids);?> |
| 168 |
<?php elseif(wdk_get_option('wdk_multi_locations_search_field_type') == 'wdk_treefield_checkboxes'):?> |
| 169 |
<?php |
| 170 |
wp_enqueue_style( 'wdk-treefield-checkboxes'); |
| 171 |
wp_enqueue_script( 'wdk-treefield-checkboxes'); |
| 172 |
?> |
| 173 |
<?php echo wdk_treefield_option_checkboxes ('search_location', 'location_m', $field_value, 'location_title', '', __('All Locations', 'wpdirectorykit'), $filter_ids);?> |
| 174 |
<?php else:?> |
| 175 |
<?php echo wdk_treefield_option ('search_location', 'location_m', $field_value, 'location_title', '', __('All Locations', 'wpdirectorykit'), $filter_ids, FALSE, '', $hide_fields);?> |
| 176 |
<?php endif;?> |
| 177 |
</div> |
| 178 |
</div> |
| 179 |
|
| 180 |
<?php endif;?> |