<?
require_once("../conn.php");
require_once("access.php");

if(isset($_POST[s1]) && !empty($_POST[NewCategory]))
{
	$q1 = "update yellow_categories set CategoryName = '$_POST[NewCategory]', description = '$_POST[description]', longdescription = '$_POST[longdescription]' where CategoryID = '$_POST[CategoryID]' ";
	mysql_query($q1) or die("<br><center><font color=red face=verdana size=2><b>Dublicate Category name!</b></font><br><a class=RedLink href=\"CategoriesEdit.php?CategoryID=$_POST[CategoryID]\">go back</a></center><br>");

	header("location:categories.php");
	exit();
}

include_once("LeftStyles.php");

//get the category info
$q1 = "select * from yellow_categories where CategoryID = '$_GET[CategoryID]' ";
$r1 = mysql_query($q1) or die(mysql_error());
$a1 = mysql_fetch_array($r1);

?>

<script>
	function CheckEditCategory() {

		if(document.f1.NewCategory.value=="")
		{
			window.alert('Enter the category new name, please!');
			document.f1.NewCategory.focus();
			return false;
		}

	}

</script>
<link rel="stylesheet" href="style.css" type="text/css">

<table align=center width=400>
</table>
&nbsp; 
<table width="90%" cellspacing="0" cellpadding="10" align="center" class="form">
  <tr> 
    <td> 
    <div align="right"><font face="Arial, Helvetica, sans-serif" size="4"><b><font color="#FFFFFF">CLASSIFIEDS v2.0</font></b></font></div>
    </td>
  </tr>
</table>
&nbsp; <br>
<br>
<form method=post onsubmit="return CheckEditCategory();" name=f1>

  <table align=center cellpadding="4" cellspacing="1">
    <tr align="left"> 
      <td colspan=2 class=TableHead><font color=black face=verdana size=2><b><img src="images/admin/categories.jpg" width="23" height="19" align="absmiddle">&nbsp;EDIT 
        CATEGORY </b></font></td>
    </tr>
    <tr> 
      <td class="form_request">Old category name:</td>
      <td class="form_answer"> 
        <?=$a1[CategoryName]?>
      </td>
    </tr>
    <tr> 
      <td class="form_request">New category name:</td>
      <td class="form_answer"> 
        <input type=text name=NewCategory size=35>
      </td>
    </tr>
   <tr> 
      <td class="form_request">Description:</td>
      <td class="form_answer"> 
         <textarea name=description rows=8 cols=43><?=$a1[description]?></textarea>
      </td>
    </tr>
<tr> 
      <td class="form_request">Long Description:</td>
      <td class="form_answer"> 
         <textarea name=longdescription rows=8 cols=43><?=$a1[longdescription]?></textarea>
      </td>
    </tr>

 <tr> 
      <td>&nbsp;</td>
      <td> 
        <input type=hidden name=CategoryID value="<?=$_GET[CategoryID]?>">
        <input type=submit name=s1 value=Save class=sub>
      </td>
    </tr>
  </table>

</form>