<?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'];
	$manufacturers_name = $_GET['manufacturers_name'];
	$query = "SELECT * FROM zen_manufacturers WHERE manufacturers_name = '$manufacturers_name'";
	$result = mysql_query($query, $zen_link);
	$row = mysql_fetch_array($result);
	if ($operation == "delete")
	{
		$delete_image_folder = $row["image_folder"];
		$delete_manufacturers_name = $manufacturers_name;
	}
	else
	{
		$edit_image_folder = $row["image_folder"];
		$edit_manufacturers_name = $manufacturers_name;
	}
		
?>
<html>
<head>
<title>Add/Edit/Delete Artist</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script language="JavaScript">
function update_folder(artist,operation)
{
	url = "artist.php?manufacturers_name=" + artist + "&operation=" + operation;
	location = url;
}

function convert_artist_to_folder(artist)
{
	artist = artist.replace(/ /g, "_");
	artist = artist.replace(/&/g, "and");
	artist = artist.toLowerCase()
	document.frm_add_artist.image_folder.value=artist;
}
</script>

</head>

<body>
<table border="0" width="80%"><tr><td>
<table border="1" width="100%"><tr><td>
<form name="frm_add_artist" method="post" action="add_artist.php">
<p>Artist: 
    <input name="manufacturers_name" type="text" id="manufacturers_name" onChange="convert_artist_to_folder(this.value)">
  Image Folder: 
  <input name="image_folder" type="text" id="image_folder">
  <input type="submit" name="Submit" value="Add">
</p>
</form>
</td></tr></table>
<br>
<table border="1" width="100%"><tr><td>
<form name="frm_delete_artist" method="post" action="delete_artist_confirm.php">
<p>
Artist: 
  <select name="artist_delete_list" onChange="update_folder(this.value, 'delete');">
  <option value=''>- not selected-</option>
 <?php
	$query = "SELECT * FROM zen_manufacturers";
	$result = mysql_query($query, $zen_link);
	$num_results = mysql_num_rows($result);
	for ($i = 0; $i < $num_results; $i++)
	{
		$row = mysql_fetch_array($result);
		$artist_name = $row["manufacturers_name"];
		if ($artist_name == $delete_manufacturers_name)
			echo "<option value='$artist_name' selected>$artist_name</option>";
		else
			echo "<option value='$artist_name'>$artist_name</option>";
	}
?>
  </select>
  Image Folder: 
  <input name="image_folder" type="text" id="image_folder" value="<?php echo $delete_image_folder; ?>" readonly="true"> 
  <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_artist" method="post" action="edit_artist.php">
<p>Artist:
<select name="artist_edit_list" onChange="update_folder(this.value, 'edit');">
 <option value=''>- not selected-</option>
 <?php
	include ("../connect/db_connection.php");

	$query = "SELECT * FROM zen_manufacturers";
	$result = mysql_query($query, $zen_link);
	$num_results = mysql_num_rows($result);
	for ($i = 0; $i < $num_results; $i++)
	{
		$row = mysql_fetch_array($result);
		$artist_name = $row["manufacturers_name"];
		if ($artist_name == $edit_manufacturers_name)
			echo "<option value='$artist_name' selected>$artist_name</option>\n";
		else
			echo "<option value='$artist_name'>$artist_name</option>\n";
	}
	
?>
  </select> 
    <input name="new_manufacturers_name" type="text" id="new_manufacturers_name" value="<?php echo $edit_manufacturers_name; ?>">
  Image Folder: 
  <input name="new_image_folder" type="text" id="new_image_folder" value="<?php echo $edit_image_folder; ?>">
  <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="Categories" type="button" id="Category" value="Go to Category Manager" onClick="location='category.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>
