<?php
session_start();
include("../include/config.php");
include("../include/functions.php"); 
 validate_admin();
  $childsubcategory=mysqli_real_escape_string($GLOBALS['conn'],$_POST['childsubcategory']);
  $subcat_id=mysqli_real_escape_string($GLOBALS['conn'],$_POST['subcat_id']);
  $cat_id=mysqli_real_escape_string($GLOBALS['conn'],$_POST['cat_id']);
  if($_REQUEST['submitForm']=='yes'){
  if($_REQUEST['id']==''){
	  $obj->query("insert into $tbl_childsubcategory set cat_id='$cat_id',subcat_id='$subcat_id',childsubcategory='$childsubcategory',status=1 ");
	  $_SESSION['sess_msg']='Child subcategory added successfully';  
	  
       }else{ 
	  $obj->query("update $tbl_childsubcategory set childsubcategory='$childsubcategory',cat_id='$cat_id',subcat_id='$subcat_id' where id=".$_REQUEST['id']);
	  $_SESSION['sess_msg']='Child subcategory updated successfully';   
        }
   header("location:childsubcat-list.php");
   exit();
  }      
	   
	   
if($_REQUEST['id']!=''){
$sql=$obj->query("select * from $tbl_childsubcategory where id=".$_REQUEST['id']);
$result=$obj->fetchNextObject($sql);
}
	
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><?php echo SITE_TITLE; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="css/admin.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" language="javascript">
function validate(obj)
{
if(obj.cat_id.value==''){
alert("Please select category");
obj.cat_id.focus();
return false;
}
if(obj.subcat_id.value==''){
alert("Please select subcategory");
obj.subcat_id.focus();
return false;
}
if(obj.childsubcategory.value==''){
alert("Please enter childsubcategory");
obj.childsubcategory.focus();
return false;
}
}
</script>
<script type="text/javascript" language="javascript" src="ajax.js"></script>
<script type="text/javascript" language="javascript">
function callSubcategory(cat_id){
url="getSubcat.php?cat_id="+cat_id+"&subcat=<?php echo $result->subcat_id;?>";
//alert(url);
xmlhttpPost(url,cat_id,"getResponseSubcategory");

}
function getResponseSubcategory(str){
//alert(str);
document.getElementById("subcat1").innerHTML=str;
}
</script>
</head>
<body>
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
<?php include("header.php") ?>
<tr>
	<td align="right" class="paddRtLt70" valign="top">
		<table width="99%" border="0" cellspacing="0" cellpadding="0">
			<tr>
			
				<td align="right" valign="top">
					<table width="100%" border="0" cellspacing="0" cellpadding="0">
						<tr>
							<td align="left" valign="middle" class="headingbg bodr text14">
					<em><img src="images/arrow2.gif" width="21" height="21" hspace="10" align="absmiddle" /></em>Admin: Add Child Subcategory 
					<span  style="float:right; padding-right:10px;">
					<input type="button" name="add" value="View Child Subcategories"  class="button" onclick="location.href='childsubcat-list.php'" /></span></td>
						</tr>
						
						<tr>
							<td height="100" align="left" valign="top" bgcolor="#f3f4f6" class="bodr">
                            <form name="frm" method="POST" enctype="multipart/form-data" action="" onsubmit="return validate(this)">
						<input type="hidden" name="submitForm" value="yes" />
						<input type="hidden" name="id" value="<?php echo $_REQUEST['id'];?>" />
							<table width="100%" cellpadding="0" cellspacing="0">
									<tr>
										<td align="center" colspan="2" class="paddRt14 paddBot11">
										<font color="#FF0000"><strong><?php echo $_SESSION['sess_msg']; $_SESSION['sess_msg']='';?></strong></font></td>
									</tr>
									<tr>
										<td width="18%" align="right" class="paddBot11 paddRt14">&nbsp; </td>
										<td width="82%" align="left" class="paddBot11"></td>
									</tr>
									<tr>
                                      <td align="right" class="paddBot11 paddRt14"><strong>Category:</strong></td>
									  <td align="left" class="paddBot11"><select name="cat_id" style="width:240px;" onchange="return callSubcategory(this.value)">
                                      <option value="">-Select Category-</option>
                                      <?php $catArr=$obj->query("select * from $tbl_category where status=1 order by category");
									   while($resultCategory=$obj->fetchNextObject($catArr)){?>
									  
									   <option value="<?php echo $resultCategory->id;?>"<?php if($resultCategory->id==$result->cat_id){ ?>selected<?php } ?>><?php echo stripslashes($resultCategory->category); ?></option>
                                       <?php }?>
                                      </select></td>
							  </tr> 
                              <tr>
                                      <td align="right" class="paddBot11 paddRt14"><strong>Select Subcategory :</strong></td>
									  <td align="left" class="paddBot11" id="subcat1"><select name="" style="width:250px;">
                                      <option value="">Select Subcategory</option>
                                     
                                      </select></td>
							  </tr>
									<tr>
                                      <td align="right" class="paddBot11 paddRt14"><strong>Child Subcategory:</strong></td>
									  <td align="left" class="paddBot11"><input name="childsubcategory" type="text" id="childsubcategory" size="36" value="<?php echo stripslashes($result->childsubcategory);?>" /></td>
							  </tr>
									
									
									<tr>
									  <td align="right" class="paddRt14 paddBot11">&nbsp;</td>
									  <td align="left" class="paddBot11">&nbsp;</td>
							  </tr>
									<tr>
										<td width="18%" align="right" class="paddRt14 paddBot11">&nbsp;</td>
										<td width="82%" align="left" class="paddBot11">
											<input type="submit" name="submit" value="Submit"  class="submit" border="0"/> 	                  		 &nbsp;&nbsp;
											<input name="Reset" type="reset" id="Reset" value="Reset" class="submit" border="0" />									  </td>
									</tr>
								</table></form>
							</td>
						</tr>
						
					</table>
				</td>
			</tr>
		</table>
	</td>
</tr>
<?php include('footer.php'); ?>
</table>
</body>
</html>
<?php if($_REQUEST['id']){ ?>
<script type="text/javascript">
callSubcategory(<?php echo $result->cat_id; ?>);
</script>
<?php } ?>

