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

	include ("../connect/db_connection_2.php");

	$categories_name = $_POST['categories_name'];
	$categories_name = str_replace("&", "and", $categories_name);
	$categories_description = $_POST['categories_description'];
	$today = date("Y-m-d H:i:s");

	$query = "INSERT INTO zen_categories (date_added) VALUES ('$today')";
	$result = mysql_query($query, $zen_link);
	
	$categories_id = mysql_insert_id();
	
	$query = "INSERT INTO zen_categories_description (categories_id, categories_name, categories_description) VALUES ('$categories_id', '$categories_name', '$categories_description')";
	$result = mysql_query($query, $zen_link);
	
	// And create actual folders.
	$cat_folder = str_replace(" ", "_", $categories_name);
	$cat_folder = strtolower($cat_folder);
	$document_root = $_SERVER['DOCUMENT_ROOT'];
	$cat_folder = $document_root . "/inventory_images/$cat_folder/";
	if (!file_exists($cat_folder))
	{
		mkdir($cat_folder, 0755);
//		chown($cat_folder, $owner);
		chmod($cat_folder, 0755);
	}
	
	header("Location: category.php");
?>