<?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">
                        所有商品
                    </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 ' >
                            新品上市
                        </option>

                        <option value="price-HTL" ';if (@$_SESSION["sort"] == ' ORDER BY price DESC') {echo 'selected="selected"';}
echo ' >
                            價格(高至低)
                        </option>

                        <option value="price-LTH" ';if (@$_SESSION["sort"] == ' ORDER BY price') {echo 'selected="selected"';}
echo ' >
                            價格(低至高)
                        </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 zh_category ='" . mysqlSecurity($conn, str_replace('_', ' ', $_GET['ategory'])) . "' and status != 'delete' and showcase ='1'  ";} elseif (isset($_GET['belong'])) {$ategory = " where zh_belong ='" . mysqlSecurity($conn, str_replace('_', ' ', $_GET['belong'])) . "' and status != 'delete' and showcase ='1'  ";}
// else{$ategory='';}
else { $ategory = ' where status != "delete" and showcase ="1"  ';}
//changed from products to productstable at 2020-04-06
// $query = "select * from products".$ategory.$sort;
$query = "select * from productstable" . $ategory . $sort;
if (isset($_GET["search"])) {$query = "SELECT * FROM  `productstable` WHERE  `zh_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;
			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="../timthumb/timthumb.php?src=' . $row["image"] . '&h=500&w=500&zc=1" style="width:100%">
			'<img class="img-responsive" src="' . $row["image"] . '" style="width:100%">'
				. '<div class="overlay">
                            <h2>
                            ' . $row["zh_name"] . '
                            </h2>
                            <p>
                            DETAIL
                            </p>
                        </div>
                    </div>

                    <div class="product-li-text">
                        <div style="height:5rem;LINE-HEIGHT:1.7rem;overflow:hidden">
                        ' . $row["zh_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 '原價  HK$' . $row["original price"];
				$pushText = "";
			}
			echo '</div>

                        <div style="color: #0E9BAD;height:35px;' . $pushText . '">';
			if (!$row["original price"] == null) {echo '推廣價&nbsp;HK$' . $row["price"];} else {echo '&nbsp;價格 HK$' . $row["price"];}
			echo '</div>
                    </div>
                </div>
            </a>';
		}
	}
}
;

echo '</div>
    <!-- end main products page -->';
?>