<?php include('menu.php');

?>

  <body>
      <?php
        if (isset($_SESSION['add'])) {
          echo $_SESSION['add'];
          unset($_SESSION['add']);
        }

       ?>

    <!-- navigation -->
    <nav>
      <!--social-link-and-phone-number  -->
      
      <!-- menu bar -->
      <div class="navigation">
        <!-- .logo -->
        <a href="<?php echo SITEURL; ?>shopping/index.php" 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-->
           <?php
               $count = 0;
               if (isset($_SESSION['cart'])){
                 $count = count($_SESSION['cart']);
               }
           ?>
           <a href="viewcart.php">

              <i class="fas fa-shopping-cart">
                 <img class="fa-shopping-cart"src="images/cart-plus.svg"width="25px">
                 <span class="num-cart-product"><?php echo $count?></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 -->
      <form action="#" method="post">
        <div class="search-input">

            <input type="search" name="search"  placeholder="Search For Product" required />
          <input type="submit"  name="submitsearch" class="btn"/>
          <!-- cansel btn -->
          <a href="javascript:void(0);" class="search-cansel"> &times;</a>
          <!-- input -->

        </div>
      </form>

    </div>
    

    <?php include('full-slider.php'); ?>
    
    <?php
      $search = mysqli_real_escape_string($conn,$_POST['search']);
    ?>
    <section class="new-arrival">
      <!-- heading -->
      <div class="arrival-heading">
        <strong>Products on Your Search "<?php echo $search ?>"</strong>
        <p>Hope you Were Looking For This👌🙏</p>
      </div>
      <div class="product-container">
        <!-- pproduct box-->
        <?php
          $sql = "SELECT * FROM products WHERE soundex(title) = soundex('%$search%') OR soundex(description) = soundex('%$search%')";
          $res = mysqli_query($conn, $sql);
          $count= mysqli_num_rows($res);
          if ($count>0) {
            while ($row = mysqli_fetch_assoc($res)) {
              // code...
              $id = $row['id'];
              $title = $row['title'];
              $image_name = $row['image_name'];
              $description = $row['description'];
              $featured = $row['featured'];
              $active = $row['active'];
              $size = $row['size'];
              $price = $row['price'];
              ?>
        <form action="item-description1.php" method="post" enctype="multipart/form-data">
          <div class="product-box">

            <div class="product-img">
                <!-- cart-->
                <!-- cart -->
            
              <!-- <input type="submit" name="submit" value="cart" class="add-cart"> -->

              <?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>";
              }

               ?>
            </div>
            <div class="product-details">
              <a href="javascript:void(0);" class="p-name"><?php echo $title?></a>
              <span class="p-price">$<?php echo $price?></span>
              <button type="submit" name="submit" class="add-cart">
                   VIEW PRODUCT
                </button>
            </div>
            <input type="hidden" name="id" value="<?php echo $id?>">
            <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="size" value="<?php echo $size?>">
            <input type="hidden" name="description" value="<?php echo $description?>">
            <input type="hidden" name="active" value="<?php echo $active?>">
            <input type="hidden" name="featured" value="<?php echo $featured?>">

          </div>
          <!-- pproduct box -->
        </form>

        <?php
      }
    }else {
      echo 'There Was No Match For Your Search';
    }
    ?>

      </div>
    </section>



    

    <?php include('products-related.php'); ?>
    <?php include('most-viewed.php'); ?>
    <?php include('banner.php'); ?>
    <?php include('footer.php'); ?>
    <?php include('js.php'); ?>

  </body>
</html>
