<?php session_start();  //Developed by ITechScripts
require 'include/configurations.php'; // ITECHBIDS Configuration File

$postformat=$_POST[postformat];
$productid=$_REQUEST[productid];
$mode=$_REQUEST[mode];

$def_sql="select * from auction_details where productid=$productid";
$def_row=mysql_query($def_sql);
$def_res=mysql_fetch_array($def_row);

 $def_cat_id=$def_res[category_id];
 $sub1="select * from site_categories where category_head_id=".$def_cat_id;
 $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=0"; 
 $res=mysql_query($sql);
 $cat_flag=$_POST[cat_flag];
 if($cat_flag==1)
 {
 $cat_id=$_POST[cat_id];
 $postformat=$_POST[postformat];
 if(empty($cat_id))
 {
		$err_cat=$err_75;
        $err_flag=1;
 }
 else
 {
 $_SESSION[modifycat]=$cat_id;
 echo '<meta http-equiv="refresh" content="0;url=modifysubcategory.php?cat_id='.$productid.'&productid='.$productid.'&mode='.$mode.'">';
  exit(); 
 }
 
 }
?>
<table width="580" border="0" cellpadding="0" cellspacing="0" align="center" >
>
  <? if(!empty($warning))
  {
  ?>
  <tr align="center"><td>
  <br>
  <br>
  <br>
    <table cellpadding="5" cellspacing="2" width="50%" class="table_border1">
	<th class="mylist">
	 Caution! 
	</th>
  <tr>
  <td>
  <font size=2 color="red"><?= $warning; ?></font>
  </td></tr> </table>
  <br>
  <br>
  <br>
   </td></tr>
  <tr><td> <? require'include/footer.php'; ?> </td></tr>
  <?
  exit();
  }
  ?>
  <tr><td>
<table width="100%" cellpadding="5" cellspacing="2" align="center" border="0">
<tr height=25>
<td class="ct">
<b>
Edit Category</b></td></tr>

<tr><td>
<? if($err_flag==1)
{ 
?>
<table width="100%" align="center"><tr><td>
<img src="images/xclabid.gif"></td><td>
<font size=2 color="red">The following must be corrected before continuing:</font></td>
<? if(!empty($err_cat))
 {
 ?>
<tr><td>&nbsp;</td><td><a href="modifyitem_cate.php#cat_form">Category</a> - <?= $err_cat; ?></td></tr>

<? 
}
?>
</td>
</tr></table>
<?
}
 ?>
<tr><td>
<tr><td>
<form name="cat_form" action="modifycategory.php" method="post">
<table cellpadding="5" cellspacing="0" class="ft" width=100% border="0">
<?  
$color=1;
 while($rec=mysql_fetch_array($res))
{ 
?>
 <tr>
<td>
<?
					
 if($rec[category_id]==$def_cat_id)
{
?>
<input type="radio" name="cat_id" value=<?=$rec[category_id]; ?> checked>
<?
}
else
{
 ?> 
<input type="radio" name="cat_id" value=<?=$rec[category_id]; ?>> 

<?
// }
}
?></td><td>
 <?=$rec[category_name]; ?> </td><td>
<? 
							$sub_count="1";
                            $sub="select * from site_categories where category_head_id=".$rec['category_id'];
				        	$sub_res=mysql_query($sub);
							$tot_sub=mysql_num_rows($sub_res);
   						    while($sub_rec=mysql_fetch_array($sub_res))
							{
							$sub_count=$sub_count+1;
							echo $sub_rec[category_name];
							if($tot_sub>$sub_count)
							{
							echo " , ";
							}
					

}
  ?>
  </td></tr>
  <? 
  }
  // }
  ?></table>
</td></tr>
<input type="hidden" name=cat_flag value=1>
<input type="hidden" name=postformat value="<?= $postformat; ?>">
<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>

  </body>
</html>
