<?php
session_start();

if ($_SESSION["denglu"] != 1)
{
	echo "<h3>you have not logged in</h3>";
	echo "If you are an administrator, <a href=../login.php>login here</a><br>";
	echo "If you are not administrator, <a href=../index.htm>visit our website</a>";
	exit;
}

include "header.php";

$link = mysql_connect("localhost", "whateversg", "what0820");
mysql_select_db("whatever_com_sg", $link);

$submit = $_POST["submit"];
$categoryName = $_POST["categoryName"];
$categoryDescrip = $_POST["categoryDescrip"];
$id = $_POST["id"];

if (isset($submit))
{
	if (!isset($categoryName))
	{
		echo "you did not specify a Category Name";
		exit;
	}
	elseif(!isset($categoryDescrip))
	{
		echo "you did not specify a Category Description";
		exit;
	}
	else
	{
		$query = "update media_category set categoryName='$categoryName', categoryDescrip='$categoryDescrip' where categoryID='$id'";
		//echo $query;
		mysql_query($query);
		//header ("location: category.php");
		echo "<center><table width=80%><tr><td>Category modified</td></tr></table></center>";
	}
}
else
{
	$query = "select categoryName, categoryDescrip from media_category where categoryID='$id'";
	$result = mysql_query($query);
	
	$row = mysql_fetch_array($result);
	
?>

<center>

<form action="modCategory.php" method="post">

<table width="80%" border="0">
  
  <tr>
    <td align="right">
    Category Name:
    </td>
    
    <td align="left">
    <input type="text" name="categoryName" size=30 value="<?php echo $row[0]?>">
    </td>
  </tr>
  
  <tr>
    <td align="right">
    Category Description:
    </td>
    
    <td align="left">
    <textarea name="categoryDescrip" rows=5 cols=30 wrap="virtual"><?php echo $row[1];?></textarea>
    </td>
  </tr>
  
  <tr>
    <td colspan=2 align="center">
    <input type="hidden" name="id" value=<?php echo $id;?>>
    <input type="submit" name="submit" value="Modify Category">
    &nbsp;
    <input type="reset" name="reset" value="Clear Changes">
    </td>
  </tr>
  
</table>

</form>

</center>

<?php
}
include "footer.php";
?>