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 / tickets / create_ticket / submit_ticket.php

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

183 lines 5.9 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 global $current_user, $wpscfunction;
7 $wpsc_captcha = get_option('wpsc_captcha',0);
8 $wpsc_guest_can_upload_files = get_option('wpsc_guest_can_upload_files');
9
10 if($wpsc_captcha){
11
12 $wpsc_recaptcha_type = get_option('wpsc_recaptcha_type');
13
14 if($wpsc_recaptcha_type){
15
16 $captcha_key = isset($_COOKIE) && isset($_COOKIE['wpsc_secure_code']) ? intval($_COOKIE['wpsc_secure_code']) : 0;
17 if( !isset($_POST['captcha_code']) || !wp_verify_nonce($_POST['captcha_code'],$captcha_key) ){
18 die(__('Cheating huh?', 'supportcandy'));
19 }
20
21 } else {
22
23 $captcha = isset($_POST['g-recaptcha-response']) ? $_POST['g-recaptcha-response'] : '';
24 if (!$captcha) die(__('Cheating huh?', 'supportcandy'));
25
26 $secretKey = get_option('wpsc_get_secret_key');
27 $ip = $_SERVER['REMOTE_ADDR'];
28
29 $response = wp_remote_get("https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&response=".$captcha."&remoteip=".$ip);
30 $body = !is_wp_error($response) ? json_decode(wp_remote_retrieve_body($response)) : false;
31 if (!$body || intval($body->success) !== 1) {
32 die(__('Cheating huh?', 'supportcandy'));
33 }
34 }
35 setcookie('wpsc_secure_code','123');
36 }
37
38 //check allow create ticket permission
39 $wpsc_allow_to_create_ticket = get_option('wpsc_allow_to_create_ticket');
40 $allow_create = false;
41 if(is_user_logged_in() && $current_user->has_cap('wpsc_agent')){ //agent
42 $cu_role_id = get_user_option('wpsc_agent_role', $current_user->ID);
43 }elseif(is_user_logged_in() && !$current_user->has_cap('wpsc_agent')){ //customer
44 $cu_role_id = 'customer';
45 }else{
46 $customer_email = isset($_POST['customer_email']) ? sanitize_email($_POST['customer_email']) : '';
47 $user = get_user_by('email', $customer_email);
48 if($user){
49 if($user->has_cap('wpsc_agent')){
50 $cu_role_id = get_user_option('wpsc_agent_role', $user->ID);
51 }else{
52 $cu_role_id = 'customer';
53 }
54 }else{
55 $cu_role_id = 'guest';
56 }
57 }
58 if( !in_array($cu_role_id, $wpsc_allow_to_create_ticket)){
59 die(__('Cheating huh? Not allowed to create ticket.', 'supportcandy'));
60 }
61
62
63 $args = array();
64
65 // Customer name
66 if(is_user_logged_in() && !$current_user->has_cap('wpsc_agent') ){
67 $customer_name = $current_user->display_name;
68 }else{
69 $customer_name = isset($_POST['customer_name']) ? sanitize_text_field($_POST['customer_name']) : '';
70 }
71 $args['customer_name'] = $customer_name;
72
73 // Customer email
74 if(is_user_logged_in() && !$current_user->has_cap('wpsc_agent') ){
75 $customer_email = $current_user->user_email;
76 $args['customer_email'] = $customer_email;
77 }else{
78 $customer_email = isset($_POST['customer_email']) ? sanitize_email($_POST['customer_email']) : '';
79 $args['customer_email'] = $customer_email;
80 }
81
82 // Subject
83 $ticket_subject = isset($_POST['ticket_subject']) ? sanitize_text_field($_POST['ticket_subject']) : '';
84 if($ticket_subject) $args['ticket_subject'] = $ticket_subject;
85
86 // Description
87 $ticket_description = isset($_POST['ticket_description']) ? wp_kses_post(htmlspecialchars_decode($_POST['ticket_description'], ENT_QUOTES)) : '';
88 if($ticket_description) $args['ticket_description'] = $ticket_description;
89 if(is_user_logged_in() || $wpsc_guest_can_upload_files ){
90 $description_attachment = isset($_POST['desc_attachment']) ? $wpscfunction->sanitize_array($_POST['desc_attachment']) : array();
91 if($description_attachment) $args['desc_attachment'] = $description_attachment;
92 }
93
94 // Category
95 $ticket_category = isset($_POST['ticket_category']) ? intval($_POST['ticket_category']) : '';
96 if($ticket_category) $args['ticket_category'] = $ticket_category;
97
98 // Priority
99 $ticket_priority = isset($_POST['ticket_priority']) ? intval($_POST['ticket_priority']) : '';
100 if($ticket_priority) $args['ticket_priority'] = $ticket_priority;
101
102 // Custom fields
103 $fields = get_terms([
104 'taxonomy' => 'wpsc_ticket_custom_fields',
105 'hide_empty' => false,
106 'orderby' => 'meta_value_num',
107 'meta_key' => 'wpsc_tf_load_order',
108 'order' => 'ASC',
109 'meta_query' => array(
110 'relation' => 'AND',
111 array(
112 'key' => 'agentonly',
113 'value' => '0',
114 'compare' => '='
115 ),
116 array(
117 'key' => 'wpsc_tf_type',
118 'value' => '0',
119 'compare' => '>'
120 ),
121 ),
122 ]);
123 foreach ($fields as $field) {
124 $tf_type = get_term_meta( $field->term_id, 'wpsc_tf_type', true);
125 switch ($tf_type) {
126 case '1':
127 case '2':
128 case '4':
129 case '6':
130 case '7':
131 case '8':
132 case '18':
133 $text = isset($_POST[$field->slug]) ? sanitize_text_field($_POST[$field->slug]) : '';
134 if($text) $args[$field->slug] = $text;
135 break;
136
137 case '3':
138 case '10':
139 $arrVal = isset($_POST[$field->slug]) ? $wpscfunction->sanitize_array($_POST[$field->slug]) : array();
140 if($arrVal) $args[$field->slug] = $wpscfunction->sanitize_array($arrVal);
141 break;
142
143 case '5':
144 $text = isset($_POST[$field->slug]) ? wp_kses_post(htmlspecialchars_decode($_POST[$field->slug], ENT_QUOTES)) : '';
145 if($text) $args[$field->slug] = $text;
146 break;
147
148 case '9':
149 $number = isset($_POST[$field->slug]) ? intval($_POST[$field->slug]) : '';
150 if($number) $args[$field->slug] = $number;
151 break;
152
153 case '21':
154 $text = isset($_POST[$field->slug]) ? sanitize_text_field($_POST[$field->slug]) : '';
155 if($text) $args[$field->slug] = date("H:i:s " ,strtotime($text));
156 break;
157
158 default:
159 $args = apply_filters('wpsc_after_create_ticket_custom_field',$args,$field,$tf_type);
160 break;
161 }
162 }
163
164 $args = apply_filters( 'wpsc_before_create_ticket_args', $args);
165
166 $ticket_id = $wpscfunction->create_ticket($args);
167 $thankyou_html = $wpscfunction->replace_macro(get_option('wpsc_thankyou_html'),$ticket_id);
168 $thankyou_html = apply_filters('wpsc_after_thankyou_page_button',$thankyou_html,$ticket_id);
169
170 ob_start();
171 ?>
172 <div class="col-sm-12" style="margin-top:20px;">
173 <?php echo wp_kses_post($thankyou_html)?>
174 </div>
175 <?php
176 $thankyou_html = ob_get_clean();
177
178 $response = array(
179 'redirct_url' => get_option('wpsc_thankyou_url'),
180 'thank_you_page' => $thankyou_html,
181 );
182
183 echo json_encode($response);