<?php session_start();  //Developed by ITechScripts
require 'include/configurations.php'; // ITECHBIDS Configuration File
$postformat=$_POST[postformat];
$productid=$_REQUEST[productid];
$mode=$_REQUEST[mode];
 
 function itechitems_11($ssid,$cat)
{
 $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))
    {
     $cat_row[category_id];
     $cat=$cat_row[category_id]." or category_id=";
     if($cat_row['category_id'])
	 {
	  $ssid=$cat_row['category_id'];
	  $_SESSION[catt]=$_SESSION[catt]."$cat";
	  itechitems_11($ssid,$cat);
	 }
   }
  }
 
 
 $sub1="select * from site_categories where category_head_id=".$_SESSION[modifycat];
 $sub_res1=mysql_query($sub1);
 $sub1_row=mysql_num_rows($sub_res1);
 if($sub1_row == 0)
 {
 $sub1="select * from site_categories where category_id=".$def_cat_id;
 $sub_res1=mysql_query($sub1);
 $def_cat=mysql_fetch_array($sub_res1);
 if($def_cat[category_head_id])
 $def_cat_id=$def_cat[category_head_id];
 else
 $def_cat_id=$def_cat[category_id];
 }

 $sql="select * from site_categories where category_head_id=$_SESSION[modifycat]"; 
 $res=mysql_query($sql);
 $cat_flag=$_POST[cat_flag];
 if($cat_flag==1)
 {
 $subcat_id=$_POST[subcat_id];
 if(empty($subcat_id))
 {
		$err_cat=$err_75;
        $err_flag=1;
 }
 else
 {
 $_SESSION[modifysubcat]=$subcat_id;
 $up_cat="update auction_details set category_id=$subcat_id where productid=$productid";
 mysql_query($up_cat);
  
 ?>
<script language="javascript">
window.close();
window.opener.getChildWinData();
</script>
 <?
 }
 }
?>
<body>
<table width="580" border="0" cellpadding="0" cellspacing="0" align="center">
>
<tr height=25><td class="ct"  width="758" ><font size="2"><b>
&nbsp;&nbsp;Edit Category </b></font> </td>
</tr> 
<tr>
<td valign="top" > 
<form name="cat_form" action="modifysubcategory.php" method="post">
<table width="100%" cellpadding="5" cellspacing="2" align="center" border="0" >
<tr>
<td  valign="top" >
<table cellpadding="5" cellspacing="0" width=100% border="0" >
<tr><td width="53%"  valign="top">
<table><tr><td valign="top">
<? 
while($rec=mysql_fetch_array($res))
{ 
$count=$count+1;

    $ssid=$rec[category_id];
	$_SESSION[catt]=" ";
	 if($ssid)
     {
     $cat="category_id=$ssid or category_id= ";
	 $_SESSION[catt]=$cat;
     itechitems_11($ssid,$cat);
     $cat=$_SESSION[catt];
     }
	 $cat=rtrim($cat," or category_id=");
	 	  

?>
							<tr><td>
							<input type="radio" name="subcat_id" value=<?=$rec[category_id]; ?>>&nbsp;
      						<?= $rec[category_name] ?> </td></tr>
							<tr><td valign="top">
							<table>
							<? 
							$sub="select * from site_categories where category_head_id=".$rec['category_id'];
				        	$sub_res=mysql_query($sub);
//							$tot_sub_count=mysql_num_rows($sub_res);
                            $sub_count=1;
							while($sub_rec=mysql_fetch_array($sub_res)  )
							{
	 $sub_count=$sub_count+1;
     $sub_ssid=$sub_rec[category_id];
	 $_SESSION[subcat]=" ";
	 if($sub_ssid)
     {
     $subcat="category_id=$sub_ssid or category_id= ";
	 $_SESSION[subcat]=$subcat;
     itechitems_11($sub_ssid,$subcat);
     $subcat=$_SESSION[subcat];
     }
	 $subcat=rtrim($subcat," or category_id=");
	 $count_item_sql="select * from auction_details where selling_method!=\"want_it_now\" and ($subcat) and status='Active' and bid_starting_date <= now() ";
	  $count_item_res=mysql_query($count_item_sql);
	  $count_item_total=mysql_num_rows($count_item_res);  
							?>
							<tr><td>
							<input type="radio" name="subcat_id" value=<?=$sub_rec[category_id]; ?>>&nbsp;
      						<?= $sub_rec[category_name] ?> </td></tr>
							<? 
							} // while($sub_rec=mysql_fetch_array($sub_res) and $sub_count <=3 )
							?>
							</table>
						</td></tr>
						

<? if($count == $first_part )
{
?>
</table>
</td>
<td width="47%" valign="top">
<table ><tr><td  valign="top">
<?
}
} 
?>
</td>
</tr>
</table></td></tr>
<input type="hidden" name=cat_flag value=1>
<input type="hidden" name=mode value="<?= $mode; ?>">
<input type="hidden" name=productid value="<?= $productid; ?>">
<tr><td align="center">
<input type="submit" class="button"   name=catsub value="Continue" class="buttonbig"></td></tr>
</table>
</form>
</td></tr></table></td></tr>

</body>
</html>
