<?php
	session_start();
	if (!isset($_SESSION['view_id']))
	{
		header('Location: index.php');
		exit;
	}

	$view_id = $_SESSION['view_id'];
	
	$categories_name = $_GET['categories_name'];

	include "../connect/db_connection_2.php";
	
	// Get category ID and delete.
	$query = "SELECT * FROM zen_categories_description WHERE categories_name = '$categories_name'";
	$result = mysql_query($query, $zen_link);
	$row = mysql_fetch_array($result);
	$categories_id = $row["categories_id"];
	
	// Now go ahead and delete records from tables.
	$query = "DELETE FROM zen_categories WHERE categories_id = '$categories_id'";
	$result = mysql_query($query, $zen_link);
	
	$query = "DELETE FROM zen_categories_description WHERE categories_name = '$categories_name'";
	$result = mysql_query($query, $zen_link);
	
	// And delete actual folder.
	$document_root = $_SERVER['DOCUMENT_ROOT'];
	$folder_name = str_replace(" ", "_", $categories_name);
	$folder_name = strtolower($folder_name);
	$folder_name = $document_root . "/inventory_images/$folder_name/";
	if (file_exists($folder_name))
	{
		// Delete folder.
		rmdir($folder_name);
	}
	
	header("Location: category.php");
	
?>
