PluginProbe
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent / 3.4.1
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent v3.4.1
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.4.1, at includes/custom-field-types/class-wpsc-cf-text-field.php

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