<?php session_start();  //Developed by ITechScripts


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


	$canAdd=$_POST['canAdd'];
	if($canAdd==1)
	{
		$category=$_POST['txtCategory'];
		$cat_sel_sql="select * from site_categories where category_name='$category'";
		$cat_sel_res=mysql_query($cat_sel_sql);
		if(mysql_num_rows($cat_sel_res)>0) $err_mess="Category $category Already Exists";
		else {
			$_SESSION['catname']=$category;
			$_SESSION['region']=$region_id;
		              echo '<meta http-equiv="refresh" content="0;url=definetable.php">';
					  exit();	
		//	  }
		}
	}


if(isset($_REQUEST['btn_Del']))
{
$chk=$_REQUEST['chkSub'];
for($i=0;$i<count($chk);$i++)
{
$select_query="select * from site_categories where category_id='$chk[$i]'";
$tab=mysql_query($select_query);
if($row=mysql_fetch_array($tab))
{
$table_name=$row['category_name'];
}

$drop_query="drop table $table_name";
mysql_query($drop_query);

	
$query="delete from site_categories where category_id='$chk[$i]'";
mysql_query($query);

$query="delete from downcats where tablename='$table_name'";
mysql_query($query);

}
}
	
?>
<html>
<head>
<title>:::Auction:::Admin Area</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<table border="0" align="center" cellpadding="5" cellspacing="2" width="80%">
<tr><td class="ft" heught=25"><b>Category Management</b></td></tr>
<tr>
    <td class="">Here you can Add, Delete Category .Please Don't Give Space between the Category Name.</td>
</tr>
<form name="frmAdd" method="post" action="<? $_SERVER['PHP_SELF']?>" onSubmit="return validate();">
<tr align="center"><td>
<?
	if($err_mess) echo "<font color=red><b>$err_mess</b></font>";
	// require 'include/footer.php';
	
?>
</td></tr>
<tr>
<td>Add New Category :&nbsp;&nbsp;<input type="text" class="bluetext"name="txtCategory">&nbsp;&nbsp;
<input type="hidden" name="canAdd" value="0">
<input type="hidden" name="cboReligion" value="<?=$region_id?>">
<input type="submit" class="button"   name="btn_Add" value=" Add ">
</td>
</tr>
</form>
<?
	$cat_sql="select * from site_categories where category_head_id=0";
	$cat_res=mysql_query($cat_sql);
	if(mysql_num_rows($cat_res)>0) {
?>
<tr><td>
<table border="0" align="center" cellpadding="5" cellspacing="2" width="100%">
<form name="frmCat" action="<? $_SERVER['PHP_SELF']?>" method="post">
<tr>
<?
	$i=0;
	while($cat_row=mysql_fetch_array($cat_res)) {
	$i=$i+1;
	if($i<=3)
	{
	?>
	
		<td><input type="checkbox" name="chkSub[]" id="chkSub" value="<?=$cat_row['category_id']?>"></td><td><?=$cat_row['category_name']?></td>
<?
}
if($i==4)
{
?>
</tr><tr><td><input type="checkbox" name="chkSub[]" id="chkSub" value="<?=$cat_row['category_id']?>"></td><td><?=$cat_row['category_name']?>
<?
$i=1;
}
}
?>
</td>
</tr>
<tr>
<td colspan="8">
<input type="hidden" name="act" value="0">
<input type="button" name="btn_All" value="Check All" onClick="selectall(1)">
&nbsp;&nbsp;&nbsp;<input type="button" name="btn_None" value="UnCheck All" onClick="selectall(0)"> 
<!-- &nbsp;&nbsp;&nbsp;<input type="button" name="btn_Del" value="Delete" onClick="editclick(1)"> -->
 &nbsp;&nbsp;&nbsp;<input type="submit" class="button"   name="btn_Del" value="Delete"  onClick="condelete()"> 
<!-- &nbsp;&nbsp;&nbsp;<input type="button" name="btn_Edit" value="Edit" onClick="editclick(2)"> -->
</td>
</tr>
</form>
</table>
</td></tr>
<?
	}
	else {
?>
<tr><td>No Categories Found</td></tr>
<?
	}
?>
<?
 require 'include/footer.php'; 
?>
</table>
</body>
</html>
<script language="javascript">
function validate()
 {
	if(document.frmAdd.txtCategory.value=="")
	{
		alert("Please Enter a Value for add new category");
		document.frmAdd.txtCategory.focus();
		return false;
	}
	document.frmAdd.canAdd.value=1;
	return true;
}
function selectall(action) {
	len=document.frmCat.chkSub.length;
	if(len>1) {
		for(i=0;i<len;i++) {
			 document.frmCat.chkSub[i].checked=action;
		}
	}
	else {
			 document.frmCat.chkSub.checked=action;
	}
}

function editclick(type) {
	document.frmCat.action='editcat.php';
	document.frmCat.target='_blank';
	document.frmCat.act.value=type;
	document.frmCat.submit();

}
function condelete()
{
var confrm;
confrm=window.confirm("Are You sure you want to delete this category");
return confrm;
}
</script>
