<?php session_start();  //Developed by ITechScripts
require 'include/configurations.php'; // ITECHBIDS Configuration File
$sub_txt=$_POST['action'];
//$txt_add=$_POST['add'];
$sub_id=$_POST['subcategory'];
$subsub_id=$_POST['subsubcategory'];
$cat_id=$_REQUEST['id'];
$mode=$_REQUEST['mode'];
$categoryname=$_POST['subcat'];

function ret($ssid,$subsub_id)
{
 $ss_sql="select * from site_categories where category_head_id=$ssid";
 $sub_res=mysql_query($ss_sql);
 while($cat_row=mysql_fetch_array($sub_res))
 {
 
	  if($subsub_id==$cat_row['category_id'])
	  {
	  ?>
	 <option value="<?=$cat_row['category_id'];?>" selected ><?=$cat_row['category_name'];?></option>
	 <?
	 }
	 else
	 {
	 ?>
	 <option value="<?=$cat_row['category_id'];?>">&nbsp;&nbsp;&nbsp;<?=$cat_row['category_name'];?></option>
	 <?
	 }
  $ssid=$cat_row['category_id'];
  ret($ssid,$subsub_id);

 }

}

$sql="select * from site_categories where category_head_id=0";
$res=mysql_query($sql);

$sub_sql="select * from site_categories where category_head_id=$sub_id";
$sub_res=mysql_query($sub_sql);

if($mode=="edit")
{
$modifysql="select * from site_categories where category_id=$cat_id";
$modifyres=mysql_query($modifysql);
$sub_row=mysql_fetch_array($modifyres);
}


if(isset($_POST['btnSubmit']))
{
 if($mode=="edit")
  {
     $sql1="update site_categories set category_name='$categoryname' where category_id=$cat_id";
     $res1=mysql_query($sql1);
  }
   
else if($subsub_id==0)
 {
  $sql1="insert into site_categories(category_name,category_head_id) values('$categoryname','$sub_id')";
  $res1=mysql_query($sql1);
 }
	  
else if($subsub_id!=0)
 {
  $sql1="insert into site_categories(category_name,category_head_id) values('$categoryname','$subsub_id')";
  $res1=mysql_query($sql1);
  
 }

  echo '<meta http-equiv="refresh" content="0;url=subcategory.php">';
}
?>

><?php
require 'include/header.php';
?>
<p>&nbsp;</p>
<p>&nbsp;</p>
<table width="600" border="0" align="center" cellpadding="5" cellspacing="0" class="ft">
<form name="sub" method="post" action="add.php">
 <td colspan="2" class="ct" height="25" align="left">
<? 
if($mode=='edit')
{
echo ("<b>Edit Category</b>");
}
else
{
echo ("<b>Add Category</b>");
}
?></td>

<tr height="25" >
<td align="right">
<?
if($mode=='edit')
{
echo ("<b>Category</b>");
}
else
{
echo ("<b>Category</b>");
}?></td>

<td align="left">

<select name=subcategory onchange="this.form.submit()">
<option value="0">Select</option>
<?
while($cat_row=mysql_fetch_array($res))
{

 if($sub_id==$cat_row['category_id'])
 {
?>
<option value="<?=$cat_row['category_id'];?>" selected><?=$cat_row['category_name'];?></option>
<?
 }
 
 else
 {
?>
 <option value="<?=$cat_row['category_id'];?>"  ><?=$cat_row['category_name'];?></option>
<?
 }
 
}
?>
</select></td></tr>

<tr height="25" >
<td align="right">
<?
if($mode=='edit')
{
echo ("<b>SubCategory</b>");
}
else
{
echo ("<b>SubCategory</b>");
}?></td>

<td align="left">
<select name=subsubcategory onchange="this.form.submit()">
  <option value="0">Select</option>
  <?
while($cat_row=mysql_fetch_array($sub_res))
{

if($subsub_id==$cat_row['category_id'])
{
?>
  <option value="<?=$cat_row['category_id'];?>" selected >
  <?=$cat_row['category_name'];?>
  </option>
  <?
}
else
{
?>
  <option value="<?=$cat_row['category_id'];?>"  >
  <?=$cat_row['category_name'];?>
  </option>
  <?
}
$ssid=$cat_row['category_id'];
ret($ssid,$subsub_id);

}
?>
</select></td>
</tr>

<tr height="25" >
<td align="right">
<?
if($mode=='edit')
{
echo ("<b>SubCategory Name</b>");
}
else
{
echo ("<b>SubCategory Name</b>");
}
?></td>

<td align="left">
	<input type="text" class="bluetext"name="subcat" value="<?=$sub_row['category_name'];?>" style="width:300;"></td>
<tr height="25" >

<input type="hidden" name="action" value="1">
<input type="hidden" name="mode" value="<?=$mode?>">
<input type="hidden" name="id" value="<?=$cat_id?>">
<td align="center" colspan="2">
<input type="submit" class="button"    name="btnSubmit"></td>
</tr>
</form>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<?
require 'include/footer.php'
?>

 