| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit( 'Direct\'s not allowed' ); |
| 4 |
} |
| 5 |
|
| 6 |
add_action( 'wp_ajax_cf7d_get_rows_data', 'cf7d_get_rows_data' ); |
| 7 |
if ( ! function_exists( 'cf7d_get_rows_data' ) ) { |
| 8 |
function cf7d_get_rows_data() { |
| 9 |
try { |
| 10 |
if ( isset( $_POST['fid'] ) && |
| 11 |
isset( $_POST['page'] ) && |
| 12 |
isset( $_POST['per_page'] ) |
| 13 |
) { |
| 14 |
cf7d_checkNonce(); |
| 15 |
global $wpdb; |
| 16 |
$fid = (int) $_POST['fid']; |
| 17 |
$page = (int) $_POST['page']; |
| 18 |
$cf7d_entry_order_by = '`data_id` DESC'; |
| 19 |
$items_per_page = (int) $_POST['per_page']; |
| 20 |
|
| 21 |
$limit_query = ''; |
| 22 |
if ( is_numeric( $items_per_page ) ) { |
| 23 |
$offset = ( $page * $items_per_page ) - $items_per_page; |
| 24 |
$limit_query = "LIMIT $offset, $items_per_page"; |
| 25 |
} |
| 26 |
|
| 27 |
$query = sprintf( 'SELECT * FROM `' . $wpdb->prefix . 'cf7_data_entry` WHERE `cf7_id` = %d AND data_id IN(SELECT * FROM (SELECT data_id FROM `' . $wpdb->prefix . 'cf7_data_entry` WHERE 1 = 1 AND `cf7_id` = ' . $fid . ' GROUP BY `data_id` ORDER BY ' . $cf7d_entry_order_by . ' %s) temp_table) ORDER BY ' . $cf7d_entry_order_by, $fid, $limit_query ); |
| 28 |
$data = $wpdb->get_results( $query ); |
| 29 |
|
| 30 |
$data_sorted = apply_filters( 'cf7d_ad_before_printing_data', cf7d_sortdata( $data ), $fid ); |
| 31 |
$data_sorted = cf7d_esc_sorted_data( $data_sorted ); |
| 32 |
|
| 33 |
$fields = cf7d_get_db_fields( $fid ); |
| 34 |
|
| 35 |
$total = $wpdb->get_results( 'SELECT data_id FROM `' . $wpdb->prefix . 'cf7_data_entry` WHERE `cf7_id` = ' . (int) $fid . ' GROUP BY `data_id`' ); |
| 36 |
$total = count( $total ); |
| 37 |
|
| 38 |
$setting_nav_arr = get_option( 'cf7d_settings_nav_table' . $fid ); |
| 39 |
|
| 40 |
$navDefault = array( |
| 41 |
'bordered' => 1, |
| 42 |
'loading' => 0, |
| 43 |
'title' => 0, |
| 44 |
'colHeader' => 1, |
| 45 |
'expandedRowRender' => 0, |
| 46 |
'checkbox' => 1, |
| 47 |
'fixedHeader' => 1, |
| 48 |
'hasData' => 1, |
| 49 |
'ellipsis' => 1, |
| 50 |
'footer' => 1, |
| 51 |
'size' => 'default', |
| 52 |
'tableScroll' => 'fixedColumn', |
| 53 |
'tableLayout' => 'unset', |
| 54 |
'paginationTop' => 'topRight', |
| 55 |
'paginationBottom' => 'bottomRight', |
| 56 |
); |
| 57 |
// Up data when choose form new. |
| 58 |
if ( $setting_nav_arr === false ) { |
| 59 |
$setting_nav_arr = $navDefault; |
| 60 |
add_option( 'cf7d_settings_nav_table' . $fid, $setting_nav_arr, '', 'no' ); |
| 61 |
} |
| 62 |
|
| 63 |
if ( is_array( $setting_nav_arr ) === false ) { |
| 64 |
$setting_nav_arr = $navDefault; |
| 65 |
} |
| 66 |
|
| 67 |
// convert to number |
| 68 |
$pro_set_navArr = array( 'bordered', 'loading', 'title', 'colHeader', 'expandedRowRender', 'checkbox', 'fixedHeader', 'hasData', 'ellipsis', 'footer' ); |
| 69 |
|
| 70 |
foreach ( $pro_set_navArr as $pro_set_nav ) { |
| 71 |
if ( isset( $setting_nav_arr[ $pro_set_nav ] ) ) { |
| 72 |
$setting_nav_arr[ $pro_set_nav ] = (int) $setting_nav_arr[ $pro_set_nav ]; |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
wp_send_json_success( |
| 77 |
array( |
| 78 |
'mess' => __( 'success', 'cf7-database' ), |
| 79 |
array( |
| 80 |
'fields' => $fields, |
| 81 |
'data_sorted' => $data_sorted, |
| 82 |
'total_row' => $total, |
| 83 |
'items_per_page' => $items_per_page, |
| 84 |
'page' => $page, |
| 85 |
'setting_nav_arr' => $setting_nav_arr, |
| 86 |
), |
| 87 |
) |
| 88 |
); |
| 89 |
} |
| 90 |
wp_send_json_error( array( 'mess' => __( 'Opp! Something went wrong.', 'cf7-database' ) ) ); |
| 91 |
} catch ( \Exception $ex ) { |
| 92 |
wp_send_json_error( |
| 93 |
array( |
| 94 |
'mess' => __( 'Error exception.', 'cf7-database' ), |
| 95 |
array( |
| 96 |
'error' => $ex, |
| 97 |
), |
| 98 |
) |
| 99 |
); |
| 100 |
} catch ( \Error $ex ) { |
| 101 |
wp_send_json_error( |
| 102 |
array( |
| 103 |
'mess' => __( 'Error.', 'cf7-database' ), |
| 104 |
array( |
| 105 |
'error' => $ex, |
| 106 |
), |
| 107 |
) |
| 108 |
); |
| 109 |
} |
| 110 |
} |
| 111 |
} |
| 112 |
|
| 113 |
add_action( 'wp_ajax_cf7d_filter_date', 'cf7d_filter_date' ); |
| 114 |
if ( ! function_exists( 'cf7d_filter_date' ) ) { |
| 115 |
function cf7d_filter_date() { |
| 116 |
try { |
| 117 |
if ( isset( $_POST['fid'] ) && |
| 118 |
isset( $_POST['page'] ) && |
| 119 |
isset( $_POST['per_page'] ) && |
| 120 |
isset( $_POST['from_date'] ) && |
| 121 |
isset( $_POST['to_date'] ) |
| 122 |
) { |
| 123 |
global $wpdb; |
| 124 |
cf7d_checkNonce(); |
| 125 |
$fid = (int) $_POST['fid']; |
| 126 |
$page = (int) $_POST['page']; |
| 127 |
$cf7d_entry_order_by = '`data_id` DESC'; |
| 128 |
$items_per_page = (int) $_POST['per_page']; |
| 129 |
$search_form_date = sanitize_text_field( $_POST['from_date'] ); |
| 130 |
$search_to_date = sanitize_text_field( $_POST['to_date'] ); |
| 131 |
|
| 132 |
$limit_query = ''; |
| 133 |
if ( is_numeric( $items_per_page ) ) { |
| 134 |
$offset = ( $page * $items_per_page ) - $items_per_page; |
| 135 |
$limit_query = "LIMIT $offset, $items_per_page"; |
| 136 |
} |
| 137 |
|
| 138 |
$search_form_date = new DateTime( $search_form_date ); |
| 139 |
$search_form_date = $search_form_date->format( 'Y-m-d' ); |
| 140 |
$search_to_date = new DateTime( $search_to_date ); |
| 141 |
$search_to_date = $search_to_date->format( 'Y-m-d' ); |
| 142 |
$query = sprintf( 'SELECT * FROM `' . $wpdb->prefix . 'cf7_data_entry` WHERE `cf7_id` = %d AND data_id IN(SELECT * FROM (SELECT data_id FROM `' . $wpdb->prefix . 'cf7_data_entry` WHERE 1 = 1 AND `cf7_id` = ' . $fid . " AND name='submit_time' AND CONVERT(value , DATE) >= " . "'" . $search_form_date . "'" . ' AND CONVERT(value, DATE) <= ' . "'" . $search_to_date . "'" . ' GROUP BY `data_id` ORDER BY ' . $cf7d_entry_order_by . ' %s) temp_table) ORDER BY ' . $cf7d_entry_order_by, $fid, $limit_query ); |
| 143 |
|
| 144 |
$data = $wpdb->get_results( $query ); |
| 145 |
$data_sorted = apply_filters( 'cf7d_ad_before_printing_data', cf7d_sortdata( $data ), $fid ); |
| 146 |
$data_sorted = cf7d_esc_sorted_data( $data_sorted ); |
| 147 |
|
| 148 |
$fields = cf7d_get_db_fields( $fid ); |
| 149 |
|
| 150 |
$total = $wpdb->get_results( 'SELECT data_id FROM `' . $wpdb->prefix . 'cf7_data_entry` WHERE `cf7_id` = ' . (int) $fid . " AND name='submit_time' AND CONVERT(value , DATE) >= " . "'" . $search_form_date . "'" . ' AND CONVERT(value, DATE) <= ' . "'" . $search_to_date . "'" . ' GROUP BY `data_id`' ); |
| 151 |
$total = count( $total ); |
| 152 |
wp_send_json_success( |
| 153 |
array( |
| 154 |
'mess' => __( 'Filter date success', 'cf7-database' ), |
| 155 |
array( |
| 156 |
'fields' => $fields, |
| 157 |
'data_sorted' => $data_sorted, |
| 158 |
'items_per_page' => $items_per_page, |
| 159 |
'page' => $page, |
| 160 |
'total_row' => $total, |
| 161 |
), |
| 162 |
) |
| 163 |
); |
| 164 |
|
| 165 |
} |
| 166 |
wp_send_json_error( array( 'mess' => __( 'Opp! Something went wrong.', 'cf7-database' ) ) ); |
| 167 |
} catch ( \Exception $ex ) { |
| 168 |
wp_send_json_error( |
| 169 |
array( |
| 170 |
'mess' => __( 'Error exception.', 'cf7-database' ), |
| 171 |
array( |
| 172 |
'error' => $ex, |
| 173 |
), |
| 174 |
) |
| 175 |
); |
| 176 |
} catch ( \Error $ex ) { |
| 177 |
wp_send_json_error( |
| 178 |
array( |
| 179 |
'mess' => __( 'Error.', 'cf7-database' ), |
| 180 |
array( |
| 181 |
'error' => $ex, |
| 182 |
), |
| 183 |
) |
| 184 |
); |
| 185 |
} |
| 186 |
} |
| 187 |
} |
| 188 |
|
| 189 |
add_action( 'wp_ajax_cf7d_search_type_something', 'cf7d_search_type_something' ); |
| 190 |
if ( ! function_exists( 'cf7d_search_type_something' ) ) { |
| 191 |
function cf7d_search_type_something() { |
| 192 |
try { |
| 193 |
if ( isset( $_POST['fid'] ) && |
| 194 |
isset( $_POST['page'] ) && |
| 195 |
isset( $_POST['per_page'] ) && |
| 196 |
isset( $_POST['search_type'] ) |
| 197 |
) { |
| 198 |
global $wpdb; |
| 199 |
cf7d_checkNonce(); |
| 200 |
$fid = (int) $_POST['fid']; |
| 201 |
$page = (int) $_POST['page']; |
| 202 |
|
| 203 |
$cf7d_entry_order_by = '`data_id` DESC'; |
| 204 |
$items_per_page = (int) $_POST['per_page']; |
| 205 |
$search = sanitize_text_field( addslashes( $_POST['search_type'] ) ); |
| 206 |
|
| 207 |
$limit_query = ''; |
| 208 |
if ( is_numeric( $items_per_page ) ) { |
| 209 |
$offset = ( $page * $items_per_page ) - $items_per_page; |
| 210 |
$limit_query = "LIMIT $offset, $items_per_page"; |
| 211 |
} |
| 212 |
$query = sprintf( 'SELECT * FROM `' . $wpdb->prefix . 'cf7_data_entry` WHERE `cf7_id` = %d AND data_id IN(SELECT * FROM (SELECT data_id FROM `' . $wpdb->prefix . 'cf7_data_entry` WHERE 1 = 1 AND `cf7_id` = ' . $fid . ' ' . ( ( ! empty( $search ) ) ? "AND `value` LIKE '%%" . $search . "%%'" : '' ) . ' GROUP BY `data_id` ORDER BY ' . $cf7d_entry_order_by . ' %s) temp_table) ORDER BY ' . $cf7d_entry_order_by, $fid, $limit_query ); |
| 213 |
$data = $wpdb->get_results( $query ); |
| 214 |
|
| 215 |
$data_sorted = apply_filters( 'cf7d_ad_before_printing_data', cf7d_sortdata( $data ), $fid ); |
| 216 |
$data_sorted = cf7d_esc_sorted_data( $data_sorted ); |
| 217 |
$fields = cf7d_get_db_fields( $fid ); |
| 218 |
|
| 219 |
$total = $wpdb->get_results( 'SELECT data_id FROM `' . $wpdb->prefix . 'cf7_data_entry` WHERE `cf7_id` = ' . (int) $fid . ' ' . ( ( ! empty( $search ) ) ? "AND `value` LIKE '%%" . $search . "%%'" : '' ) . ' GROUP BY `data_id`' ); |
| 220 |
$total = count( $total ); |
| 221 |
|
| 222 |
wp_send_json_success( |
| 223 |
array( |
| 224 |
'mess' => __( 'Search type success', 'cf7-database' ), |
| 225 |
array( |
| 226 |
'fields' => $fields, |
| 227 |
'data_sorted' => $data_sorted, |
| 228 |
'total_row' => $total, |
| 229 |
'items_per_page' => $items_per_page, |
| 230 |
'page' => $page, |
| 231 |
), |
| 232 |
) |
| 233 |
); |
| 234 |
} |
| 235 |
wp_send_json_error( array( 'mess' => __( 'Opp! Something went wrong.', 'cf7-database' ) ) ); |
| 236 |
} catch ( \Exception $ex ) { |
| 237 |
wp_send_json_error( |
| 238 |
array( |
| 239 |
'mess' => __( 'Error exception.', 'cf7-database' ), |
| 240 |
array( |
| 241 |
'error' => $ex, |
| 242 |
), |
| 243 |
) |
| 244 |
); |
| 245 |
} catch ( \Error $ex ) { |
| 246 |
wp_send_json_error( |
| 247 |
array( |
| 248 |
'mess' => __( 'Error', 'cf7-database' ), |
| 249 |
array( |
| 250 |
'error' => $ex, |
| 251 |
), |
| 252 |
) |
| 253 |
); |
| 254 |
} |
| 255 |
} |
| 256 |
} |
| 257 |
|
| 258 |
add_action( 'wp_ajax_cf7d_delete_row', 'cf7d_delete_row' ); |
| 259 |
if ( ! function_exists( 'cf7d_delete_row' ) ) { |
| 260 |
function cf7d_delete_row() { |
| 261 |
if( ! apply_filters( 'cf7db-allowed-to-delete', true ) ) { |
| 262 |
wp_send_json_error( array( 'mess' => __( 'You are not allowed to delete this row.', 'cf7-database' ) ) ); |
| 263 |
} |
| 264 |
|
| 265 |
try { |
| 266 |
if ( isset( $_POST['del_id'] ) |
| 267 |
) { |
| 268 |
cf7d_checkNonce(); |
| 269 |
|
| 270 |
global $wpdb; |
| 271 |
$del_id = cf7d_sanitize_arr( json_decode( stripslashes( $_POST['del_id'] ), true ) ); |
| 272 |
$del_id = implode( ',', array_map( 'intval', $del_id ) ); |
| 273 |
$wpdb->query( "DELETE FROM {$wpdb->prefix}cf7_data_entry WHERE data_id IN($del_id)" ); |
| 274 |
$wpdb->query( "DELETE FROM {$wpdb->prefix}cf7_data WHERE id IN($del_id)" ); |
| 275 |
wp_send_json_success( array( 'mess' => __( 'Delete success', 'cf7-database' ) ) ); |
| 276 |
if ( $check_data && $check_data_entry ) { |
| 277 |
wp_send_json_success( array( 'mess' => __( 'Delete success', 'cf7-database' ) ) ); |
| 278 |
} else { |
| 279 |
wp_send_json_error( array( 'mess' => __( 'Opp! Something went wrong.', 'cf7-database' ) ) ); |
| 280 |
} |
| 281 |
} |
| 282 |
wp_send_json_error( array( 'mess' => __( 'Opp! Something went wrong.', 'cf7-database' ) ) ); |
| 283 |
} catch ( \Exception $ex ) { |
| 284 |
wp_send_json_error( |
| 285 |
array( |
| 286 |
'mess' => __( 'Error exception', 'cf7-database' ), |
| 287 |
array( |
| 288 |
'error' => $ex, |
| 289 |
), |
| 290 |
) |
| 291 |
); |
| 292 |
} catch ( \Error $ex ) { |
| 293 |
wp_send_json_error( |
| 294 |
array( |
| 295 |
'mess' => __( 'Error', 'cf7-database' ), |
| 296 |
array( |
| 297 |
'error' => $ex, |
| 298 |
), |
| 299 |
) |
| 300 |
); |
| 301 |
} |
| 302 |
} |
| 303 |
} |
| 304 |
|
| 305 |
add_action( 'wp_ajax_cf7d_edit_row', 'cf7d_edit_row' ); |
| 306 |
if ( ! function_exists( 'cf7d_edit_row' ) ) { |
| 307 |
function cf7d_edit_row() { |
| 308 |
try { |
| 309 |
global $wpdb; |
| 310 |
if ( isset( $_POST['fid'] ) && |
| 311 |
isset( $_POST['rid'] ) && |
| 312 |
isset( $_POST['field'] ) |
| 313 |
) { |
| 314 |
cf7d_checkNonce(); |
| 315 |
$fid = (int) $_POST['fid']; |
| 316 |
$rid = (int) $_POST['rid']; |
| 317 |
|
| 318 |
$field = cf7d_sanitize_arr( json_decode( stripslashes( $_POST['field'] ), true ) ); |
| 319 |
foreach ( $field as $key => $value ) { |
| 320 |
$check = $wpdb->query( $wpdb->prepare( 'UPDATE ' . $wpdb->prefix . 'cf7_data_entry SET `value` = %s WHERE `name` = %s AND `data_id` = %d', cf7d_sanitize_arr( $value ), cf7d_sanitize_arr( $key ), $rid ) ); |
| 321 |
} |
| 322 |
wp_send_json_success( array( 'mess' => __( 'Edit row success', 'cf7-database' ) ) ); |
| 323 |
} |
| 324 |
wp_send_json_error( array( 'mess' => __( 'Opp! Something went wrong.', 'cf7-database' ) ) ); |
| 325 |
} catch ( \Exception $ex ) { |
| 326 |
wp_send_json_error( |
| 327 |
array( |
| 328 |
'mess' => __( 'Error exception', 'cf7-database' ), |
| 329 |
array( |
| 330 |
'error' => $ex, |
| 331 |
), |
| 332 |
) |
| 333 |
); |
| 334 |
} catch ( \Error $ex ) { |
| 335 |
wp_send_json_error( |
| 336 |
array( |
| 337 |
'mess' => __( 'Error', 'cf7-database' ), |
| 338 |
array( |
| 339 |
'error' => $ex, |
| 340 |
), |
| 341 |
) |
| 342 |
); |
| 343 |
} |
| 344 |
} |
| 345 |
} |
| 346 |
|
| 347 |
add_action( 'wp_ajax_cf7d_edit_setting_table', 'cf7d_edit_setting_table' ); |
| 348 |
if ( ! function_exists( 'cf7d_edit_setting_table' ) ) { |
| 349 |
function cf7d_edit_setting_table() { |
| 350 |
try { |
| 351 |
global $wpdb; |
| 352 |
if ( isset( $_POST['fid'] ) && |
| 353 |
isset( $_POST['setting_nav_arr'] ) |
| 354 |
) { |
| 355 |
cf7d_checkNonce(); |
| 356 |
$fid = (int) $_POST['fid']; |
| 357 |
$setting_nav_arr = json_decode( stripslashes( $_POST['setting_nav_arr'] ), true ); |
| 358 |
add_option( 'cf7d_settings_nav_table' . $fid, cf7d_sanitize_arr( $setting_nav_arr ), '', 'no' ); |
| 359 |
update_option( 'cf7d_settings_nav_table' . $fid, cf7d_sanitize_arr( $setting_nav_arr ) ); |
| 360 |
wp_send_json_success( |
| 361 |
array( |
| 362 |
'mess' => __( 'Settings saved.', 'cf7-database' ), |
| 363 |
) |
| 364 |
); |
| 365 |
} |
| 366 |
} catch ( \Exception $ex ) { |
| 367 |
wp_send_json_error( |
| 368 |
array( |
| 369 |
'mess' => __( 'Error exception', 'cf7-database' ), |
| 370 |
array( |
| 371 |
'error' => $ex, |
| 372 |
), |
| 373 |
) |
| 374 |
); |
| 375 |
} catch ( \Error $ex ) { |
| 376 |
wp_send_json_error( |
| 377 |
array( |
| 378 |
'mess' => __( 'Error', 'cf7-database' ), |
| 379 |
array( |
| 380 |
'error' => $ex, |
| 381 |
), |
| 382 |
) |
| 383 |
); |
| 384 |
} |
| 385 |
} |
| 386 |
} |
| 387 |
|
| 388 |
add_action( 'wp_ajax_cf7d_edit_setting', 'cf7d_edit_setting' ); |
| 389 |
if ( ! function_exists( 'cf7d_edit_setting' ) ) { |
| 390 |
function cf7d_edit_setting() { |
| 391 |
try { |
| 392 |
if ( isset( $_POST['field'] ) && |
| 393 |
isset( $_POST['fid'] ) && |
| 394 |
isset( $_POST['page'] ) && |
| 395 |
isset( $_POST['per_page'] ) |
| 396 |
) { |
| 397 |
cf7d_checkNonce(); |
| 398 |
// Up data edit setting |
| 399 |
$fid = (int) $_POST['fid']; |
| 400 |
$field = json_decode( stripslashes( $_POST['field'] ), true ); |
| 401 |
$checkAddOption = add_option( 'cf7d_settings_field_' . $fid, cf7d_sanitize_arr( $field ), '', 'no' ); |
| 402 |
$checkUpOption = update_option( 'cf7d_settings_field_' . $fid, cf7d_sanitize_arr( $field ) ); |
| 403 |
|
| 404 |
// Get Data |
| 405 |
if ( $checkUpOption || $checkAddOption ) { |
| 406 |
global $wpdb; |
| 407 |
|
| 408 |
$fid = (int) $_POST['fid']; |
| 409 |
$page = (int) $_POST['page']; |
| 410 |
$cf7d_entry_order_by = '`data_id` DESC'; |
| 411 |
$items_per_page = (int) $_POST['per_page']; |
| 412 |
|
| 413 |
$limit_query = ''; |
| 414 |
if ( is_numeric( $items_per_page ) ) { |
| 415 |
$offset = ( $page * $items_per_page ) - $items_per_page; |
| 416 |
$limit_query = "LIMIT $offset, $items_per_page"; |
| 417 |
} |
| 418 |
|
| 419 |
$query = sprintf( 'SELECT * FROM `' . $wpdb->prefix . 'cf7_data_entry` WHERE `cf7_id` = %d AND data_id IN(SELECT * FROM (SELECT data_id FROM `' . $wpdb->prefix . 'cf7_data_entry` WHERE 1 = 1 AND `cf7_id` = ' . $fid . ' GROUP BY `data_id` ORDER BY ' . $cf7d_entry_order_by . ' %s) temp_table) ORDER BY ' . $cf7d_entry_order_by, $fid, $limit_query ); |
| 420 |
$data = $wpdb->get_results( $query ); |
| 421 |
|
| 422 |
$data_sorted = apply_filters( 'cf7d_ad_before_printing_data', cf7d_sortdata( $data ), $fid ); |
| 423 |
$data_sorted = cf7d_esc_sorted_data( $data_sorted ); |
| 424 |
$fields = cf7d_get_db_fields( $fid ); |
| 425 |
|
| 426 |
$total = $wpdb->get_results( 'SELECT data_id FROM `' . $wpdb->prefix . 'cf7_data_entry` WHERE `cf7_id` = ' . (int) $fid . ' GROUP BY `data_id`' ); |
| 427 |
$total = count( $total ); |
| 428 |
|
| 429 |
wp_send_json_success( |
| 430 |
array( |
| 431 |
'mess' => __( 'Settings saved.', 'cf7-database' ), |
| 432 |
array( |
| 433 |
'fields' => $fields, |
| 434 |
'data_sorted' => $data_sorted, |
| 435 |
'total' => $total, |
| 436 |
'items_per_page' => $items_per_page, |
| 437 |
'page' => $page, |
| 438 |
), |
| 439 |
) |
| 440 |
); |
| 441 |
|
| 442 |
} |
| 443 |
|
| 444 |
wp_send_json_error( array( 'mess' => __( 'Error save data.', 'cf7-database' ) ) ); |
| 445 |
} |
| 446 |
} catch ( \Exception $ex ) { |
| 447 |
wp_send_json_error( |
| 448 |
array( |
| 449 |
'mess' => __( 'Error exception', 'cf7-database' ), |
| 450 |
array( |
| 451 |
'error' => $ex, |
| 452 |
), |
| 453 |
) |
| 454 |
); |
| 455 |
} catch ( \Error $ex ) { |
| 456 |
wp_send_json_error( |
| 457 |
array( |
| 458 |
'mess' => __( 'Error', 'cf7-database' ), |
| 459 |
array( |
| 460 |
'error' => $ex, |
| 461 |
), |
| 462 |
) |
| 463 |
); |
| 464 |
} |
| 465 |
} |
| 466 |
} |
| 467 |
// Handle review tracking |
| 468 |
add_action( 'wp_ajax_cf7db_review', 'cf7db_handle_review_tracking' ); |
| 469 |
if ( ! function_exists( 'cf7db_handle_review_tracking' ) ) { |
| 470 |
function cf7db_handle_review_tracking() { |
| 471 |
try { |
| 472 |
cf7d_checkNonce(); |
| 473 |
|
| 474 |
// Save review tracking to option |
| 475 |
$review_date = time(); |
| 476 |
update_option( 'cf7db_user_reviewed', true ); |
| 477 |
update_option( 'cf7db_review_date', $review_date ); |
| 478 |
|
| 479 |
wp_send_json_success( |
| 480 |
array( |
| 481 |
'message' => __( 'Thank you for your review!', 'cf7-database' ), |
| 482 |
) |
| 483 |
); |
| 484 |
} catch ( Exception $ex ) { |
| 485 |
wp_send_json_error( |
| 486 |
array( |
| 487 |
'message' => __( 'Error', 'cf7-database' ), |
| 488 |
'error' => $ex->getMessage(), |
| 489 |
) |
| 490 |
); |
| 491 |
} |
| 492 |
} |
| 493 |
} |
| 494 |
|