<?php session_start();  //Developed by ITechScripts
require 'include/configurations.php'; // ITECHBIDS Configuration File
$cat_id=$_GET['id'];
$mode=$_GET['mode'];
?>
<html>
<body>
><?php
require 'include/header.php';
?>


<table width="80%" border="0" cellpadding="5" cellspacing="1" class="ft" align="center">

<form name="sub" method="post" action="add.php">

         <tr class="ct" height="25">
        <td width="25%"><div align="center"><span height="25">Category </span></div></td>
		<td width="25%"><div align="center"><span height="25">SubCategory </span></div></td>
        <td width="27%"><div align="center"><span height="25">Edit</span></div></td>
        <td width="22%" class="ct" height="25"><div align="center">Delete</div></td>
		</tr>
		
<?
if($mode=='delete')
{
$sql1="delete from site_categories where category_id='$cat_id'";
$del=mysql_query($sql1);
if($del)
$message="Category deleted sucessfully";
else
$message="Category not deleted ";
}
$mode='';
 if(!empty($message))
{
echo "<tr><td align=center colspan=4><font color=red size=2>$message</font></td></tr>";
}

if($mode=='edit')
{
}
$sql="select * from site_categories where category_head_id=0";
$res=mysql_query($sql);
$cat_row=mysql_fetch_array($res);
$categoryid=$row['category_id'];
?><?php
	$total_records=mysql_num_rows($res);
	$curpage=$_GET['curpage'];
	if(strlen($_GET['curpage']) == 0) $curpage=1;
	$start=($curpage-1) * 10;
	$end=10;
	if($curpage==''|| $curpage==1)
	$i=1;
	else $i=$_GET['sno']+1;
	$sql.=" limit $start,$end";
	$res=mysql_query($sql);
 ?>


        <tr> 
          <td align="right" colspan="5"> 
            <?php
	     if($curpage!=1) 
	     {
         ?>
            <a href="subcategory.php?mode=<?=$mode; ?>&curpage=<?=($curpage-1);?>" id="link2">Prev</a> 
            | 
            <?php
            }
           ?>
            <?php
           if($total_records > ($start + $end)) 
		   {
           ?>
            <a href="subcategory.php?mode=<?=$mode; ?>&curpage=<?=($curpage+1);?>" id="link2">Next</a> 
            <?php
            }
            ?>
          </td>
        </tr>
        
        <?php
         while($cat_row=mysql_fetch_array($res))
        {
		$sub_sql="select * from site_categories where category_head_id=$cat_row[category_id]";
		$sub_res=mysql_query($sub_sql);
       	?>
	   <tr >
       	
	   <td height="41" align="center"><?= $cat_row['category_name'];?></td>
	   <td>&nbsp;</td>
	   <td>&nbsp;</td>
	   <td>&nbsp;</td>
	   </tr>
	   
	   
	    <?
		while($row=mysql_fetch_array($sub_res))
        {
        ?>
		 <tr >
		<td>&nbsp;</td>	
		
	   <td><a href="#" onclick=window.open('subcategory_view.php?id=<?=$row['category_id'] ?>','my_win','width=550,height=300')><?= $row[category_name]; ?></a></td>		
	   <td><div align="center" class="style3">
	    <a href="add.php?id=<?=$row['category_id']; ?>&mode=edit" style="text-decoration:none" id="link1">Edit</a></div></td>
	   <td><div align="center" class="style3">
	   <a href="subcategory.php?id=<?=$row['category_id']; ?>&mode=delete"  id="link1" style="text-decoration:none" onClick="javascript:return condelete();">Delete</a></div></td>
	   </tr>
	   <?
	   } //        while($row=mysql_fetch_array($sub_res))
         } //          while($cat_row=mysql_fetch_array($res))
       ?>	
	<tr>
    <tr><td>

</td></tr>
	<td colspan="5" align="center">
	
	<input type="submit" class="button"   name="add" value="Add Subcategory" ></div>
	</td>
	</tr>
  </form></table>
  <script language="JavaScript">
function condelete()
{
var confrm;
confrm=window.confirm("Are You sure you want to delete this category");
return confrm;
}
</script>

<?
	require 'include/footer.php';
?>
</body></html>
