diff --git a/includes/class-forum-abo.php b/includes/class-forum-abo.php index a6d76ca..90a5748 100644 --- a/includes/class-forum-abo.php +++ b/includes/class-forum-abo.php @@ -49,6 +49,30 @@ class WBF_Abo { ]; } + // Item-Abos aus WordPress DB (wis_item_abo_subs) + $item_abos = $wpdb->get_results( $wpdb->prepare( + "SELECT id, label, item_id, daily_qty, cancelled, + DATE_FORMAT(expires_at, '%%d.%%m.%%Y') AS expires_at_fmt + FROM {$wpdb->prefix}wis_item_abo_subs + WHERE player_name = %s + AND status = 'active' + AND expires_at > NOW() + ORDER BY created_at ASC", + $mc_name + ), ARRAY_A ); + + if ( $item_abos ) { + foreach ( $item_abos as &$row ) { + $row['id'] = (int) $row['id']; + $row['daily_qty'] = (int) $row['daily_qty']; + $row['cancelled'] = (bool) $row['cancelled']; + } + unset($row); + $result['item_abos'] = $item_abos; + } else { + $result['item_abos'] = []; + } + // Spigot MySQL für Fly-Usage + Plot-Daten $conn = self::get_spigot_db(); if ( $conn ) { @@ -78,7 +102,7 @@ class WBF_Abo { return $result; } - public static function cancel_abo( string $mc_name, string $type ): bool { + public static function cancel_abo( string $mc_name, string $type, int $abo_id = 0 ): bool { global $wpdb; if ( $type === 'fly_abo' ) { $rows = $wpdb->update( @@ -97,6 +121,22 @@ class WBF_Abo { $a = $stmt->affected_rows; $stmt->close(); $conn->close(); return $a > 0; } + if ( $type === 'item_abo' ) { + if ( $abo_id <= 0 ) return false; + // Sicherheitscheck: Abo muss dem Spieler gehören + $existing = $wpdb->get_row( $wpdb->prepare( + "SELECT id, label FROM {$wpdb->prefix}wis_item_abo_subs + WHERE id = %d AND player_name = %s AND status = 'active' AND cancelled = 0", + $abo_id, $mc_name + ) ); + if ( ! $existing ) return false; + $rows = $wpdb->update( + $wpdb->prefix . 'wis_item_abo_subs', + ['cancelled' => 1, 'cancelled_at' => current_time('mysql')], + ['id' => $abo_id] + ); + return $rows > 0; + } return false; } @@ -110,6 +150,7 @@ class WBF_Abo { $abos = self::get_all_abos($mc_name); $fly_abo = $abos['fly_abo'] ?? null; $plot_abo = $abos['plot_abo'] ?? null; + $item_abos = $abos['item_abos'] ?? []; $plot_extra = (int)($abos['plot_extra'] ?? 0); $fly_used = (int)($abos['fly_used_sec'] ?? 0); $fly_max = (int) get_option('wis_fly_abo_max_daily_hours', 6) * 3600; @@ -117,7 +158,7 @@ class WBF_Abo { $shop_url = esc_url(get_option('wis_shop_url', home_url('/ingame-shop/'))); $nonce = wp_create_nonce('wbf_nonce'); $ajax_url = admin_url('admin-ajax.php'); - $has_any = $fly_abo || $plot_abo || $plot_extra > 0; + $has_any = $fly_abo || $plot_abo || $plot_extra > 0 || !empty($item_abos); ob_start(); ?>