PluginProbe
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent / trunk
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent vtrunk
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 / class-wpsc-cf.php

class-wpsc-cf.php in SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent trunk, at includes/admin/custom-fields/class-wpsc-cf.php

211 lines 6.6 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 ( ! class_exists( 'WPSC_CF' ) ) :
7
8 final class WPSC_CF {
9
10 /**
11 * Allowed custom field properties
12 *
13 * @var array
14 */
15 public static $allowed_properties = array(
16 'extra_info',
17 'placeholder_text',
18 'char_limit',
19 'date_format',
20 'date_range',
21 'start_range',
22 'end_range',
23 'time_format',
24 'tl_width',
25 'allow_ticket_form',
26 'allow_my_profile',
27 'is_personal_info',
28 'number_type',
29 );
30
31 /**
32 * Initialize this class
33 */
34 public static function init() {
35
36 // Register this field category (ticket).
37 add_filter( 'wpsc_custom_field_categories', array( __CLASS__, 'register_field' ) );
38
39 // List.
40 add_action( 'wp_ajax_wpsc_get_customer_fields', array( __CLASS__, 'get_customer_fields' ) );
41
42 // Filter custom field types for new custom field.
43 add_filter( 'wpsc_add_new_custom_field_cf_types', array( __CLASS__, 'filter_cf_types' ), 10, 2 );
44 }
45
46 /**
47 * Register field category
48 *
49 * @param array $fields - customer fields.
50 * @return array
51 */
52 public static function register_field( $fields ) {
53
54 $fields['customer'] = __CLASS__;
55 return $fields;
56 }
57
58 /**
59 * Get customer fields
60 *
61 * @return void
62 */
63 public static function get_customer_fields() {
64
65 if ( ! WPSC_Functions::is_site_admin() ) {
66 wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 );
67 }
68 $custom_fields_types = array_merge( WPSC_Custom_Field::$cf_types, WPSC_Custom_Field::$default_cf_types );
69 ?>
70
71 <div class="wpsc-setting-header">
72 <h2><?php esc_attr_e( 'Customer Fields', 'supportcandy' ); ?></h2>
73 </div>
74 <div class="wpsc-setting-section-body">
75 <div class="wpsc-dock-container">
76 <?php
77 printf(
78 /* translators: Click here to see the documentation */
79 esc_attr__( '%s to see the documentation!', 'supportcandy' ),
80 '<a href="https://supportcandy.net/docs/customer-fields/" target="_blank">' . esc_attr__( 'Click here', 'supportcandy' ) . '</a>'
81 );
82 ?>
83 </div>
84 <table class="ticket-fields wpsc-setting-tbl">
85 <thead>
86 <tr>
87 <th style="width: 30px;"><?php esc_attr_e( 'Sort', 'supportcandy' ); ?></th>
88 <th><?php esc_attr_e( 'Field', 'supportcandy' ); ?></th>
89 <th><?php esc_attr_e( 'Extra info', 'supportcandy' ); ?></th>
90 <th><?php esc_attr_e( 'Type', 'supportcandy' ); ?></th>
91 <th><?php esc_attr_e( 'Auto Fill', 'supportcandy' ); ?></th>
92 <th><?php esc_attr_e( 'Personal Info', 'supportcandy' ); ?></th>
93 <th><?php esc_attr_e( 'Allow in My Profile', 'supportcandy' ); ?></th>
94 <th><?php esc_attr_e( 'Allow in Ticket Form', 'supportcandy' ); ?></th>
95 <th><?php esc_attr_e( 'Actions', 'supportcandy' ); ?></th>
96 </tr>
97 </thead>
98 <tbody>
99 <?php
100 foreach ( WPSC_Custom_Field::$custom_fields as $cf ) {
101 if ( $cf->field != 'customer' ) {
102 continue;
103 }
104 ?>
105 <tr data-id="<?php echo esc_attr( $cf->id ); ?>">
106 <td class="sort-handle"><?php WPSC_Icons::get( 'sort' ); ?></td>
107 <td><?php echo esc_attr( $cf->name ); ?></td>
108 <td><?php echo esc_attr( $cf->extra_info ); ?></td>
109 <td><?php echo esc_attr( $custom_fields_types[ $cf->type::$slug ]['label'] ); ?></td>
110 <td><?php echo esc_attr( $cf->is_auto_fill ? __( 'Yes', 'supportcandy' ) : __( 'No', 'supportcandy' ) ); ?></td>
111 <td><?php echo esc_attr( $cf->is_personal_info ? __( 'Yes', 'supportcandy' ) : __( 'No', 'supportcandy' ) ); ?></td>
112 <td><?php echo esc_attr( $cf->allow_my_profile ? __( 'Yes', 'supportcandy' ) : __( 'No', 'supportcandy' ) ); ?></td>
113 <td><?php echo esc_attr( $cf->allow_ticket_form ? __( 'Yes', 'supportcandy' ) : __( 'No', 'supportcandy' ) ); ?></td>
114 <td>
115 <span class="wpsc-link" onclick="wpsc_get_edit_custom_field(<?php echo esc_attr( $cf->id ); ?>, '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_edit_custom_field' ) ); ?>');"><?php esc_attr_e( 'Edit', 'supportcandy' ); ?></span>
116 <?php
117 if ( ! $cf->type::$is_default ) {
118 echo esc_attr( ' | ' );
119 ?>
120 <span class="wpsc-link" onclick="wpsc_delete_custom_field(<?php echo esc_attr( $cf->id ); ?>, '<?php echo esc_attr( wp_create_nonce( 'wpsc_delete_custom_field' ) ); ?>');"><?php esc_attr_e( 'Delete', 'supportcandy' ); ?></span>
121 <?php
122 }
123 ?>
124 </td>
125 </tr>
126 <?php
127 }
128 ?>
129 </tbody>
130 </table>
131 <script>
132 jQuery('table.ticket-fields').DataTable({
133 ordering: false,
134 autoWidth: false,
135 pageLength: 20,
136 bLengthChange: false,
137 columnDefs: [
138 { targets: 0, width: '30px', searchable: false },
139 { targets: -1, searchable: false },
140 { targets: '_all', className: 'dt-left' }
141 ],
142 layout: {
143 topStart: {
144 buttons: [
145 {
146 text: '<?php esc_attr_e( 'Add new', 'supportcandy' ); ?>',
147 className: 'wpsc-button small primary',
148 action: function ( e, dt, node, config ) {
149 wpsc_get_add_new_custom_field('customer', '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_add_new_custom_field' ) ); ?>');
150 }
151 }
152 ],
153 },
154 },
155 language: supportcandy.translations.datatables
156 });
157
158 jQuery(function() {
159 // Enable sorting with jQuery UI.
160 jQuery('table.ticket-fields tbody').sortable({
161 handle: '.sort-handle',
162 helper: function(e, tr) {
163 var $originals = tr.children();
164 var $helper = tr.clone();
165 $helper.children().each(function(index) {
166 jQuery(this).width($originals.eq(index).width());
167 });
168 return $helper;
169 },
170 update: function(event, ui) {
171 var ids = jQuery(this).sortable('toArray', { attribute: 'data-id' });
172 jQuery.post(
173 supportcandy.ajax_url,
174 {
175 action: 'wpsc_set_custom_field_load_order',
176 _ajax_nonce: '<?php echo esc_attr( wp_create_nonce( 'wpsc_set_custom_field_load_order' ) ); ?>',
177 ids: ids
178 },
179 function(response) {
180
181 }
182 );
183 }
184 });
185 });
186 </script>
187 </div>
188 <?php
189 wp_die();
190 }
191
192 /**
193 * Filter out unwanted custom field types from add new custom field section for customer fields
194 *
195 * @param array $cf_types - cf_types.
196 * @param string $field - custom field category (ticket, agentonly, customer, etc.).
197 * @return array
198 */
199 public static function filter_cf_types( $cf_types, $field ) {
200
201 if ( $field == 'customer' && in_array( 'cf_html', array_keys( $cf_types ) ) ) {
202 unset( $cf_types['cf_html'] );
203 }
204
205 return $cf_types;
206 }
207 }
208 endif;
209
210 WPSC_CF::init();
211