<?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"];

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 = "select categoryName from media_category where categoryName='$categoryName'";
		
		//echo "lalala $query lalala<br>";
		
		$result = mysql_query($query);
		
		if (mysql_num_rows($result) > 0)
		{
			echo "<center><table width=80%><tr><td>There is already a category called $categoryName</td></tr></table></center>";
		}
		else
		{
			$query = "insert into media_category(categoryName, categoryDescrip) values('$categoryName', '$categoryDescrip')";
			mysql_query($query);
			//header ("location: category.php");
			echo "<center><table width=80%><tr><td>Category added</td></tr></table></center>";
		}
	}
}
else
{
?>


<script language="javascript">
<!--
function openSmallWindow(url)  
{ 
	window.open(url,"smallWindow","width=500,height=375,scrollbars,resizable"); 
	return false; 
}
-->

</script>

<center>

<form action="addCategory.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>
    </td>
  </tr>
  
  <tr>
    <td align="right" valign="top">
    Category Description:</font>
    </td>
    
    <td align="left">
    <textarea name="categoryDescrip" rows=5 cols=30 wrap="virtual"></textarea>
    </td>
  </tr>
  
  <tr>
    <td colspan=2 align="center">
    <input type="submit" name="submit" value="Add Category">
    &nbsp;
    <input type="reset" name="reset" value="Clear Input">
    </td>
  </tr>
  
</table>

</form>

</center>

</style>

<?php
}

include "footer.php";
?>