PluginProbe
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent / 3.3.9
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent v3.3.9
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 / custom-field-types / class-wpsc-df-customer-email.php

class-wpsc-df-customer-email.php in SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent 3.3.9, at includes/custom-field-types/class-wpsc-df-customer-email.php

404 lines 10.7 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_DF_Customer_Email' ) ) :
7
8 final class WPSC_DF_Customer_Email {
9
10 /**
11 * Slug for this custom field type
12 *
13 * @var string
14 */
15 public static $slug = 'df_customer_email';
16
17 /**
18 * Set whether this custom field type is of type date
19 *
20 * @var boolean
21 */
22 public static $is_date = false;
23
24 /**
25 * Set whether this custom field type has applicable to date range
26 *
27 * @var boolean
28 */
29 public static $has_date_range = false;
30
31 /**
32 * Set whether this custom field field type is system default (no fields can be created from it).
33 *
34 * @var boolean
35 */
36 public static $is_default = true;
37
38 /**
39 * Set whether this field type has extra information that can be used in ticket form, edit custom fields, etc.
40 *
41 * @var boolean
42 */
43 public static $has_extra_info = true;
44
45 /**
46 * Set whether this custom field type can accept personal info.
47 *
48 * @var boolean
49 */
50 public static $has_personal_info = true;
51
52 /**
53 * Set whether this custom field type has multiple values
54 *
55 * @var boolean
56 */
57 public static $has_multiple_val = false;
58
59 /**
60 * Set whether this custom field type has reference to other class
61 *
62 * @var boolean
63 */
64 public static $has_ref = false;
65
66 /**
67 * Reference class for this custom field type so that its value(s) return with object or array of objects automatically. Empty string indicate no reference.
68 *
69 * @var string
70 */
71 public static $ref_class = '';
72
73 /**
74 * Data type for column created in customer table
75 *
76 * @var string
77 */
78 public static $data_type = 'VARCHAR(200) NOT NULL';
79
80 /**
81 * Set whether fields created from this custom field type is allowed in create ticket form
82 *
83 * @var boolean
84 */
85 public static $is_ctf = true;
86
87 /**
88 * Set whether fields created from this custom field type is allowed in ticket list
89 *
90 * @var boolean
91 */
92 public static $is_list = true;
93
94 /**
95 * Set whether fields created from this custom field type is allowed in ticket filter
96 *
97 * @var boolean
98 */
99 public static $is_filter = false;
100
101 /**
102 * Set whether fields created from this custom field type can be given character limits
103 *
104 * @var boolean
105 */
106 public static $has_char_limit = false;
107
108 /**
109 * Set whether fields created from this custom field type has custom options set in options table
110 *
111 * @var boolean
112 */
113 public static $has_options = false;
114
115 /**
116 * Set whether fields created from this custom field type can be auto-filled
117 *
118 * @var boolean
119 */
120 public static $is_auto_fill = false;
121
122 /**
123 * Set whether fields created from this custom field type can be available for ticket list sorting
124 *
125 * @var boolean
126 */
127 public static $is_sort = true;
128
129 /**
130 * Set whether fields created from this custom field type can have placeholder
131 *
132 * @var boolean
133 */
134 public static $is_placeholder = true;
135
136 /**
137 * Set whether fields created from this custom field type is applicable for visibility conditions in create ticket form
138 *
139 * @var boolean
140 */
141 public static $is_visibility_conditions = false;
142
143 /**
144 * Set whether fields created from this custom field type is applicable for macros.
145 * Set false in order to avoid {{email}} to be listed. Customer email can be achived by {{customer_email}} macro.
146 *
147 * @var boolean
148 */
149 public static $has_macro = false;
150
151 /**
152 * Set whether fields of this custom field type is applicalbe for search on ticket list page.
153 *
154 * @var boolean
155 */
156 public static $is_search = false;
157
158 /**
159 * Initialize the class
160 *
161 * @return void
162 */
163 public static function init() {
164
165 // Get object of this class.
166 add_filter( 'wpsc_load_ref_classes', array( __CLASS__, 'load_ref_class' ) );
167
168 // TFF!
169 add_action( 'wpsc_js_validate_ticket_form', array( __CLASS__, 'js_validate_ticket_form' ) );
170 }
171
172 /**
173 * Load current class to reference classes
174 *
175 * @param array $classes - Associative array of class names indexed by its slug.
176 * @return array
177 */
178 public static function load_ref_class( $classes ) {
179
180 $classes[ self::$slug ] = array(
181 'class' => __CLASS__,
182 'save-key' => 'id',
183 );
184 return $classes;
185 }
186
187 /**
188 * Print ticket form field
189 *
190 * @param WPSC_Custom_Field $cf - Custom field object.
191 * @param array $tff - Array of ticket form field settings for this field.
192 * @return string
193 */
194 public static function print_tff( $cf, $tff ) {
195
196 $current_user = WPSC_Current_User::$current_user;
197 ob_start();
198 if ( ! $current_user->is_customer ) {
199 ?>
200
201 <div class="<?php echo esc_attr( WPSC_Functions::get_tff_classes( $cf, $tff ) ); ?>" data-cft="<?php echo esc_attr( self::$slug ); ?>">
202 <div class="wpsc-tff-label">
203 <span class="name"><?php echo esc_attr( $cf->name ); ?></span>
204 <?php
205 if ( $tff['is-required'] ) {
206 ?>
207 <span class="required-indicator">*</span>
208 <?php
209 }
210 ?>
211 </div>
212 <span class="extra-info"><?php echo esc_attr( $cf->extra_info ); ?></span>
213 <input
214 type="text"
215 class="<?php echo esc_attr( $cf->slug ); ?>"
216 name="<?php echo esc_attr( $cf->slug ); ?>"
217 placeholder="<?php echo esc_attr( $cf->placeholder_text ); ?>"
218 autocomplete="off"/>
219 </div>
220 <?php
221
222 } else {
223 ?>
224
225 <input
226 type="hidden"
227 class="<?php echo esc_attr( $cf->slug ); ?>"
228 name="<?php echo esc_attr( $cf->slug ); ?>"
229 value="<?php echo esc_attr( $current_user->customer->email ); ?>"/>
230 <?php
231 }
232
233 return ob_get_clean();
234 }
235
236 /**
237 * Validate this type field in create ticket
238 *
239 * @return void
240 */
241 public static function js_validate_ticket_form() {
242 ?>
243
244 case '<?php echo esc_attr( self::$slug ); ?>':
245 var val = customField.find('input').first().val().trim();
246 if (customField.hasClass('required') && !val) {
247 isValid = false;
248 alert(supportcandy.translations.req_fields_missing);
249 break;
250 }
251 if (val && !validateEmail(val)) {
252 isValid = false;
253 alert('<?php esc_attr_e( 'Invalid email address!', 'supportcandy' ); ?>');
254 break;
255 }
256 break;
257 <?php
258 echo PHP_EOL;
259 }
260
261 /**
262 * Return custom field value in $_POST
263 * Ignore phpcs nonce issue as we already checked where it is called from.
264 *
265 * @param string $slug - Custom field slug.
266 * @param mixed $cf - Custom field object or false.
267 * @return mixed
268 */
269 public static function get_tff_value( $slug, $cf = false ) {
270
271 $email = isset( $_POST[ $slug ] ) ? sanitize_text_field( wp_unslash( $_POST[ $slug ] ) ) : ''; // phpcs:ignore
272 if ( ! filter_var( $email, FILTER_VALIDATE_EMAIL ) ) {
273 $email = '';
274 }
275 return $email;
276 }
277
278 /**
279 * Return slug string to be used in where condition of ticket model for this type of field
280 *
281 * @param WPSC_Custom_Field $cf - custom field object.
282 * @return string
283 */
284 public static function get_sql_slug( $cf ) {
285
286 return 'c.' . $cf->slug;
287 }
288
289 /**
290 * Print edit custom field properties
291 *
292 * @param WPSC_Custom_Fields $cf - custom field object.
293 * @param string $field_class - class name of field category.
294 * @return void
295 */
296 public static function get_edit_custom_field_properties( $cf, $field_class ) {
297
298 if ( in_array( 'extra_info', $field_class::$allowed_properties ) ) :
299 ?>
300 <div data-type="textfield" data-required="false" class="wpsc-input-group extra-info">
301 <div class="label-container">
302 <label for=""><?php esc_attr_e( 'Extra info', 'supportcandy' ); ?></label>
303 </div>
304 <input name="extra_info" type="text" value="<?php echo esc_attr( $cf->extra_info ); ?>" autocomplete="off" />
305 </div>
306 <?php
307 endif;
308
309 if ( in_array( 'placeholder_text', $field_class::$allowed_properties ) ) :
310 ?>
311 <div data-type="textfield" data-required="false" class="wpsc-input-group placeholder_text">
312 <div class="label-container">
313 <label for="">
314 <?php esc_attr_e( 'Placeholder', 'supportcandy' ); ?>
315 </label>
316 </div>
317 <input type="text" name="placeholder_text" value="<?php echo esc_attr( $cf->placeholder_text ); ?>" autocomplete="off">
318 </div>
319 <?php
320 endif;
321
322 if ( in_array( 'tl_width', $field_class::$allowed_properties ) ) :
323 ?>
324 <div data-type="number" data-required="false" class="wpsc-input-group tl_width">
325 <div class="label-container">
326 <label for="">
327 <?php esc_attr_e( 'Ticket list width (pixels)', 'supportcandy' ); ?>
328 </label>
329 </div>
330 <input type="number" name="tl_width" value="<?php echo esc_attr( intval( $cf->tl_width ) ); ?>" autocomplete="off">
331 </div>
332 <?php
333 endif;
334 }
335
336 /**
337 * Set custom field properties. Can be used by add/edit custom field.
338 * Ignore phpcs nonce issue as we already checked where it is called from.
339 *
340 * @param WPSC_Custom_Field $cf - custom field object.
341 * @param string $field_class - class of field category.
342 * @return void
343 */
344 public static function set_cf_properties( $cf, $field_class ) {
345
346 // extra info.
347 if ( in_array( 'extra_info', $field_class::$allowed_properties ) ) {
348 $cf->extra_info = isset( $_POST['extra_info'] ) ? sanitize_text_field( wp_unslash( $_POST['extra_info'] ) ) : ''; // phpcs:ignore
349 }
350
351 // placeholder!
352 if ( in_array( 'placeholder_text', $field_class::$allowed_properties ) ) {
353 $cf->placeholder_text = isset( $_POST['placeholder_text'] ) ? sanitize_text_field( wp_unslash( $_POST['placeholder_text'] ) ) : ''; // phpcs:ignore
354 }
355
356 // tl_width!
357 if ( in_array( 'tl_width', $field_class::$allowed_properties ) ) {
358 $tl_width = isset( $_POST['tl_width'] ) ? intval( $_POST['tl_width'] ) : 0; // phpcs:ignore
359 $cf->tl_width = $tl_width ? $tl_width : 100;
360 }
361
362 // save!
363 $cf->save();
364 }
365
366 /**
367 * Return orderby string
368 *
369 * @param WPSC_Custom_Field $cf - custom field object.
370 * @return string
371 */
372 public static function get_orderby_string( $cf ) {
373
374 return 'c.' . $cf->slug;
375 }
376
377 /**
378 * Returns printable customer value for custom field. Can be used in export tickets, replace macros etc.
379 *
380 * @param WPSC_Custom_Field $cf - custom field object.
381 * @param WPSC_Customer $customer - customer object.
382 * @return string
383 */
384 public static function get_customer_field_val( $cf, $customer ) {
385
386 return $customer->email;
387 }
388
389 /**
390 * Print customer value for given custom field on ticket list
391 *
392 * @param WPSC_Custom_Field $cf - custom field object.
393 * @param WPSC_Customer $customer - customer object.
394 * @return void
395 */
396 public static function print_tl_customer_field_val( $cf, $customer ) {
397
398 echo esc_attr( self::get_customer_field_val( $cf, $customer ) );
399 }
400 }
401 endif;
402
403 WPSC_DF_Customer_Email::init();
404