PluginProbe
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent / 2.3.1
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent v2.3.1
3.5.4 3.5.3 3.5.2 3.5.1 3.4.9 3.5.0 3.4.8 3.4.7 trunk 2.3.1 3.3.6 3.3.7 3.3.8 3.3.9 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6
supportcandy / includes / admin / custom_fields / set_edit_agentonly_field.php

set_edit_agentonly_field.php in SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent 2.3.1, at includes/admin/custom_fields/set_edit_agentonly_field.php

110 lines 4.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit; // Exit if accessed directly
4 }
5
6 if (
7 check_ajax_referer('set_edit_agentonly_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 $date_range = isset($_POST) && isset($_POST['date_range']) ? sanitize_text_field($_POST['date_range']) : '';
25 $date_range_from = isset($_POST) && isset($_POST['date_range_from']) ? sanitize_text_field($_POST['date_range_from']) : '';
26 $date_range_to = isset($_POST) && isset($_POST['date_range_to']) ? sanitize_text_field($_POST['date_range_to']) : '';
27
28 $field_type = isset($_POST) && isset($_POST['field_type']) ? intval($_POST['field_type']) : '';
29 if (!$field_type) {exit;}
30
31 $field_opt = isset($_POST) && isset($_POST['field_options']) ? sanitize_textarea_field($_POST['field_options']) : '';
32 $field_options = $field_opt ? explode("\n", $field_opt) : array();
33
34 $field_types = $wpscfunction->get_custom_field_types();
35 if ($field_types[$field_type]['has_options']==1 && !$field_options) {exit;}
36
37 foreach ($field_options as $key => $value) {
38 $field_options[$key] = trim(sanitize_text_field($value));
39 }
40
41 $time_format = isset($_POST) && isset($_POST['time_format']) ? intval($_POST['time_format']) : '12';
42
43 $old_tf_type = get_term_meta( $field_id, 'wpsc_tf_type', true);
44 $wpsc_limit = isset($_POST) && isset($_POST['limit']) && $_POST['limit'] ? sanitize_text_field($_POST['limit']) : '0';
45
46 $field_label = stripslashes($field_label);
47
48 update_term_meta ($field_id, 'wpsc_tf_label', $field_label);
49 update_term_meta ($field_id, 'wpsc_tf_extra_info', $extra_info);
50 update_term_meta ($field_id, 'wpsc_tf_type', $field_type);
51 update_term_meta ($field_id, 'wpsc_tf_options', $field_options);
52 update_term_meta ($field_id, 'wpsc_tf_personal_info', $personal_info);
53 update_term_meta ($field_id, 'wpsc_tf_limit', $wpsc_limit);
54 update_term_meta ($field_id, 'wpsc_date_range',$date_range);
55 update_term_meta ($field_id, 'date_range_from', $date_range_from);
56 update_term_meta ($field_id, 'date_range_to', $date_range_to);
57 update_term_meta($field_id, 'wpsc_time_format', $time_format);
58
59
60 if ($old_tf_type!=$field_type) {
61 if ($field_types[$field_type]['allow_ticket_list']) {
62 update_term_meta ($field_id, 'wpsc_allow_ticket_list', '1');
63 update_term_meta ($field_id, 'wpsc_customer_ticket_list_status', '0');
64 update_term_meta ($field_id, 'wpsc_agent_ticket_list_status', '0');
65 } else {
66 update_term_meta ($field_id, 'wpsc_allow_ticket_list', '0');
67 }
68 if ($field_types[$field_type]['allow_ticket_filter']) {
69 update_term_meta ($field_id, 'wpsc_allow_ticket_filter', '1');
70 update_term_meta ($field_id, 'wpsc_ticket_filter_type', $field_types[$field_type]['ticket_filter_type']);
71 update_term_meta ($field_id, 'wpsc_customer_ticket_filter_status', '0', '0');
72 update_term_meta ($field_id, 'wpsc_agent_ticket_filter_status', '0');
73 } else {
74 update_term_meta ($field_id, 'wpsc_allow_ticket_filter', '0');
75 }
76 if ($field_types[$field_type]['allow_orderby']) {
77 update_term_meta ($field_id, 'wpsc_allow_orderby', '1');
78 } else {
79 update_term_meta ($field_id, 'wpsc_allow_orderby', '0');
80 $agent_orderby = get_option('wpsc_tl_agent_orderby');
81 if($custom_field->slug == $agent_orderby){
82 update_option('wpsc_tl_agent_orderby', 'date_updated');
83 update_option('wpsc_tl_agent_orderby_order','DESC');
84 }
85 $customer_orderby = get_option('wpsc_tl_customer_orderby');
86 if($custom_field->slug == $customer_orderby){
87 update_option('wpsc_tl_customer_orderby', 'date_updated');
88 update_option('wpsc_tl_customer_orderby_order','DESC');
89 }
90 }
91 }
92
93 $custom_fields_localize = get_option('wpsc_custom_fields_localize');
94 if (!$custom_fields_localize) {
95 $custom_fields_localize = array();
96 }
97 $custom_fields_localize['custom_fields_'.$field_id] = $field_label;
98 update_option('wpsc_custom_fields_localize', $custom_fields_localize);
99
100 $custom_fields_extra_info = get_option('wpsc_custom_fields_extra_info');
101 if (!$custom_fields_extra_info) {
102 $custom_fields_extra_info = array();
103 }
104 $custom_fields_extra_info['custom_fields_extra_info_' . $field_id] = $extra_info;
105 update_option('wpsc_custom_fields_extra_info', $custom_fields_extra_info);
106
107 do_action('wpsc_set_edit_agentonly_field',$field_id);
108
109 echo '{ "sucess_status":"1","messege":"'.__('updated successfully.','supportcandy').'" }';
110