PluginProbe
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent / 3.5.4
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent v3.5.4
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 / class-wpsc-aof.php

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

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