query("SELECT * FROM festivos ORDER BY fecha ASC"); echo json_encode(['success' => true, 'data' => $stmt->fetchAll()]); break; case 'POST': $input = json_decode(file_get_contents('php://input'), true); if (empty($input['fecha']) || empty($input['motivo'])) { http_response_code(400); echo json_encode(['success' => false, 'message' => 'Fecha y motivo son obligatorios']); exit(); } $stmt = $pdo->prepare(" INSERT INTO festivos (fecha, motivo, es_recurrente, horario_especial_apertura, horario_especial_cierre, cerrado_total) VALUES (:fecha, :motivo, :recurrente, :apertura, :cierre, :cerrado) "); $stmt->execute([ ':fecha' => $input['fecha'], ':motivo' => $input['motivo'], ':recurrente' => !empty($input['es_recurrente']) ? 1 : 0, ':apertura' => !empty($input['horario_especial_apertura']) ? $input['horario_especial_apertura'] : null, ':cierre' => !empty($input['horario_especial_cierre']) ? $input['horario_especial_cierre'] : null, ':cerrado' => !empty($input['cerrado_total']) ? 1 : 0 ]); echo json_encode(['success' => true, 'message' => 'Día festivo/espacial guardado correctamente']); break; case 'DELETE': $id = isset($_GET['id']) ? (int)$_GET['id'] : 0; if ($id <= 0) { http_response_code(400); echo json_encode(['success' => false, 'message' => 'ID no válido']); exit(); } $stmt = $pdo->prepare("DELETE FROM festivos WHERE id = ?"); $stmt->execute([$id]); echo json_encode(['success' => true, 'message' => 'Día festivo eliminado']); break; default: http_response_code(405); echo json_encode(['success' => false, 'message' => 'Método no permitido']); break; } } catch (PDOException $e) { http_response_code(500); echo json_encode(['success' => false, 'message' => 'Error en el servidor', 'error' => $e->getMessage()]); } ?>