| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly |
| 4 |
} |
| 5 |
|
| 6 |
if ( |
| 7 |
check_ajax_referer('set_edit_form_field', '_ajax_nonce', false) != 1 |
| 8 |
) wp_send_json_error('Unauthorised request!', 400); |
| 9 |
|
| 10 |
global $current_user, $wpdb, $wpscfunction; |
| 11 |
if (!($current_user->ID && $current_user->has_cap('manage_options'))) {exit;} |
| 12 |
|
| 13 |
$field_id = isset($_POST) && isset($_POST['field_id']) ? intval($_POST['field_id']) : 0; |
| 14 |
if (!$field_id) {exit;} |
| 15 |
|
| 16 |
$custom_field = get_term_by('id', $field_id, 'wpsc_ticket_custom_fields'); |
| 17 |
|
| 18 |
$field_label = isset($_POST) && isset($_POST['field_label']) ? sanitize_text_field($_POST['field_label']) : ''; |
| 19 |
if (!$field_label) {exit;} |
| 20 |
|
| 21 |
$extra_info = isset($_POST) && isset($_POST['extra_info']) ? sanitize_text_field($_POST['extra_info']) : ''; |
| 22 |
|
| 23 |
$personal_info = isset($_POST) && isset($_POST['personal_info']) ? intval($_POST['personal_info']) : '1'; |
| 24 |
|
| 25 |
$field_type = isset($_POST) && isset($_POST['field_type']) ? intval($_POST['field_type']) : ''; |
| 26 |
if (!$field_type) {exit;} |
| 27 |
|
| 28 |
$wpsc_tf_placeholder_text = isset($_POST) && isset($_POST['wpsc_tf_placeholder_text']) ? sanitize_text_field($_POST['wpsc_tf_placeholder_text']) : ''; |
| 29 |
|
| 30 |
$field_opt = isset($_POST) && isset($_POST['field_options']) ? sanitize_textarea_field($_POST['field_options']) : ''; |
| 31 |
$field_options = $field_opt ? explode("\n", $field_opt) : array(); |
| 32 |
|
| 33 |
$field_types = $wpscfunction->get_custom_field_types(); |
| 34 |
if ($field_types[$field_type]['has_options']==1 && !$field_options) {exit;} |
| 35 |
|
| 36 |
foreach ($field_options as $key => $value) { |
| 37 |
$field_options[$key] = trim(sanitize_text_field($value)); |
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
$html_content = isset($_POST) && isset($_POST['html_content']) ? wp_kses_post(htmlspecialchars_decode($_POST['html_content'], ENT_QUOTES)) : ''; |
| 42 |
|
| 43 |
$required = isset($_POST) && isset($_POST['required']) ? intval($_POST['required']) : '1'; |
| 44 |
|
| 45 |
if($field_type == '22'){ |
| 46 |
$required = 0; |
| 47 |
} |
| 48 |
|
| 49 |
$time_format = isset($_POST) && isset($_POST['time_format']) ? intval($_POST['time_format']) : '12'; |
| 50 |
|
| 51 |
$width = isset($_POST) && isset($_POST['width']) ? sanitize_text_field($_POST['width']) : '1'; |
| 52 |
$date_range = isset($_POST) && isset($_POST['date_range']) ? sanitize_text_field($_POST['date_range']) : ''; |
| 53 |
|
| 54 |
$date_range_from = isset($_POST) && isset($_POST['date_range_from']) ? sanitize_text_field($_POST['date_range_from']) : ''; |
| 55 |
$date_range_to = isset($_POST) && isset($_POST['date_range_to']) ? sanitize_text_field($_POST['date_range_to']) : ''; |
| 56 |
|
| 57 |
$visibility = isset($_POST) && isset($_POST['visibility']) ? $wpscfunction->sanitize_array($_POST['visibility']) : array(); |
| 58 |
foreach ($visibility as $key => $value) { |
| 59 |
$visibility[$key] = sanitize_text_field($value); |
| 60 |
} |
| 61 |
$wpsc_limit = isset($_POST) && isset($_POST['limit']) && $_POST['limit'] ? sanitize_text_field($_POST['limit']) : '0'; |
| 62 |
|
| 63 |
$old_tf_type = get_term_meta( $field_id, 'wpsc_tf_type', true); |
| 64 |
|
| 65 |
$field_label = stripslashes($field_label); |
| 66 |
$extra_info = stripslashes($extra_info); |
| 67 |
|
| 68 |
update_term_meta ($field_id, 'wpsc_tf_label', $field_label); |
| 69 |
update_term_meta ($field_id, 'wpsc_tf_extra_info',$extra_info ); |
| 70 |
update_term_meta ($field_id, 'wpsc_tf_type', $field_type); |
| 71 |
update_term_meta ($field_id, 'wpsc_tf_placeholder_text',$wpsc_tf_placeholder_text); |
| 72 |
update_term_meta ($field_id, 'wpsc_tf_options', $field_options); |
| 73 |
update_term_meta ($field_id, 'wpsc_tf_required', $required); |
| 74 |
update_term_meta ($field_id, 'wpsc_tf_width', $width); |
| 75 |
update_term_meta ($field_id, 'wpsc_date_range', $date_range); |
| 76 |
update_term_meta ($field_id, 'date_range_from', $date_range_from); |
| 77 |
update_term_meta ($field_id, 'date_range_to', $date_range_to); |
| 78 |
update_term_meta ($field_id, 'wpsc_tf_visibility', $visibility); |
| 79 |
update_term_meta ($field_id, 'wpsc_tf_personal_info', $personal_info); |
| 80 |
update_term_meta ($field_id, 'wpsc_tf_limit', $wpsc_limit); |
| 81 |
update_term_meta ($field_id, 'wpsc_html_content', $html_content); |
| 82 |
update_term_meta ($field_id, 'wpsc_time_format', $time_format); |
| 83 |
|
| 84 |
if ($old_tf_type!=$field_type) { |
| 85 |
if ($field_types[$field_type]['allow_ticket_list']) { |
| 86 |
update_term_meta ($field_id, 'wpsc_allow_ticket_list', '1'); |
| 87 |
update_term_meta ($field_id, 'wpsc_customer_ticket_list_status', '0'); |
| 88 |
update_term_meta ($field_id, 'wpsc_agent_ticket_list_status', '0'); |
| 89 |
} else { |
| 90 |
update_term_meta ($field_id, 'wpsc_allow_ticket_list', '0'); |
| 91 |
} |
| 92 |
if ($field_types[$field_type]['allow_ticket_filter']) { |
| 93 |
update_term_meta ($field_id, 'wpsc_allow_ticket_filter', '1'); |
| 94 |
update_term_meta ($field_id, 'wpsc_ticket_filter_type', $field_types[$field_type]['ticket_filter_type']); |
| 95 |
update_term_meta ($field_id, 'wpsc_customer_ticket_filter_status', '0', '0'); |
| 96 |
update_term_meta ($field_id, 'wpsc_agent_ticket_filter_status', '0'); |
| 97 |
} else { |
| 98 |
update_term_meta ($field_id, 'wpsc_allow_ticket_filter', '0'); |
| 99 |
} |
| 100 |
if ($field_types[$field_type]['allow_orderby']) { |
| 101 |
update_term_meta ($field_id, 'wpsc_allow_orderby', '1'); |
| 102 |
} else { |
| 103 |
update_term_meta ($field_id, 'wpsc_allow_orderby', '0'); |
| 104 |
$agent_orderby = get_option('wpsc_tl_agent_orderby'); |
| 105 |
if($custom_field->slug == $agent_orderby){ |
| 106 |
update_option('wpsc_tl_agent_orderby', 'date_updated'); |
| 107 |
update_option('wpsc_tl_agent_orderby_order','DESC'); |
| 108 |
} |
| 109 |
$customer_orderby = get_option('wpsc_tl_customer_orderby'); |
| 110 |
if($custom_field->slug == $customer_orderby){ |
| 111 |
update_option('wpsc_tl_customer_orderby', 'date_updated'); |
| 112 |
update_option('wpsc_tl_customer_orderby_order','DESC'); |
| 113 |
} |
| 114 |
} |
| 115 |
} |
| 116 |
|
| 117 |
/** |
| 118 |
* Update translation option for custom field label in order to support WPML |
| 119 |
*/ |
| 120 |
$custom_fields_localize = get_option('wpsc_custom_fields_localize'); |
| 121 |
if (!$custom_fields_localize) { |
| 122 |
$custom_fields_localize = array(); |
| 123 |
} |
| 124 |
$custom_fields_localize['custom_fields_'.$field_id] = $field_label; |
| 125 |
update_option('wpsc_custom_fields_localize', $custom_fields_localize); |
| 126 |
|
| 127 |
$custom_fields_extra_info = get_option('wpsc_custom_fields_extra_info'); |
| 128 |
if (!$custom_fields_extra_info) { |
| 129 |
$custom_fields_extra_info = array(); |
| 130 |
} |
| 131 |
$custom_fields_extra_info['custom_fields_extra_info_' . $field_id] = $extra_info; |
| 132 |
update_option('wpsc_custom_fields_extra_info', $custom_fields_extra_info); |
| 133 |
|
| 134 |
do_action('wpsc_set_edit_form_field',$field_id); |
| 135 |
|
| 136 |
echo '{ "sucess_status":"1","messege":"'.__('updated successfully.','supportcandy').'" }'; |
| 137 |
|