<?php
    /*session_start();
    require_once(__DIR__ . "/../conf.php");
    $login = session("login") ? : post('login');
    $summa = request("summa") ? : post('summa');
    $address = trim(request("address")) ? : post('address');
    //$summa = bm_convert_usd_2_btc($summa);
    $summa = format_btc($summa);
    $order = request("order") ? : post('order');
    $system = "Bitcoin";
    $comment = request("comment") ? : post('comment');
    $url_success = request('url_success') ? : post('url_success');
    $url_fail = request('url_fail') ? : post('url_fail');
    $data = [
        'api_key' => $block_io_sci_api_key,
        'addresses' => $address,
    ];
    $url = 'https://block.io/api/v2/get_address_balance/?' . http_build_query($data);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    //    curl_setopt($ch, CURLOPT_PROXY, '93.90.220.11:3128');
    $result = curl_exec($ch);
    curl_close($ch);
    $json_result = json_decode($result);
    $available_balance = format_btc($json_result->data->available_balance);
    $check = $available_balance === $summa;*/

    session_start();
    require_once(__DIR__."/../conf.php");

    /* прием биткоина для блокио */
    $url = request_get_protocol().$_SERVER["SERVER_NAME"]."/";
    $access = get_row_by_field('payment_system', 'access', 'block.io');
    if ($access && $access['status'] === 'on') {
        file_get_contents($url."pay/blockio/index.php");
    }

    $login = session("login");
    $summa = request("summa");
    $address = trim(request("address"));
    //$summa = bm_convert_usd_2_btc($summa);
    $summa = format_btc($summa);
    $order = request("order");

    $res = get_row_by_field('invest', 'id', $order);
    if ($res['login'] !== $login) {
        redirect('/');
    }

    $system = $res['system'];
    $currency = $res['currency'];
    if ($system === "BitCoin") {
        $currency = 'BTC';
    } else if ($system === "LiteCoin") {
        $currency = 'LTC';
    } else if ($system === "DogeCoin") {
        $currency = 'DOGE';
    }

    $check = $res['status'];
    $comment = request("comment");
?>
<title>Oplata</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">

<div class="container">
    <div class="row">
        <div class="col-sm-6 col-sm-offset-3 bl-panel-1">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <?php echo T("Оплата счета "); ?><b>#<?php echo $order; ?></b>
                    <?php echo T("на сумму "); ?><b>
                        <span><?php echo $summa; ?></span>
                    </b> <b><?php echo escape($currency); ?></b>
                </div>
                <div class="panel-body">
                    <p>
                        <?php echo T("Выполните перевод на адрес "); ?>
                        <span style="font-weight: bold;"><?php echo $address; ?></span>
                        <?php echo T(" в размере "); ?>
                        <span style="font-weight: bold;"><?php echo $summa; ?></span>
                        <b><?php echo escape($currency); ?></b>

                    </p>
                    <p>
                        <i>
                            <?php echo escape($comment); ?>
                        </i>
                    </p>
                    <div class="row">
                        <div class="col-sm-3 col-sm-offset-3">
                            <form action="<?php echo request("url_fail"); ?>">
                                <button type="submit" class="btn btn-lg btn-default">
                                    <?php echo T("Назад"); ?>
                                </button>
                            </form>
                        </div>
                        <div class="col-sm-3">
                            <form action="<?php echo ($check) ? request('url_success') : ''; ?>" <?php echo ($check) ? '' : 'method="post"'; ?>>
                                <input type="hidden" name="login" value="<?php echo escape($login); ?>">
                                <input type="hidden" name="summa" value="<?php echo escape($summa); ?>">
                                <input type="hidden" name="address" value="<?php echo escape($address); ?>">
                                <input type="hidden" name="order" value="<?php echo escape($order); ?>">
                                <input type="hidden" name="system" value="<?php echo escape($system); ?>">
                                <input type="hidden" name="comment" value="<?php echo escape($comment); ?>">
                                <input type="hidden" name="url_fail" value="<?php echo escape($url_fail); ?>">
                                <input type="hidden" name="url_success" value="<?php echo escape($url_success); ?>">
                                <?php if ($check) { ?>
                                    <button type="submit" class="btn btn-lg btn-success">
                                        <?php echo T("Оплачено"); ?>
                                    </button>
                                <?php } else { ?>
                                    <button type="submit" class="btn btn-lg btn-warning">
                                        <?php echo T("Обновить"); ?>
                                    </button>
                                <?php } ?>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div style="position: absolute;bottom:20px;right:20px;">
        <a target="_blank" href="http://blitz-market.ru/?utm_term=СтраницаПереводаБиткойновBlockIO&utm_source=<?php echo server("SERVER_NAME"); ?>">
            Oplata
        </a>
    </div>
    <style>
        .bl-panel-1 {
            margin-top: 15%;
        }

        .bl-panel-1 .panel-heading {
            background-color: #ffe046;
            border-color: black;
        }

        .bl-panel-1 .panel {
            border-color: black;
        }
    </style>
