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