<?php session_start();
include_once('includes/config.php');
include_once('includes/settings.php');
if (strlen($_SESSION['id']) == 0) {
    header('location:logout.php');
} else {
    ?>
    <!DOCTYPE html>
    <html lang="en">
    <?php include('includes/head.php'); ?>
    <style type="text/css"></style>

    <body class="cnt-home">
        <header class="header-style-1">
            <?php include('includes/top-header.php'); ?>
            <?php include('includes/main-header.php'); ?>
            <?php include('includes/menu-bar.php'); ?>
        </header>

        <!-- Breadcrumb -->
        <div class="breadcrumb mt-2">
            <div class="container">
                <nav aria-label="breadcrumb">
                    <ol class="breadcrumb">
                        <li class="breadcrumb-item"><a href="index.php">Home</a></li>
                        <li class="breadcrumb-item active">My Orders</li>
                    </ol>
                </nav>
            </div>
        </div>

        <!-- Main Content -->
        <div class="body-content outer-top-xs">
            <div class="container">
                <!-- Section-->
                <section class="py-5">
                    <div class="container px-4  mt-5">


                        <div class="table-responsive">
                            <table class="table">
                                <thead>
                                    <tr>
                                        <th colspan="4">
                                            <h4>My Orders</h4>
                                        </th>
                                    </tr>
                                </thead>
                                <tr>
                                    <thead>
                                        <th>#</th>
                                        <th>Order Number </th>
                                        <th>Order Date</th>
                                        <th>Transaction Type</th>
                                        <th>Total Amount</th>
                                        <th>Order Status</th>
                                        <th>Action</th>
                                    </thead>
                                </tr>
                                <tbody>
                                    <?php
                                    $uid = $_SESSION['id'];
                                    $ret = mysqli_query($con, "select * from orders where userId='$uid'");
                                    $num = mysqli_num_rows($ret);
                                    $cnt = 1;
                                    if ($num > 0) {
                                        while ($row = mysqli_fetch_array($ret)) {

                                            ?>

                                            <tr>
                                                <td><?php echo htmlentities($cnt); ?></td>
                                                <td><?php echo htmlentities($row['orderNumber']); ?></td>
                                                <td><?php echo htmlentities($row['orderDate']); ?></td>
                                                <td><?php echo htmlentities($row['txnType']); ?></td>
                                                <td><?php echo htmlentities($row['totalAmount']); ?></td>
                                                <td><?php $ostatus = $row['orderStatus'];
                                                if ($ostatus == ''):
                                                    echo "Not Processed Yet";
                                                else:
                                                    echo $ostatus;
                                                endif; ?><br />
                                                </td>
                                                <td><a href="order-details.php?onumber=<?php echo htmlentities($row['orderNumber']); ?>"
                                                        class="btn-upper btn btn-primary">Details</a></td>

                                            </tr>

                                            <?php $cnt++;
                                        }
                                    } else { ?>
                                        <tr>
                                            <td style="font-size: 18px; font-weight:bold ">Not Order Yet.&nbsp;
                                                <a href="shop-categories.php" class="btn-upper btn btn-warning">Continue
                                                    Shopping</a>
                                            </td>

                                        </tr>
                                    <?php } ?>
                                </tbody>
                            </table>
                        </div>

                    </div>


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

        <!-- Footer -->
        <?php include('includes/footer.php'); ?>
        <?php include('includes/foot.php'); ?>
    </body>

    </html>
<?php } ?>
