<?php
require_once __DIR__ . '/Config.php'; require_once SRC_PATH . '/classes/Database.php'; header('Content-Type: application/json'); if (session_status() === PHP_SESSION_NONE) { session_start(); } $action = isset($_GET['action']) ? $_GET['action'] : (isset($_POST['action']) ? $_POST['action'] : null); try { switch ($action) { case 'check_save': $dbExists = file_exists(DATABASE_PATH . '/game.db'); if (!$dbExists) { echo json_encode(['exists' => false]); exit; } $db = Database::getInstance(); $result = $db->query("SELECT COUNT(*) as count FROM game_state")->fetch(PDO::FETCH_ASSOC); echo json_encode(['exists' => isset($result['count']) && $result['count'] > 0]); break; case 'reset_session': $_SESSION['from_menu'] = false; if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest') { echo json_encode(['success' => true]); } else { header('Location: ' . BASE_URL . '/src/utils/Menu.php'); } break; default: http_response_code(400); echo json_encode(['error' => 'Invalid action']); } } catch (Exception $e) { http_response_code(500); echo json_encode(['error' => $e->getMessage()]); } 