
<!-- Header Wrap Starts -->
<?php include "common/header.php"; ?> 
<?php include "common/navbar.php"; ?> 

<!-- Header Wrap Ends -->

<!-- <?php //include "common/navbar.php"; 
?>  -->

<?php
$records_per_page = 40;
require 'wp-content/pagination/pagination.php';
$pagination = new Pagination();

if(isset($_GET['key'])) { 
  $skey = htmlspecialchars(strip_tags(trim($_GET['key'])), ENT_QUOTES, 'UTF-8');
  
  if(empty($skey)) {
    $redirectUrl = "index";
    echo "<script type=\"text/javascript\">";
    echo "window.location.href = '$redirectUrl'";
    echo "</script>";   
    
  } else if(strlen($skey) >= 3){
    $key = str_replace('-', '', $skey);;
    
    $sql_pro = "
    SELECT
      SQL_CALC_FOUND_ROWS
      *
    FROM
      items
    WHERE 
      -- (name LIKE '%$key%' OR REPLACE(`isbn`, '-', '') LIKE '%$key%' OR REPLACE(`isbn`, ' ', '') LIKE '%$key%' OR author LIKE '%$key%') AND flag=0
      item_name LIKE '%$key%' OR item_code LIKE '%$key%'

    ORDER BY 
      id DESC
    LIMIT
      " . (($pagination->get_page() - 1) * $records_per_page) . ', ' . $records_per_page . '';
      
    $tot = mysqli_num_rows(mysqli_query($conn, "SELECT * FROM items WHERE item_name LIKE '%$key%' OR item_code LIKE '%$key%'"));
    
    //echo $sql_pro;

  if (!($result_pro = @mysqli_query($conn, $sql_pro))) {
    die(mysqli_error($conn));
  }
  $rows = mysqli_fetch_assoc(mysqli_query($conn, 'SELECT FOUND_ROWS() AS row_count'));
  $pagination->records($rows['row_count']);
  $pagination->records_per_page($records_per_page);

  $row_count = mysqli_num_rows($result_pro);
  $start = (($pagination->get_page() - 1) * $records_per_page);
        
?>



<!-- Main Container Starts -->
<div class="main-container" >
  <!-- Product Container Starts -->
  <div id="product-product" class="container" style="background-image: url(image/bg.jpg); ">
    <!-- Row Starts -->  
    <div class="row">

      <div id="content" class="col-sm-12">
        <h3 class="page-heading-1">Search Keyword : <span><?php echo $skey; ?></span></h3>
        <div class="product-sort-wrap">
          <div class="row">
            <div class="col-md-6 col-sm-6 hidden-xs">
              <div class="btn-group btn-group-sm">
                <button type="button" id="list-view" class="btn btn-default" data-toggle="tooltip" title="List"><i class="fa fa-th-list"></i></button>
                <button type="button" id="grid-view" class="btn btn-default" data-toggle="tooltip" title="Grid"><i class="fa fa-th"></i></button>
              </div>
            </div>
            <div class="col-md-6 col-sm-6">
              <div align="right"> Total Result : <?php echo $tot; if($tot > 0) { ?> | Current View : <?php echo ($start+1) . '-' . ($start+$row_count); } ?> &nbsp; 
                </div>
            </div>
           
          </div>
        </div>
        <div class="row">  
        <?php while ($shrow = mysqli_fetch_array($result_pro)){
        
        ?>       
          <!-- Product Col Starts -->
          <div class="product-layout product-list col-xs-12">
            <!-- Product Module Starts -->
            <div class="product-thumb module-product animation clearfix">
              <!-- Product Image Starts -->
              <div class="module-product-image">
                <a href="product-details?id=<?php echo $shrow['detail']; ?>">
                  <img src="backend/upload/item/<?php echo $shrow['item_code']; ?>/<?php echo $shrow['f_img']; ?>" alt="<?php echo $shrow['item_name']; ?>" title="<?php echo $shrow['item_name']; ?>" class="img-responsive img-center" />
                </a>
              </div>
              <!-- Product Image Ends -->
              <!-- Product Caption Starts -->
              <div class="module-product-caption">
                <!-- Product Name Starts -->
                <h6 class="module-product-title"><a href="product-details?id=<?php echo $shrow['detail']; ?>"><?php echo $shrow['item_name']; ?></a></h6>
                <!-- Product Name Ends -->
                <!-- Product Price Starts -->
                <div class="module-product-price">
                  <?php echo $shrow['price']; ?>
                  <span class="price-tax"><?php echo $shrow['ori_price']; ?></span>
                </div>
                <!-- Product Price Ends -->
              </div>
              <!-- Product Caption Ends -->
              <!-- Product Buttons Starts -->
              <div class="module-product-btns-wrap button-group">
                <button type="button" id="button-cart" data-loading-text="Loading..." class="btn btn_cart" value="<?php echo $shrow['id']; ?>">
                        <i class="fa fa-shopping-cart"></i> <span class="hidden-xs hidden-sm hidden-md">Add to Cart</span></button>
                <button type="button" class="btn rounded-0 animation" data-toggle="tooltip" title="Add to Wish List" onclick="wishlist.add('41');"><i class="fa fa-heart"></i></button>
                <button type="button" class="btn rounded-0 animation" data-toggle="tooltip" title="Compare this Product" onclick="compare.add('41');"><i class="fa fa-exchange"></i></button>
              </div>
              <!-- Product Buttons Ends -->
            </div>
            <!-- Product Module Ends -->
          </div>
          <!-- Product Col Ends -->
          
        <?php } } }?>



        </div>
        <hr>
        <div class="row">
          <div style="margin-top:40px;">
        <?php $pagination->render(); ?>
      </div>
        </div>
      </div>
    </div>
  </div>
</div>
<!-- Main Container Ends -->


<!-- Footer Starts -->
<?php include "common/footer.php"; ?> 

<!-- Footer Ends -->

</body>
</html> 
