<?php
    session_start();
    include("../scripts/connection.php");
    include("../scripts/functions.php");
    $user_data = check_admin($con);

    if($_SERVER['REQUEST_METHOD'] == "POST") {
        try {
            $selected_user_id  = get_id_user_by_user_id($con, $_SESSION['user_id']);
            if($selected_user_id != $_POST['id']) {
                $stmt = $con->prepare("DELETE FROM users WHERE id = :id");
                $stmt->execute(['id' => $_POST['id']]);
            }
        } catch(PDOException $e) {
            handle_pdo_exception($e);
        }
    }

    $con = null;

    header("Location: manage_user.php");
    die;
?>