
<?

require 'include/configurations.php'; // ITECHBIDS Configuration File




function ret($ssid)
{
 $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($ssid==$cat_row['category_head_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);

 }

}


$btn=$_POST['btn'];
$delete=$_POST['delete_btn'];

$val=$_POST['subcat'];
$v=$_POST['hd_val'];
$tsub=$_POST['txt_sub'];
$hd_val=$_POST['hd'];
if(isset($_POST['edit']))
{
  $u="update site_categories set category_name='$tsub' where category_id=$hd_val";
	mysql_query($u) or die("Can't update");
}
if($v==1)
{
	$del="delete from site_categories where category_id=$val";
	mysql_query($del) or die("Can't delete the record");
	
}



$get_id=$_REQUEST['id'];
$qry="select * from site_categories where category_id=$get_id";
$rs=mysql_query($qry);
$fetch=mysql_fetch_array($rs);
 $qry_sub="select * from site_categories where category_head_id=$get_id";
$rs_sub=mysql_query($qry_sub);
?>

>

     <table width="100%" border="0" align="center">
       <tr>
         <td height="142" ><table width="100%" border="0" align="center">
		 
           <form name="frm" method="post" action="<? $_SERVER['PHP_SELF'];?>"   >
             <tr>
               <td height="46" colspan="3" class="style5"><strong>Edit Sub Category </strong></td>
             </tr>
             <tr>
               <td width="27%" ><span class="smalltxt">Sub Category</span> </td>
               <td colspan="2" ><input name="txtcat" type="text" class="bluetext"disabled="disabled" class="smalltxt"  value="<?= $fetch['category_name']  ?>"/></td>
             </tr>
             <tr>
               <td height="49" ><span class="smalltxt">Sub Category Name</span> </td>
               <td colspan="2" ><select name="subcat" class="smalltxt">
                   <option value="0">Select</option>
                   <?
	while($ft=mysql_fetch_array($rs_sub))
	{
	$cid=$ft['category_id'];
	?>
                   <option value="<?=  $cid ?> ">
                     <?= $ft['category_name']?>
                 </option>
                   <?
		
	ret($cid);
		
	}
	?>
                 </select>               </td>
             </tr>
             <tr>
               <td >&nbsp;</td>
               <td width="10%" ><input type="submit" class="button"   name="btn" value="Modify" /></td>
               <td width="63%" ><input type="button" name="delete_btn" value="Delete" onClick="confirm1();" /></td>
             </tr>
             <input type="hidden" name="hd_val" value="0"/>
           </form>
         </table></td>
       </tr>
       
	   <? if($btn=="Modify") 
 {
	$m="select * from site_categories where category_id=$val";
	$mq=mysql_query($m);
	$f=mysql_fetch_array($mq);
 ?>
 <tr>
         <td ><table width="100%" border="0" align="center">
           <form name="frm1" method="post" action="<? $_SERVER['PHP_SELF']; ?>">
             
             <tr>
               <td width="35%" height="42"  class="smalltxt">Sub Category Name </td>
               <td width="65%" ><input name="txt_sub" type="text" class="bluetext"class="smalltxt"  value="<?= $f['category_name']?>"></td>
             </tr>
             <tr>
               <td ><input type="hidden" name="hd" value="<?= $f['category_id'] ?>" ></td>
               <td ><input type="submit" class="button"   name="edit" value="Edit" ></td>
             </tr>
           </form>
    </table></td> </tr>
		  <?
  }
  ?>
      
</table>
<p>&nbsp;</p>
 

<p>
    <script language="javascript">
function confirm1()
{
	var cf;
	cf=confirm("Confirm to delete the record");
	if (cf)
	{
	document.frm.hd_val.value=1;
	} 
	 document.frm.submit();
}
  </script>
</p>
    </p>
