<?php session_start();?>
<!DOCTYPE html>
<html lang="en">
<?php
    if(!isset($_SESSION['id'])){
        echo"<script>alert('you have to log back in to continue');</script>";
        header("Location: Logout.php");
      
    }

include("db.php");
    session_start();
    include('db.php');
    $sql="SELECT o.Order_id as order_id, o.User_id,o.Type,o.DateMade,o.DeliveryDate,o.DeliveryTime,oi.Product_name,oi.Amount,oi.Price FROM Orders o JOIN Order_items oi on o.Order_id = oi.Order_id WHERE o.User_id=? ORDER BY o.id DESC;";
    $stmt=mysqli_stmt_init($conn);
    mysqli_stmt_bind_param($stmt,"i",$_SESSION['id']);
    mysqli_stmt_prepare($stmt,$sql);
    if(!mysqli_stmt_execute($stmt)){
        die("ERROR, failed to fetch order history".mysqli_stmt_error($stmt));
    }
    else{
        $result=mysqli_stmt_get_result($stmt);
        mysqli_stmt_close($stmt);
    }
?>
    
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.13.1/font/bootstrap-icons.min.css">

    <title>Account creation</title>
</head>
<style>
    .pill-navbar{
        border-radius: 50px;  
        padding:10px 20px;
        
    }
    @media(max-width:900px){
        
        .pill-navbar{
        border-radius: 25px;  
        margin-top:10px;

        }
        .pill-navbar .collapse-navbar{
            margin-top:10px;
            padding-top:10px;
            border-top:1px#eee
        }
    }
    .card{
        min-width:70vw;
        min-height:40vh;
        border-radius: 40px;  
        padding: 50px;
        max-height:80vh;
        overflow-y:auto;
    }

   
    .button{
        min-height:5vh;
        max-height:5vh;
    }

    body{

        background-image: linear-gradient(rgba(0,0,0,0.2),rgba(0,0,0,0.7)), url("Dark-theme.jpg");
        background-position: center;
        background-repeat: no-repeat;
        background-size: cover;
        min-height:100vh;
      
    }
    .form-group{
        margin-bottom:1rem;
    }

</style>
<body>
    
  
    
    
    <!-- navbar -->
    <nav class="navbar navbar-expand-lg navbar-light bg-light shadow pill-navbar w-50 mx-auto my-4 mb-5  ">
    
        <a class="navbar-brand" href="#">Logo</a>

        <!-- expand/collapse button -->
        <button
            class="navbar-toggler"
            type="button"
            data-bs-toggle="collapse"
            data-bs-target="#Navbar">
            <span class="navbar-toggler-icon"></span>
        </button>

        <!-- nav links -->
        <div class="collapse navbar-collapse ms-4" id="Navbar">
            <ul class="navbar-nav mt-auto">
                <li class="nav-item"><a class="nav-link" href="ProducerProducts.php">Products</a></li>
                <li class="nav-item"><a class="nav-link" href="ProducerSuppliers.php">Suppliers</a></li>
                <li class="nav-item"><a class="nav-link" href="ProducerOrders.php">Orders</a></li>
            </ul>
            <!-- right side nav links -->
            <ul class="navbar-nav ms-auto ">
                <li class="nav-item"><a class="nav-link" href="Logout.php">Log out<span class="bi bi-person-fill"></span></a></li>
                <li class="nav-item"><a class="nav-link" href="">Settings<span class="bi bi-gear-fill"></span></a></li>
            </ul>
        </div>

    </nav>

    
    
    <!-- main content -->
    <div class="container p-auto mt-5">

        <div class="row">
            <div class="col-lg-12 mx-auto mt-5 text-center" style="color:white;">
                Orders
            </div>
        </div>
        <table
            class="table table-primary"
        >
            
    </div>
        
        <?php 
            
        ?>

    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
</body>
</html>
