<?php
/**
 *  Copyright (C) 2022, 2024  Double Bastion LLC
 *
 *  This file is part of Roundpin, which is licensed under the
 *  GNU Affero General Public License Version 3.0. The license terms
 *  are detailed in the "LICENSE.txt" file located in the root directory.
 */

session_start();

if (isset($_POST['s_ajax_call']) && ($_POST['s_ajax_call'] == $_SESSION['validate_s_access'])) {

 define('ACCESSCONST', TRUE);

 require('db-connect.php');

    $username = $_POST['username'];

    // Close Roundpin user account
    $enabled = 0;
    $closeacquery = $mysqli->prepare("UPDATE app_users SET enabled = ? WHERE username = ?");
    $closeacquery->bind_param("is", $enabled, $username);
    $closeacquery->execute();

    if ($closeacquery) {
        $closeaccountmessage = "Your Roundpin user account has been closed successfully!";
    } else { $closeaccountmessage = "An error occurred while attempting to close your user account! Please talk to the system administrator about this issue."; }

    echo json_encode($closeaccountmessage);

} else {
    header("Location: ../login.php");
}

?>
