query('SELECT id, image_url, target_url FROM gtl_fake_ads WHERE is_active=1 ORDER BY id DESC')->fetchAll(); respond(['ok' => true, 'ads' => $rows]); } public function fake_ads_all(): void { $pdo = Database::pdo(); $now = time(); $authUserId = $_SESSION['user_id'] ?? null; RoomService::requireAdminApi($pdo, $authUserId); $rows = $pdo->query('SELECT id, image_url, target_url, is_active, created_at FROM gtl_fake_ads ORDER BY id DESC')->fetchAll(); respond(['ok' => true, 'ads' => $rows]); } public function fake_ad_create(): void { $pdo = Database::pdo(); $now = time(); $authUserId = $_SESSION['user_id'] ?? null; RoomService::requireAdminApi($pdo, $authUserId); $body = input(); $img = substr(trim((string) ($body['image_url'] ?? '')), 0, 500); $target= substr(trim((string) ($body['target_url'] ?? '')), 0, 500); if ($img === '') respond(['error' => 'Bild-URL erforderlich.'], 400); $pdo->prepare('INSERT INTO gtl_fake_ads (image_url, target_url, is_active, created_at) VALUES (?,?,1,?)') ->execute([$img, $target !== '' ? $target : null, $now]); respond(['ok' => true, 'id' => (int) $pdo->lastInsertId()]); } public function fake_ad_toggle(): void { $pdo = Database::pdo(); $now = time(); $authUserId = $_SESSION['user_id'] ?? null; RoomService::requireAdminApi($pdo, $authUserId); $body = input(); $id = (int) ($body['id'] ?? 0); $pdo->prepare('UPDATE gtl_fake_ads SET is_active = 1 - is_active WHERE id = ?')->execute([$id]); respond(['ok' => true]); } public function fake_ad_delete(): void { $pdo = Database::pdo(); $now = time(); $authUserId = $_SESSION['user_id'] ?? null; RoomService::requireAdminApi($pdo, $authUserId); $body = input(); $id = (int) ($body['id'] ?? 0); $pdo->prepare('DELETE FROM gtl_fake_ads WHERE id = ?')->execute([$id]); respond(['ok' => true]); } }