<?php
session_start();
include("db.php");

if (!isset($_SESSION['id'])) {
    header("Location: Logout.php");

}

if ($_SERVER["REQUEST_METHOD"] == "POST") {

    $name = $_POST['ProductName'];
    $des = $_POST['ProductDesc'];
    $img = $_POST['ProductImage'];
    $price = $_POST['ProductPrice'];
    $stock = $_POST['Stock'];

    $sql = "INSERT INTO Products (ProductName, ProductDescription, ProductImage, ProductPrice, Stock)VALUES (?, ?, ?, ?, ?)";

    $stmt = mysqli_stmt_init($conn);
    if (mysqli_stmt_prepare($stmt, $sql)) {
        mysqli_stmt_bind_param($stmt, "sssii", $name, $des, $img, $price, $stock);
        if (mysqli_stmt_execute($stmt)) {
            echo "<script>alert('Product successfully recorded');</script>";
        } 
        else {
            echo "ERROR: " . mysqli_stmt_error($stmt);
        }
    }
}
?>

<!DOCTYPE html>
<html lang="en">
<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>Product 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{
        max-width:50vw;
        border-radius: 40px;  
        padding: 50px;
        max-height:90vh;
        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 ">
    
        <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="col-lg-7 mx-auto">
            <div class="card mx-auto">
                <div class="header">
                    <div class="card-title text-center">  
                        <h1>Product Creation</h1><h5 class="text-muted">Add products that you want to sell and supply in store<br>products that are created would be visable to all customers who would be able to purchases these items</h5>
                    </div>
                </div>
                <div class="card-body px-auto mt-3">
                    <h3 class="card-sutitle text-center">Add a product</h3>
                    <div class="card-text px-auto">
                        

                        <form action="ProducerItemsInsert.php" method="post">

                            <div class="form-group">
                                <label for="ProductName">Product Name</label>
                                <input class="form-control" type="text" name="ProductName" id="ProductName" required>
                            </div>


                            <div class="form-group">
                                <label for="ProductImage">Product Image Link</label>
                                <input class="form-control" type="text" name="ProductImage" id="ProductImage" required>
                            </div>


                            <div class="form-group">
                                <label for="ProductDesc">Product Description</label>
                                <textarea class="form-control" type="text" name="ProductDesc" id="ProductDesc" rows="5" required></textarea>
                            </div>

                            <div class="form-group">
                                <label for="ProductPrice">Product Price</label>
                                <input class="form-control" type="number" name="ProductPrice" id="ProductPrice " required>
                            </div>


                            <div class="form-group">
                                <label for="Stock">Stock</label>
                                <input class="form-control" type="number" name="Stock" id="Stock" required>
                            </div>
                            
                            <button class="btn btn-primary" type="submit">Enter</button>

                        </form>
                    </div>
                </div>
            </div>
            

        </div>
    </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>