<?php
require_once('session.php');
require_once('../../api/nexus.php');
if (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] !== 'on') {
    header("HTTP/1.1 403 Forbidden");
    echo "Access forbidden. Use HTTPS.";
    exit();
}
$id = $_GET['cuid'];
$sql_1 = mysqli_query($conn, "SELECT * FROM `tb_transaksi` WHERE cuid = '$id'") or die(mysqli_error());
$s1 = mysqli_fetch_array($sql_1);
$usersID = $s1['userID'];
$amounts = $s1['total'];
$nominal = intval($amounts);

if ($s1['status'] == 0) {
    $cek_usernya = mysqli_query($conn, "SELECT * FROM tb_user WHERE cuid = '$usersID'");
    $data_usernya = mysqli_fetch_array($cek_usernya);
    $extplayer = $data_usernya['extplayer'];
    $sql_255 = mysqli_query($conn, "SELECT * FROM `tb_apigames` WHERE cuid = 1") or die(mysqli_error($conn));
    $s255 = mysqli_fetch_array($sql_255);
    $update = mysqli_query($conn, "UPDATE `tb_transaksi` SET `status` = 2 WHERE `cuid` = '$id'") or die(mysqli_error($conn));

    $getBalance = mysqli_query($conn, "SELECT * FROM `tb_balance` WHERE userID = '$usersID'") or die(mysqli_error());
    $gb = mysqli_fetch_array($getBalance);
    $saldoAktif = $gb['active'];

    // Update saldo pengguna
    $newSaldo = $saldoAktif + $amounts;
    $updateBalance = mysqli_query($conn, "UPDATE `tb_balance` SET `active` = '$newSaldo' WHERE `userID` = '$usersID'") or die(mysqli_error($conn));
}
header('location:../withdraw/');
