
<?php ob_start(); ?>
<?php
 include('../config/constants.php');
?>
<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE-edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Shopping Website</title>
    <link rel="stylesheet" type="text/css" href="css/style.css"/>
    <link rel="stylesheet" type="text/css" href="css/pstyle.css"/>
    <link rel="stylesheet" type="text/css" href="css/lightslider.css"/>
    <script src="js/jQuery.js"></script>
    <script src="js/lightslider.js"></script>
    <link rel="shortcut icon" href="images/fav-icon.png"/>
  </head>

  <body>

       <?php
          if (isset($_POST['submit'])) {
            // code...
            $id = $_POST['id'];
            $image_name = $_POST['image_name'];
            $title = $_POST['title'];
            $price = $_POST['price'];
            $description = $_POST['description'];
            $featured = $_POST['featured'];
            $active = $_POST['active'];

          }

        ?>
    <!-- navigation -->
    <nav>
      <!--social-link-and-phone-number  -->
      
      <!-- menu bar -->
      <div class="navigation">
        <!-- .logo -->
        <a href="javascript:void(0);" class="logo">
          <img src="images/logo.png">
        </a>
        <div class="toggle"></div>
        <!-- munu -->
        <ul class="menu">
            <li><a href="<?php echo SITEURL;?>shopping/index.php">Home</a></li>
          <li><a href="<?php echo SITEURL;?>shopping/general.php">General</a></li>
          <li><a href="<?php echo SITEURL;?>shopping/men.php">Men</a>
            <!-- label -->
            <!-- <label class="sale-label">Sale</label> -->
          </li>
          <li><a href="<?php echo SITEURL;?>shopping/women.php">Women</a></li>
          <li><a href="<?php echo SITEURL;?>shopping/kids.php">Kids</a></li>


        </ul>
         <!-- right-menu -->
         <div class="right-menu">
           <!-- search -->
           <a href="javascript:void(0);">
             <img class="search" src="images/search.svg" width="25px">
           </a>
           <!-- user -->
           <a href="javascript:void(0);">
             <img class="user"src="images/user.svg" width="25px">
           </a>
           <!-- cart-icon-->
           <a href="javascript:void(0);">

              <i class="fas fa-shopping-cart">
                 <img class="fa-shopping-cart"src="images/cart-plus.svg"width="25px">
                 <span class="num-cart-product">0</span>
              </i>
             <!--img class="cart"src="images/cart-plus.svg" width="20px" number of products in a cart -->

           </a>
         </div>

      </div>
    </nav>
    <!-- search bar -->
    <div class="search-bar">
      <!-- search-input -->
      <div class="search-input">
        <!-- input -->
        <input type="text" placeholder="Search For Product"/>
        <!-- cansel btn -->
        <a href="javascript:void(0);" class="search-cansel"> &times;</a>
      </div>
    </div>

    <form action="" method="post" enctype="multipart/form-data">
      <div class='order-message'>
      <div class='messagecontainer'>
         <h3>We value you😍😍</h3>
         <div class='order-detail'>
           <?php
           if ($image_name) {
             //img is available
             ?>
             <img src="<?php echo SITEURL; ?>images/products/<?php echo $image_name; ?>" width="100px" >
             <?php
           }else {
             //img is not available
             echo  "<div class='error'>Img is not Added</div>";
           }

            ?>
            <span><?php echo $title ?></span>
            <span class='total'>$<?php echo number_format($price,2)?></span>
            <span>Qty: <input type="number" min="1" max="10" class="qty" name="qty" placeholder="0"></span>


            <span>size
              <select name="size">
                <option>Small</option>
                <option>Medium</option>
                <option>Large</option>
                <option>Extra Large</option>
              </select>
            </span>

         </div>
         <div class='customer-details'>

            <!-- <p> Description : <span><?php echo $description ?></span> </p> -->

         </div>

            <input type="submit" name="addcart" value="Add Cart 🛒🛒" class='btn'>
            <input type="hidden" name="title" value="<?php echo $title ?>">
            <input type="hidden" name="image_name" value="<?php echo $image_name ?>">
            <input type="hidden" name="price" value="<?php echo $price ?>">
            <input type="hidden" name="id" value="<?php echo $id?>">

         </div>
      </div>

    </form>
    <?php 

      if (isset($_POST['addcart'])) {
          //redirect
          //header('location:'.SITEURL.'shopping/login.php');
          //echo $_SESSION('userid');
        if ($_SESSION('userid') !== null) {
          // code...
           $userid = $_SESSION['userid'];
           //1.GET THE DATA FRO FORM
            //$title =mysqli_real_escape_string($conn, $_POST['title']);
            $size =mysqli_real_escape_string($conn, $_POST['size']);
            $qty =mysqli_real_escape_string($conn, $_POST['qty']);
            $prodid =mysqli_real_escape_string($conn, $_POST['id']);
            
            //$price = mysqli_real_escape_string($conn, $_POST['price']);
           
            //$size = mysqli_real_escape_string($conn,$_POST['size']);
            //CHECK if featured and active are checked or not
           
           //2UPLOAD IMG IF SELECTED
           //check if the select img is clicked or not and upload the img only if the img selected
          
                
           //3. INSERT data TO DB
           //create sqlto save data in the db
           $sql2 = "INSERT INTO cart SET
           
           qty = $qty,
           
           user_id = '$userid',
           prodid = $prodid,
           size  ='$size'
           ";
           //execute the querry
           $res2 = mysqli_query($conn, $sql2);
           //check whether the data is inserted or not
           //4.REDIRECT WITH MSG TO MANAGE FOOD PAGE
           if ($res2 == true) {
             // data is inserted Successfully
             //echo "food added Successfully";
             $_SESSION['ADD'] = "<div class='success'>Product added Successfully.</div>";
             header('location:'.SITEURL.'shopping/viewcart.php');
           }else {
             //failed to insert data
             $_SESSION['ADD'] = "<div class='error'>Failed to Add Product.</div>";
             header('location:'.SITEURL.'shopping/index.php');
           }

         }
         else{
           $_SESSION['verify'] = "<div class='success'>Login first to add things to cart.</div>";
             header('location:'.SITEURL.'shopping/login.php');
         }
}
     
        
    



    ?>


   

    <?php include('full-slider.php'); ?>
    <?php include('featured.php'); ?>
    <?php include('new-arrival.php'); ?>
    <?php include('sale.php'); ?>
    <?php include('featured-items.php'); ?>


    <?php include('banner.php'); ?>
    <?php include('footer.php'); ?>
    <?php include('js.php'); ?>

  </body>
</html>
