<?php session_start();  //Developed by ITechScripts
require 'include/configurations.php'; // ITECHBIDS Configuration File
if($_POST[postformat])
$_SESSION[postformat]=$_POST[postformat];

if($_GET[mode])
{
$mode=$_GET[mode];
}
else
{
$mode=$_POST[mode];
}
 $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[radio_cat];
 $postformat=$_POST[postformat];
 
 if(empty($cat_id))
 {
 $err_cat="Please Select Category";
 $err_flag=1;
 }
 else
 {
  $_SESSION[categoryid]=$cat_id;
  if($mode=="")
  {
   echo '<meta http-equiv="refresh" content="0;url=postdetails.php?cat_id='.$cat_id.'&postformat='.$postformat.'">';
   echo "$lang_675 <a href=postdetails.php?cat_id=$cat_id&postformat='$postformat'>Click here</a>"; 
 }
 else if($mode=="change")
 {
 echo '<meta http-equiv="refresh" content="0;url=preview.php">';
 echo "$lang_675 <a href=preview.php>Click here</a>"; 
 }

 exit(); 
 }
  }
?>
<html>
<head>
<title>Sell Your Item step 1 of 5:Select Category</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>
<body>
<? require 'include/header.php'; ?>
<table width="580" border="0" cellpadding="0" cellspacing="0" align="center">
 
  <link href="cssfiles/css.css" rel="stylesheet" type="text/css">
  <? if(!empty($warning))
  {
  ?>
  <tr align="center"><td>
  <br>
  <br>
  <br>
    <table cellpadding="5" cellspacing="2" width="50%" class="table_border1">
	<th class="mylist">
	 Oops! 
	</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><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="catselect.php#cat_form">Category</a> - <?= $err_cat; ?></td></tr>

<? 
}
?>
<tr><td colspan="2"><hr noshade class="hr_color" size="1"></td></tr>
</td>
</tr></table>
<?
}
 ?>
 <tr>
    <td colspan=2 align="center" heught=25" class="ct" height="25">
	<font><b>Select Category</b></font></td>
  </tr>
<tr><td>
<font size="2"><b>Select from all categories</b></font>
<br>
<br>
What type of item are you selling?. 
Select the best category to help buyers find your item. 
Select a top-level category and click <b>Continue</b>.
</td></tr>

<tr><td><font size="2"><b>Main Category</b></font></td></tr>
<tr><td>
<form name="cat_form" action="catselect.php" method="post">

<table cellpadding="5" cellspacing="0" width=100% border="0">
<?  
 while($rec=mysql_fetch_array($res))
{ 
?>
 <tr>
 <? 
  if( $rec[category_id] == $_SESSION[categoryid])
 {
 ?>
 <td><input type="radio" name="radio_cat" value="<?=$rec[category_id];?>" checked></td><td>
 <?=$rec[category_name]; ?> </td>
 <?
 }
 else
 {
 ?>
 <td><input type="radio" name="radio_cat" 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=mode value=<?= $mode ?>>
<input type="hidden" name=postformat value="<?= $postformat; ?>">
<tr><td align="center">
<? if($mode=="")
{ ?>
<input type="submit" name=catsub value="Continue" class="button">
<?
 }
else if($mode=="change")
{
 ?>
<input type="submit" name=catsub value="SaveChanges" class="button">
<? 
} 
?>

</td></tr>
<tr align="center"><td><? require 'include/footer.php'?></td></tr>
</table>
</form>
</td></tr>
</table>
  </body>
</html>
