PluginProbe
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent / 3.3.8
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent v3.3.8
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-email.php

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

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