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

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