<?php
include("../include/config.php");
include("../include/functions.php");
include("../include/simpleimage.php"); 
 validate_admin();
  $specialcategory=mysqli_real_escape_string($GLOBALS['conn'],$_POST['specialcategory']);
 
  if($_REQUEST['submitForm']=='yes'){
	    $Image= new SimpleImage();
  if($_FILES['photo']['size']>0 && $_FILES['photo']['error']==''){
  $img=time().substr($_FILES['photo']['name'],-5);
  move_uploaded_file($_FILES['photo']['tmp_name'],"../upload_images/banner/".$img);
  copy("../upload_images/banner/".$img,"../upload_images/banner/thumb/".$img);
  $Image->load("../upload_images/banner/thumb/".$img);	  
   $Image->resize(160,50);	  
  $Image->save("../upload_images/banner/thumb/".$img);	 
   }
    if($_FILES['icon']['size']>0 && $_FILES['icon']['error']==''){
					  $iconimg=time().substr($_FILES['icon']['name'],-5);
					  move_uploaded_file($_FILES['icon']['tmp_name'],"../upload_images/banner/".$iconimg);
				  } 
  if($_REQUEST['id']==''){
	  $obj->query("insert into $tbl_specialcategory set specialcategory='".ucfirst($specialcategory)."',cat_image='$img',cat_icon='$iconimg',status=1 ");
	  $_SESSION['sess_msg']='specialcategory added sucessfully';  
	  
       }else{ 
	   
	  $sql="update $tbl_specialcategory set specialcategory='".ucfirst($specialcategory)."' ";	  
	  if($img){
		$imageArr=$obj->query("select cat_image from $tbl_specialcategory where id='".$_REQUEST['id']."' "); 
		$resultImage=$obj->fetchNextObject($imageArr);
		@unlink("../upload_images/banner/".$resultImage->cat_image); 
		@unlink("../upload_images/banner/thumb/".$resultImage->cat_image);
		$sql.=" ,cat_image='$img' ";
	   }
	  if($iconimg){
		$imageArr=$obj->query("select cat_icon from $tbl_specialcategory where id='".$_REQUEST['id']."' "); 
		$resultImage=$obj->fetchNextObject($imageArr);
		@unlink("../upload_images/banner/".$resultImage->cat_icon); 
		@unlink("../upload_images/banner/thumb/".$resultImage->cat_icon);
		$sql.=" ,cat_icon='$iconimg' ";
	   }
	  $sql.=" where id=".$_REQUEST['id'];
	  $obj->query($sql);
	  $_SESSION['sess_msg']='Special category updated sucessfully';   
        }
   header("location:specialcategory-list.php");
   exit();
  }      
	   
	   
if($_REQUEST['id']!=''){
$sql=$obj->query("select * from $tbl_specialcategory 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.specialcategory.value==''){
alert("Please enter specialcategory");
obj.specialcategory.focus();
return false;
}
}
</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 Special Category 
					<span  style="float:right; padding-right:10px;">
					<input type="button" name="add" value="View Special Category"  class="button" onclick="location.href='specialcategory-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>Special Category:</strong></td>
									  <td align="left" class="paddBot11"><input name="specialcategory" type="text" id="specialcategory" size="36" value="<?php echo stripslashes($result->specialcategory);?>" <?php if($result->id=='8010'){?> readonly="readonly"<?php }?> /></td>
							  </tr>
									<tr>
                                      <td align="right" class="paddBot11 paddRt14"><strong>Banner Image(750px X 250px):</strong></td>
									  <td align="left" class="paddBot11"><input type="file" name="photo"  /><br/>
                                      <?php if(is_file("../upload_images/banner/".$result->cat_image)) {?>
                                      <img src="../upload_images/banner/thumb/<?php echo  $result->cat_image; ?>"  />
                                      <?php } ?></td>
							  </tr>
                              <tr>
                                      <td align="right" class="paddBot11 paddRt14"><strong>App Icon:</strong></td>
									  <td align="left" class="paddBot11"><input type="file" name="icon"  /><br/>
                                      <?php if(is_file("../upload_images/banner/".$result->cat_icon)) {?>
                                      <img src="../upload_images/banner/<?php echo  $result->cat_icon; ?>" width="20" height="20" />
                                      <?php } ?></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>


