<?php
if ($c['level'] == "superadmin") {

    if (isset($_GET['id'])) {
        $id = intval($_GET['id']);

        // Ambil status user sekarang
        $cek = mysqli_query($koneksi, "SELECT status FROM tb_user WHERE id='$id'");
        $user = mysqli_fetch_assoc($cek);

        if ($user) {

            if ($user['status'] == 'Suspend') {
                // UNSUSPEND
                $query = mysqli_query(
                    $koneksi,
                    "UPDATE tb_user SET status='Active' WHERE id='$id'"
                );
                $pesan = "User berhasil di-Unsuspend";
            } else {
                // SUSPEND
                $query = mysqli_query(
                    $koneksi,
                    "UPDATE tb_user SET status='Suspend' WHERE id='$id'"
                );
                $pesan = "User berhasil di-Suspend";
            }

            if ($query) {
                echo "
                <script>
                    alert('$pesan');
                    window.location='?page=user';
                </script>
                ";
            } else {
                echo "
                <script>
                    alert('Gagal update status user');
                    window.location='?page=user';
                </script>
                ";
            }

        }

    }

} else {
    echo "
    <script>
        alert('Akses ditolak!');
        window.location='?page=user';
    </script>
    ";
}
?>