<?php
session_start();

include "../functions.php";

include "../conn.php";

checkAdmin(session_id());

$parentid = $_POST["parentid"];
$catid = $_POST["catid"];
	
delcat($catid);
	
header ("location: products.php?catid=$parentid");

function delcat($catid)
{
	$res = mysql_query("select catid from cats where parentid='$catid'");
	while ($row = mysql_fetch_array($res))
	{
		delcat($row[0]);
	}
	
	$res = mysql_query("select productpic from products where catid='$catid'");
	while ($row = mysql_fetch_array($res))
	{
		$productpic = $row[0];
		@unlink($productpic);
	}
	mysql_query("delete from products where catid='$catid'");
	
	
	$res = mysql_query("select catpic from cats where catid='$catid'");
	while ($row = mysql_fetch_array($res))
	{
		$catpic = $row[0];
		@unlink ($catpic);
	}
	mysql_query("delete from cats where catid='$catid'");
}
?>