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

	include ("../connect/db_connection_2.php");
	
	$operation = $_GET['operation'];
	$categories_name = $_GET['categories_name'];
	$query = "SELECT * FROM zen_categories_description WHERE categories_name = '$categories_name'";
	$result = mysql_query($query, $zen_link);
	$row = mysql_fetch_array($result);
	if ($operation == "delete")
	{
		$delete_categories_name = $categories_name;
		$delete_categories_description = $row["categories_description"];
	}
	else
	{
		$edit_categories_name = $categories_name;
		$edit_categories_description = $row["categories_description"];
	}
		
?>
<html>
<head>
<title>Add/Edit/Delete Category</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script language="JavaScript">
function update_description(category,operation)
{
	url = "category.php?categories_name=" + category + "&operation=" + operation;
	location = url;
}
</script>

</head>

<body>
<table border="0" width="80%"><tr><td>
<table border="1" width="100%"><tr><td>
<form name="frm_add_category" method="post" action="add_category.php">
<p>Category: 
    <input name="categories_name" type="text" id="categories_name">
Description:    
<textarea name="categories_description" id="categories_description"></textarea>
  <input type="submit" name="Submit" value="Add">
</p>
</form>
</td></tr></table>
<br>
<table border="1" width="100%"><tr><td>
<form name="frm_delete_category" method="post" action="delete_category_confirm.php">
<p>
Category: 
  <select name="category_delete_list" onChange="update_description(this.value, 'delete');">
  <option value=''>- not selected-</option>
 <?php
	$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);
		$category_name = $row["categories_name"];
		if ($category_name == $delete_categories_name)
			echo "<option value='$category_name' selected>$category_name</option>";
		else
			echo "<option value='$category_name'>$category_name</option>";
	}
?>
  </select>
  Description:    
  <textarea name="categories_description_delete" id="categories_description_delete" readonly><?php echo $delete_categories_description; ?></textarea>
  <input name="Submit" type="submit" id="Submit" value="Delete">
</p>
</form>
</td></tr></table>
<br>
<table border="1" width="100%"><tr><td>
<form name="frm_edit_category" method="post" action="edit_category.php">
<p>Category:
 <select name="category_edit_list" onChange="update_description(this.value, 'edit');">
  <option value=''>- not selected-</option>
 <?php
	$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);
		$category_name = $row["categories_name"];
		if ($category_name == $edit_categories_name)
			echo "<option value='$category_name' selected>$category_name</option>";
		else
			echo "<option value='$category_name'>$category_name</option>";
	}
	
?>
  </select> 
  <input name="new_categories_name" type="text" id="new_categories_name" value="<?php echo $edit_categories_name; ?>">
  Description:    
  <textarea name="categories_description_update" id="categories_description_update"><?php echo $edit_categories_description; ?></textarea> 
  <input type="submit" name="Submit" value="Update">
</p>

</form>
</td></tr></table>
<table width="100%"><tr>
  <td align="center"><input name="Inventory" type="button" id="Inventory" value="Go to Inventory Manager" onClick="location='manage_inventory.php'"></td>
  <td align="center"><input name="Artists" type="button" id="Artist" value="Go to Artist Manager" onClick="location='artist.php'"></td>
  <td align="center"><input name="Users" type="button" id="User" value="Go to User Manager" onClick="location='users.php'"></td>
</tr></table>
</td></tr></table>
</body>
</html>
