<?php
    require_once('session.php');
    
    $metode = htmlspecialchars(strip_tags(trim($_POST['metode'] ?? '')), ENT_QUOTES, 'UTF-8');
    $nominal = preg_replace('/[^A-Za-z0-9\-]/', '', $_POST['nominal']);
    $pay_from = htmlspecialchars(strip_tags(trim($_POST['pay_from'] ?? '')), ENT_QUOTES, 'UTF-8');
    $catatan = htmlspecialchars(strip_tags(trim($_POST['catatan'] ?? '')), ENT_QUOTES, 'UTF-8');
    $postID = htmlspecialchars(strip_tags(trim($_POST['postID'] ?? '')), ENT_QUOTES, 'UTF-8');

    $unik = date('Hs');
    $kode_unik = substr(str_shuffle(1234567890), 0, 3);
    $kd_transaksi = date('Ymds') . $kode_unik;

    $totalBayar = $nominal + $kode_unik;

    $created_date = date('Y-m-d H:i:s');

    if (isset($_POST['submit'])) {
        if ($nominal < 0) {
            header('location:../bank/deposit?notif=2');
            exit();
        } else {
            // $message = "Ada permintaan deposit\n\n";
            $message .= "Nominal : Rp" . number_format($nominal) . "\n\n";
            $message .= "Id pengirim : ". $u['user'];
            // $api = new BotTelegram();
            // $sendertele = $api->sendToTelegram($message);
            $insert_transaksi = mysqli_query($conn, "INSERT INTO `tb_transaksi` (`kd_transaksi`, `date`, `transaksi`, `total`, `saldo`, `note`, `gameid`, `providerID`, `jenis`, `metode`, `pay_from`, `userID`, `status`) VALUES ('$kd_transaksi','$created_date','Top Up','$nominal',0, '$catatan', '', '0','1','$metode','$pay_from','$postID',0)") or die(mysqli_error());
//echo 'sukse';
    header('location:../bank/deposit?notif=1');
            exit();
        }
    } else {
     header('location:../bank/deposit?notif=3');
    }
 ?>