<?php
require '../../conexao/conexao.php';
session_start();
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['id_percentual'])) {
    $id_percentual = $_POST['id_percentual'];

    if (isset($_POST['confirmacao']) && $_POST['confirmacao'] === 'sim') {
        $stmt_pessoa = $connectionmysql->prepare("DELETE FROM percentual WHERE id_percentual = ?");
        $stmt_pessoa->bind_param("i", $id_percentual);
        $stmt_pessoa->execute();

        $filtros = isset($_SESSION['filtros']) ? http_build_query($_SESSION['filtros']) : '';

        $location = './index.php?status=sucesso';
        if (!empty($filtros)) {
            $location .= '&' . $filtros;
        }

        header("Location: $location");
        exit;
    } else {
        $filtros = isset($_SESSION['filtros']) ? http_build_query($_SESSION['filtros']) : '';

        $location = 'index.php';
        if (!empty($filtros)) {
            $location .= '?' . $filtros;
        }

        header("Location: $location");
        exit;
    }
}
