| 1 |
<?php |
| 2 |
/** |
| 3 |
* The template for Edit Search Form. |
| 4 |
* |
| 5 |
* This is the template that form edit |
| 6 |
* |
| 7 |
*/ |
| 8 |
|
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
exit; // Exit if accessed directly. |
| 11 |
} |
| 12 |
?> |
| 13 |
|
| 14 |
<!-- This file should primarily consist of HTML with a little bit of PHP. --> |
| 15 |
|
| 16 |
<div class="wrap wdk-wrap"> |
| 17 |
|
| 18 |
<h1 class="wp-heading-inline"><?php echo esc_html__('Ai Search Designer','wpdirectorykit'); ?></h1> |
| 19 |
<br /> |
| 20 |
|
| 21 |
<div class="wdk-body"> |
| 22 |
<form method="post" action="<?php echo esc_url(wmvc_current_edit_url()); ?>" novalidate="novalidate"> |
| 23 |
<?php wp_nonce_field( 'wdk-searchform-edit_'.wmvc_show_data('idsearchform', $db_data, 1), '_wpnonce'); ?> |
| 24 |
|
| 25 |
<div class="postbox" style="display: block;"> |
| 26 |
<div class="postbox-header"> |
| 27 |
<h3><?php echo esc_html__('AI Search Fields','wpdirectorykit'); ?></h3> |
| 28 |
</div> |
| 29 |
<div class="inside"> |
| 30 |
<p class="alert alert-info"> |
| 31 |
<?php echo esc_html__( |
| 32 |
'Select the listing fields AI can use to understand and process search queries. For better performance and faster responses, we recommend selecting only the fields that are relevant to your search.', |
| 33 |
'wpdirectorykit' |
| 34 |
); ?> |
| 35 |
</p> |
| 36 |
<div class="wdk-ai-fields-list"> |
| 37 |
|
| 38 |
<?php foreach ($fields as $field): ?> |
| 39 |
|
| 40 |
<?php |
| 41 |
|
| 42 |
$allowed_types = ['INPUTBOX', 'NUMBER', 'DROPDOWN', 'DROPDOWNMULTIPLE', 'CHECKBOX']; |
| 43 |
if (!in_array($field->field_type, $allowed_types, true)) { |
| 44 |
continue; |
| 45 |
} |
| 46 |
|
| 47 |
$field_id = (int) $field->idfield; |
| 48 |
?> |
| 49 |
|
| 50 |
<label class="wdk-ai-field"> |
| 51 |
|
| 52 |
<input |
| 53 |
type="checkbox" |
| 54 |
class="wdk-ai-field-checkbox" |
| 55 |
value="<?php echo esc_attr($field_id); ?>" |
| 56 |
<?php checked(in_array($field_id, array_map('intval', $selected_fields), true)); ?> |
| 57 |
> |
| 58 |
|
| 59 |
<span class="wdk-ai-field-label"> |
| 60 |
<?php echo esc_html($field->field_label); ?> |
| 61 |
</span> |
| 62 |
|
| 63 |
<span class="wdk-ai-field-type"> |
| 64 |
<?php echo esc_html($field->field_type); ?> |
| 65 |
</span> |
| 66 |
|
| 67 |
</label> |
| 68 |
|
| 69 |
<?php endforeach; ?> |
| 70 |
|
| 71 |
</div> |
| 72 |
</div> |
| 73 |
</div> |
| 74 |
</form> |
| 75 |
</div> |
| 76 |
|
| 77 |
</div> |
| 78 |
<?php |
| 79 |
wp_enqueue_style('wdk-notify'); |
| 80 |
wp_enqueue_script('wdk-notify'); |
| 81 |
?> |
| 82 |
|
| 83 |
<script> |
| 84 |
jQuery(document).ready(function ($) { |
| 85 |
|
| 86 |
$(document).on( |
| 87 |
'change', |
| 88 |
'.wdk-ai-field-checkbox', |
| 89 |
function () { |
| 90 |
|
| 91 |
const selectedFields = []; |
| 92 |
|
| 93 |
$('.wdk-ai-field-checkbox:checked').each(function () { |
| 94 |
selectedFields.push($(this).val()); |
| 95 |
}); |
| 96 |
|
| 97 |
const $status = $('.wdk-ai-search-status'); |
| 98 |
|
| 99 |
var ajax_param = { |
| 100 |
"page": 'wdk_backendajax', |
| 101 |
"function": 'wdk_save_ai_search_fields', |
| 102 |
"action": 'wdk_public_action', |
| 103 |
"_wpnonce": '<?php echo esc_js(wp_create_nonce('wdk-backendajax')); ?>', |
| 104 |
"fields": selectedFields, |
| 105 |
}; |
| 106 |
|
| 107 |
$.ajax({ |
| 108 |
url: "<?php echo esc_url(admin_url('admin-ajax.php')); ?>", |
| 109 |
type: 'POST', |
| 110 |
data: ajax_param, |
| 111 |
|
| 112 |
success: function (response) { |
| 113 |
if (response.popup_text_success) |
| 114 |
wdk_log_notify(response.popup_text_success); |
| 115 |
|
| 116 |
if (response.popup_text_error) |
| 117 |
wdk_log_notify(response.popup_text_error, 'error'); |
| 118 |
}, |
| 119 |
|
| 120 |
error: function () { |
| 121 |
$status |
| 122 |
.addClass('error') |
| 123 |
.text('Request failed'); |
| 124 |
} |
| 125 |
|
| 126 |
}); |
| 127 |
|
| 128 |
} |
| 129 |
); |
| 130 |
}); |
| 131 |
</script> |
| 132 |
<?php $this->view('general/footer', $data); ?> |