|
|
|
|
|
|
|
|
|
'; print_r($meta_info); echo '';
$bg_image = $others['bg_image'] ?? '';
if (!empty($bg_image) && $bg_image > 0) {
ABPET_Layout::image('', $bg_image, '', '_max_100');
} ?> |
|
|
|
|
|
|
__('Invalid security token or Insufficient permissions.', 'abp-event-ticket'), 'type' => 'warn'], 403);
}
ob_start();
$id = isset($_POST['id']) ? absint(wp_unslash($_POST['id'])) : '';
$clone = isset($_POST['clone']) ? absint(wp_unslash($_POST['clone'])) : '';
$sp_info = [];
if (!empty($id)) {
$row = ABPET_Query::get_sp($id);
if (!empty($row)) {
$sp_info = current($row);
}
}
$id = !empty($clone) && $clone > 0 ? '' : $id;
//echo '';print_r($sp);echo '
';
$others = json_decode($sp_info['others'] ?? '', true) ?: [];
$bg_image = $others['bg_image'] ?? '';
$bg_color = $others['bg_color'] ?? '#fff';
$img_url = !empty($bg_image) && $bg_image > 0 ? ABPET_Function::get_image_url('', $bg_image) : '';
?>
🖱 →
|
→
|
→
|
→
$html, 'type' => 'success', 'msg' => __('Seat Plan Loaded Successfully .....! ', 'abp-event-ticket')]);
}
public function view_sp(): void {
if (!check_ajax_referer('abpet_admin_ajax_nonce', 'nonce', false) || !current_user_can('manage_options')) {
wp_send_json_error(['msg' => __('Invalid security token or Insufficient permissions.', 'abp-event-ticket'), 'type' => 'warn'], 403);
}
ob_start();
$id = isset($_POST['id']) ? absint(wp_unslash($_POST['id'])) : '';
$sp_info = [];
if (!empty($id)) {
$row = ABPET_Query::get_sp($id);
if (!empty($row)) {
$sp_info = current($row);
}
}
$others = json_decode($sp_info['others'] ?? '', true) ?: [];
$bg_image = $others['bg_image'] ?? '';
$bg_color = $others['bg_color'] ?? '#fff';
$layout = json_decode($sp_info['layout_data'] ?? '', true) ?: [];
//echo ''; print_r($ticket_types); echo '
';
$cols = intval($others['column'] ?? 10);
$meta_info = json_decode($sp_info['seat_info'] ?? '', true) ?: [];
$hidden_cells = [];
foreach ($layout as $index => $cell) {
$c_span = intval($cell['width_ratio'] ?? 1);
$r_span = intval($cell['height_ratio'] ?? 1);
if ($c_span > 1 || $r_span > 1) {
for ($r = 0; $r < $r_span; $r++) {
for ($c = 0; $c < $c_span; $c++) {
if ($r === 0 && $c === 0)
continue;
$target_idx = $index + ($r * $cols) + $c;
$hidden_cells[$target_idx] = true;
}
}
}
}
?>
$html, 'type' => 'success', 'msg' => __('Seat Plan Loaded Successfully .....! ', 'abp-event-ticket')]);
}
public function save_sp(): void {
if (!check_ajax_referer('abpet_admin_ajax_nonce', 'nonce', false) || !current_user_can('manage_options')) {
wp_send_json_error(['msg' => __('Invalid security token or Insufficient permissions.', 'abp-event-ticket'), 'type' => 'warn'], 403);
}
global $wpdb;
$table_name = $wpdb->prefix . 'abpet_sp';
$post_val = fn($key, $default = '') => isset($_POST[$key]) ? sanitize_text_field(wp_unslash($_POST[$key])) : $default;
$post_int = fn($key, $default = 0) => isset($_POST[$key]) ? absint($_POST[$key]) : $default;
$post_json = function ($key) {
if (!check_ajax_referer('abpet_admin_ajax_nonce', 'nonce', false) || !current_user_can('manage_options')) {
wp_send_json_error(['msg' => __('Invalid security token or Insufficient permissions.', 'abp-event-ticket'), 'type' => 'warn'], 403);
}
if (isset($_POST[$key])) {
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitized below via map_deep.
$raw_input = wp_unslash($_POST[$key]);
$raw_data = json_decode($raw_input, true);
if (!is_array($raw_data)) {
return array();
}
return map_deep($raw_data, 'sanitize_text_field');
}
return [];
};
$id = $post_int('id');
$layout_data = $post_json('layout_data');
$total_seats = 0;
foreach ($layout_data as $cell) {
if (isset($cell['type']) && $cell['type'] === 'seat' && !empty($cell['name'])) {
$total_seats++;
}
}
$seat_info = $post_json('seat_info');
$ticket_info['type'] = $seat_info;
$ticket_info['total'] = $total_seats;
$ticket_infos = ABPET_Function::get_option('abpet_ticket_sp');
$others['bg_image'] = $post_val('bg_image', '');
$others['bg_color'] = $post_val('bg_color', '');
$others['row'] = $post_int('rows', 10);
$others['column'] = $post_int('cols', 10);
$others['width'] = $post_int('width', 50);
$others['height'] = $post_int('width', 50);
$others['gap'] = $post_int('gap', 5);
$others['radius'] = $post_int('radius', 5);
$data = [
'name' => $post_val('name', uniqid('sp_')),
'total_seats' => $total_seats,
'others' => wp_json_encode($others),
'layout_data' => wp_json_encode($layout_data),
'seat_info' => wp_json_encode($seat_info),
];
if ($id > 0) {
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
$wpdb->update($table_name, $data, ['id' => $id]);
ABPET_Query::flush_cache($id);
$ticket_infos[$id] = $ticket_info;
update_option('abpet_ticket_sp', $ticket_infos);
wp_send_json_success(['msg' => __('Seat Plan Updated Successfully.....!', 'abp-event-ticket'), 'type' => 'success']);
} else {
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
$wpdb->insert($table_name, $data);
ABPET_Query::flush_cache($wpdb->insert_id);
$ticket_infos[$wpdb->insert_id] = $ticket_info;
update_option('abpet_ticket_sp', $ticket_infos);
wp_send_json_success(['msg' => __('Seat Plan Saved Successfully...!', 'abp-event-ticket'), 'type' => 'success']);
}
}
public function delete_sp(): void {
if (!check_ajax_referer('abpet_admin_ajax_nonce', 'nonce', false) || !current_user_can('manage_options')) {
wp_send_json_error(['msg' => __('Invalid security token or Insufficient permissions.', 'abp-event-ticket'), 'type' => 'warn'], 403);
}
$id = isset($_POST['id']) ? absint(wp_unslash($_POST['id'])) : 0;
if (!empty($id) && $id > 0) {
global $wpdb;
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
$wpdb->delete($wpdb->prefix . 'abpet_sp', ['id' => $id], ['%d']);
ABPET_Query::flush_cache($id);
$ticket_infos = ABPET_Function::get_option('abpet_ticket_sp');
unset($ticket_infos[$id]);
update_option('abpet_ticket_sp', $ticket_infos);
}
ob_start();
$this->sp_list();
$html_content = ob_get_clean();
wp_send_json_success(['html' => $html_content, 'msg' => __('Seat Plan deleted Successfully ..... !! ', 'abp-event-ticket'), 'type' => 'success'], 200);
}
public static function sp_seat_list($options, $meta_info): void {
if (ABPET_Function::on_off('ticket_type') && sizeof($options) > 0) { ?>
$item) {
$label = $item['label'] ?? '';
if (!empty($label) && array_key_exists($key, $meta_info)) { ?>
( )
0) {
$sp_data = ABPET_Query::get_sp();
$types = ABPET_Function::get_option('abpet_ticket');
$types = is_array($types) ? $types : [];
if (sizeof($types) > 0) {
if (!ABPET_Function::on_off('ticket_type')) {
$types = array_slice($types, 0, 1, true);
}
} else {
$types[uniqid()]['label'] = 'Ticket/Seat';
update_option('abpet_ticket', $types);
}
if (!empty($sp_data)) {
foreach ($sp_data as $sp_info) {
$id = $sp_info['id'] ?? '';
$meta_infos = json_decode($sp_info['seat_info'] ?? '', true) ?: [];
if (!empty($id) && !empty($meta_infos)) {
foreach ($meta_infos as $key => $item) {
if (array_key_exists($key, $types)) {
$type = $types[$key];
} else {
$type = current($types);
}
$icon = $type['icon'] ?? '';
$image = (!empty($icon) && is_numeric($icon)) ? ABPET_Function::get_image_url('', $icon) : '';
$data[$id][$key] = ['id' => ($sp_info['id'] ?? ''), 'icon' => $icon, 'img' => $image, 'label' => ($type['label'] ?? ''), 'color' => ($type['color'] ?? ''), 'seat' => $item];
}
}
}
}
}
return $data;
}
/************************************/
public function color_control(): void {
$colors = ABPET_Function::get_option('abpet_color');
//echo ''; print_r($colors); echo '
';
$available = !empty($colors['available']) ? $colors['available'] : "#D4EDDA";
$sold = !empty($colors['sold']) ? $colors['sold'] : "#F8D7DA";
$booked = !empty($colors['booked']) ? $colors['booked'] : "#6C757D";
$selected = !empty($colors['selected']) ? $colors['selected'] : "#007BFF";
?>
__('Invalid security token or Insufficient permissions.', 'abp-event-ticket'), 'type' => 'warn'], 403);
}
ob_start();
$colors = ABPET_Function::get_option('abpet_color');
$available = !empty($colors['available']) ? $colors['available'] : "#D4EDDA";
$sold = !empty($colors['sold']) ? $colors['sold'] : "#F8D7DA";
$booked = !empty($colors['booked']) ? $colors['booked'] : "#6C757D";
$selected = !empty($colors['selected']) ? $colors['selected'] : "#007BFF";
?>
$html, 'type' => 'success', 'msg' => __('Color Combination Form Loaded Successfully .....! ', 'abp-event-ticket')]);
}
public function save_color_control(): void {
if (!check_ajax_referer('abpet_admin_ajax_nonce', 'nonce', false) || !current_user_can('manage_options')) {
wp_send_json_error(['msg' => __('Invalid security token or Insufficient permissions.', 'abp-event-ticket'), 'type' => 'warn'], 403);
}
$post_val = fn($key, $default = '') => isset($_POST[$key]) ? sanitize_text_field(wp_unslash($_POST[$key])) : $default;
$options['available'] = $post_val('available_color');
$options['sold'] = $post_val('sold_color');
$options['booked'] = $post_val('booked_color');
$options['selected'] = $post_val('selected_color');
update_option('abpet_color', $options);
ob_start();
$this->color_control();
$html = ob_get_clean();
wp_send_json_success([
'html' => $html,
'msg' => __('Color Combination Saved Successfully..........!!', 'abp-event-ticket'),
'type' => 'success'
]);
}
/************************************/
public function ticket_list(): void {
$options = ABPET_Function::get_option('abpet_ticket');
if (count($options) > 0) { ?>
$item) {
if ($is_on || $counter === 0) {
$label = $item['label'] ?? '';
$prefix = $item['prefix'] ?? '';
if (!empty($label)) { ?>
__('Invalid security token or Insufficient permissions.', 'abp-event-ticket'), 'type' => 'warn'], 403);
}
ob_start();
$options = ABPET_Function::get_option('abpet_ticket');
?>
$html, 'type' => 'success', 'msg' => __('Ticket Type Form Loaded Successfully .....! ', 'abp-event-ticket')]);
}
public function save_ticket_type(): void {
if (!check_ajax_referer('abpet_admin_ajax_nonce', 'nonce', false) || !current_user_can('manage_options')) {
wp_send_json_error(['msg' => __('Invalid security token or Insufficient permissions.', 'abp-event-ticket'), 'type' => 'warn'], 403);
}
$post_int = fn($key, $default = 0) => isset($_POST[$key]) ? absint($_POST[$key]) : $default;
$post_array = fn($key) => (isset($_POST[$key]) && is_array($_POST[$key])) ? array_map('sanitize_text_field', wp_unslash($_POST[$key])) : [];
$options = [];
$ids = $post_array('id');
$names = $post_array('name');
$icon = $post_array('icon');
$color = $post_array('color');
$prefix = $post_array('prefix');
$post_id = $post_int('post_id');
if (!empty($names)) {
foreach ($names as $key => $name) {
if ($name !== '') {
$id = $ids[$key] ?? '';
$id = empty($id) ? uniqid() : $id;
$options[$id] = [
'label' => $name,
'icon' => $icon[$key] ?? '',
'color' => $color[$key] ?? '',
'prefix' => $prefix[$key] ?? '',
];
}
}
}
if (empty($options)) {
$options[uniqid()]['label'] = 'Ticket/Seat';
}
update_option('abpet_ticket', $options);
$html = '';
if (empty($post_id) || $post_id <= 0) {
ob_start();
$this->ticket_list();
$html = ob_get_clean();
}
wp_send_json_success([
'html' => $html,
'msg' => __('Ticket types Saved Successfully..........!!', 'abp-event-ticket'),
'js' => self::get_ticket_type_js(),
'type' => 'success'
]);
}
public function delete_ticket_type(): void {
if (!check_ajax_referer('abpet_admin_ajax_nonce', 'nonce', false) || !current_user_can('manage_options')) {
wp_send_json_error(['msg' => __('Invalid security token or Insufficient permissions.', 'abp-event-ticket'), 'type' => 'warn'], 403);
}
$id = isset($_POST['id']) ? sanitize_text_field(wp_unslash($_POST['id'])) : 0;
$options = ABPET_Function::get_option('abpet_ticket');
$options = is_array($options) ? $options : [];
if (!empty($id) && isset($options[$id])) {
unset($options[$id]);
if (empty($options)) {
$options[uniqid()]['label'] = 'Ticket/Seat';
}
update_option('abpet_ticket', $options);
}
ob_start();
$this->ticket_list();
$html = ob_get_clean();
wp_send_json_success([
'html' => $html,
'msg' => __('Ticket type Deleted Successfully!', 'abp-event-ticket'),
'js' => self::get_ticket_type_js(),
'type' => 'success'
]);
}
public static function form_ticket($ticket = [], $id = ''): void {
?>
|
|
|
|
|
0) {
foreach ($options as $key => $item) {
$icon = $item['icon'] ?? '';
$image = (!empty($icon) && is_numeric($icon)) ? ABPET_Function::get_image_url('', $icon) : '';
$data[] = ['id' => $key, 'icon' => $icon, 'img' => $image, 'label' => ($item['label'] ?? ''), 'prefix' => ($item['prefix'] ?? ''), 'color' => ($item['color'] ?? '#333'), 'type' => 'seat'];
}
}
}
return $data;
}
/******************************/
public function decor_list(): void {
$options = ABPET_Function::get_option('abpet_decor');
//echo ''; print_r($options); echo '
';
if (sizeof($options) > 0) { ?>
$item) {
$label = $item['label'] ?? '';
if (!empty($label)) { ?>
__('Invalid security token or Insufficient permissions.', 'abp-event-ticket'), 'type' => 'warn'], 403);
}
ob_start();
$options = ABPET_Function::get_option('abpet_decor'); ?>
$html, 'type' => 'success', 'msg' => __('Decor item Form Loaded Successfully .....! ', 'abp-event-ticket')]);
}
public function save_decor_item(): void {
if (!check_ajax_referer('abpet_admin_ajax_nonce', 'nonce', false) || !current_user_can('manage_options')) {
wp_send_json_error(['msg' => __('Invalid security token or Insufficient permissions.', 'abp-event-ticket'), 'type' => 'warn'], 403);
}
$post_array = fn($key) => (isset($_POST[$key]) && is_array($_POST[$key])) ? array_map('sanitize_text_field', wp_unslash($_POST[$key])) : [];
$options = [];
$ids = $post_array('id');
$names = $post_array('name');
$icon = $post_array('icon');
$color = $post_array('color');
if (!empty($names)) {
foreach ($names as $key => $name) {
if ($name !== '') {
$id = $ids[$key] ?? '';
$id = empty($id) ? uniqid() : $id;
$options[$id] = [
'label' => $name,
'icon' => $icon[$key] ?? '',
'color' => $color[$key] ?? '',
];
}
}
}
if (empty($options)) {
$options[uniqid()]['label'] = 'Ticket/Seat';
}
if (!array_key_exists(1, $options)) {
$options[1]['label'] = 'Blank';
}
$options[1]['icon'] = '';
$options[1]['color'] = '';
update_option('abpet_decor', $options);
ob_start();
$this->decor_list();
$html = ob_get_clean();
wp_send_json_success([
'html' => $html,
'msg' => __('Decoration Item Saved Successfully..........!!', 'abp-event-ticket'),
'js' => self::get_decor_js(),
'type' => 'success'
]);
}
public function delete_decor_item(): void {
if (!check_ajax_referer('abpet_admin_ajax_nonce', 'nonce', false) || !current_user_can('manage_options')) {
wp_send_json_error(['msg' => __('Invalid security token or Insufficient permissions.', 'abp-event-ticket'), 'type' => 'warn'], 403);
}
$id = isset($_POST['id']) ? absint(wp_unslash($_POST['id'])) : 0;
$options = ABPET_Function::get_option('abpet_decor');
$options = is_array($options) ? $options : [];
if (!empty($id) && isset($options[$id])) {
unset($options[$id]);
if (!array_key_exists(1, $options)) {
$options[1]['label'] = 'Blank';
}
$options[1]['icon'] = '';
$options[1]['color'] = '';
ksort($options);
update_option('abpet_decor', $options);
}
ob_start();
$this->decor_list();
$html = ob_get_clean();
wp_send_json_success([
'html' => $html,
'msg' => __('Decor Item Deleted Successfully!', 'abp-event-ticket'),
'js' => self::get_decor_js(),
'type' => 'success'
]);
}
public static function form_decor($item = [], $id = ''): void {
?>
|
|
|
|
0) {
foreach ($options as $key => $item) {
$icon = $item['icon'] ?? '';
$image = (!empty($icon) && is_numeric($icon)) ? ABPET_Function::get_image_url('', $icon) : '';
$data[] = ['id' => $key, 'icon' => $icon, 'img' => $image, 'label' => ($item['label'] ?? ''), 'color' => ($item['color'] ?? '#333'), 'type' => 'other'];
}
}
}
return $data;
}
}
new ABPET_Seat_Plan();
}