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 / individual_ticket / set_clone_ticket.php

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

123 lines 3.5 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
8 if (
9 check_ajax_referer('set_clone_ticket', '_ajax_nonce', false) != 1
10 ) wp_send_json_error('Unauthorised request!', 400);
11
12 if (!($current_user->ID && $current_user->has_cap('wpsc_agent'))) {
13 exit;
14 }
15 $ticket_id = isset($_POST['ticket_id']) ? sanitize_text_field($_POST['ticket_id']) : '' ;
16 $subject = isset($_POST['subject']) ? stripslashes(sanitize_text_field($_POST['subject'])) : '';
17 $ticket = $wpscfunction->get_ticket($ticket_id);
18
19 $tickets =array();
20 foreach ($ticket as $key => $value) {
21 $tickets[$key] =$value;
22 }
23
24 $ip_address = isset($_SERVER) && isset($_SERVER['REMOTE_ADDR'])?$_SERVER['REMOTE_ADDR']:'';
25 if (strlen($ip_address)>28 || $ip_address == '::1') {
26 $ip_address = '';
27 }
28
29 $values = array(
30
31 'ticket_subject' => $subject,
32 'customer_name' => $tickets['customer_name'],
33 'customer_email' => $tickets['customer_email'],
34 'ticket_status' => $tickets['ticket_status'],
35 'ticket_category' => $tickets['ticket_category'],
36 'ticket_priority' => $tickets['ticket_priority'],
37 'date_created' => $tickets['date_created'],
38 'date_updated' => $tickets['date_updated'],
39 'agent_created' => $tickets['agent_created'],
40 'ip_address' => $ip_address,
41 );
42
43 $custom_fields = get_terms([
44 'taxonomy' => 'wpsc_ticket_custom_fields',
45 'hide_empty' => false,
46 'orderby' => 'meta_value_num',
47 'meta_key' => 'wpsc_tf_load_order',
48 'order' => 'ASC',
49 'meta_query' => array(
50 array(
51 'key' => 'agentonly',
52 'value' => array(0,1),
53 'compare' => 'IN'
54 )
55 ),
56 ]);
57
58 if($custom_fields){
59 foreach ($custom_fields as $field) {
60 $wpsc_tf_type = get_term_meta( $field->term_id, 'wpsc_tf_type',true);
61 if($wpsc_tf_type == 3 || $wpsc_tf_type==10){
62 $value = $wpscfunction->get_ticket_meta($ticket_id,$field->slug);
63 }
64 else {
65 $value = $wpscfunction->get_ticket_meta($ticket_id,$field->slug,true);
66 }
67 if($value){
68 $values[$field->slug]=$value;
69 }
70 }
71 }
72
73 $args = array(
74 'post_type' => 'wpsc_ticket_thread',
75 'post_status' => 'publish',
76 'order' => 'ASC',
77 'meta_query' => array(
78 array(
79 'key' => 'ticket_id',
80 'value' => $ticket_id,
81 'compare' => '='
82 ),
83 ),
84 );
85 $ticket_threads = get_posts($args);
86 $clone_ticket_id = $wpscfunction->create_clone_ticket($values);
87
88
89 foreach ($ticket_threads as $ticket_thread) {
90 $thread_type = get_post_meta( $ticket_thread->ID, 'thread_type', true);
91 if($thread_type=='log'){
92 continue;
93 }
94 $customer_name = get_post_meta( $ticket_thread->ID, 'customer_name', true);
95 $customer_email = get_post_meta( $ticket_thread->ID, 'customer_email', true);
96 $attachments = get_post_meta( $ticket_thread->ID, 'attachments', true);
97 if(!$attachments){
98 $attachments = '';
99 }
100 $thread_body = $ticket_thread->post_content;
101 $create_time = $ticket_thread->post_date;
102
103 $os_platform = $wpscfunction->get_os();
104 $browser = $wpscfunction->get_browser();
105
106 $thread_args = array(
107 'ticket_id' => $clone_ticket_id,
108 'reply_body' => $thread_body,
109 'customer_name' => $customer_name,
110 'customer_email' => $customer_email,
111 'attachments' => $attachments,
112 'thread_type' => $thread_type,
113 'create_time' => $create_time,
114 'ip_address' => $ip_address,
115 'reply_source' => 'browser' ,
116 'os' => $os_platform,
117 'browser' => $browser
118 );
119 $thread_id = $wpscfunction->submit_cloned_ticket_thread($thread_args);
120 }
121
122 echo json_encode($clone_ticket_id);
123 ?>