<?php
if (empty($_SESSION["admin"])) redirect("index.php?e=1");
if (!empty($_POST["btnSave"])) {
	
	$active=1;
	
	if (pdbfx("product_status")=='')
		$active=0;
	if ($_GET["product_id"]=='') //New merchant
	{
		
		$sql="Insert into product_master(product_name,product_description,product_category_id,product_status,ring_count)";
		$sql.="values ('".pdbfx("product_name") ."','".pdbfx("product_description") ."',".pdbfx("product_category_id") .",".$active .",".pdbfx("ring_count") .")";
		
		mysql_query($sql);
		$product_id=mysql_insert_id();
		$errMsg="<font color=red><b>Product added</b></font>";
	}
	if ($_GET["product_id"]!='') //Edit merchant
	{
		
		$product_id=$_GET["product_id"];
		$sql="update product_master set product_name='".pdbfx("product_name") ."',product_description='".pdbfx("product_description") ."',product_category_id=".pdbfx("product_category_id") .",product_status=".$active .",ring_count=".pdbfx("ring_count") ." where product_id=".$_GET["product_id"];
		mysql_query($sql);
		$errMsg="<font color=red><b>Product Information Saved.</b></font>";
	}
$sql="delete from ring_master where product_id=".$product_id;
mysql_query($sql);
for($i = 1; $i < 7; $i++){
	if (pdbfx("ring_image".$i)!='') {
		$sql="Insert into ring_master(ring_number,product_id,ring_image,max_characters,outside_engraving,inside_engraving)";
		$sql.="values ('".pdbfx("ring_number".$i) ."',".$product_id.",'".pdbfx("ring_image".$i) ."','".pdbfx("max_characters".$i) ."','".pdbfx("outside_engraving".$i) ."','".pdbfx("inside_engraving".$i) ."')";
		
		mysql_query($sql);
	}
}



	echo("<script language='javascript' type='text/javascript'>");
	echo("window.opener.navigate(window.opener.document.location.href);");
	echo("</script>");




}

if ($_GET["product_id"]!='') //edit Product
{
$sql = "SELECT * from product_master where product_id=".$_GET["product_id"];
$cmd = mysql_query($sql);
$rs = mysql_fetch_array($cmd);	

$sql = "SELECT * from ring_master where product_id=".$_GET["product_id"];
$cmd = mysql_query($sql);

}



?>
