<?php
if (empty($_SESSION["admin"])) redirect("index.php?e=1");
if (!empty($_POST["btnSave"])) {
	
	$active=1;
	if (pdbfx("active")=='')
		$active=0;
	$category_sub_yes_no=1;
	if (pdbfx("category_sub_yes_no")=='')
		$category_sub_yes_no=0;
	
	if ($_GET["category_id"]=='') //New Category
	{

		$sql="Insert into category_master(category_name,category_parent_id,category_status,category_description,category_level,category_sub_yes_no,category_image)";
		$sql.="values ('".pdbfx("category_name") ."',".pdbfx("category_parent_id").",".$active .",'".pdbfx("category_description") ."',".pdbfx("category_level").",".$category_sub_yes_no.",'".pdbfx("category_image") ."')";
		
		mysql_query($sql);
		$errMsg="<font color=red><b>Category added</b></font>";
	}
	if ($_GET["category_id"]!='') //Edit Category
	{
		if (pdbfx("category_parent_id")==$_GET["category_id"]) {
			echo "Invalid Entry";
			die;
		}
		$sql="update category_master set category_name='".pdbfx("category_name") ."',category_parent_id=".pdbfx("category_parent_id").",category_status=".$active .",category_description='".pdbfx("category_description") ."',category_level=".pdbfx("category_level").",category_sub_yes_no=".$category_sub_yes_no.",category_image='".pdbfx("category_image") ."' where category_id=".$_GET["category_id"];
		mysql_query($sql);
		
		$errMsg="<font color=red><b>Category Information Saved.</b></font>";
	}
	
	
	
	echo("<script language='javascript' type='text/javascript'>");
	echo("window.opener.navigate(window.opener.document.location.href);");
	echo("</script>");

}

if ($_GET["category_id"]!='') //edit Category
{
$sql = "SELECT * from category_master where category_id=".$_GET["category_id"];
$cmd = mysql_query($sql);
$rs = mysql_fetch_array($cmd);	
}







?>
