<?php
session_start();
include("../include/config.php");
include("../include/functions.php"); 
 validate_admin();
	$maincategory=mysql_real_escape_string($_POST['maincategory']);
	$parent_id=mysql_real_escape_string($_REQUEST['parent_id']);
	$h1tag=mysql_real_escape_string($_POST['h1tag']);
	$meta_title=mysql_real_escape_string($_POST['meta_title']);
	$meta_keywords=mysql_real_escape_string($_POST['meta_keywords']);
	$meta_description=mysql_real_escape_string($_POST['meta_description']);
	$content=mysql_real_escape_string($_POST['content']);
  
  if($_REQUEST['submitForm']=='yes'){
  if($_REQUEST['id']==''){
	  $obj->query("insert into wholesale_maincategory set parent_id='$parent_id',maincategory='".ucfirst($maincategory)."',meta_title='$meta_title',meta_keywords='$meta_keywords',meta_description='$meta_description',content='$content',status=1 ");
	  $_SESSION['sess_msg']='Category added sucessfully';  
	  
       }else{ 
	   if($_REQUEST['parent_id']!=$_REQUEST['id']){
	    $obj->query("update wholesale_maincategory set parent_id='$parent_id',maincategory='".ucfirst($maincategory)."',h1='$h1tag',meta_title='$meta_title',meta_keywords='$meta_keywords',meta_description='$meta_description',content='$content' where id=".$_REQUEST['id']);
	    }
	  $_SESSION['sess_msg']='Category updated sucessfully';   
        }
   header("location:wholesale-maincategory-list.php");
   exit();
  }      
	   
	   
if($_REQUEST['id']!=''){
$sql=$obj->query("select * from wholesale_maincategory where id=".$_REQUEST['id']);
$result=$obj->fetchNextObject($sql);
}
	
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><?php echo SITE_TITLE; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="css/admin.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" language="javascript">
function validate(obj)
{

if(obj.maincategory.value==''){
alert("Please enter maincategory");
obj.maincategory.focus();
return false;
}
}
</script>
<script type="text/javascript" src="../include/ckeditor/ckeditor.js"></script>

</head>
<body>
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
<?php include("header.php") ?>
<tr>
	<td align="right" class="paddRtLt70" valign="top">
		<table width="99%" border="0" cellspacing="0" cellpadding="0">
			<tr>
			
				<td align="right" valign="top">
					<table width="100%" border="0" cellspacing="0" cellpadding="0">
						<tr>
							<td align="left" valign="middle" class="headingbg bodr text14">
					<em><img src="images/arrow2.gif" width="21" height="21" hspace="10" align="absmiddle" /></em>Admin: Update Category 
					<span  style="float:right; padding-right:10px;">
					<input type="button" name="add" value="View Category"  class="button" onclick="location.href='wholesale-maincategory-list.php'" /></span></td>
						</tr>
						
						<tr>
							<td height="100" align="left" valign="top" bgcolor="#f3f4f6" class="bodr">
                            <form name="frm" method="POST" enctype="multipart/form-data" action="" onsubmit="return validate(this)">
						<input type="hidden" name="submitForm" value="yes" />
						<input type="hidden" name="id" value="<?php echo $_REQUEST['id'];?>" />
							<table width="100%" cellpadding="0" cellspacing="0">
									<tr>
										<td align="center" colspan="2" class="paddRt14 paddBot11">
										<font color="#FF0000"><strong><?php echo $_SESSION['sess_msg']; $_SESSION['sess_msg']='';?></strong></font></td>
									</tr>
									<tr>
										<td width="18%" align="right" class="paddBot11 paddRt14">&nbsp;</td>
										<td width="82%" align="left" class="paddBot11"></td>
									</tr>
								<tr>
                                      <td align="right" class="paddBot11 paddRt14"><strong>Parent Category:</strong></td>
									  <td align="left" class="paddBot11"><select name="parent_id" style="width:240px;">
                                      <option value="">-Select Parent-</option>
                                      <?php $catArr=$obj->query("select * from wholesale_maincategory where status=1 order by parent_id");
									   while($resultP=$obj->fetchNextObject($catArr)){?>
										<option value="<?php echo stripslashes($resultP->id); ?>" <?php if($resultP->id==$result->parent_id){?>selected<?php }?>><?php echo getCategoryTree($resultP->id,$array=''); ?></option>   
										<?php } ?>                                      
                                      </select></td>
							  </tr>
									<tr>
                                      <td align="right" class="paddBot11 paddRt14"><strong>Category:</strong></td>
									  <td align="left" class="paddBot11"><input name="maincategory" type="text" id="maincategory" size="36" value="<?php echo stripslashes($result->maincategory);?>" /></td>
							  </tr>
							  <tr>
                                      <td align="right" class="paddBot11 paddRt14"><strong>H1 Tag:</strong></td>
									  <td align="left" class="paddBot11"><textarea name="h1tag" rows="3" cols="40"><?php echo stripslashes($result->h1); ?></textarea></td>
							  </tr>
									 <tr>
                                      <td align="right" class="paddBot11 paddRt14"><h2>Meta Tags</h2></td>
									  <td align="left" class="paddBot11">&nbsp;</td>
							       </tr>
                             <tr>
                                      <td align="right" class="paddBot11 paddRt14"><strong>Meta Title:</strong></td>
									  <td align="left" class="paddBot11"><textarea name="meta_title" rows="5" cols="40"><?php echo stripslashes($result->meta_title); ?></textarea></td>
							  </tr>
                              <tr>
                                      <td align="right" class="paddBot11 paddRt14"><strong>Meta Keywords:</strong></td>
									  <td align="left" class="paddBot11"><textarea name="meta_keywords" rows="5" cols="40"><?php echo stripslashes($result->meta_keywords); ?></textarea></td>
							  </tr>
                              <tr>
                                      <td align="right" class="paddBot11 paddRt14"><strong>Meta Description:</strong></td>
									  <td align="left" class="paddBot11"><textarea name="meta_description" rows="5" cols="40"><?php echo stripslashes($result->meta_description); ?></textarea></td>
							  </tr> 
							   <tr>
                                      <td align="right" class="paddBot11 paddRt14"><strong>Content:</strong></td>
									  <td align="left" class="paddBot11"><textarea name="content" class="ckeditor" id="content" rows="10" cols="40"><?php echo stripslashes($result->content); ?></textarea></td>
							  </tr> 
									
									<tr>
									  <td align="right" class="paddRt14 paddBot11">&nbsp;</td>
									  <td align="left" class="paddBot11">&nbsp;</td>
							  </tr>
									<tr>
										<td width="18%" align="right" class="paddRt14 paddBot11">&nbsp;</td>
										<td width="82%" align="left" class="paddBot11">
											<input type="submit" name="submit" value="Submit"  class="submit" border="0"/> 	                  		 &nbsp;&nbsp;
											<input name="Reset" type="reset" id="Reset" value="Reset" class="submit" border="0" /></td>
									</tr>
								</table></form>
							</td>
						</tr>
						
					</table>
				</td>
			</tr>
		</table>
	</td>
</tr>
<?php include('footer.php'); ?>
</table>
</body>
</html>


