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

	$view_id = $_SESSION['view_id'];
	
	$new_manufacturers_name = $_POST['new_manufacturers_name'];
	$new_image_folder = $_POST['new_image_folder'];
	$old_manufacturers_name = $_POST['artist_edit_list'];

	include "../connect/db_connection_2.php";
	
	//First get old folder name.
	$query = "SELECT * FROM zen_manufacturers WHERE manufacturers_name = '$old_manufacturers_name'";
	$result = mysql_query($query, $zen_link);
	$row = mysql_fetch_array($result);
	$old_image_folder = $row["image_folder"];
	
	// Now go ahead and update artist record from table.
	$query = "UPDATE zen_manufacturers SET manufacturers_name = '$new_manufacturers_name', image_folder = '$new_image_folder' WHERE manufacturers_name = '$old_manufacturers_name'";
	$result = mysql_query($query, $zen_link);
	
	// For each category, rename the artist image folder if it exists.
	$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"];
		$categories_name = str_replace(" ", "_", $categories_name);
		// And rename actual folder.
		$document_root = $_SERVER['DOCUMENT_ROOT'];
		$new_image_folder = $document_root . "/inventory_images/$categories_name/" . $new_image_folder;
		$old_image_folder = $document_root . "/inventory_images/$categories_name/" . $old_image_folder;
		if (file_exists($old_image_folder))
		{
			// rename folder.
			rename($old_image_folder, $new_image_folder);
		}
	}
	
	header("Location: artist.php");
	
?>
