<?php

include("../include/config.php");

include("../include/functions.php"); 

include("../include/simpleimage.php");

 validate_admin();

  $title=mysqli_real_escape_string($GLOBALS['conn'],$_POST['title']);

 

  if($_REQUEST['submitForm']=='yes'){

                    $Image=new SimpleImage();

					 if($_FILES['specialcatproduct']['size']>0 && $_FILES['specialcatproduct']['error']==''){

  $Image= new SimpleImage();

  $img=time().substr($_FILES['specialcatproduct']['name'],-5);

  move_uploaded_file($_FILES['specialcatproduct']['tmp_name'],"../upload_images/product/".$img);

  copy("../upload_images/product/".$img,"../upload_images/product/thumb/".$img);

  copy("../upload_images/product/".$img,"../upload_images/product/tiny/".$img);

  $Image->load("../upload_images/product/thumb/".$img);	  

  $Image->resize(124,85);	  

  $Image->save("../upload_images/product/thumb/".$img);	 

  $Image->load("../upload_images/product/tiny/".$img);	  

  $Image->resize(300,300);	  

  $Image->save("../upload_images/product/tiny/".$img);	 

  }

					

					

if($_REQUEST['id']==''){

$obj->query("insert into  $tbl_specialcatproduct set title='$title', specialcatproduct='$img',status=1,spcat_id=".$_REQUEST['spcat_id']);

$_SESSION['sess_msg']='Image  added sucessfully';

} else {

$sql="update $tbl_specialcatproduct set title='$title', status=1 , spcat_id='".$_REQUEST['spcat_id']."' ";

			if($img){

			$query=$obj->query("select * from $tbl_specialcatproduct where id=".$_REQUEST['id']);

			$resultImage=$obj->fetchNextObject($query);

			@unlink("../upload_images/product/".$resultImage->specialcatproduct);

			@unlink("../upload_images/product/thumb/".$resultImage->specialcatproduct);

			@unlink("../upload_images/product/tiny/".$resultImage->specialcatproduct);

			$sql.=" ,specialcatproduct='$img' ";

			}

			

  $sql.=" where id=".$_REQUEST['id'];

$obj->query($sql);

$_SESSION['sess_msg']='Image updated sucessfully';

}

header("location:specialcatproduct-list.php?spcat_id=".$_REQUEST['spcat_id']);

}      

	   

	   

if($_REQUEST['id']!=''){

$sql=$obj->query("select * from $tbl_specialcatproduct 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.title.value==''){

alert("Please enter title");

obj.title.focus();

return false;

}

<?php if($_REQUEST['id']==''){ ?>

if(obj.specialcatproduct.value==''){

alert("Please enter specialcatproduct");

obj.specialcatproduct.focus();

return false;

}

<?php } ?>

}

</script>

</head>

<body>

<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">

<?php include("header.php") ?>

<script type="text/javascript">

 function doAjaxSearchig(keyword){

	 $.ajax({

		 url:"ajax-product-listing-search.php",

		 data:{"q":keyword,spcat_id:"<?php echo $_REQUEST['spcat_id']; ?>"},

		 beforeSend:function(){

			  $("#loader").show();

			 },

		 success:function(data){

			 $("#search_result").html(data);

			   $("#loader").hide();  

			 }		 

		 })

	 

 }

</script>

<script type="text/javascript">

function addProduct(product_id,spcat_id,chk){

	  $.ajax({

		  url:"addSpecialProduct.php",

		  data:{product_id:product_id,spcat_id:spcat_id,chk:chk},

		  beforeSend:function(){

			

			  },

		  success:function(data){

		  $("#msg").html("Record added successfully").show().fadeOut();	

		

		  }		  

		  })

	}

</script>

<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: Add Products In <?php echo getFieldWhere('specialcategory','tbl_specialcategory','id',$_REQUEST['spcat_id']); ?><span  style="float:right; padding-right:10px;">

					<input type="button" name="add" value="Back to Special Category"  class="button" onclick="location.href='specialcategory-list.php'" />&nbsp;&nbsp;

					<input type="button" name="add" value="View Products"  class="button" onclick="location.href='specialcatproduct-list.php?spcat_id=<?php echo $_REQUEST['spcat_id']; ?>'" /></span></td>

						</tr>

						<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'];?>" />

						<input type="hidden" name="spcat_id" value="<?php echo $_REQUEST['spcat_id'];?>" />

						<tr>

							<td height="100" align="left" valign="top" bgcolor="#f3f4f6" class="bodr">

							<table width="100%" cellpadding="0" cellspacing="0">

									<tr>

										<td align="center" colspan="2" class="paddRt14 paddBot11">

										<font color="#FF0000"><strong id="msg"><?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>Search Product :</strong></td>

									  <td align="left" class="paddBot11"><input name="keyword" type="text"   value=""  style="width:300px;"  placeholder="Enter Product Name,Brand Name" onkeyup="return doAjaxSearchig(this.value)"/></td>

							  </tr>

							

									<tr>

										<td width="18%" align="right" class="paddBot11 paddRt14">&nbsp;</td>

										<td width="82%" align="left" class="paddBot11"><div  id="loader" style=" display:none;"><img src="images/gif-load.gif" /></div></td>

									</tr>

									<tr>

									  <td align="right" class="paddRt14 paddBot11">&nbsp;</td>

									  <td align="left" class="paddBot11" id="search_result" width="82%">&nbsp;</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">

                                        

                                        

											 </td>

									</tr>

								</table>

							</td>

						</tr>

						</form>

					</table>

				</td>

			</tr>

		</table>

	</td>

</tr>

<?php include('footer.php'); ?>

</table>

</body>

</html>

