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

$accountId = $_SESSION['usr_accountId'];

$bot1 = "";
$bot2 = "";
$bot3 = "";
$bot4 = "";
$bot5 = "";
$bot6 = "";
$bot7 = "";
$bot8 = "";
$bot9 = "";
$bot10 = "";
$bot_purchase_id1 = "";
$bot_purchase_id2 = "";
$bot_purchase_id3 = "";
$bot_purchase_id4 = "";
$bot_purchase_id5 = "";
$bot_purchase_id6 = "";
$bot_purchase_id7 = "";
$bot_purchase_id8 = "";
$bot_purchase_id9 = "";
$bot_purchase_id10 = "";

// community bot
$sql = "SELECT * FROM bot_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, "Community Bot", 1]);
$history = $sth->fetchAll();

if (count($history) > 0) {
    $bot10 = "<div><span class='badge badge-pill badge-success' style='float:right;'>Active</span></div>";
    $bot_purchase_id10 = $history[0]['bot_purchase_id'];
}

// monthly
$sql = "SELECT * FROM monthly_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 (Monthly)", 1]);
$history1 = $sth->fetchAll();

if (count($history1) > 0) {
    $bot1 = "<div><span class='badge badge-pill badge-success' style='float:right;'>Active</span></div>";
    $bot_purchase_id1 = $history1[0]['bot_purchase_id'];
}

$sql = "SELECT * FROM monthly_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 (Monthly)", 1]);
$history2 = $sth->fetchAll();

if (count($history2) > 0) {
    $bot2 = "<div><span class='badge badge-pill badge-success' style='float:right;'>Active</span></div>";
    $bot_purchase_id2 = $history2[0]['bot_purchase_id'];
}

$sql = "SELECT * FROM monthly_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 (Monthly)", 1]);
$history3 = $sth->fetchAll();

if (count($history3) > 0) {
    $bot3 = "<div><span class='badge badge-pill badge-success' style='float:right;'>Active</span></div>";
    $bot_purchase_id3 = $history3[0]['bot_purchase_id'];
}

// quarterly
$sql = "SELECT * FROM quarterly_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 (Quarterly)", 1]);
$history7 = $sth->fetchAll();

if (count($history7) > 0) {
    $bot7 = "<div><span class='badge badge-pill badge-success' style='float:right;'>Active</span></div>";
    $bot_purchase_id7 = $history7[0]['bot_purchase_id'];
}

$sql = "SELECT * FROM quarterly_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 (Quarterly)", 1]);
$history8 = $sth->fetchAll();

if (count($history8) > 0) {
    $bot8 = "<div><span class='badge badge-pill badge-success' style='float:right;'>Active</span></div>";
    $bot_purchase_id8 = $history8[0]['bot_purchase_id'];
}

$sql = "SELECT * FROM quarterly_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 (Quarterly)", 1]);
$history9 = $sth->fetchAll();

if (count($history9) > 0) {
    $bot9 = "<div><span class='badge badge-pill badge-success' style='float:right;'>Active</span></div>";
    $bot_purchase_id9 = $history9[0]['bot_purchase_id'];
}

// annually
$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]);
$history4 = $sth->fetchAll();

if (count($history4) > 0) {
    $bot4 = "<div><span class='badge badge-pill badge-success' style='float:right;'>Active</span></div>";
    $bot_purchase_id4 = $history4[0]['bot_purchase_id'];
}

$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]);
$history5 = $sth->fetchAll();

if (count($history5) > 0) {
    $bot5 = "<div><span class='badge badge-pill badge-success' style='float:right;'>Active</span></div>";
    $bot_purchase_id5 = $history5[0]['bot_purchase_id'];
}

$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]);
$history6 = $sth->fetchAll();

if (count($history6) > 0) {
    $bot6 = "<div><span class='badge badge-pill badge-success' style='float:right;'>Active</span></div>";
    $bot_purchase_id6 = $history6[0]['bot_purchase_id'];
}


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

if (count($history10) > 0) {
    switch ($history10[0]['type']) {
        case 'Ninja 2.1 (Monthly)':
            $bot1 = "<div><span class='badge badge-pill badge-success' style='float:right;'>Active</span></div>";
            $bot_purchase_id1 = $history10[0]['bot_purchase_id'];
            break;
        case 'Subzero 3.2 (Monthly)':
            $bot2 = "<div><span class='badge badge-pill badge-success' style='float:right;'>Active</span></div>";
            $bot_purchase_id2 = $history10[0]['bot_purchase_id'];
            break;
        case 'Rocket 4.1 (Monthly)':
            $bot3 = "<div><span class='badge badge-pill badge-success' style='float:right;'>Active</span></div>";
            $bot_purchase_id3 = $history10[0]['bot_purchase_id'];
            break;
        
        default:
            # code...
            break;
    }
    
}


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

