<?php
header("Content-Type:text/html; charset=utf-8");
?>
<?php 



session_start();

$_SESSION["page"] = $_GET["page"];


//added at 2020-11-30
//get category name
$url = $_GET["url"];
$query_str = parse_url($url, PHP_URL_QUERY);
parse_str($query_str, $query_params);
// print_r($query_params);
echo $query_params['ategory'];
$searchcategory= $query_params['ategory'];


$language=substr($url,1,2);
echo "language";
echo $language;  //zh for chinese //en for english current page languange
include('../../conf/conn.php');

// echo "escaped category";
// $searchcategory=mysqli_real_escape_string($searchcategory);
// echo $searchcategory;
// $searchcategory =urldecode($searchcategory);
$searchcategory =str_replace("_"," ",$searchcategory);
$searchcategory = mysqlSecurity($conn, $searchcategory);


 // echo $searchcategory;

// $stmt=$conn->prepare("Select ategory, zh_category from ategories where ategory = '?' ");
// $stmt->bind_param($searchcategory);


 //    $username = mysqlSecurity($conn, $_SESSION["username"]);
// $query = "select * from productstable";
if($language=='zh'){
	$query = "Select ategory, zh_category from ategories where zh_category = '".$searchcategory. "'";
	echo $query;
}
if($language=='en'){
	$query = "Select ategory, zh_category from ategories where ategory = '".$searchcategory. "'";
	echo $query;
}

if($result=mysqli_query($conn,$query)){
// $stmt->execute();

// if($result=$stmt->get_result()){
    if(mysqli_num_rows($result) > 0){

        while($row = mysqli_fetch_assoc($result)) {

        	// echo $row["zh_category"];
        	$displayurl='';
        	if($language=='zh'){
        		$displayurl.='/en/e-shop.php?ategory=';
        	}
        	if($language=='en'){
        		$displayurl.='/zh/e-shop.php?ategory=';
        	}
        	if($language=='zh'){
        		$displayurl.=$row["ategory"];
        	}
        	if($language=='en'){
        		$displayurl.=$row["zh_category"];
        	}
        	// $displayurl.=$row["zh_category"];
        	echo $displayurl;
    //     	echo "<script>
				// document.location.href='$displayurl';
	  	// 		</script>";
        }
     }
     else{
     	return "";
     }
}
function sql_escape($param, $is_like_param = false) {
	$param = mysql_real_escape_string($param);
	if ($is_like_param) {
		$param = addcslashes($param, "%_");
	}

	return $param;
}
//end get category name


//search other language category name


//end search other language category name



// $url = str_replace("belong=","",str_replace("ategory=","",str_replace("en","zh",$_GET["url"])));

// echo "<script>
// 		document.location.href='$url';
// 	  </script>";
?>