<?php
echo '<!-- left list -->
    <div class="col-lg-3 col-md-3 hidden-sm hidden-xs" >
        <div class="left-list">';
include "includes/e-shop-left-list.php";
echo    '</div>
    </div>
    <!-- end left list -->';
      
echo '<!-- products page support -->
        <div  role="tabpanel" class="tab-pane active col-lg-8 col-md-9 col-sm-12 col-xs-12" id="products">
        <div class="page-bar col-lg-12 col-md-12 col-sm-12 col-xs-12" style="margin-top: 20px;">
            <!-- Breadcrumb -->
			<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12" style="padding:0px 0px">
            <ol class="breadcrumb" style="display: inline;">
                <li class="text-primary-color dark-primary">
                    <a href="e-shop.php">
                        All Products
                    </a>
                </li>
                
                <li class="active">
                    '.@str_replace('_',' ',$_GET['ategory']).@str_replace('_',' ',$_GET['belong']).@$_SESSION["search"].'
                </li>
            </ol>
			</div>
            <!-- end Breadcrumb -->
            
            <!-- Number of Items Ori -->
			<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12" style="padding:0px 0px">
            <div class="shop-setting-section" ng-controller="ProductsFetchController">
                <div class="shop-setting-wrapper">
					<form action="includes/sort.php" method="post">
                    <select name="sort" class="shop-setting" onchange="submit()" >
                        <option value="New-Arrival" ';if(@$_SESSION["sort"]==' ORDER BY created desc'){echo 'selected="selected"';} echo ' >
                            New Arrival
                        </option>
                        
                        <option value="price-HTL" ';if(@$_SESSION["sort"]==' ORDER BY price DESC'){echo 'selected="selected"';} echo ' >
                            Price(High to Low)
                        </option>
                        
                        <option value="price-LTH" ';if(@$_SESSION["sort"]==' ORDER BY price'){echo 'selected="selected"';} echo ' >
                            Price(Low to High)
                        </option>
                    </select>
                    </form>
					
                    <!-- Makes select bar match search bar -->
                    <button class="pull-right" style="height: 27x; opacity: 0;">
                        <i class="fa fa-search"></i>
                    </button>
                    <!-- end Makes select bar match search bar -->
                </div>
            </div>
			</div>
            <!-- end Number of Items Ori -->
        </div>
        </div>
        <!-- end porducts page support -->';
echo '<div  role="tabpanel" class="tab-pane active col-lg-8 col-md-9 col-sm-12 col-xs-12" id="products">  
';
if(isset($_SESSION["sort"])){$sort = $_SESSION["sort"];
}else{
$sort = " ORDER BY created desc";}
unset($_SESSION["sort"]);

if(isset($_GET['ategory'])){$ategory = " where ategory ='".mysqlSecurity($conn, str_replace('_',' ',$_GET['ategory']))."' and status != 'delete' ";}
elseif(isset($_GET['belong'])){$ategory = " where belong ='".mysqlSecurity($conn, str_replace('_',' ',$_GET['belong']))."' and status != 'delete' ";}
else{$ategory=' where status != "delete" ';}
// else{$ategory='  ';}
//changed from products to productstable at 2020-04-06
$query = "select * from productstable".$ategory.$sort;
if(isset($_GET["search"])){$query = "SELECT * FROM  `productstable` WHERE  `name` LIKE  '%".$_SESSION["search"]."%' and status != 'delete' ".$sort; unset($_SESSION["search"]);}

//Skip if mysqli return false
if($result=mysqli_query($conn,$query)){
    if(mysqli_num_rows($result) > 0){
        //Push in product name in the while loop,skip loop if a product with the same name have already created.
        $duplicate = [];
        while($row = mysqli_fetch_assoc($result)) {

            if($duplicate[$row["name"]]) continue;
            $duplicate[$row["name"]] = true;
            $ext=explode("/",$row["image"])[5];
            $arr=array();
            if(in_array($ext,$arr)){
                $link=$row["image"];
                $height="height:100%";
            }else{
                $link="../timthumb/timthumb.php?src=".$row["image"]."&h=500&w=500&zc=1";
                $height="";
            }
        echo '<!-- main products page -->
                <a href="includes/product_select.php?id='.$row["id"].'">
                    <div class="col-lg-3 col-md-3 col-sm-6 col-xs-12 product-li-img"> 
                        <div class="hovereffect">
                        <img class="img-responsive" src="'.$link.'" style="'.$height.'"width:100%">
                        <div class="overlay">
                        <h2>
                        '.$row["name"].'
                        </h2>
                        <p> 
                        DETAIL
                        </p> 
                        </div>
                        </div>
                         
                        <div class="product-li-text">
                            <div style="height:5rem;LINE-HEIGHT:1.7rem;overflow:hidden">
                            '.$row["name"].'</div>
                            
                            <div style="height:16px;color: #9D9D9D; text-decoration: line-through; margin:5px 0px;">';
                            
                            $pushText = "transform:translate(0,-50%);";
                            if(!$row["original price"]==null){
                                echo 'Original Price  HK$'.$row["original price"];
                                $pushText = "";
                            }
                            
                            echo '</div>
                            
                            <div style="color: #0E9BAD;height:35px;'.$pushText.'">';
                            if(!$row["original price"]==null){echo 'Promotional';echo '&nbsp;Price HK$'.$row["price"];}
                            else{echo '&nbsp;Price HK$'.$row["price"];}
                            echo '</div>
                        </div>
                    </div>
                </a>';
        }
    }	
};
	
echo '</div> 
    <!-- end main products page -->';
?>