if (count($history11) > 0) {
    switch ($history11[0]['type']) {
        case 'Ninja 2.1 (Quarterly)':
            $bot7 = "<div><span class='badge badge-pill badge-success' style='float:right;'>Active</span></div>";
            $bot_purchase_id7 = $history11[0]['bot_purchase_id'];
            break;
        case 'Subzero 3.2 (Quarterly)':
            $bot8 = "<div><span class='badge badge-pill badge-success' style='float:right;'>Active</span></div>";
            $bot_purchase_id8 = $history11[0]['bot_purchase_id'];
            break;
        case 'Rocket 4.1 (Quarterly)':
            $bot9 = "<div><span class='badge badge-pill badge-success' style='float:right;'>Active</span></div>";
            $bot_purchase_id9 = $history11[0]['bot_purchase_id'];
            break;
        
        default:
            # code...
            break;
    }
    
}



$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]);
$history12 = $sth->fetchAll();

if (count($history12) > 0) {
    switch ($history12[0]['type']) {
        case 'Ninja 2.1 (Annually)':
            $bot4 = "<div><span class='badge badge-pill badge-success' style='float:right;'>Active</span></div>";
            $bot_purchase_id4 = $history12[0]['bot_purchase_id'];
            break;
        case 'Subzero 3.2 (Annually)':
            $bot5 = "<div><span class='badge badge-pill badge-success' style='float:right;'>Active</span></div>";
            $bot_purchase_id5 = $history12[0]['bot_purchase_id'];
            break;
        case 'Rocket 4.1 (Annually)':
            $bot6 = "<div><span class='badge badge-pill badge-success' style='float:right;'>Active</span></div>";
            $bot_purchase_id6 = $history12[0]['bot_purchase_id'];
            break;
        
        default:
            # code...
            break;
    }
}

$sql = "SELECT * FROM purchased_bots WHERE accountId=? AND type = 'Community Bot' AND status=?  ORDER BY date DESC LIMIT 1";
$sth = $conn->prepare($sql, [PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY]);
$sth->execute([$accountId, 1]);
$history13 = $sth->fetchAll();

if (count($history13) > 0) {
    $bot10 = "<div><span class='badge badge-pill badge-success' style='float:right;'>Active</span></div>";
    $bot_purchase_id10 = $history13[0]['bot_purchase_id'];
}


