<?php
require_once('session.php');
if (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] !== 'on') {
    header("HTTP/1.1 403 Forbidden");
    echo "Access forbidden. Use HTTPS.";
    exit();
    }

// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

// Delete all users except 'superadmin'
$sqlu = "DELETE FROM tb_user WHERE level != 'superadmin'";
if (mysqli_query($conn, $sqlu)) {
    header('location:../?notif=1');
} else {
    echo "Error deleting user data: " . mysqli_error($conn);
}

// Delete from tb_bank where userID is not '1'
$sqlb = "DELETE FROM tb_bank WHERE userID != '1'";
if (mysqli_query($conn, $sqlb)) {
    header('location:../?notif=1');
} else {
    echo "Error deleting bank data: " . mysqli_error($conn);
}

// Delete from tb_balance where userID is not '1'
$sqlba = "DELETE FROM tb_balance WHERE userID != '1'";
if (mysqli_query($conn, $sqlba)) {
    header('location:../?notif=1');
} else {
    echo "Error deleting balance data: " . mysqli_error($conn);
}

$sqlt = "DELETE FROM tb_transaksi WHERE userID != '1'";
if (mysqli_query($conn, $sqlt)) {
    header('location:../?notif=1');
} else {
    echo "Error deleting balance data: " . mysqli_error($conn);
}
$sqlto = "DELETE FROM tb_token WHERE cuid";
if (mysqli_query($conn, $sqlto)) {
    header('location:../?notif=1');
} else {
    echo "Error deleting balance data: " . mysqli_error($conn);
}
$sqlst = "DELETE FROM tb_stat WHERE cuid";
if (mysqli_query($conn, $sqlst)) {
    header('location:../?notif=1');
} else {
    echo "Error deleting balance data: " . mysqli_error($conn);
}

// Close connection
mysqli_close($conn);
?>
