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

	$view_id = $_SESSION['view_id'];
	
	$new_categories_name = $_POST['new_categories_name'];
	$old_categories_name = $_POST['category_edit_list'];
	$categories_description = $_POST['categories_description_update'];

	include "../connect/db_connection_2.php";
	
	//First get old and new folder names.
	$old_categories_folder = $old_categories_name;
	$old_categories_folder = str_replace(" ", "_", $old_categories_folder);
	$new_categories_folder = $new_categories_name;
	$new_categories_folder = str_replace(" ", "_", $new_categories_folder);
	
	// Now go ahead and update category record from table.
	$query = "UPDATE `zen_categories_description` SET `categories_name`='$new_categories_name', `categories_description`='$categories_description' WHERE `categories_name` = '$old_categories_name'";
	$result = mysql_query($query, $zen_link);
	
	// And rename actual folder.
	$document_root = $_SERVER['DOCUMENT_ROOT'];
	$new_image_folder = $document_root . "/inventory_images/$categories_name/" . $new_categories_folder;
	$old_image_folder = $document_root . "/inventory_images/$categories_name/" . $old_categories_folder;
	if (file_exists($old_image_folder))
	{
		// rename folder.
		rename($old_image_folder, $new_image_folder);
	}
	
	header("Location: category.php");
	
?>
