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-tf.php

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

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