PluginProbe
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent / 3.5.2
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent v3.5.2
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-cf-text-field.php

class-wpsc-cf-text-field.php in SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent 3.5.2, at includes/custom-field-types/class-wpsc-cf-text-field.php

1,497 lines 44.8 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_Text_Field' ) ) :
7
8 final class WPSC_CF_Text_Field {
9
10 /**
11 * Slug for this custom field type
12 *
13 * @var string
14 */
15 public static $slug = 'cf_textfield';
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 type has multiple values
33 *
34 * @var boolean
35 */
36 public static $has_multiple_val = false;
37
38 /**
39 * Data type for column created in tickets table
40 *
41 * @var string
42 */
43 public static $data_type = 'TINYTEXT NULL';
44
45 /**
46 * Set whether this custom field type has reference to other class
47 *
48 * @var boolean
49 */
50 public static $has_ref = false;
51
52 /**
53 * 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.
54 *
55 * @var string
56 */
57 public static $ref_class = '';
58
59 /**
60 * Set whether this custom field field type is system default (no fields can be created from it).
61 *
62 * @var boolean
63 */
64 public static $is_default = false;
65
66 /**
67 * Set whether this field type has extra information that can be used in ticket form, edit custom fields, etc.
68 *
69 * @var boolean
70 */
71 public static $has_extra_info = true;
72
73 /**
74 * Set whether this custom field type can accept personal info.
75 *
76 * @var boolean
77 */
78 public static $has_personal_info = true;
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 = true;
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 = true;
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 = true;
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 = true;
142
143 /**
144 * Set whether fields created from this custom field type is applicable for macros
145 *
146 * @var boolean
147 */
148 public static $has_macro = true;
149
150 /**
151 * Set whether fields of this custom field type is applicalbe for search on ticket list page.
152 *
153 * @var boolean
154 */
155 public static $is_search = true;
156
157 /**
158 * Initialize the class
159 *
160 * @return void
161 */
162 public static function init() {
163
164 // Get object of this class.
165 add_filter( 'wpsc_load_ref_classes', array( __CLASS__, 'load_ref_class' ) );
166
167 // Set custom field type.
168 add_filter( 'wpsc_cf_types', array( __CLASS__, 'add_cf_type' ), 1 );
169
170 // ticket form.
171 add_action( 'wpsc_js_validate_ticket_form', array( __CLASS__, 'js_validate_ticket_form' ) );
172 add_filter( 'wpsc_create_ticket_data', array( __CLASS__, 'set_create_ticket_data' ), 10, 3 );
173 add_action( 'wpsc_js_clear_value_hidden_fields', array( __CLASS__, 'js_clear_value_hidden_fields' ) );
174
175 // create ticket data for rest api.
176 add_filter( 'wpsc_rest_create_ticket', array( __CLASS__, 'set_rest_ticket_data' ), 10, 3 );
177
178 // Ticket model.
179 add_filter( 'wpsc_ticket_search', array( __CLASS__, 'ticket_search' ), 10, 5 );
180 add_filter( 'wpsc_archive_ticket_search', array( __CLASS__, 'ticket_search' ), 10, 5 );
181 }
182
183 /**
184 * Load current class to reference classes
185 *
186 * @param array $classes - Associative array of class names indexed by its slug.
187 * @return array
188 */
189 public static function load_ref_class( $classes ) {
190
191 $classes[ self::$slug ] = array(
192 'class' => __CLASS__,
193 'save-key' => 'id',
194 );
195 return $classes;
196 }
197
198 /**
199 * Add custom field type to list
200 *
201 * @param array $cf_types - custom field types array.
202 * @return array
203 */
204 public static function add_cf_type( $cf_types ) {
205
206 $cf_types[ self::$slug ] = array(
207 'label' => esc_attr__( 'Textfield', 'supportcandy' ),
208 'class' => __CLASS__,
209 );
210 return $cf_types;
211 }
212
213 /**
214 * Print operators for ticket form filter
215 *
216 * @param WPSC_Custom_Field $cf - custom field object.
217 * @param array $filter - Existing filters (if any).
218 * @return void
219 */
220 public static function get_operators( $cf, $filter = array() ) {
221 ?>
222
223 <div class="item conditional">
224 <select class="operator" onchange="wpsc_tc_get_operand(this, '<?php echo esc_attr( $cf->slug ); ?>', '<?php echo esc_attr( wp_create_nonce( 'wpsc_tc_get_operand' ) ); ?>');">
225 <option value=""><?php esc_attr_e( 'Compare As', 'supportcandy' ); ?></option>
226 <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], '=' ); ?> value="="><?php esc_attr_e( 'Equals', 'supportcandy' ); ?></option>
227 <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], 'IN' ); ?> value="IN"><?php esc_attr_e( 'Matches', 'supportcandy' ); ?></option>
228 <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], 'NOT IN' ); ?> value="NOT IN"><?php esc_attr_e( 'Not Matches', 'supportcandy' ); ?></option>
229 <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], 'LIKE' ); ?> value="LIKE"><?php esc_attr_e( 'Has Words', 'supportcandy' ); ?></option>
230 </select>
231 </div>
232 <?php
233 }
234
235 /**
236 * Print operators for ticket form filter
237 *
238 * @param string $operator - condition operator on which operands should be returned.
239 * @param WPSC_Custom_Field $cf - custom field object.
240 * @param array $filter - Exising functions (if any).
241 * @return void
242 */
243 public static function get_operands( $operator, $cf, $filter = array() ) {
244
245 $value = isset( $filter['operand_val_1'] ) ? stripslashes( $filter['operand_val_1'] ) : '';
246 if ( in_array( $operator, array( 'IN', 'NOT IN', 'LIKE' ) ) ) {
247 ?>
248
249 <div class="item conditional operand single">
250 <textarea class="operand_val_1" placeholder="<?php esc_attr_e( 'One condition per line!', 'supportcandy' ); ?>" style="width: 100%;"><?php echo esc_attr( $value ); ?></textarea>
251 </div>
252 <?php
253
254 } else {
255 ?>
256
257 <div class="item conditional operand single">
258 <input
259 type="text"
260 class="operand_val_1"
261 value="<?php echo esc_attr( $value ); ?>"
262 autocomplete="off"/>
263 </div>
264 <?php
265 }
266 }
267
268 /**
269 * Check condition for this type
270 *
271 * @param array $condition - condition data.
272 * @param WPSC_Custom_Field $cf - custom field object.
273 * @param mixed $value - value to compare.
274 * @return boolean
275 */
276 public static function is_valid( $condition, $cf, $value ) {
277
278 $response = false;
279 $value = stripslashes( $value );
280 $terms = explode( PHP_EOL, $condition['operand_val_1'] );
281 switch ( $condition['operator'] ) {
282
283 case '=':
284 $response = $condition['operand_val_1'] == $value ? true : false;
285 break;
286
287 case 'IN':
288 foreach ( $terms as $term ) {
289 $term = trim( $term );
290 if ( $term == $value ) {
291 $response = true;
292 break;
293 }
294 }
295 break;
296
297 case 'NOT IN':
298 $response = true;
299 foreach ( $terms as $term ) {
300 $term = trim( $term );
301 if ( $term == $value ) {
302 $response = false;
303 break;
304 }
305 }
306 break;
307
308 case 'LIKE':
309 $response = false;
310 foreach ( $terms as $term ) {
311 $index = strpos( $value, trim( stripslashes( $term ) ) );
312 if ( is_numeric( $index ) ) {
313 $response = true;
314 break;
315 }
316 }
317 break;
318 }
319 return $response;
320 }
321
322 /**
323 * Parse filter and return sql query to be merged in ticket model query builder
324 *
325 * @param WPSC_Custom_Field $cf - custom field of this type.
326 * @param mixed $compare - comparison operator.
327 * @param mixed $val - value to compare.
328 * @return string
329 */
330 public static function parse_filter( $cf, $compare, $val ) {
331
332 global $wpdb;
333
334 $column = self::get_sql_slug( $cf );
335
336 switch ( $compare ) {
337
338 case '=':
339 return $wpdb->prepare(
340 "{$column} = %s",
341 (string) $val
342 );
343
344 case 'IN':
345 case 'NOT IN':
346 if ( ! is_array( $val ) || empty( $val ) ) {
347 return '1=0';
348 }
349
350 $placeholders = array_fill( 0, count( $val ), '%s' );
351
352 return $wpdb->prepare(
353 "CONVERT({$column} USING utf8) {$compare} (" . implode( ',', $placeholders ) . ')',
354 $val
355 );
356
357 case 'LIKE':
358 $terms = explode( PHP_EOL, (string) $val );
359 $sql = array();
360 $args = array();
361
362 foreach ( $terms as $term ) {
363 $term = trim( $term );
364 if ( $term === '' ) {
365 continue;
366 }
367
368 $term = str_replace( '*', '%', $term );
369 $term = '%' . $wpdb->esc_like( $term ) . '%';
370
371 $sql[] = "CONVERT({$column} USING utf8) LIKE %s";
372 $args[] = $term;
373 }
374
375 if ( empty( $sql ) ) {
376 return '1=0';
377 }
378
379 return $wpdb->prepare(
380 '(' . implode( ' OR ', $sql ) . ')',
381 $args
382 );
383
384 default:
385 return '1=1';
386 }
387 }
388
389 /**
390 * Return orderby string
391 *
392 * @param WPSC_Custom_Field $cf - custom field object.
393 * @return string
394 */
395 public static function get_orderby_string( $cf ) {
396
397 return self::get_sql_slug( $cf );
398 }
399
400 /**
401 * Check ticket condition
402 *
403 * @param array $condition - array with condition data.
404 * @param WPSC_Custom_Field $cf - custom field object.
405 * @param WPSC_Ticket $ticket - ticket object.
406 * @return boolean
407 */
408 public static function is_valid_ticket_condition( $condition, $cf, $ticket ) {
409
410 $flag = true;
411 $value = stripslashes( $ticket->{$cf->slug} );
412 $terms = explode( PHP_EOL, $condition['operand_val_1'] );
413
414 switch ( $condition['operator'] ) {
415
416 case '=':
417 $flag = $condition['operand_val_1'] == $value ? true : false;
418 break;
419
420 case 'IN':
421 $flag = false;
422 foreach ( $terms as $term ) {
423 $term = trim( $term );
424 if ( $term == $value ) {
425 $flag = true;
426 break;
427 }
428 }
429 break;
430
431 case 'NOT IN':
432 foreach ( $terms as $term ) {
433 $term = trim( $term );
434 if ( $term == $value ) {
435 $flag = false;
436 break;
437 }
438 }
439 break;
440
441 case 'LIKE':
442 $flag = false;
443 foreach ( $terms as $term ) {
444 $index = strpos( $value, trim( stripslashes( $term ) ) );
445 if ( is_numeric( $index ) ) {
446 $flag = true;
447 break;
448 }
449 }
450 break;
451
452 default:
453 $flag = true;
454 }
455
456 return $flag;
457 }
458
459 /**
460 * Check customer condition
461 *
462 * @param array $condition - array with condition data.
463 * @param WPSC_Custom_Field $cf - custom field object.
464 * @param WPSC_Customer $customer - customer object.
465 * @return boolean
466 */
467 public static function is_valid_customer_condition( $condition, $cf, $customer ) {
468
469 $flag = true;
470 $value = stripslashes( $customer->{$cf->slug} );
471 $terms = explode( PHP_EOL, $condition['operand_val_1'] );
472
473 switch ( $condition['operator'] ) {
474
475 case '=':
476 $flag = $condition['operand_val_1'] == $value ? true : false;
477 break;
478
479 case 'IN':
480 $flag = false;
481 foreach ( $terms as $term ) {
482 $term = trim( $term );
483 if ( $term == $value ) {
484 $flag = true;
485 break;
486 }
487 }
488 break;
489
490 case 'NOT IN':
491 foreach ( $terms as $term ) {
492 $term = trim( $term );
493 if ( $term == $value ) {
494 $flag = false;
495 break;
496 }
497 }
498 break;
499
500 case 'LIKE':
501 $flag = false;
502 foreach ( $terms as $term ) {
503 $index = strpos( $value, trim( stripslashes( $term ) ) );
504 if ( is_numeric( $index ) ) {
505 $flag = true;
506 break;
507 }
508 }
509 break;
510
511 default:
512 $flag = true;
513 }
514
515 return $flag;
516 }
517
518 /**
519 * Print ticket form field
520 *
521 * @param WPSC_Custom_Field $cf - Custom field object.
522 * @param array $tff - Array of ticket form field settings for this field.
523 * @return string
524 */
525 public static function print_tff( $cf, $tff ) {
526
527 $val = '';
528 if ( $cf->field == 'ticket' ) {
529 $val = $cf->is_auto_fill && $cf->default_value ? $cf->default_value[0] : '';
530 } else {
531 $current_user = WPSC_Current_User::$current_user;
532 $val = $current_user->is_customer && $current_user->customer->{$cf->slug} ? $current_user->customer->{$cf->slug} : '';
533 }
534 $val = apply_filters( 'wpsc_default_text_field_value', $val, $cf, $tff );
535
536 ob_start();
537 ?>
538 <div class="<?php echo esc_attr( WPSC_Functions::get_tff_classes( $cf, $tff ) ); ?>" data-cft="<?php echo esc_attr( self::$slug ); ?>" data-slug="<?php echo esc_attr( $cf->slug ); ?>">
539 <div class="wpsc-tff-label">
540 <span class="name"><?php echo esc_attr( $cf->name ); ?></span>
541 <?php
542 if ( $tff['is-required'] ) {
543 ?>
544 <span class="required-indicator">*</span>
545 <?php
546 }
547 ?>
548 </div>
549 <span class="extra-info"><?php echo esc_attr( $cf->extra_info ); ?></span>
550 <input
551 type="text"
552 name="<?php echo esc_attr( $cf->slug ); ?>"
553 placeholder="<?php echo esc_attr( $cf->placeholder_text ); ?>"
554 onchange="wpsc_check_tff_visibility()"
555 maxlength="<?php echo $cf->char_limit && $cf->char_limit < 255 ? intval( $cf->char_limit ) : '255'; ?>"
556 value="<?php echo esc_attr( $val ); ?>"
557 autocomplete="off"/>
558 </div>
559 <?php
560 return ob_get_clean();
561 }
562
563 /**
564 * Validate this type field in create ticket
565 *
566 * @return void
567 */
568 public static function js_validate_ticket_form() {
569 ?>
570
571 case '<?php echo esc_attr( self::$slug ); ?>':
572 var val = customField.find('input').first().val().trim();
573 if (isRequired && !val) {
574 isValid = false;
575 }
576 break;
577 <?php
578 echo PHP_EOL;
579 }
580
581 /**
582 * Return custom field value in $_POST
583 * Ignore phpcs nonce issue as we already checked where it is called from.
584 *
585 * @param string $slug - Custom field slug.
586 * @param mixed $cf - Custom field object or false.
587 * @return mixed
588 */
589 public static function get_tff_value( $slug, $cf = false ) {
590
591 return isset( $_POST[ $slug ] ) ? sanitize_text_field( wp_unslash( $_POST[ $slug ] ) ) : ''; // phpcs:ignore
592 }
593
594 /**
595 * Return default value for custom field of this type
596 *
597 * @param WPSC_Custom_Field $cf - custom field object.
598 * @return mixed
599 */
600 public static function get_default_value( $cf ) {
601
602 return $cf->default_value ? $cf->default_value[0] : '';
603 }
604
605 /**
606 * Check and return custom field value for new ticket to be created.
607 * This function is used by filter for set create ticket form and called directly by my-profile for each applicable custom fields.
608 * Ignore phpcs nonce issue as we already checked where it is called from.
609 *
610 * @param array $data - Array of values to to stored in ticket in an insert function.
611 * @param array $custom_fields - Array containing all applicable custom fields indexed by unique custom field types.
612 * @param boolean $is_my_profile - Whether it or not it is created from my-profile. This function is used by create ticket as well as my-profile. Due to customer fields handling is done same way, this flag gives apportunity to identify where it being called.
613 * @return array
614 */
615 public static function set_create_ticket_data( $data, $custom_fields, $is_my_profile ) {
616
617 if ( isset( $custom_fields[ self::$slug ] ) ) {
618 foreach ( $custom_fields[ self::$slug ] as $cf ) {
619 $value = self::get_tff_value( $cf->slug );
620 $limit = $cf->char_limit && $cf->char_limit < 255 ? $cf->char_limit : 255;
621 $value = substr( $value, 0, $limit );
622
623 if (
624 $cf->char_limit && mb_strlen( $value ) > $cf->char_limit
625 ) {
626 wp_send_json_error( new WP_Error( 'WPSC_CF_Text_Field', 'Character limit exceed!!' ), 400 );
627 }
628
629 if ( $cf->field == 'ticket' ) {
630
631 $default_val = self::get_default_value( $cf );
632 $data[ $cf->slug ] = $value ? $value : $default_val;
633
634 } elseif ( $cf->field == 'agentonly' ) {
635
636 $data[ $cf->slug ] = self::get_default_value( $cf );
637
638 } elseif ( $cf->field == 'customer' && $data['customer'] != 0 ) {
639
640 $tff = get_option( 'wpsc-tff' );
641 if ( ! $is_my_profile && ! isset( $tff[ $cf->slug ] ) ) {
642 continue;
643 }
644 $customer = new WPSC_Customer( $data['customer'] );
645 $prev_val = $customer->{$cf->slug} ? $customer->{$cf->slug} : '';
646 if ( $prev_val != $value ) {
647 $customer->{$cf->slug} = $value;
648 $customer->save();
649
650 // Set log for this change.
651 WPSC_Log::insert(
652 array(
653 'type' => 'customer',
654 'ref_id' => $customer->id,
655 'modified_by' => WPSC_Current_User::$current_user->customer->id,
656 'body' => wp_json_encode(
657 array(
658 'slug' => $cf->slug,
659 'prev' => $prev_val,
660 'new' => $value,
661 )
662 ),
663 'date_created' => ( new DateTime() )->format( 'Y-m-d H:i:s' ),
664 )
665 );
666 }
667 }
668 }
669 }
670 return $data;
671 }
672
673 /**
674 * Set create ticket data for rest api request
675 *
676 * @param array $data - create ticket data array.
677 * @param WP_REST_Request $request - rest request object.
678 * @param array $custom_fields - custom field objects indexed by unique custom field types.
679 * @return array
680 */
681 public static function set_rest_ticket_data( $data, $request, $custom_fields ) {
682
683 $current_user = WPSC_Current_User::$current_user;
684 $tff = get_option( 'wpsc-tff' );
685
686 if ( isset( $custom_fields[ self::$slug ] ) ) {
687 foreach ( $custom_fields[ self::$slug ] as $cf ) {
688
689 if (
690 ! in_array( $cf->field, array( 'ticket', 'agentonly', 'customer' ) ) ||
691 ( $cf->field == 'customer' && ! isset( $tff[ $cf->slug ] ) )
692 ) {
693 continue;
694 }
695
696 $value = sanitize_text_field( $request->get_param( $cf->slug ) );
697
698 if ( in_array( $cf->field, array( 'ticket', 'agentonly' ) ) ) {
699
700 $data[ $cf->slug ] = $cf->field == 'ticket' && $value ? $value : self::get_default_value( $cf );
701
702 } else {
703
704 $customer = new WPSC_Customer( $data['customer'] );
705 $existing_val = $customer->{$cf->slug};
706
707 if ( $value && $value != $existing_val ) {
708
709 $customer->{$cf->slug} = $value;
710 $customer->save();
711
712 // Set log for this change.
713 WPSC_Log::insert(
714 array(
715 'type' => 'customer',
716 'ref_id' => $customer->id,
717 'modified_by' => $current_user->customer->id,
718 'body' => wp_json_encode(
719 array(
720 'slug' => $cf->slug,
721 'prev' => $existing_val,
722 'new' => $value,
723 )
724 ),
725 'date_created' => ( new DateTime() )->format( 'Y-m-d H:i:s' ),
726 )
727 );
728 }
729 }
730 }
731 }
732
733 return $data;
734 }
735
736 /**
737 * Return slug string to be used in where condition of ticket model for this type of field
738 *
739 * @param WPSC_Custom_Field $cf - custom field object.
740 * @return string
741 */
742 public static function get_sql_slug( $cf ) {
743
744 $join_char = in_array( $cf->field, array( 'ticket', 'agentonly' ) ) ? 't.' : 'c.';
745 return $join_char . $cf->slug;
746 }
747
748 /**
749 * Add ticket search compatibility for fields of this custom field type.
750 *
751 * @param array $sql - Array of sql peices that can be joined later.
752 * @param array $filter - User filter.
753 * @param array $custom_fields - Custom fields array applicable for search.
754 * @param string $search - search string.
755 * @param array $allowed_search_fields - Allowed search fields.
756 * @return array
757 */
758 public static function ticket_search( $sql, $filter, $custom_fields, $search, $allowed_search_fields ) {
759
760 if ( isset( $custom_fields[ self::$slug ] ) ) {
761 foreach ( $custom_fields[ self::$slug ] as $cf ) {
762 if ( in_array( $cf->slug, $allowed_search_fields ) ) {
763
764 $join_char = in_array( $cf->field, array( 'ticket', 'agentonly' ) ) ? 't.' : 'c.';
765 $sql[] = 'CONVERT(' . $join_char . $cf->slug . ' USING utf8) LIKE \'%' . $search . '%\'';
766 }
767 }
768 }
769
770 return $sql;
771 }
772
773 /**
774 * Return val field for meta query of this type of custom field
775 *
776 * @param array $condition - condition data.
777 * @return mixed
778 */
779 public static function get_meta_value( $condition ) {
780
781 $operator = $condition['operator'];
782 switch ( $operator ) {
783
784 case '=':
785 return $condition['operand_val_1'];
786
787 case 'IN':
788 case 'NOT IN':
789 $val = explode( PHP_EOL, $condition['operand_val_1'] );
790 $temp_val = array();
791 foreach ( $val as $value ) {
792 $value = trim( $value );
793 if ( $value ) {
794 $temp_val[] = $value;
795 }
796 }
797 return $temp_val ? $temp_val : false;
798
799 case 'LIKE':
800 return trim( $condition['operand_val_1'] );
801 }
802 return false;
803 }
804
805 /**
806 * Print generic input field for this type.
807 *
808 * @param WPSC_Custom_Field $cf - Custom field object.
809 * @param mixed $value - optional. Input field will be printed with given value if given.
810 * @return void
811 */
812 public static function print_cf_input( $cf, $value = '' ) {
813
814 ?>
815 <div class="wpsc-tff wpsc-sm-12 wpsc-md-12 wpsc-lg-12 wpsc-visible wpsc-xs-12" data-cft="<?php echo esc_attr( self::$slug ); ?>">
816 <div class="wpsc-tff-label">
817 <span class="name"><?php echo esc_attr( $cf->name ); ?></span>
818 </div>
819 <?php
820 $extra_info = stripslashes( $cf->extra_info );
821 if ( $extra_info ) :
822 ?>
823 <span class="extra-info"><?php echo esc_attr( $cf->extra_info ); ?></span>
824 <?php
825 endif
826 ?>
827 <input
828 type="text"
829 name="<?php echo esc_attr( $cf->slug ); ?>"
830 placeholder="<?php echo esc_attr( $cf->placeholder_text ); ?>"
831 maxlength="<?php echo $cf->char_limit && $cf->char_limit < 255 ? intval( $cf->char_limit ) : '255'; ?>"
832 value="<?php echo esc_attr( $value ); ?>"
833 autocomplete="off"/>
834 </div>
835 <?php
836 }
837
838 /**
839 * Get value for generic field from post.
840 * Ignore phpcs nonce issue as we already checked where it is called from.
841 *
842 * @param WPSC_Custom_Field $cf - custom field object.
843 * @return string
844 */
845 public static function get_cf_input_val( $cf ) {
846
847 return isset( $_POST[ $cf->slug ] ) ? sanitize_text_field( wp_unslash( $_POST[ $cf->slug ] ) ) : ''; // phpcs:ignore
848 }
849
850 /**
851 * Print edit ticket custom field in individual ticket
852 *
853 * @param WPSC_Custom_Field $cf - custom field object.
854 * @param WPSC_Ticket $ticket - ticket object.
855 * @return void
856 */
857 public static function print_edit_ticket_cf( $cf, $ticket ) {
858
859 ?>
860 <div class="wpsc-tff wpsc-sm-12 wpsc-md-12 wpsc-lg-12 wpsc-visible wpsc-xs-12" data-cft="<?php echo esc_attr( self::$slug ); ?>">
861 <div class="wpsc-tff-label">
862 <span class="name"><?php echo esc_attr( $cf->name ); ?></span>
863 </div>
864 <?php
865 $extra_info = stripslashes( $cf->extra_info );
866 if ( $extra_info ) :
867 ?>
868 <span class="extra-info"><?php echo esc_attr( $cf->extra_info ); ?></span>
869 <?php
870 endif
871 ?>
872 <input
873 type="text"
874 name="<?php echo esc_attr( $cf->slug ); ?>"
875 placeholder="<?php echo esc_attr( $cf->placeholder_text ); ?>"
876 maxlength="<?php echo $cf->char_limit && $cf->char_limit < 255 ? intval( $cf->char_limit ) : '255'; ?>"
877 value="<?php echo esc_attr( $ticket->{$cf->slug} ); ?>"
878 autocomplete="off"/>
879 </div>
880 <?php
881 }
882
883 /**
884 * Set edit individual ticket for this custom field type.
885 * Ignore phpcs nonce issue as we already checked where it is called from.
886 *
887 * @param WPSC_Custom_Field $cf - custom field object.
888 * @param WPSC_Ticket $ticket - ticket object.
889 * @return WPSC_Ticket
890 */
891 public static function set_edit_ticket_cf( $cf, $ticket ) {
892
893 $prev = $ticket->{$cf->slug} ? $ticket->{$cf->slug} : '';
894 $new = isset( $_POST[ $cf->slug ] ) ? sanitize_text_field( wp_unslash( $_POST[ $cf->slug ] ) ) : ''; // phpcs:ignore
895
896 // Truncate input if it exceeds 255 characters.
897 $char_limit = $cf->char_limit && $cf->char_limit < 255 ? $cf->char_limit : 255;
898 $new = substr( $new, 0, $char_limit );
899
900 // Exit if there is no change.
901 if ( $prev == $new ) {
902 return $ticket;
903 }
904
905 // Change value.
906 $ticket->{$cf->slug} = $new;
907 $ticket->save();
908
909 return $ticket;
910 }
911
912 /**
913 * Modify ticket field value of this custom field type using rest api
914 *
915 * @param WPSC_Ticket $ticket - ticket object.
916 * @param WPSC_Custom_Field $cf - custom field.
917 * @param mixed $value - value to be set.
918 * @return void
919 */
920 public static function set_rest_edit_ticket_cf( $ticket, $cf, $value ) {
921
922 $value = sanitize_text_field( $value );
923 if ( $ticket->{$cf->slug} != $value ) {
924 $ticket->{$cf->slug} = $value;
925 }
926 }
927
928 /**
929 * Insert log thread for this custom field type change
930 *
931 * @param WPSC_Custom_Field $cf - current custom field of this type.
932 * @param WPSC_Ticket $prev - ticket object before making any changes.
933 * @param WPSC_Ticket $new - ticket object after making changes.
934 * @param string $current_date - date string to be stored as create time.
935 * @param int $customer_id - current user customer id for blame.
936 * @return void
937 */
938 public static function insert_ticket_log( $cf, $prev, $new, $current_date, $customer_id ) {
939
940 // Exit if there is no change.
941 if ( $prev->{$cf->slug} == $new->{$cf->slug} ) {
942 return;
943 }
944
945 $prev_val = htmlspecialchars( $prev->{$cf->slug}, ENT_QUOTES );
946 $new_val = htmlspecialchars( $new->{$cf->slug}, ENT_QUOTES );
947
948 $thread = WPSC_Thread::insert(
949 array(
950 'ticket' => $prev->id,
951 'customer' => $customer_id,
952 'type' => 'log',
953 'body' => wp_json_encode(
954 array(
955 'slug' => $cf->slug,
956 'prev' => $prev_val,
957 'new' => $new_val,
958 )
959 ),
960 'date_created' => $current_date,
961 'date_updated' => $current_date,
962 )
963 );
964 }
965
966 /**
967 * Return data for this custom field while creating duplicate ticket
968 *
969 * @param WPSC_Custom_Field $cf - custom field object.
970 * @param WPSC_Ticket $ticket - ticket object.
971 * @return mixed
972 */
973 public static function get_duplicate_ticket_data( $cf, $ticket ) {
974
975 return $ticket->{$cf->slug};
976 }
977
978 /**
979 * Print edit field for this type in edit customer info
980 *
981 * @param WPSC_Custom_field $cf - custom field object.
982 * @param WPSC_Customer $customer - customer object.
983 * @param array $tff - ticket form field data.
984 * @return string
985 */
986 public static function print_edit_customer_info( $cf, $customer, $tff ) {
987
988 $val = $customer->id && $customer->{$cf->slug} ? stripslashes( htmlspecialchars( $customer->{$cf->slug} ) ) : '';
989
990 ob_start();
991 ?>
992 <div class="<?php echo esc_attr( WPSC_Functions::get_tff_classes( $cf, $tff ) ); ?>" data-cft="<?php echo esc_attr( self::$slug ); ?>">
993 <div class="wpsc-tff-label">
994 <span class="name"><?php echo esc_attr( $cf->name ); ?></span>
995 </div>
996 <span class="extra-info"><?php echo esc_attr( $cf->extra_info ); ?></span>
997 <input
998 type="text"
999 name="<?php echo esc_attr( $cf->slug ); ?>"
1000 placeholder="<?php echo esc_attr( $cf->placeholder_text ); ?>"
1001 maxlength="<?php echo $cf->char_limit ? intval( $cf->char_limit ) : ''; ?>"
1002 value="<?php echo esc_attr( $val ); ?>"
1003 autocomplete="off"/>
1004 </div>
1005 <?php
1006 return ob_get_clean();
1007 }
1008
1009 /**
1010 * Print add new custom field setting properties
1011 *
1012 * @param string $field_class - Class name of the field.
1013 * @return void
1014 */
1015 public static function get_add_new_custom_field_properties( $field_class ) {
1016
1017 if ( in_array( 'extra_info', $field_class::$allowed_properties ) ) :
1018 ?>
1019 <div data-type="textfield" data-required="false" class="wpsc-input-group extra-info">
1020 <div class="label-container">
1021 <label for=""><?php esc_attr_e( 'Extra info', 'supportcandy' ); ?></label>
1022 </div>
1023 <input name="extra_info" type="text" autocomplete="off" />
1024 </div>
1025 <?php
1026 endif;
1027
1028 if ( in_array( 'default_value', $field_class::$allowed_properties ) ) :
1029 ?>
1030 <div data-type="textfield" data-required="false" class="wpsc-input-group default_value">
1031 <div class="label-container">
1032 <label for="">
1033 <?php esc_attr_e( 'Default value', 'supportcandy' ); ?>
1034 </label>
1035 </div>
1036 <input type="text" name="default_value" autocomplete="off">
1037 </div>
1038 <?php
1039 endif;
1040
1041 if ( in_array( 'is_auto_fill', $field_class::$allowed_properties ) ) :
1042 ?>
1043 <div data-type="single-select" data-required="false" class="wpsc-input-group is_auto_fill">
1044 <div class="label-container">
1045 <label for="">
1046 <?php esc_attr_e( 'Auto-fill in ticket form', 'supportcandy' ); ?>
1047 </label>
1048 </div>
1049 <select name="is_auto_fill">
1050 <option value="0"><?php esc_attr_e( 'No', 'supportcandy' ); ?></option>
1051 <option value="1"><?php esc_attr_e( 'Yes', 'supportcandy' ); ?></option>
1052 </select>
1053 </div>
1054 <?php
1055 endif;
1056
1057 if ( in_array( 'char_limit', $field_class::$allowed_properties ) ) :
1058 ?>
1059 <div data-type="number" data-required="false" class="wpsc-input-group char_limit">
1060 <div class="label-container">
1061 <label for="">
1062 <?php esc_attr_e( 'Character limit', 'supportcandy' ); ?>
1063 </label>
1064 </div>
1065 <input type="number" name="char_limit" autocomplete="off">
1066 </div>
1067 <?php
1068 endif;
1069
1070 if ( in_array( 'placeholder_text', $field_class::$allowed_properties ) ) :
1071 ?>
1072 <div data-type="textfield" data-required="false" class="wpsc-input-group placeholder_text">
1073 <div class="label-container">
1074 <label for="">
1075 <?php esc_attr_e( 'Placeholder', 'supportcandy' ); ?>
1076 </label>
1077 </div>
1078 <input type="text" name="placeholder_text" autocomplete="off">
1079 </div>
1080 <?php
1081 endif;
1082
1083 if ( in_array( 'tl_width', $field_class::$allowed_properties ) ) :
1084 ?>
1085 <div data-type="number" data-required="false" class="wpsc-input-group tl_width">
1086 <div class="label-container">
1087 <label for="">
1088 <?php esc_attr_e( 'Ticket list width (pixels)', 'supportcandy' ); ?>
1089 </label>
1090 </div>
1091 <input type="number" name="tl_width" autocomplete="off">
1092 </div>
1093 <?php
1094 endif;
1095
1096 if ( in_array( 'is_personal_info', $field_class::$allowed_properties ) ) :
1097 ?>
1098 <div data-type="single-select" data-required="false" class="wpsc-input-group is_personal_info">
1099 <div class="label-container">
1100 <label for="">
1101 <?php esc_attr_e( 'Has personal info', 'supportcandy' ); ?>
1102 </label>
1103 </div>
1104 <select name="is_personal_info">
1105 <option value="0"><?php esc_attr_e( 'No', 'supportcandy' ); ?></option>
1106 <option value="1"><?php esc_attr_e( 'Yes', 'supportcandy' ); ?></option>
1107 </select>
1108 </div>
1109 <?php
1110 endif;
1111
1112 if ( in_array( 'allow_my_profile', $field_class::$allowed_properties ) ) :
1113 ?>
1114 <div data-type="single-select" data-required="false" class="wpsc-input-group allow_my_profile">
1115 <div class="label-container">
1116 <label for="">
1117 <?php esc_attr_e( 'Allow in my profile?', 'supportcandy' ); ?>
1118 </label>
1119 </div>
1120 <select name="allow_my_profile">
1121 <option value="0"><?php esc_attr_e( 'No', 'supportcandy' ); ?></option>
1122 <option value="1"><?php esc_attr_e( 'Yes', 'supportcandy' ); ?></option>
1123 </select>
1124 </div>
1125 <?php
1126 endif;
1127
1128 if ( in_array( 'allow_ticket_form', $field_class::$allowed_properties ) ) :
1129 ?>
1130 <div data-type="single-select" data-required="false" class="wpsc-input-group allow_ticket_form">
1131 <div class="label-container">
1132 <label for="">
1133 <?php esc_attr_e( 'Allow in ticket form?', 'supportcandy' ); ?>
1134 </label>
1135 </div>
1136 <select name="allow_ticket_form">
1137 <option value="0"><?php esc_attr_e( 'No', 'supportcandy' ); ?></option>
1138 <option value="1"><?php esc_attr_e( 'Yes', 'supportcandy' ); ?></option>
1139 </select>
1140 </div>
1141 <?php
1142 endif;
1143 }
1144
1145 /**
1146 * Print edit custom field properties
1147 *
1148 * @param WPSC_Custom_Fields $cf - custom field object.
1149 * @param string $field_class - class name of field category.
1150 * @return void
1151 */
1152 public static function get_edit_custom_field_properties( $cf, $field_class ) {
1153
1154 if ( in_array( 'extra_info', $field_class::$allowed_properties ) ) :
1155 ?>
1156 <div data-type="textfield" data-required="false" class="wpsc-input-group extra-info">
1157 <div class="label-container">
1158 <label for=""><?php esc_attr_e( 'Extra info', 'supportcandy' ); ?></label>
1159 </div>
1160 <input name="extra_info" type="text" value="<?php echo esc_attr( $cf->extra_info ); ?>" autocomplete="off" />
1161 </div>
1162 <?php
1163 endif;
1164
1165 if ( in_array( 'default_value', $field_class::$allowed_properties ) ) :
1166 $default_val = $cf->default_value ? $cf->default_value[0] : '';
1167 ?>
1168 <div data-type="textfield" data-required="false" class="wpsc-input-group default_value">
1169 <div class="label-container">
1170 <label for="">
1171 <?php esc_attr_e( 'Default value', 'supportcandy' ); ?>
1172 </label>
1173 </div>
1174 <input type="text" name="default_value" value="<?php echo esc_attr( $default_val ); ?>" autocomplete="off">
1175 </div>
1176 <?php
1177 endif;
1178
1179 if ( in_array( 'is_auto_fill', $field_class::$allowed_properties ) ) :
1180 ?>
1181 <div data-type="single-select" data-required="false" class="wpsc-input-group is_auto_fill">
1182 <div class="label-container">
1183 <label for="">
1184 <?php esc_attr_e( 'Auto-fill in ticket form', 'supportcandy' ); ?>
1185 </label>
1186 </div>
1187 <select name="is_auto_fill">
1188 <option <?php selected( $cf->is_auto_fill, 0 ); ?> value="0"><?php esc_attr_e( 'No', 'supportcandy' ); ?></option>
1189 <option <?php selected( $cf->is_auto_fill, 1 ); ?> value="1"><?php esc_attr_e( 'Yes', 'supportcandy' ); ?></option>
1190 </select>
1191 </div>
1192 <?php
1193 endif;
1194
1195 if ( in_array( 'char_limit', $field_class::$allowed_properties ) ) :
1196 ?>
1197 <div data-type="number" data-required="false" class="wpsc-input-group char_limit">
1198 <div class="label-container">
1199 <label for="">
1200 <?php esc_attr_e( 'Character limit', 'supportcandy' ); ?>
1201 </label>
1202 </div>
1203 <input type="number" name="char_limit" value="<?php echo intval( $cf->char_limit ); ?>" autocomplete="off">
1204 </div>
1205 <?php
1206 endif;
1207
1208 if ( in_array( 'placeholder_text', $field_class::$allowed_properties ) ) :
1209 ?>
1210 <div data-type="textfield" data-required="false" class="wpsc-input-group placeholder_text">
1211 <div class="label-container">
1212 <label for="">
1213 <?php esc_attr_e( 'Placeholder', 'supportcandy' ); ?>
1214 </label>
1215 </div>
1216 <input type="text" name="placeholder_text" value="<?php echo esc_attr( $cf->placeholder_text ); ?>" autocomplete="off">
1217 </div>
1218 <?php
1219 endif;
1220
1221 if ( in_array( 'tl_width', $field_class::$allowed_properties ) ) :
1222 ?>
1223 <div data-type="number" data-required="false" class="wpsc-input-group tl_width">
1224 <div class="label-container">
1225 <label for="">
1226 <?php esc_attr_e( 'Ticket list width (pixels)', 'supportcandy' ); ?>
1227 </label>
1228 </div>
1229 <input type="number" name="tl_width" value="<?php echo intval( $cf->tl_width ); ?>" autocomplete="off">
1230 </div>
1231 <?php
1232 endif;
1233
1234 if ( in_array( 'is_personal_info', $field_class::$allowed_properties ) ) :
1235 ?>
1236 <div data-type="single-select" data-required="false" class="wpsc-input-group is_personal_info">
1237 <div class="label-container">
1238 <label for="">
1239 <?php esc_attr_e( 'Has personal info', 'supportcandy' ); ?>
1240 </label>
1241 </div>
1242 <select name="is_personal_info">
1243 <option <?php selected( $cf->is_personal_info, '0' ); ?> value="0"><?php esc_attr_e( 'No', 'supportcandy' ); ?></option>
1244 <option <?php selected( $cf->is_personal_info, '1' ); ?> value="1"><?php esc_attr_e( 'Yes', 'supportcandy' ); ?></option>
1245 </select>
1246 </div>
1247 <?php
1248 endif;
1249
1250 if ( in_array( 'allow_my_profile', $field_class::$allowed_properties ) ) :
1251 ?>
1252 <div data-type="single-select" data-required="false" class="wpsc-input-group allow_my_profile">
1253 <div class="label-container">
1254 <label for="">
1255 <?php esc_attr_e( 'Allow in my profile?', 'supportcandy' ); ?>
1256 </label>
1257 </div>
1258 <select name="allow_my_profile">
1259 <option <?php selected( $cf->allow_my_profile, '0' ); ?> value="0"><?php esc_attr_e( 'No', 'supportcandy' ); ?></option>
1260 <option <?php selected( $cf->allow_my_profile, '1' ); ?> value="1"><?php esc_attr_e( 'Yes', 'supportcandy' ); ?></option>
1261 </select>
1262 </div>
1263 <?php
1264 endif;
1265
1266 if ( in_array( 'allow_ticket_form', $field_class::$allowed_properties ) ) :
1267 ?>
1268 <div data-type="single-select" data-required="false" class="wpsc-input-group allow_ticket_form">
1269 <div class="label-container">
1270 <label for="">
1271 <?php esc_attr_e( 'Allow in ticket form?', 'supportcandy' ); ?>
1272 </label>
1273 </div>
1274 <select name="allow_ticket_form">
1275 <option <?php selected( $cf->allow_ticket_form, '0' ); ?> value="0"><?php esc_attr_e( 'No', 'supportcandy' ); ?></option>
1276 <option <?php selected( $cf->allow_ticket_form, '1' ); ?> value="1"><?php esc_attr_e( 'Yes', 'supportcandy' ); ?></option>
1277 </select>
1278 </div>
1279 <?php
1280 endif;
1281 }
1282
1283 /**
1284 * Set custom field properties. Can be used by add/edit custom field.
1285 * Ignore phpcs nonce issue as we already checked where it is called from.
1286 *
1287 * @param WPSC_Custom_Field $cf - custom field object.
1288 * @param string $field_class - class of field category.
1289 * @return void
1290 */
1291 public static function set_cf_properties( $cf, $field_class ) {
1292
1293 // extra info.
1294 if ( in_array( 'extra_info', $field_class::$allowed_properties ) ) {
1295 $cf->extra_info = isset( $_POST['extra_info'] ) ? sanitize_text_field( wp_unslash( $_POST['extra_info'] ) ) : ''; // phpcs:ignore
1296 }
1297
1298 // default value.
1299 if ( in_array( 'default_value', $field_class::$allowed_properties ) ) {
1300 $default_value = isset( $_POST['default_value'] ) ? sanitize_text_field( wp_unslash( $_POST['default_value'] ) ) : ''; // phpcs:ignore
1301 $cf->default_value = $default_value ? array( $default_value ) : array();
1302 }
1303
1304 // auto fill.
1305 if ( in_array( 'is_auto_fill', $field_class::$allowed_properties ) ) {
1306 $cf->is_auto_fill = isset( $_POST['is_auto_fill'] ) ? sanitize_text_field( wp_unslash( $_POST['is_auto_fill'] ) ) : ''; // phpcs:ignore
1307 }
1308
1309 // char limit.
1310 if ( in_array( 'char_limit', $field_class::$allowed_properties ) ) {
1311 $cf->char_limit = isset( $_POST['char_limit'] ) ? intval( $_POST['char_limit'] ) : 0; //phpcs:ignore
1312 }
1313
1314 // check whether char limit is honored by default value.
1315 if ( $cf->default_value && $cf->char_limit && count( $cf->default_value ) > $cf->char_limit ) {
1316 wp_send_json_error( 'Incorrect request!', 400 );
1317 }
1318
1319 // placeholder!
1320 if ( in_array( 'placeholder_text', $field_class::$allowed_properties ) ) {
1321 $cf->placeholder_text = isset( $_POST['placeholder_text'] ) ? sanitize_text_field( wp_unslash( $_POST['placeholder_text'] ) ) : ''; // phpcs:ignore
1322 }
1323
1324 // personal info.
1325 if ( in_array( 'is_personal_info', $field_class::$allowed_properties ) ) {
1326 $cf->is_personal_info = isset( $_POST['is_personal_info'] ) ? intval( $_POST['is_personal_info'] ) : 0; // phpcs:ignore
1327 }
1328
1329 // my-profile.
1330 if ( in_array( 'allow_my_profile', $field_class::$allowed_properties ) ) {
1331 $cf->allow_my_profile = isset( $_POST['allow_my_profile'] ) ? intval( $_POST['allow_my_profile'] ) : 0; // phpcs:ignore
1332 }
1333
1334 // ticket form.
1335 if ( in_array( 'allow_ticket_form', $field_class::$allowed_properties ) ) {
1336 $cf->allow_ticket_form = isset( $_POST['allow_ticket_form'] ) ? intval( $_POST['allow_ticket_form'] ) : 0; // phpcs:ignore
1337 }
1338
1339 // tl_width!
1340 if ( in_array( 'tl_width', $field_class::$allowed_properties ) ) {
1341 $tl_width = isset( $_POST['tl_width'] ) ? intval( $_POST['tl_width'] ) : 0; // phpcs:ignore
1342 $cf->tl_width = $tl_width ? $tl_width : 100;
1343 }
1344
1345 // save!
1346 $cf->save();
1347 }
1348
1349 /**
1350 * Returns printable ticket value for custom field. Can be used in export tickets, replace macros etc.
1351 *
1352 * @param WPSC_Custom_Field $cf - custom field object.
1353 * @param WPSC_Ticket $ticket - ticket object.
1354 * @param string $module - module name.
1355 * @return string
1356 */
1357 public static function get_ticket_field_val( $cf, $ticket, $module = '' ) {
1358
1359 return apply_filters( 'wpsc_ticket_field_val_text_field', $ticket->{$cf->slug}, $cf, $ticket, $module );
1360 }
1361
1362 /**
1363 * Print ticket value for given custom field on ticket list
1364 *
1365 * @param WPSC_Custom_Field $cf - custom field object.
1366 * @param WPSC_Ticket $ticket - ticket object.
1367 * @return void
1368 */
1369 public static function print_tl_ticket_field_val( $cf, $ticket ) {
1370
1371 echo esc_attr( self::get_ticket_field_val( $cf, $ticket ) );
1372 }
1373
1374 /**
1375 * Print ticket value for given custom field on widget
1376 *
1377 * @param WPSC_Custom_Field $cf - custom field object.
1378 * @param WPSC_Ticket $ticket - ticket object.
1379 * @return void
1380 */
1381 public static function print_widget_ticket_field_val( $cf, $ticket ) {
1382
1383 echo esc_attr( self::get_ticket_field_val( $cf, $ticket ) );
1384 }
1385
1386 /**
1387 * Returns printable customer value for custom field. Can be used in export tickets, replace macros etc.
1388 *
1389 * @param WPSC_Custom_Field $cf - custom field object.
1390 * @param WPSC_Customer $customer - customer object.
1391 * @return string
1392 */
1393 public static function get_customer_field_val( $cf, $customer ) {
1394
1395 return $customer->{$cf->slug};
1396 }
1397
1398 /**
1399 * Print customer value for given custom field on ticket list
1400 *
1401 * @param WPSC_Custom_Field $cf - custom field object.
1402 * @param WPSC_Customer $customer - customer object.
1403 * @return void
1404 */
1405 public static function print_tl_customer_field_val( $cf, $customer ) {
1406
1407 echo esc_attr( self::get_customer_field_val( $cf, $customer ) );
1408 }
1409
1410 /**
1411 * Print customer value for given custom field on widget
1412 *
1413 * @param WPSC_Custom_Field $cf - custom field object.
1414 * @param WPSC_Customer $customer - customer object.
1415 * @return void
1416 */
1417 public static function print_widget_customer_field_val( $cf, $customer ) {
1418
1419 echo esc_attr( self::get_customer_field_val( $cf, $customer ) );
1420 }
1421
1422 /**
1423 * Print given value for custom field
1424 *
1425 * @param WPSC_Custom_Field $cf - custom field object.
1426 * @param mixed $val - value to convert and print.
1427 * @return void
1428 */
1429 public static function print_val( $cf, $val ) {
1430
1431 echo $val ? esc_attr( $val ) : esc_attr__( 'None', 'supportcandy' );
1432 }
1433
1434 /**
1435 * Return printable value for history log macro
1436 *
1437 * @param WPSC_Custom_Field $cf - custom field object.
1438 * @param mixed $val - value to convert and return.
1439 * @return string
1440 */
1441 public static function get_history_log_val( $cf, $val ) {
1442
1443 ob_start();
1444 self::print_val( $cf, $val );
1445 return ob_get_clean();
1446 }
1447
1448 /**
1449 * Print dashboard activity function
1450 *
1451 * @param WPSC_Custom_Field $cf - custom field object.
1452 * @param array $recent_logs - recent_logs object.
1453 * @param array $body - body object.
1454 * @param int $view - check if frontend.
1455 * @return string
1456 */
1457 public static function print_activity( $cf, $recent_logs, $body, $view ) {
1458
1459 $url = WPSC_Functions::get_ticket_url( $recent_logs->ticket->id, $view );
1460 if ( $body->new ) {
1461 $tf_value = $body->new;
1462 } else {
1463 $tf_value = 'None';
1464 }
1465 return esc_attr( $recent_logs->customer->name ) . ' updated the' . esc_attr( $cf->name ) . ' value of <a href="' . esc_attr( $url ) . '" target="_blank">#' . esc_attr( $recent_logs->ticket->id ) . '</a> to ' . esc_attr( $tf_value );
1466 }
1467
1468 /**
1469 * Return given value for custom field
1470 *
1471 * @param WPSC_Custom_Field $cf - custom field object.
1472 * @param mixed $val - value to convert and print.
1473 * @return string
1474 */
1475 public static function get_field_value( $cf, $val ) {
1476
1477 return $val ? esc_attr( $val ) : esc_attr__( 'None', 'supportcandy' );
1478 }
1479
1480 /**
1481 * Clear value of hidden fields
1482 *
1483 * @return void
1484 */
1485 public static function js_clear_value_hidden_fields() {
1486 ?>
1487 case '<?php echo esc_attr( self::$slug ); ?>':
1488 customField.find('input').first().val('');
1489 break;
1490 <?php
1491 echo PHP_EOL;
1492 }
1493 }
1494 endif;
1495
1496 WPSC_CF_Text_Field::init();
1497