<?php
// session_start();
require("../includes/db_connect.php");
require_once("includes/session_token.php");

$accountId = $_SESSION['usr_accountId'];

$sql = "SELECT * FROM annual_trade_history WHERE accountId=? AND type=? AND status=?  ORDER BY date DESC LIMIT 1";
$sth = $conn->prepare($sql, [PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY]);
$sth->execute([$accountId, "Ninja 2.1 (Annually)", 1]);
$history1 = $sth->fetchAll();

$sql = "SELECT * FROM annual_trade_history WHERE accountId=? AND type=? AND status=? ORDER BY date DESC LIMIT 1";
$sth = $conn->prepare($sql, [PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY]);
$sth->execute([$accountId, "Subzero 3.2 (Annually)", 1]);
$history2 = $sth->fetchAll();

$sql = "SELECT * FROM annual_trade_history WHERE accountId=? AND type=? AND status=?  ORDER BY date DESC LIMIT 1";
$sth = $conn->prepare($sql, [PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY]);
$sth->execute([$accountId, "Rocket 4.1 (Annually)", 1]);
$history3 = $sth->fetchAll();

$sql = "SELECT * FROM purchased_bots WHERE accountId=? AND type IN ('Ninja 2.1 (Annually)','Subzero 3.2 (Annually)','Rocket 4.1 (Annually)') AND status=?  ORDER BY date DESC LIMIT 1";
$sth = $conn->prepare($sql, [PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY]);
$sth->execute([$accountId, 1]);
$history4 = $sth->fetchAll();

if((count($history3) > 0) || (count($history2) > 0) || (count($history1) > 0) || (count($history4) > 0) ){
    header('Location: trade-annually');
    exit();
}

?>
<!DOCTYPE html>
<html lang="en">

<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>Purchase Trading Bot</title>
    <link rel="stylesheet" href="../css/bootstrap-select-country.min.css" />
    <link rel="stylesheet" href="../build/css/intlTelInput.css">

    <?php require_once("includes/header.php"); ?>


    <div class="content ht-100v pd-0">
        <div class="content-header center">
            <img src="../img/logo-white.png" class="aside-logo" style="width: 160px;" />
        </div>
        <div class="content-body">
            <div class="container pd-x-0">
                <div class="d-sm-flex align-items-center justify-content-between mg-b-20 mg-lg-b-25 mg-xl-b-30">
                    <div>
                        <nav aria-label="breadcrumb">
                            <ol class="breadcrumb breadcrumb-style1 mg-b-10">
                                <li class="breadcrumb-item"><a href="account">Dashboard</a></li>
                            </ol>
                        </nav>
                        <h4 class="mg-b-0 tx-spacing--1">Purchase Trading Bot</h4>
                    </div>
                </div>

                <div class="row row-xs">
                    <div class="col-lg-3 col-md-3 col-sm-12">
                        <div class="card">
                            <div class="card-body d-flex flex-column text-center">
                                <div class="tx-100 lh-1"><i class="icon ion-ios-bicycle"></i></div>
                                <h3 class="mg-b-25">Ninja 3.6</h3>
                                <!-- <p class="tx-color-03 mg-b-25">Bot ID: <span style="color:#000">1548980</span></p> -->
                                <a href="trade?package=annually-ninja" class="btn btn-primary btn-block">Add
                                    subscription</a>
                            </div>
                        </div>
                    </div>
                    <div class="col-lg-3 col-md-3 col-sm-12">
                        <div class="card">
                            <div class="card-body d-flex flex-column text-center">
                                <div class="tx-100 lh-1"><i class="icon ion-ios-car"></i></div>
                                <h3 class="mg-b-25">Subzero 5.2</h3>
                                <!-- <p class="tx-color-03 mg-b-25">Bot ID: <span style="color:#000">1548981</span></p> -->
                                <a href="trade?package=annually-subzero" class="btn btn-primary btn-block">Add
                                    subscription</a>
                            </div>
                        </div>
                    </div>
                    <div class="col-lg-3 col-md-3 col-sm-12">
                        <div class="card">
                            <div class="card-body d-flex flex-column text-center">
                                <div class="tx-100 lh-1"><i class="icon ion-ios-boat"></i></div>
                                <h3 class="mg-b-25">Rocket 7.1</h3>
                                <!-- <p class="tx-color-03 mg-b-25">Bot ID: <span style="color:#000">1548982</span></p> -->
                                <a href="trade?package=annually-rocket" class="btn btn-primary btn-block">Add
                                    subscription</a>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
        </div><!-- content-body -->
    </div><!-- content -->

    <?php require_once("includes/footer.php"); ?>
    <script src="../build/js/intlTelInput.min.js"></script>
    <script src="../build/js/intlTelInput-jquery.min.js"></script>
    <script src="../js/bootstrap-select-country.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function() {
        var classes = $("#mn-trading").prop('class');
        $("#mn-trading").prop('class', classes + ' active pcoded-trigger');

        var classes = $("#mn-annually-trading").prop('class');
        $("#mn-annually-trading").prop('class', classes + ' active pcoded-trigger');

    });
    </script>

    </body>

</html>