<?php
session_start();
require '../config.php';
require '../lib/session_login_admin.php';
// Coin DEPOSIT //
$cek_CoinDepo = $conn->query("SELECT * FROM penukaran_coin WHERE tipe = 'Deposit'");
$data_CoinDepo = $cek_CoinDepo->fetch_assoc();

// Coin PEMESANAN //
$cek_CoinOrder = $conn->query("SELECT * FROM penukaran_coin WHERE tipe = 'Pemesanan'");
$data_CoinOrder = $cek_CoinOrder->fetch_assoc();

if (isset($_POST['coin_deposit'])) {
    $coin = $conn->real_escape_string($_POST['coin']);
    $pesan = $conn->real_escape_string($_POST['pesan']);
    $nilai = $conn->real_escape_string($_POST['nilai']);
    $min = $conn->real_escape_string($_POST['min']);

    if (!$coin || !$nilai || !$pesan || !$min) {
        $_SESSION['hasil'] = array('alert' => 'danger', 'judul' => 'Gagal', 'pesan' => 'Input Masih Ada Yang Kosong');
    } else {
        if ($conn->query("UPDATE penukaran_coin SET jumlah_coin = '$coin', coin_pemesanan = '$pesan', nominal = '$nilai', min = '$min' WHERE tipe = 'Deposit'") == true) {
            $_SESSION['hasil'] = array('alert' => 'success', 'judul' => 'Berhasil', 'pesan' => 'Berhasil Di Update');
        } else {
            $_SESSION['hasil'] = array('alert' => 'danger', 'judul' => 'Gagal', 'pesan' => 'Error.');
        }
    }
    header("Location: " . $_SERVER['REQUEST_URI'] . "");
    exit();
} else if (isset($_POST['kosong'])) {
}
require '../lib/header_admin.php';
?>
<div class="content-wrapper">
    <div class="page-header">
        <h3 class="page-title"> Pengaturan Coin</h3>
        <nav aria-label="breadcrumb">
            <ol class="breadcrumb">
                <li class="breadcrumb-item"><a href="/admin/penukaran-coin">Settings</a></li>
                <li class="breadcrumb-item active" aria-current="page">Coin</li>
            </ol>
        </nav>
    </div>
    <?php
    if (isset($_SESSION['hasil'])) {
    ?>
        <div class="alert alert-<?php echo $_SESSION['hasil']['alert'] ?>">
            <button type="button" class="close" data-dismiss="alert">×</button>
            <b><?php echo $_SESSION['hasil']['judul'] ?></b> <?php echo $_SESSION['hasil']['pesan'] ?>
        </div>
    <?php
        unset($_SESSION['hasil']);
    }
    ?>

    <div class="row">
        <div class="col-md-12 grid-margin stretch-card">
            <div class="card">
                <div class="card-body">
                    <h4 class="card-title">Referral Coin Deposit <button data-toggle="modal" data-target="#exampleModalLong4" class="btn btn-info btn-icon-text"><i class="mdi mdi-bell-ring"></i></button></h4>
                    <form class="forms-sample" method="POST">
                        <div class="form-group row">
                            <label for="coin" class="col-sm-3 col-form-label">Coin Deposit</label>
                            <div class="col-sm-9">
                                <input type="number" class="form-control" id="coin" name="coin" value="<?php echo $data_CoinDepo['jumlah_coin']; ?>">
                            </div>
                        </div>
                        <div class="form-group row">
                            <label for="pesan" class="col-sm-3 col-form-label">Coin Pemesanan</label>
                            <div class="col-sm-9">
                                <input type="number" class="form-control" id="pesan" name="pesan" value="<?php echo $data_CoinDepo['coin_pemesanan']; ?>">
                            </div>
                        </div>
                        <div class="form-group row">
                            <label for="nilai" class="col-sm-3 col-form-label">Nilai Rp /1 Coin</label>
                            <div class="col-sm-9">
                                <input type="number" class="form-control" id="nilai" name="nilai" value="<?php echo $data_CoinDepo['nominal']; ?>">
                            </div>
                        </div>
                        <div class="form-group row">
                            <label for="min" class="col-sm-3 col-form-label">Minimal Penukaran</label>
                            <div class="col-sm-9">
                                <input type="number" class="form-control" id="min" name="min" value="<?php echo $data_CoinDepo['min']; ?>">
                            </div>
                        </div>
                        <button type="submit" name="coin_deposit" class="btn btn-info btn-lg btn-block">Submit</button>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- content-wrapper ends -->
<!--MODAL-->
<div class="modal fade" id="exampleModalLong4">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title">Ilustrasi Nilai Penukaran Coin</h4>
                <button type="button" class="close text-white" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <ul>
                    <li>Ketika Users/Member A Melakukan Deposit Yang Sudah Mendaftar Dengan Kode Referral B</li>
                    <li>Jumlah Coin = Adalah jumlah/total coin yang di dapat setiap deposit user yang memakai referal kode B dan coin akan masuk ke pemilik kode referal B yang kode referral B di pakai oleh A</li>
                    <li>Nilai Rp /1 Coin = Adalah nilai per/ 1 coin Atau rupiah Contoh : Jumlah Coin 10 & Nilai Rp /1 Coin 100 maka (10 x 100 = 1000) jika coin di tukarkan maka saldo yang di dapat oleh member B adalah 1000</li>
                    <li>Minimal Penukaran = Adalah Nilai Minimal Penukaran Total Jumlah Coin, Jika Coin Belum Mencapai Jumlah Minimal Maka Member B Belum Bisa Menukarkan Coin Menjadi Saldo</li>
                    <li>Coin Pemesanan Adalah Jumlah Coin Yang Di Dapat Oleh Member Setiap Transaksi PPOB.</li>
                </ul>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>
<!-- /.modal -->
<?php
require '../lib/footer_admin.php';
?>