| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly! |
| 4 |
} |
| 5 |
|
| 6 |
if ( ! class_exists( 'WPSC_TF' ) ) : |
| 7 |
|
| 8 |
final class WPSC_TF { |
| 9 |
|
| 10 |
/** |
| 11 |
* Allowed custom field properties |
| 12 |
* |
| 13 |
* @var array |
| 14 |
*/ |
| 15 |
public static $allowed_properties = array( |
| 16 |
'extra_info', |
| 17 |
'default_value', |
| 18 |
'placeholder_text', |
| 19 |
'char_limit', |
| 20 |
'date_format', |
| 21 |
'date_range', |
| 22 |
'start_range', |
| 23 |
'end_range', |
| 24 |
'time_format', |
| 25 |
'is_personal_info', |
| 26 |
'is_auto_fill', |
| 27 |
'tl_width', |
| 28 |
'number_type', |
| 29 |
); |
| 30 |
|
| 31 |
/** |
| 32 |
* Initialize this class |
| 33 |
*/ |
| 34 |
public static function init() { |
| 35 |
|
| 36 |
// Register this field category (ticket). |
| 37 |
add_filter( 'wpsc_custom_field_categories', array( __CLASS__, 'register_field' ) ); |
| 38 |
|
| 39 |
// List. |
| 40 |
add_action( 'wp_ajax_wpsc_get_ticket_fields', array( __CLASS__, 'get_ticket_fields' ) ); |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Register field category |
| 45 |
* |
| 46 |
* @param array $fields - ticket fields. |
| 47 |
* @return array |
| 48 |
*/ |
| 49 |
public static function register_field( $fields ) { |
| 50 |
|
| 51 |
$fields['ticket'] = __CLASS__; |
| 52 |
return $fields; |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* Get ticket fields |
| 57 |
*/ |
| 58 |
public static function get_ticket_fields() { |
| 59 |
|
| 60 |
if ( ! WPSC_Functions::is_site_admin() ) { |
| 61 |
wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); |
| 62 |
} |
| 63 |
$custom_fields_types = array_merge( WPSC_Custom_Field::$cf_types, WPSC_Custom_Field::$default_cf_types ); |
| 64 |
?> |
| 65 |
|
| 66 |
<div class="wpsc-setting-header"> |
| 67 |
<h2><?php esc_attr_e( 'Ticket Fields', 'supportcandy' ); ?></h2> |
| 68 |
</div> |
| 69 |
|
| 70 |
<div class="wpsc-setting-section-body"> |
| 71 |
<div class="wpsc-dock-container"> |
| 72 |
<?php |
| 73 |
printf( |
| 74 |
/* translators: Click here to see the documentation */ |
| 75 |
esc_attr__( '%s to see the documentation!', 'supportcandy' ), |
| 76 |
'<a href="https://supportcandy.net/docs/ticket-fields/" target="_blank">' . esc_attr__( 'Click here', 'supportcandy' ) . '</a>' |
| 77 |
); |
| 78 |
?> |
| 79 |
</div> |
| 80 |
<table class="ticket-fields wpsc-setting-tbl"> |
| 81 |
<thead> |
| 82 |
<tr> |
| 83 |
<th><?php esc_attr_e( 'Field', 'supportcandy' ); ?></th> |
| 84 |
<th><?php esc_attr_e( 'Extra info', 'supportcandy' ); ?></th> |
| 85 |
<th><?php esc_attr_e( 'Type', 'supportcandy' ); ?></th> |
| 86 |
<th><?php esc_attr_e( 'Auto Fill', 'supportcandy' ); ?></th> |
| 87 |
<th><?php esc_attr_e( 'Personal Info', 'supportcandy' ); ?></th> |
| 88 |
<th><?php esc_attr_e( 'Actions', 'supportcandy' ); ?></th> |
| 89 |
</tr> |
| 90 |
</thead> |
| 91 |
<tbody> |
| 92 |
<?php |
| 93 |
foreach ( WPSC_Custom_Field::$custom_fields as $cf ) { |
| 94 |
if ( $cf->field != 'ticket' ) { |
| 95 |
continue; |
| 96 |
} |
| 97 |
?> |
| 98 |
<tr> |
| 99 |
<td><?php echo esc_attr( $cf->name ); ?></td> |
| 100 |
<td><?php echo esc_attr( $cf->extra_info ); ?></td> |
| 101 |
<td><?php echo esc_attr( $custom_fields_types[ $cf->type::$slug ]['label'] ); ?></td> |
| 102 |
<td><?php echo esc_attr( $cf->is_auto_fill ? __( 'Yes', 'supportcandy' ) : __( 'No', 'supportcandy' ) ); ?></td> |
| 103 |
<td><?php echo esc_attr( $cf->is_personal_info ? __( 'Yes', 'supportcandy' ) : __( 'No', 'supportcandy' ) ); ?></td> |
| 104 |
<td> |
| 105 |
<span class="wpsc-link" onclick="wpsc_get_edit_custom_field(<?php echo esc_attr( $cf->id ); ?>, '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_edit_custom_field' ) ); ?>');"><?php esc_attr_e( 'Edit', 'supportcandy' ); ?></span> |
| 106 |
<?php |
| 107 |
if ( ! $cf->type::$is_default ) { |
| 108 |
echo esc_attr( ' | ' ); |
| 109 |
?> |
| 110 |
<span class="wpsc-link" onclick="wpsc_delete_custom_field(<?php echo esc_attr( $cf->id ); ?>, '<?php echo esc_attr( wp_create_nonce( 'wpsc_delete_custom_field' ) ); ?>');"><?php esc_attr_e( 'Delete', 'supportcandy' ); ?></span> |
| 111 |
<?php |
| 112 |
} |
| 113 |
?> |
| 114 |
</td> |
| 115 |
</tr> |
| 116 |
<?php |
| 117 |
} |
| 118 |
?> |
| 119 |
</tbody> |
| 120 |
</table> |
| 121 |
<script> |
| 122 |
jQuery('table.ticket-fields').DataTable({ |
| 123 |
ordering: false, |
| 124 |
pageLength: 20, |
| 125 |
bLengthChange: false, |
| 126 |
columnDefs: [ |
| 127 |
{ targets: -1, searchable: false }, |
| 128 |
{ targets: '_all', className: 'dt-left' } |
| 129 |
], |
| 130 |
layout: { |
| 131 |
topStart: { |
| 132 |
buttons: [ |
| 133 |
{ |
| 134 |
text: '<?php esc_attr_e( 'Add new', 'supportcandy' ); ?>', |
| 135 |
className: 'wpsc-button small primary', |
| 136 |
action: function ( e, dt, node, config ) { |
| 137 |
wpsc_get_add_new_custom_field('ticket', '<?php echo esc_attr( wp_create_nonce( 'wpsc_get_add_new_custom_field' ) ); ?>'); |
| 138 |
} |
| 139 |
} |
| 140 |
], |
| 141 |
}, |
| 142 |
}, |
| 143 |
language: supportcandy.translations.datatables |
| 144 |
}); |
| 145 |
</script> |
| 146 |
</div> |
| 147 |
<?php |
| 148 |
wp_die(); |
| 149 |
} |
| 150 |
} |
| 151 |
endif; |
| 152 |
|
| 153 |
WPSC_TF::init(); |
| 154 |
|