// if((count($history6) > 0) || (count($history5) > 0) || (count($history4) > 0) || (count($history3) > 0) || (count($history2) > 0) || (count($history1) > 0) ){
//     header('Location: account');
//     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>Bot Softwares</title>
    <style type="text/css">
    h3.bot-price {
        color: #009933;
    }
    </style>
    <?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><!-- content-header -->

        <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">Bot Softwares</h4>
                    </div>

                </div>

                <h4 class="mg-b-20 tx-spacing--1">Monthly</h4>
                <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">
                                <?php echo($bot1); ?>
                                <div class="tx-100 lh-1"><i class="icon ion-ios-bicycle"></i></div>
                                <h3 class="mg-b-25">Ninja 3.6</h3>
                                <h3 class="mg-b-25 bot-price"><sup>$</sup>1,700/mo</h3>
                                <?php if(!empty($bot_purchase_id1)){ ?><p class="tx-color-03 mg-b-25">Bot ID: <span
                                        style="color:#000"><?php echo $bot_purchase_id1; ?></span></p><?php }?>
                                <a href="trade?package=monthly-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">
                                <?php echo($bot2); ?>
                                <div class="tx-100 lh-1"><i class="icon ion-ios-car"></i></div>
                                <h3 class="mg-b-25">Subzero 5.2</h3>
                                <h3 class="mg-b-25 bot-price"><sup>$</sup>3,600/mo</h3>
                                <?php if(!empty($bot_purchase_id2)){ ?><p class="tx-color-03 mg-b-25">Bot ID: <span
                                        style="color:#000"><?php echo $bot_purchase_id2; ?></span></p><?php }?>
                                <a href="trade?package=monthly-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">
                                <?php echo($bot3); ?>
                                <div class="tx-100 lh-1"><i class="icon ion-ios-boat"></i></div>
                                <h3 class="mg-b-25">Rocket 7.1</h3>
                                <h3 class="mg-b-25 bot-price"><sup>$</sup>7,300/mo</h3>
                                <?php if(!empty($bot_purchase_id3)){ ?><p class="tx-color-03 mg-b-25">Bot ID: <span
                                        style="color:#000"><?php echo $bot_purchase_id3; ?></span></p><?php }?>
                                <a href="trade?package=monthly-rocket" class="btn btn-primary btn-block">Add
                                    subscription</a>
                            </div>
                        </div>
                    </div>
                </div>

                <h4 class="mg-b-20 mg-t-40 tx-spacing--1 tx-spacing--1">Quarterly</h4>
                <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">
                                <?php echo($bot7); ?>
                                <div class="tx-100 lh-1"><i class="icon ion-ios-bicycle"></i></div>
                                <h3 class="mg-b-25">Ninja 3.6</h3>
                                <h3 class="mg-b-25 bot-price"><sup>$</sup>1,300/mo</h3>
                                <?php if(!empty($bot_purchase_id7)){ ?><p class="tx-color-03 mg-b-25">Bot ID: <span
                                        style="color:#000"><?php echo $bot_purchase_id7; ?></span></p><?php }?>
                                <a href="trade?package=quarterly-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">
                                <?php echo($bot8); ?>
                                <div class="tx-100 lh-1"><i class="icon ion-ios-car"></i></div>
                                <h3 class="mg-b-25">Subzero 5.2</h3>
                                <h3 class="mg-b-25 bot-price"><sup>$</sup>2,800/mo</h3>
                                <?php if(!empty($bot_purchase_id8)){ ?><p class="tx-color-03 mg-b-25">Bot ID: <span
                                        style="color:#000"><?php echo $bot_purchase_id8; ?></span></p><?php }?>
                                <a href="trade?package=quarterly-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">
                                <?php echo($bot9); ?>
                                <div class="tx-100 lh-1"><i class="icon ion-ios-boat"></i></div>
                                <h3 class="mg-b-25">Rocket 7.1</h3>
                                <h3 class="mg-b-25 bot-price"><sup>$</sup>6,250/mo</h3>
                                <?php if(!empty($bot_purchase_id9)){ ?><p class="tx-color-03 mg-b-25">Bot ID: <span
                                        style="color:#000"><?php echo $bot_purchase_id9; ?></span></p><?php }?>
                                <a href="trade?package=quarterly-rocket" class="btn btn-primary btn-block">Add
                                    subscription</a>
                            </div>
                        </div>
                    </div>
                </div>

                <h4 class="mg-b-20 mg-t-40 tx-spacing--1">Annually</h4>
                <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">
                                <?php echo($bot4); ?>
                                <div class="tx-100 lh-1"><i class="icon ion-ios-bicycle"></i></div>
                                <h3 class="mg-b-25">Ninja 3.6</h3>
                                <h3 class="mg-b-25 bot-price"><sup>$</sup>900/mo</h3>
                                <?php if(!empty($bot_purchase_id4)){ ?><p class="tx-color-03 mg-b-25">Bot ID: <span
                                        style="color:#000"><?php echo $bot_purchase_id4; ?></span></p><?php }?>
                                <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">
                                <?php echo($bot5); ?>
                                <div class="tx-100 lh-1"><i class="icon ion-ios-car"></i></div>
                                <h3 class="mg-b-25">Subzero 5.2</h3>
                                <h3 class="mg-b-25 bot-price"><sup>$</sup>2,000/mo</h3>
                                <?php if(!empty($bot_purchase_id5)){ ?><p class="tx-color-03 mg-b-25">Bot ID: <span
                                        style="color:#000"><?php echo $bot_purchase_id5; ?></span></p><?php }?>
                                <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">
                                <?php echo($bot6); ?>
                                <div class="tx-100 lh-1"><i class="icon ion-ios-boat"></i></div>
                                <h3 class="mg-b-25">Rocket 7.1</h3>
                                <h3 class="mg-b-25 bot-price"><sup>$</sup>5,200/mo</h3>
                                <?php if(!empty($bot_purchase_id6)){ ?><p class="tx-color-03 mg-b-25">Bot ID: <span
                                        style="color:#000"><?php echo $bot_purchase_id6; ?></span></p><?php }?>
                                <a href="trade?package=annually-rocket" class="btn btn-primary btn-block">Add
                                    subscription</a>
                            </div>
                        </div>
                    </div>
                </div>

                <h4 class="mg-b-20 mg-t-40 tx-spacing--1">Community Bot</h4>
                <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">
                                <?php echo($bot10); ?>
                                <div class="tx-100 lh-1"><i class="icon ion-md-people"></i></div>
                                <h3 class="mg-b-25">Community Bot</h3>
                                <h3 class="mg-b-25 bot-price"><sup>$</sup>100</h3>
                                <?php if(!empty($bot_purchase_id10)){ ?><p class="tx-color-03 mg-b-25">Bot ID: <span
                                        style="color:#000"><?php echo $bot_purchase_id10; ?></span></p><?php }?>
                                <a href="trade?package=community-bot" class="btn btn-primary btn-block">Add
                                    subscription</a>
                            </div>
                        </div>
                    </div>
                </div>

            </div><!-- container -->
        </div>
    </div>

    <?php require_once("includes/footer.php"); ?>
    <script type="text/javascript">
    $(document).ready(function() {
        var classes = $("#mn-bot-softwares").prop('class');
        $("#mn-bot-softwares").prop('class', classes + ' active pcoded-trigger');

    });
    </script>

    </body>

</html>