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

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

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

	//$query = "INSERT INTO zen_manufacturers (manufacturers_name, image_folder, date_added) VALUES ('$manufacturers_name', '$image_folder', '$today')";
	$query = "INSERT INTO zen_manufacturers (manufacturers_name, manufacturers_image, date_added) VALUES ('$manufacturers_name', '$image_folder', '$today')";
	$result = mysql_query($query, $zen_link);
	
	// And create actual folders.
	// For each category, create the artist image folder.
	$query = "SELECT * FROM zen_categories_description";
	$result = mysql_query($query, $zen_link);
	$num_results = mysql_num_rows($result);
	for ($i = 0; $i < $num_results; $i++)
	{
		$row = mysql_fetch_array($result);
		$categories_name = $row["categories_name"];
		$cat_folder = str_replace(" ", "_", $categories_name);
		$cat_folder = strtolower($cat_folder);
		$document_root = $_SERVER['DOCUMENT_ROOT'];
		$category_folder = $document_root . "/inventory_images/$cat_folder/";
		$folder_name = $document_root . "/inventory_images/$cat_folder/$image_folder";
		if (!file_exists($category_folder))
		{
			mkdir($category_folder, 0755);
//			chown($cat_folder, $owner);
			chmod($category_folder, 0755);
		}
		if (!file_exists($folder_name))
		{
			// Create folder.
			mkdir($folder_name, 0755);
//			chown($folder_name, $owner);
			chmod($folder_name, 0755);
		}
	}
	
	header("Location: artist.php");
?>