<?include("includes/connection.php");
include("includes/func.php");
if ($_POST["newsletter"]!='') {
	$user_date=date("Y-m-d");
	$sql="Insert into user_master(email,user_type,user_date)";
		$sql.="values ('".strip_tags(pdbfx("newsletter")) ."',2,'".$user_date."')";
		mysql_query($sql);

}
if ($_GET["category"]!='') {
$sql="select category_id,category_name,category_description,category_sub_yes_no,category_parent_id from category_master where category_status=1 and category_id='".gdbfx("category")."'";
	$cmd = mysql_query($sql);
	$rscategory = mysql_fetch_array($cmd);
	//while ($rskeyword = mysql_fetch_array($cmdkeyword)) {
	if ($rscategory["category_sub_yes_no"]==1) {
		$sql="select category_id,category_name,category_image from category_master where category_status=1 and category_parent_id=".$rscategory["category_id"];
		$cmdsub = mysql_query($sql);
		$cmdsubtemp = mysql_query($sql);
		while ($rscategorysub = mysql_fetch_array($cmdsubtemp)) {
			if ($sub=='')
				$sub=$rscategorysub["category_id"];
			else
				$sub.=",".$rscategorysub["category_id"];
			}	
	}



$pg = new paging;
if ($sub!='') {
		$pg->setpages("select count(*) from product_master P,category_master C where product_status=1 and (product_category_id=".gdbfx("category")." OR product_category_id in (".$sub.")) AND P.product_category_id=C.category_id");
		$sql="select P.*,C.category_name,R.ring_image as product_image1 from product_master P,category_master C,ring_master R where product_status=1 and (product_category_id=".gdbfx("category")." ) AND P.product_category_id=C.category_id AND P.product_id=R.product_id  AND R.ring_status=1  group by product_id";
		
	}
else {
		$pg->setpages("select count(*) from product_master P,category_master C where product_status=1 and product_category_id=".gdbfx("category")." AND P.product_category_id=C.category_id");
		$sql="select P.*,C.category_name,R.ring_image as product_image1 from product_master P,category_master C ,ring_master R where product_status=1 and product_category_id=".gdbfx("category")." AND P.product_category_id=C.category_id AND P.product_id=R.product_id  AND R.ring_status=1  group by product_id";
		}
		
	$sql .=$pg->getlimit();
	//echo OR product_category_id in (".$sub.");
	$cmdproduct = mysql_query($sql);

}
if (str_contains($_SERVER['PHP_SELF'],"allproducts.php")) {
		$pg = new paging;
		$pg->setpages("select count(*) from product_master P,category_master C where product_status=1  AND P.product_category_id=C.category_id and P.ring_count>0");
		$sql="select P.*,C.category_name,R.ring_image as product_image1 from product_master P,category_master C ,ring_master R where product_status=1 AND P.product_category_id=C.category_id AND P.product_id=R.product_id  AND R.ring_status=1 and P.ring_count>0 group by product_id";
	
		
	$sql .=$pg->getlimit();
	$cmdproduct = mysql_query($sql);

}
if ($_GET["page"]!='') {
	$sql="select * from document_master D where doc_title Like '%".gdbfx("page")."%'";
	$cmdpage = mysql_query($sql);
	$rspage = mysql_fetch_array($cmdpage);
}

if ($_POST["usernamelogin"]!='' && $_POST["passwordlogin"]!='') {
	$sql="select * from user_master where active=1 and user_type=3 and user_name='".pdbfx("usernamelogin")."'";
	
		$cmd = mysql_query($sql);
		$rs = mysql_fetch_array($cmd);
	if (cmpfx($rs["user_name"], $_POST["usernamelogin"]) && cmpfx($rs["password"], $_POST["passwordlogin"])) {
			$_SESSION["username"] = $_POST["usernamelogin"];
			$_SESSION["userid"] = $rs["user_id"];
			
		}
		else
		{
			 $_SESSION["errmsg"].="@Invalid Login Info,Try again.";
			 $_SESSION["errmsg"].="@You can click <a href=\"#\" onClick=\"javascript:openWin('forget_password.php', 'width=380, height=180');\">Forget password</a> to retrieve your login name & password.";
			 redirect("message.php");
		}
}
?>