MMCT TEAM
Server IP : 162.214.80.37  /  Your IP : 216.73.216.83
Web Server : Apache
System : Linux sh013.webhostingservices.com 4.19.286-203.ELK.el7.x86_64 #1 SMP Wed Jun 14 04:33:55 CDT 2023 x86_64
User : imyrqtmy ( 2189)
PHP Version : 8.2.18
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0755) :  /home2/imyrqtmy/public_html/agriba/admin/dataQuery/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home2/imyrqtmy/public_html/agriba/admin/dataQuery/process copy 2.php
<?php
error_reporting(E_ERROR | E_PARSE);
	require_once '../dbc.php';
	require_once 'common-function.php'; 
	$action = isset($_POST['action']) ? $_POST['action'] : ''; 
	switch($action)
	{
		case 'addBanner':
		 	addBanner($conn);		
			break;	
		case 'editBanner':
		 	editBanner($conn);
			break;
		case 'addBannerOffer':
		 	addBannerOffer($conn);		
			break;	
		case 'editBannerOffer':
		 	editBannerOffer($conn);
			break;
		case 'addCategory':
			addCategory($conn);
			break;
		case 'editCategory':
			editCategory($conn);
			break;
		case 'addSubSubCategory':
			addSubSubCategory($conn);
			break;
		case 'editSubSubCategory':
			editSubSubCategory($conn);
			break;
		case 'addBrand':
			addBrand($conn);
			break;
		case 'editBrand':
			editBrand($conn);
			break;	
		case 'addSubCategory':
			addSubCategory($conn);
			break;
		case 'editSubCategory':
			editSubCategory($conn);
			break;
		case 'addSize':
			addSize($conn);
			break;
		case 'editSize':
			editSize($conn);
			break;
		case 'addColor':
			addColor($conn);
			break;
		case 'editColor':
			editColor($conn);
			break;
		case 'addProduct':
		 	addProduct($conn);		
			break;	
		case 'editProduct':
		 	editProduct($conn);
			break;
		case 'addProductVarient':
		 	addProductVarient($conn);		
			break;	
		case 'editProductVarient':
		 	editProductVarient($conn);
			break;			
		case 'addGallery':
		 	addGallery($conn);		
			break;	
		case 'editGallery':
		 	editGallery($conn);
			break;
		case 'addBlog':
		 	addBlog($conn);		
			break;	
		case 'editBlog':
		 	editBlog($conn);
			break;	
			case 'addOffer':
		 	addOffer($conn);		
			break;	
		case 'editOffer':
		 	editOffer($conn);
			break;
		case 'addPromocode':
		 	addPromocode($conn);		
			break;	
		case 'editPromocode':
		 	editPromocode($conn);
			break;
		case 'addInvoice':
		 	addInvoice($conn);		
			break;	
		case 'editInvoice':
		 	editInvoice($conn);
			break;
		case 'addProductvideo':
		 	addProductvideo($conn);
			break;
		case 'addWalletamount':
			addWalletamount($conn);
			break;	
		default :	
	}
	$action2 = isset($_GET['action2']) ? $_GET['action2'] : '';
	switch($action2)
	{
		case 'deleteBanner':
		 	deleteBanner($conn);
			break;
		case 'deleteBannerOffer':
		 	deleteBannerOffer($conn);
			break;	
		case 'deleteCategory':
			deleteCategory($conn);
			break;
		case 'deleteBrand':
			deleteBrand($conn);
			break;
		case 'deleteSubCategory':
			deleteSubCategory($conn);
			break;
		case 'deleteSubSubCategory':
			deleteSubSubCategory($conn);
			break;
		case 'deleteSize':
			deleteSize($conn);
			break;
		case 'deleteColor':
			deleteColor($conn);
			break;	
		case 'deleteProduct':
		 	deleteProduct($conn);
			break;	
		case 'deleteProductVarient':
		 	deleteProductVarient($conn);
			break;	
		case 'deleteGallery':
		 	deleteGallery($conn);
			break;	
		case 'deleteBlog':
		 	deleteBlog($conn);
			break;	
		case 'deleteContactEnquiry':
		 	deleteContactEnquiry($conn);
			break;
		case 'deleteSuggestion':
		 	deleteSuggestion($conn);
			break;
		case 'deleteOrder':
		 	deleteOrder($conn);
			break;
		case 'deletePromocode':
		 	deletePromocode($conn);
			break;
		case 'deletePromoCodeUser':
		 	deletePromoCodeUser($conn);
			break;
		case 'DeleteReview':
		 	DeleteReview($conn);
			break;
		case 'ActiveReview':
		 	ActiveReview($conn);
			break;	
		case 'DeactiveReview':
		 	DeactiveReview($conn);
			break;
		case 'deleteInvoice':
		 	deleteInvoice($conn);
			break;
		case 'deleteVideo':
		 	deleteVideo($conn);
			break;
		case 'deleteClient':
			deleteClient($conn);	
			break;		
		default :	
	}


	
	/*--------Add Wallet Amount-----------------------------------------------*/

function addWalletamount($conn)
{  	
	$id	= mysqli_real_escape_string($conn,$_POST['txtuserid']); 
	$walletamount = mysqli_real_escape_string($conn,$_POST['txtwalletamount']);
	
	$sqladd = mysqli_query($conn,"update tbl_registration set 
	wallet_amount='$walletamount'
	 where id = '$id'") or die(mysqli_error($conn));
	if(mysqli_affected_rows($conn) > 0)
	{
		// echo "1";
		header('Location: ../user-list.php?m=4');
	}
	else
	{
		// echo "0";
		header('Location: ../user-list.php?m=5');
	}
} 	
   /*--------Add Wallet amount close-----------------------------------------------*/	

/*--------Add Client-----------------------------------------------*/

function addClient($conn)
{  	
	$name		= mysqli_real_escape_string($conn,$_POST['txtname']); 
	$order		 	    = mysqli_real_escape_string($conn,$_POST['txtorder']); 

	
	if(isset($_POST['txtstatus'])){$status=1;}else{$status=0;}

	$imagefleimagename1 			= $_FILES['image1fleimage']['name']; 
	$imagefleimagename1_tmp 		= $_FILES['image1fleimage']['tmp_name'];

	//---------------------condition--check dots------------------------ 
	$dots=substr_count($imagefleimagename1, '.');
	if($dots>1){header('Location: ../client.php?m=2&n=Rooms Image');exit(0);}
	//------------------------------------------------------------------
		//------now clear all condtion is good-------------if two image not avale-----
	function getExtension($str) {
		$i = strrpos($str,".");
         if (!$i) { return ""; } 

         $l = strlen($str) - $i;
         $ext = substr($str,$i+1,$l);
         return $ext;
	}
			$no = rand(1,999);
			$tno = rand(1,999);	
	///////--------------Upload Logo Image-----------------////////////


	global $clientPath;	
	global $clientPathThumb;	
	$ImagePath = "$clientPath/";
	$ImageThumbPath = "$clientPathThumb/";
	//================================ Image 1 ==============================	

		if(	$imagefleimagename1!=""){
			//check if image has 2 dot then exit program
			//$catfile = $imagefleimagename1;
			$image = $imagefleimagename1;
			$uploadedfile = $imagefleimagename1;
			$imagefleimagename1 = stripslashes($imagefleimagename1);
			$extension = getExtension($imagefleimagename1);
			$extension = strtolower($extension);
			/*-------------------------------*/
			/*---------------------------------*/
			if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") ) {
					header('Location: ../client.php?m=3');
					exit();
			}
			if($extension=="jpg" || $extension=="jpeg" ){
				$uploadedfile = $imagefleimagename1_tmp;
				$src = imagecreatefromjpeg($uploadedfile);
			}else if($extension=="png"){
				$uploadedfile = $imagefleimagename1_tmp;
				$src = imagecreatefrompng($uploadedfile);
			}else {
				$src = imagecreatefromgif($uploadedfile);
			}
			list($width,$height)=getimagesize($uploadedfile);
			 $setheight=400;
			 $ratio=0.0;
			 /*if($width>$setwidth){
				$ratio=$setwidth/$width;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				$newheight = $height ;
            	$newwidth = $width ;
			 }*/
			if($height>$setheight){
				$ratio=$setheight/$height;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				  $newheight = $height ;
            	  $newwidth = $width ;
			 }
			 $newfile1=$imagefleimagename1;

			move_uploaded_file($_FILES["image1fleimage"]['tmp_name'], "$ImagePath".$newfile1);
			
			
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight, $width,$height);
			$imageThumbName = $imagefleimagename1;
			$imagefleimagename = "$ImageThumbPath/". $imageThumbName;
				
			imagejpeg($tmp,$imagefleimagename,100);
			imagedestroy($src);
			imagedestroy($tmp);
			

	//////---------------End Image 1 end------------////////////
	}else{
	$newfile1="";
	 $imageThumbName="";
	}


	$sql="insert into  tbl_client(name,image,thumb,order_number,status) values('$name','$newfile1','$imageThumbName','$order','$status')";
	if(mysqli_query($conn,$sql) or die(mysqli_error($conn)))
	{
		header('Location: ../client-list.php?m=1');
		//echo "success";
	}
	else
	{
		header('Location: ../client-list.php?m=0');
		//echo "fail";
	}
} 	
   /*--------Add client close-----------------------------------------------*/	

 /*--------Delete client-----------------------------------------------*/	
   function deleteClient($conn)
{

	$id =isset($_GET['id'])? $_GET['id'] : "";
	//echo "value is ".$id;

			$del =	"delete from tbl_client where id = '$id' ";

			if(mysqli_query($conn,$del) or die(mysqli_error($conn)))
			{
				
				header('Location: ../client-list.php?&m=6');
			}
			else
			{
			
				header('Location: ../client-list.php?m=7');
			}
		
}
 /*--------Delete clientclose-----------------------------------------------*/

  /*--------Edit client close-----------------------------------------------*/

 function editClient($conn)
{

	$id				    = $_POST['txtid']; 
	$name		= mysqli_real_escape_string($conn,$_POST['txtname']); 
	$order		 	    = mysqli_real_escape_string($conn,$_POST['txtorder']); 

	
	if(isset($_POST['txtstatus'])){$status=1;}else{$status=0;} 

	$imagefleimagename1 			= $_FILES['image1fleimage']['name']; 
	$imagefleimagename1_tmp 		= $_FILES['image1fleimage']['tmp_name'];

	//------now clear all condtion is good-------------if two image not avale-----
function getExtension($str) {
	$i = strrpos($str,".");
	 if (!$i) { return ""; } 

	 $l = strlen($str) - $i;
	 $ext = substr($str,$i+1,$l);
	 return $ext;
}

// ------------- get all images  name  -------------------------
$sel = mysqli_query($conn,"select * from tbl_client where id = '$id' ");
$row = mysqli_fetch_assoc($sel);
$Un_OrginalImage1 	= $row['image'];	
$Un_Image1 			= $row['thumb'];

/*--------------insert record varible record------------*/
$InsertImage1 				= $row['image'];	
$InsertImagethumb1 			= $row['thumb'];

/*---------------------------*/
$flagImage1		=0;
$flagImage2		=0;
// ------------- get all images  name  -------------------------	
			$no = rand(1,999);
			$tno = rand(1,999);	
///////--------------Upload Logo Image-----------------////////////
 	global $clientPath;	
	global $clientPathThumb;	
	$ImagePath = "$clientPath/";
	$ImageThumbPath = "$clientPathThumb/";
//================================ Image 1 ==============================	
if(	$imagefleimagename1!=""){
	$flagImage1		=1;
	//check if image has 2 dot then exit program
			//$catfile = $imagefleimagename1;
			$image = $imagefleimagename1;
			$uploadedfile = $imagefleimagename1;
			$imagefleimagename1 = stripslashes($imagefleimagename1);
			$extension = getExtension($imagefleimagename1);
			$extension = strtolower($extension);
			/*-------------------------------*/
			/*---------------------------------*/
			if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png")) {
					header('Location: ../client-list.php?m=16&id='.$id);
					exit();
			}
			if($extension=="jpg" || $extension=="jpeg" ){
				$uploadedfile = $imagefleimagename1_tmp;
				$src = imagecreatefromjpeg($uploadedfile);
			}else if($extension=="png"){
				$uploadedfile = $imagefleimagename1_tmp;
				$src = imagecreatefrompng($uploadedfile);
			}else {
				$src = imagecreatefromgif($uploadedfile);
			}
			list($width,$height)=getimagesize($uploadedfile);
			 $setwidth=400;
			 $ratio=0.0;
			 if($width>$setwidth){
				$ratio=$setwidth/$width;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				$newheight = $height ;
            	$newwidth = $width ;
			 }
			/*if($height>$setheight){
				$ratio=$setheight/$height;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				  $newheight =350;
			 }*/
			 

			 $InsertImage1=$imagefleimagename1;

			move_uploaded_file($_FILES["image1fleimage"]['tmp_name'], "$ImagePath".$InsertImage1);
			
			
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight, $width,$height);
			$InsertImagethumb1 = $imagefleimagename1;
			$imagefleimagename = "$ImageThumbPath/". $InsertImagethumb1;
				
			imagejpeg($tmp,$imagefleimagename,100);
			imagedestroy($src);
			imagedestroy($tmp);
	//////---------------End Upload Brand Image------------////////////
}	



	$sqladd = mysqli_query($conn,"update tbl_client set 
	name='$name',
	image='$InsertImage1',
	thumb='$InsertImagethumb1',
	order_number='$order',
	status='$status'
	 where id = '$id'") or die(mysqli_error($conn));
	if(mysqli_affected_rows($conn) > 0)
	{
		// echo "1";
		header('Location: ../client-list.php?m=4');
	}
	else
	{
		// echo "0";
		header('Location: ../client-list.php?m=5');
	}

} 
 /*--------Edit Client close-----------------------------------------------*/		
	/*--------Delete video-----------------------------------------------*/	
   function deleteVideo($conn)
{

	$id =isset($_GET['id'])? $_GET['id'] : "";
	//echo "value is ".$id;
	$del =	"delete from tbl_varient_product_video where id = '$id' ";

			if(mysqli_query($conn,$del) or die(mysqli_error($conn)))
			{
				
				 header('Location: ../product-list.php?m=1');
			}
			else
			{
			
				header('Location: ../product-list.php?m=0');
			}		
}
 /*--------Delete video close-----------------------------------------------*/
	
	
	/*--------Add Product Video-----------------------------------------------*/

function addProductvideo($conn)
{  	
	$productid	= mysqli_real_escape_string($conn,$_POST['txtproductid']); 
	$productname = mysqli_real_escape_string($conn,$_POST['txtproductname']);
	$videolink = mysqli_real_escape_string($conn,$_POST['txtvideolink']);
	// $varientid = mysqli_real_escape_string($conn,$_POST['txtvarientid']);
	// $idd = mysqli_real_escape_string($conn,$_POST['txtidd']);
	
	$sql="insert into tbl_varient_product_video(product_id,video_link,product_name,status) values('$productid','$videolink','$productname','1')";
	if(mysqli_query($conn,$sql) or die(mysqli_error($conn)))
	{
		 header('Location: ../product-list.php?m=1');
		//echo "success";
	}
	else
	{
	header('Location: ../product-list.php?m=0');
		//echo "fail";
	}
} 	
   /*--------Add product video close-----------------------------------------------*/	
	/*--------Add  Sub Sub Category-----------------------------------------------*/

function addSubSubCategory($conn)
{  	
	$category		        = mysqli_real_escape_string($conn,$_POST['selcategory']); 
	$subcategory		        = mysqli_real_escape_string($conn,$_POST['selsubcategory']); 
	$subsubcategoryname		= mysqli_real_escape_string($conn,$_POST['txtname']); 
	$order		 	        = mysqli_real_escape_string($conn,$_POST['txtorder']); 
	$url	                = strtolower(str_replace(" ","-",$subsubcategoryname));
	$url	                = strtolower(str_replace("&","and",$url));

	if(isset($_POST['txtstatus'])){$status=1;}else{$status=0;}
		$imagefleimagename1 			= $_FILES['image1fleimage']['name']; 
	$imagefleimagename1_tmp 		= $_FILES['image1fleimage']['tmp_name'];

	//---------------------condition--check dots------------------------ 
	$dots=substr_count($imagefleimagename1, '.');
	if($dots>1){header('Location: ../sub-sub-category.php?m=2&n=Rooms Image');exit(0);}
	//------------------------------------------------------------------
		//------now clear all condtion is good-------------if two image not avale-----
	function getExtension($str) {
		$i = strrpos($str,".");
         if (!$i) { return ""; } 

         $l = strlen($str) - $i;
         $ext = substr($str,$i+1,$l);
         return $ext;
	}
			$no = rand(1,999);
			$tno = rand(1,999);	
	///////--------------Upload Logo Image-----------------////////////


	global $subsubcategoryPath;	
	global $subsubcategoryPathThumb;	
	$ImagePath = "$subsubcategoryPath/";
	$ImageThumbPath = "$subsubcategoryPathThumb/";
	//================================ Image 1 ==============================	

	if(	$imagefleimagename1!=""){
			//check if image has 2 dot then exit program
			//$catfile = $imagefleimagename1;
			$image = $imagefleimagename1;
			$uploadedfile = $imagefleimagename1;
			$imagefleimagename1 = stripslashes($imagefleimagename1);
			$extension = getExtension($imagefleimagename1);
			$extension = strtolower($extension);
			/*-------------------------------*/
			/*---------------------------------*/
			if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") ) {
					header('Location: ../sub-sub-category.php?m=3');
					exit();
			}
			if($extension=="jpg" || $extension=="jpeg" ){
				$uploadedfile = $imagefleimagename1_tmp;
				$src = imagecreatefromjpeg($uploadedfile);
			}else if($extension=="png"){
				$uploadedfile = $imagefleimagename1_tmp;
				$src = imagecreatefrompng($uploadedfile);
			}else {
				$src = imagecreatefromgif($uploadedfile);
			}
			list($width,$height)=getimagesize($uploadedfile);
			 $setheight=400;
			 $ratio=0.0;
			 /*if($width>$setwidth){
				$ratio=$setwidth/$width;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				$newheight = $height ;
            	$newwidth = $width ;
			 }*/
			if($height>$setheight){
				$ratio=$setheight/$height;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				  $newheight = $height ;
            	  $newwidth = $width ;
			 }
			 $newfile1=$imagefleimagename1;

			move_uploaded_file($_FILES["image1fleimage"]['tmp_name'], "$ImagePath".$newfile1);
			
			
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight, $width,$height);
			$imageThumbName = $imagefleimagename1;
			$imagefleimagename = "$ImageThumbPath/". $imageThumbName;
				
			imagejpeg($tmp,$imagefleimagename,100);
			imagedestroy($src);
			imagedestroy($tmp);
			

	//////---------------End Image 1 end------------////////////
	}else{
	$newfile1="";
	 $imageThumbName="";
	}
	$sql="insert into  tbl_sub_subcategory(category_id,sub_category_id,name,image,thumb,url,order_number,status) values('$category','$subcategory','$subsubcategoryname','$newfile1','$imageThumbName','$url','$order','$status')";
	if(mysqli_query($conn,$sql) or die(mysqli_error($conn)))
	{
		header('Location: ../sub-sub-category-list.php?m=1');
		//echo "success";
	}
	else
	{
		header('Location: ../sub-sub-category-list.php?m=0');
		//echo "fail";
	}
} 	
   /*--------Add Sub Sub Category close-----------------------------------------------*/	
    /*--------Delete Sub Sub Category -----------------------------------------------*/	
   function deleteSubSubCategory($conn)
{

	$id =isset($_GET['id'])? $_GET['id'] : "";
	//echo "value is ".$id;
	$sql="SELECT * FROM tbl_product where 	sub_sub_category_id='$id'";
     $run=mysqli_query($conn,$sql) or die(mysqli_error($conn));
      $row=mysqli_num_rows($run);
	if($row<1)
	{
	
			$del =	"delete from tbl_sub_subcategory where id = '$id' ";

			if(mysqli_query($conn,$del) or die(mysqli_error($conn)))
			{
				
				header('Location: ../sub-sub-category-list.php?&m=6');
			}
			else
			{
			
				header('Location: ../sub-sub-category-list.php?m=7');
			}
    }
    else
    {
    	header('Location: ../sub_sub-category-list.php?m=18');
    }
}
 /*--------Delete Sub Sub Category close-----------------------------------------------*/

 /*--------Edit Sub Category close-----------------------------------------------*/

 function editSubSubCategory($conn)
{

	$id				        = $_POST['txtid']; 
	$category		        = mysqli_real_escape_string($conn,$_POST['selcategory']); 
	$subcategory		        = mysqli_real_escape_string($conn,$_POST['selsubcategory']); 
	$subsubcategoryname		= mysqli_real_escape_string($conn,$_POST['txtname']);  
	$order		 	        = mysqli_real_escape_string($conn,$_POST['txtorder']); 
	$url	                = strtolower(str_replace(" ","-",$subsubcategoryname));
	$url	                = strtolower(str_replace("&","and",$url));

	if(isset($_POST['txtstatus'])){$status=1;}else{$status=0;}
	$imagefleimagename1 			= $_FILES['image1fleimage']['name']; 
	$imagefleimagename1_tmp 		= $_FILES['image1fleimage']['tmp_name'];
	//------now clear all condtion is good-------------if two image not avale-----
function getExtension($str) {
	$i = strrpos($str,".");
	 if (!$i) { return ""; } 

	 $l = strlen($str) - $i;
	 $ext = substr($str,$i+1,$l);
	 return $ext;
}

// ------------- get all images  name  -------------------------
$sel = mysqli_query($conn,"select * from tbl_sub_subcategory where id = '$id' ");
$row = mysqli_fetch_assoc($sel);
$Un_OrginalImage1 	= $row['image'];	
$Un_Image1 			= $row['thumb'];

/*--------------insert record varible record------------*/
$InsertImage1 				= $row['image'];	
$InsertImagethumb1 			= $row['thumb'];

/*---------------------------*/
$flagImage1		=0;
$flagImage2		=0;
// ------------- get all images  name  -------------------------	
			$no = rand(1,999);
			$tno = rand(1,999);	
///////--------------Upload Logo Image-----------------////////////
 	global $subsubcategoryPath;	
	global $subsubcategoryPathThumb;	
	$ImagePath = "$subsubcategoryPath/";
	$ImageThumbPath = "$subsubcategoryPathThumb/";
//================================ Image 1 ==============================	
if(	$imagefleimagename1!=""){
	$flagImage1		=1;
	//check if image has 2 dot then exit program
			//$catfile = $imagefleimagename1;
			$image = $imagefleimagename1;
			$uploadedfile = $imagefleimagename1;
			$imagefleimagename1 = stripslashes($imagefleimagename1);
			$extension = getExtension($imagefleimagename1);
			$extension = strtolower($extension);
			/*-------------------------------*/
			/*---------------------------------*/
			if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png")) {
					header('Location: ../sub-sub-category-list.php?m=16&id='.$id);
					exit();
			}
			if($extension=="jpg" || $extension=="jpeg" ){
				$uploadedfile = $imagefleimagename1_tmp;
				$src = imagecreatefromjpeg($uploadedfile);
			}else if($extension=="png"){
				$uploadedfile = $imagefleimagename1_tmp;
				$src = imagecreatefrompng($uploadedfile);
			}else {
				$src = imagecreatefromgif($uploadedfile);
			}
			list($width,$height)=getimagesize($uploadedfile);
			 $setwidth=400;
			 $ratio=0.0;
			 if($width>$setwidth){
				$ratio=$setwidth/$width;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				$newheight = $height ;
            	$newwidth = $width ;
			 }
			/*if($height>$setheight){
				$ratio=$setheight/$height;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				  $newheight =350;
			 }*/
			 

			 $InsertImage1=$imagefleimagename1;

			move_uploaded_file($_FILES["image1fleimage"]['tmp_name'], "$ImagePath".$InsertImage1);
			
			
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight, $width,$height);
			$InsertImagethumb1 = $imagefleimagename1;
			$imagefleimagename = "$ImageThumbPath/". $InsertImagethumb1;
				
			imagejpeg($tmp,$imagefleimagename,100);
			imagedestroy($src);
			imagedestroy($tmp);
	//////---------------End Upload Brand Image------------////////////
}	



	$sqladd = mysqli_query($conn,"update tbl_sub_subcategory set 
	category_id='$category',	
	sub_category_id='$subcategory',
	name='$subsubcategoryname',
	image='$InsertImage1',
	thumb='$InsertImagethumb1',
	url='$url',
	order_number='$order',
	status='$status'
	where id = '$id'") or die(mysqli_error($conn));
	if(mysqli_affected_rows($conn) > 0)
	{
		// echo "1";
		header('Location: ../sub-sub-category-list.php?m=4');
	}
	else
	{
		// echo "0";
		header('Location: ../sub-sub-category-list.php?m=5');
	}

} 
/*--------Edit Sub Sub Category close-----------------------------------------------*/
/*--------Add Brand-----------------------------------------------*/

function addBrand($conn)
{  	
	$categoryname		= mysqli_real_escape_string($conn,$_POST['txtname']); 
	
	if(isset($_POST['txtstatus'])){$status=1;}else{$status=0;}

	$imagefleimagename1 			= $_FILES['image1fleimage']['name']; 
	$imagefleimagename1_tmp 		= $_FILES['image1fleimage']['tmp_name'];

	//---------------------condition--check dots------------------------ 
	$dots=substr_count($imagefleimagename1, '.');
	if($dots>1){header('Location: ../brand.php?m=2&n=Rooms Image');exit(0);}
	//------------------------------------------------------------------
		//------now clear all condtion is good-------------if two image not avale-----
	function getExtension($str) {
		$i = strrpos($str,".");
         if (!$i) { return ""; } 

         $l = strlen($str) - $i;
         $ext = substr($str,$i+1,$l);
         return $ext;
	}
			$no = rand(1,999);
			$tno = rand(1,999);	
	///////--------------Upload Logo Image-----------------////////////


	global $brandPath;	
	global $brandPathThumb;	
	$ImagePath = "$brandPath/";
	$ImageThumbPath = "$brandPathThumb/";
	//================================ Image 1 ==============================	

	if(	$imagefleimagename1!=""){
			//check if image has 2 dot then exit program
			//$catfile = $imagefleimagename1;
			$image = $imagefleimagename1;
			$uploadedfile = $imagefleimagename1;
			$imagefleimagename1 = stripslashes($imagefleimagename1);
			$extension = getExtension($imagefleimagename1);
			$extension = strtolower($extension);
			/*-------------------------------*/
			/*---------------------------------*/
			if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") ) {
					header('Location: ../brand.php?m=3');
					exit();
			}
			if($extension=="jpg" || $extension=="jpeg" ){
				$uploadedfile = $imagefleimagename1_tmp;
				$src = imagecreatefromjpeg($uploadedfile);
			}else if($extension=="png"){
				$uploadedfile = $imagefleimagename1_tmp;
				$src = imagecreatefrompng($uploadedfile);
			}else {
				$src = imagecreatefromgif($uploadedfile);
			}
			list($width,$height)=getimagesize($uploadedfile);
			 $setheight=400;
			 $ratio=0.0;
			 /*if($width>$setwidth){
				$ratio=$setwidth/$width;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				$newheight = $height ;
            	$newwidth = $width ;
			 }*/
			if($height>$setheight){
				$ratio=$setheight/$height;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				  $newheight = $height ;
            	  $newwidth = $width ;
			 }
			 $newfile1=$imagefleimagename1;

			move_uploaded_file($_FILES["image1fleimage"]['tmp_name'], "$ImagePath".$newfile1);
			
			
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight, $width,$height);
			$imageThumbName = $imagefleimagename1;
			$imagefleimagename = "$ImageThumbPath/". $imageThumbName;
				
			imagejpeg($tmp,$imagefleimagename,100);
			imagedestroy($src);
			imagedestroy($tmp);
			

	//////---------------End Image 1 end------------////////////
	}else{
	$newfile1="";
	 $imageThumbName="";
	}


	$sql="insert into  tbl_brand(name,image,thumb,status) values('$categoryname','$newfile1','$imageThumbName','$status')";
	if(mysqli_query($conn,$sql) or die(mysqli_error($conn)))
	{
		header('Location: ../brand-list.php?m=1');
		//echo "success";
	}
	else
	{
		header('Location: ../brand-list.php?m=0');
		//echo "fail";
	}
} 	
   /*--------Add Brand close-----------------------------------------------*/	

 /*--------Delete Brand -----------------------------------------------*/	
   function deleteBrand($conn)
{

	$id =isset($_GET['id'])? $_GET['id'] : "";
	//echo "value is ".$id;
	
			$del =	"delete from tbl_brand where id = '$id' ";

			if(mysqli_query($conn,$del) or die(mysqli_error($conn)))
			{
				
				header('Location: ../brand-list.php?&m=6');
			}
			else
			{
			
				header('Location: ../brand-list.php?m=7');
			}

			
}
 /*--------Delete Brand close-----------------------------------------------*/

  /*--------Edit BRAND close-----------------------------------------------*/

 function editBrand($conn)
{

	$id				    = $_POST['txtid']; 
	$categoryname		= mysqli_real_escape_string($conn,$_POST['txtname']); 
	
	if(isset($_POST['txtstatus'])){$status=1;}else{$status=0;} 

	$imagefleimagename1 			= $_FILES['image1fleimage']['name']; 
	$imagefleimagename1_tmp 		= $_FILES['image1fleimage']['tmp_name'];

	//------now clear all condtion is good-------------if two image not avale-----
function getExtension($str) {
	$i = strrpos($str,".");
	 if (!$i) { return ""; } 

	 $l = strlen($str) - $i;
	 $ext = substr($str,$i+1,$l);
	 return $ext;
}

// ------------- get all images  name  -------------------------
$sel = mysqli_query($conn,"select * from tbl_brand where id = '$id' ");
$row = mysqli_fetch_assoc($sel);
$Un_OrginalImage1 	= $row['image'];	
$Un_Image1 			= $row['thumb'];

/*--------------insert record varible record------------*/
$InsertImage1 				= $row['image'];	
$InsertImagethumb1 			= $row['thumb'];

/*---------------------------*/
$flagImage1		=0;
$flagImage2		=0;
// ------------- get all images  name  -------------------------	
			$no = rand(1,999);
			$tno = rand(1,999);	
///////--------------Upload Logo Image-----------------////////////
 	global $brandPath;	
	global $brandPathThumb;	
	$ImagePath = "$brandPath/";
	$ImageThumbPath = "$brandPathThumb/";
//================================ Image 1 ==============================	
if(	$imagefleimagename1!=""){
	$flagImage1		=1;
	//check if image has 2 dot then exit program
			//$catfile = $imagefleimagename1;
			$image = $imagefleimagename1;
			$uploadedfile = $imagefleimagename1;
			$imagefleimagename1 = stripslashes($imagefleimagename1);
			$extension = getExtension($imagefleimagename1);
			$extension = strtolower($extension);
			/*-------------------------------*/
			/*---------------------------------*/
			if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png")) {
					header('Location: ../brand-list.php?m=16&id='.$id);
					exit();
			}
			if($extension=="jpg" || $extension=="jpeg" ){
				$uploadedfile = $imagefleimagename1_tmp;
				$src = imagecreatefromjpeg($uploadedfile);
			}else if($extension=="png"){
				$uploadedfile = $imagefleimagename1_tmp;
				$src = imagecreatefrompng($uploadedfile);
			}else {
				$src = imagecreatefromgif($uploadedfile);
			}
			list($width,$height)=getimagesize($uploadedfile);
			 $setwidth=400;
			 $ratio=0.0;
			 if($width>$setwidth){
				$ratio=$setwidth/$width;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				$newheight = $height ;
            	$newwidth = $width ;
			 }
			/*if($height>$setheight){
				$ratio=$setheight/$height;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				  $newheight =350;
			 }*/
			 

			 $InsertImage1=$imagefleimagename1;

			move_uploaded_file($_FILES["image1fleimage"]['tmp_name'], "$ImagePath".$InsertImage1);
			
			
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight, $width,$height);
			$InsertImagethumb1 = $imagefleimagename1;
			$imagefleimagename = "$ImageThumbPath/". $InsertImagethumb1;
				
			imagejpeg($tmp,$imagefleimagename,100);
			imagedestroy($src);
			imagedestroy($tmp);
	//////---------------End Upload Brand Image------------////////////
}	



	$sqladd = mysqli_query($conn,"update tbl_brand set 
	name='$categoryname',
	image='$InsertImage1',
	thumb='$InsertImagethumb1',
	status='$status'
	 where id = '$id'") or die(mysqli_error($conn));
	if(mysqli_affected_rows($conn) > 0)
	{
		// echo "1";
		header('Location: ../brand-list.php?m=4');
	}
	else
	{
		// echo "0";
		header('Location: ../brand-list.php?m=5');
	}

} 
 /*--------Edit Brand close-----------------------------------------------*/
	/*--------Add  Size-----------------------------------------------*/

function addSize($conn)
{  	

	$name		     = mysqli_real_escape_string($conn,$_POST['txtname']); 

	if(isset($_POST['txtstatus'])){$status=1;}else{$status=0;}

	$sql="insert into  tbl_size(name,status) values('$name','$status')";

	if(mysqli_query($conn,$sql) or die(mysqli_error($conn)))
	{
		header('Location: ../size-list.php?m=1');
		//echo "success";
	}
	else
	{
		header('Location: ../size-list.php?m=0');
		//echo "fail";
	}
} 	
   /*--------Add Size close-----------------------------------------------*/	
    /*--------Delete Size -----------------------------------------------*/	
   function deleteSize($conn)
{

	$id =isset($_GET['id'])? $_GET['id'] : "";
	//echo "value is ".$id;

			$del =	"delete from tbl_size where id = '$id' ";

			if(mysqli_query($conn,$del) or die(mysqli_error($conn)))
			{
				
				header('Location: ../size-list.php?&m=6');
			}
			else
			{
			
				header('Location: ../size-list.php?m=7');
			}
  
}
 /*--------Delete Size close-----------------------------------------------*/

 /*--------Edit Size close-----------------------------------------------*/

 function editSize($conn)
{

	$id				        = $_POST['txtid']; 
	$name		= mysqli_real_escape_string($conn,$_POST['txtname']);  
	

	if(isset($_POST['txtstatus'])){$status=1;}else{$status=0;}
	
	$sqladd = mysqli_query($conn,"update tbl_size set 
	name='$name',
	status='$status'
	where id = '$id'") or die(mysqli_error($conn));
	if(mysqli_affected_rows($conn) > 0)
	{
		// echo "1";
		header('Location: ../size-list.php?m=4');
	}
	else
	{
		// echo "0";
		header('Location: ../size-list.php?m=5');
	}

} 
/*--------Edit Size close-----------------------------------------------*/

		/*--------Add Banner Offer-----------------------------------------------*/

function addBannerOffer($conn)
{  	
	$name		= mysqli_real_escape_string($conn,$_POST['txtname']);
	$order		 	    = mysqli_real_escape_string($conn,$_POST['txtorder']);  

	
	if(isset($_POST['txtstatus'])){$status=1;}else{$status=0;}

	$imagefleimagename1 			= $_FILES['image1fleimage']['name']; 
	$imagefleimagename1_tmp 		= $_FILES['image1fleimage']['tmp_name'];

	//---------------------condition--check dots------------------------ 
	$dots=substr_count($imagefleimagename1, '.');
	if($dots>1){header('Location: ../banneroffer.php?m=2&n=Rooms Image');exit(0);}
	//------------------------------------------------------------------
		//------now clear all condtion is good-------------if two image not avale-----
	function getExtension($str) {
		$i = strrpos($str,".");
         if (!$i) { return ""; } 

         $l = strlen($str) - $i;
         $ext = substr($str,$i+1,$l);
         return $ext;
	}
			$no = rand(1,999);
			$tno = rand(1,999);	
	///////--------------Upload Logo Image-----------------////////////


	global $bannerofferPath;	
	global $bannerofferPathThumb;	
	$ImagePath = "$bannerofferPath/";
	$ImageThumbPath = "$bannerofferPathThumb/";
	//================================ Image 1 ==============================	

	if(	$imagefleimagename1!=""){
			//check if image has 2 dot then exit program
			//$catfile = $imagefleimagename1;
			$image = $imagefleimagename1;
			$uploadedfile = $imagefleimagename1;
			$imagefleimagename1 = stripslashes($imagefleimagename1);
			$extension = getExtension($imagefleimagename1);
			$extension = strtolower($extension);
			/*-------------------------------*/
			/*---------------------------------*/
			if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") ) {
					header('Location: ../banneroffer.php?m=3');
					exit();
			}
			if($extension=="jpg" || $extension=="jpeg" ){
				$uploadedfile = $imagefleimagename1_tmp;
				$src = imagecreatefromjpeg($uploadedfile);
			}else if($extension=="png"){
				$uploadedfile = $imagefleimagename1_tmp;
				$src = imagecreatefrompng($uploadedfile);
			}else {
				$src = imagecreatefromgif($uploadedfile);
			}
			list($width,$height)=getimagesize($uploadedfile);
			 $setheight=400;
			 $ratio=0.0;
			 /*if($width>$setwidth){
				$ratio=$setwidth/$width;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				$newheight = $height ;
            	$newwidth = $width ;
			 }*/
			if($height>$setheight){
				$ratio=$setheight/$height;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				  $newheight = $height ;
            	  $newwidth = $width ;
			 }
			 $newfile1=$imagefleimagename1;

			move_uploaded_file($_FILES["image1fleimage"]['tmp_name'], "$ImagePath".$newfile1);
			
			
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight, $width,$height);
			$imageThumbName = $imagefleimagename1;
			$imagefleimagename = "$ImageThumbPath/". $imageThumbName;
				
			imagejpeg($tmp,$imagefleimagename,100);
			imagedestroy($src);
			imagedestroy($tmp);
			

	//////---------------End Image 1 end------------////////////
	}else{
	$newfile1="";
	 $imageThumbName="";
	}


	$sql="insert into  tbl_banneroffer(name,order_number,image,thumb,status) values('$name','$order','$newfile1','$imageThumbName','$status')";
	if(mysqli_query($conn,$sql) or die(mysqli_error($conn)))
	{
		header('Location: ../banneroffer-list.php?m=1');
		//echo "success";
	}
	else
	{
		header('Location: ../banneroffer-list.php?m=0');
		//echo "fail";
	}
} 	
   /*--------Add Banner offer close-----------------------------------------------*/

   /*--------Delete Banner offer -----------------------------------------------*/	
   function deleteBannerOffer($conn)
{
	$id =isset($_GET['id'])? $_GET['id'] : "";
	//echo "value is ".$id;
	
	$del =	"delete from tbl_banneroffer where id = '$id' ";

	if(mysqli_query($conn,$del) or die(mysqli_error($conn)))
	{
			
		header('Location: ../banneroffer-list.php?&m=6');
	}
	else
	{
	
		header('Location: ../banneroffer-list.php?m=7');
	}

}
 /*--------Delete Banner Offer close-----------------------------------------------*/
  /*--------Edit Banner  Offerclose-----------------------------------------------*/

 function editBannerOffer($conn)
{

	$id				    = $_POST['txtid']; 
	
	$name		= mysqli_real_escape_string($conn,$_POST['txtname']);
	$order		 	    = mysqli_real_escape_string($conn,$_POST['txtorder']);  

	
	if(isset($_POST['txtstatus'])){$status=1;}else{$status=0;} 

	$imagefleimagename1 			= $_FILES['image1fleimage']['name']; 
	$imagefleimagename1_tmp 		= $_FILES['image1fleimage']['tmp_name'];

	//------now clear all condtion is good-------------if two image not avale-----
function getExtension($str) {
	$i = strrpos($str,".");
	 if (!$i) { return ""; } 

	 $l = strlen($str) - $i;
	 $ext = substr($str,$i+1,$l);
	 return $ext;
}

// ------------- get all images  name  -------------------------
$sel = mysqli_query($conn,"select * from tbl_banneroffer where id = '$id' ");
$row = mysqli_fetch_assoc($sel);
$Un_OrginalImage1 	= $row['image'];	
$Un_Image1 			= $row['thumb'];

/*--------------insert record varible record------------*/
$InsertImage1 				= $row['image'];	
$InsertImagethumb1 			= $row['thumb'];

/*---------------------------*/
$flagImage1		=0;
$flagImage2		=0;
// ------------- get all images  name  -------------------------	
			$no = rand(1,999);
			$tno = rand(1,999);	
///////--------------Upload Logo Image-----------------////////////
 	global $bannerofferPath;	
	global $bannerofferPathThumb;	
	$ImagePath = "$bannerofferPath/";
	$ImageThumbPath = "$bannerofferPathThumb/";
//================================ Image 1 ==============================	
if(	$imagefleimagename1!=""){
	$flagImage1		=1;
	//check if image has 2 dot then exit program
			//$catfile = $imagefleimagename1;
			$image = $imagefleimagename1;
			$uploadedfile = $imagefleimagename1;
			$imagefleimagename1 = stripslashes($imagefleimagename1);
			$extension = getExtension($imagefleimagename1);
			$extension = strtolower($extension);
			/*-------------------------------*/
			/*---------------------------------*/
			if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png")) {
					header('Location: ../banneroffer-list.php?m=16&id='.$id);
					exit();
			}
			if($extension=="jpg" || $extension=="jpeg" ){
				$uploadedfile = $imagefleimagename1_tmp;
				$src = imagecreatefromjpeg($uploadedfile);
			}else if($extension=="png"){
				$uploadedfile = $imagefleimagename1_tmp;
				$src = imagecreatefrompng($uploadedfile);
			}else {
				$src = imagecreatefromgif($uploadedfile);
			}
			list($width,$height)=getimagesize($uploadedfile);
			 $setwidth=400;
			 $ratio=0.0;
			 if($width>$setwidth){
				$ratio=$setwidth/$width;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				$newheight = $height ;
            	$newwidth = $width ;
			 }
			/*if($height>$setheight){
				$ratio=$setheight/$height;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				  $newheight =350;
			 }*/
			 

			 $InsertImage1=$imagefleimagename1;

			move_uploaded_file($_FILES["image1fleimage"]['tmp_name'], "$ImagePath".$InsertImage1);
			
			
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight, $width,$height);
			$InsertImagethumb1 = $imagefleimagename1;
			$imagefleimagename = "$ImageThumbPath/". $InsertImagethumb1;
				
			imagejpeg($tmp,$imagefleimagename,100);
			imagedestroy($src);
			imagedestroy($tmp);
	//////---------------End Upload Brand Image------------////////////
}	



	$sqladd = mysqli_query($conn,"update tbl_banneroffer set 
	name='$name',
	order_number='$order',
	image='$InsertImage1',
	thumb='$InsertImagethumb1',
	status='$status'
	 where id = '$id'") or die(mysqli_error($conn));
	if(mysqli_affected_rows($conn) > 0)
	{
		// echo "1";
		header('Location: ../banneroffer-list.php?m=4');
	}
	else
	{
		// echo "0";
		header('Location: ../banneroffer-list.php?m=5');
	}

} 
 /*--------Edit banner Offer close-----------------------------------------------*/	
/*--------Add Banner-----------------------------------------------*/

function addBanner($conn)
{  	
	$name		= mysqli_real_escape_string($conn,$_POST['txtname']);
	$order		 	    = mysqli_real_escape_string($conn,$_POST['txtorder']);  

	
	if(isset($_POST['txtstatus'])){$status=1;}else{$status=0;}

	$imagefleimagename1 			= $_FILES['image1fleimage']['name']; 
	$imagefleimagename1_tmp 		= $_FILES['image1fleimage']['tmp_name'];

	//---------------------condition--check dots------------------------ 
	$dots=substr_count($imagefleimagename1, '.');
	if($dots>1){header('Location: ../banner.php?m=2&n=Rooms Image');exit(0);}
	//------------------------------------------------------------------
		//------now clear all condtion is good-------------if two image not avale-----
	function getExtension($str) {
		$i = strrpos($str,".");
         if (!$i) { return ""; } 

         $l = strlen($str) - $i;
         $ext = substr($str,$i+1,$l);
         return $ext;
	}
			$no = rand(1,999);
			$tno = rand(1,999);	
	///////--------------Upload Logo Image-----------------////////////


	global $bannerPath;	
	global $bannerPathThumb;	
	$ImagePath = "$bannerPath/";
	$ImageThumbPath = "$bannerPathThumb/";
	//================================ Image 1 ==============================	

	if(	$imagefleimagename1!=""){
			//check if image has 2 dot then exit program
			//$catfile = $imagefleimagename1;
			$image = $imagefleimagename1;
			$uploadedfile = $imagefleimagename1;
			$imagefleimagename1 = stripslashes($imagefleimagename1);
			$extension = getExtension($imagefleimagename1);
			$extension = strtolower($extension);
			/*-------------------------------*/
			/*---------------------------------*/
			if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") ) {
					header('Location: ../banner.php?m=3');
					exit();
			}
			if($extension=="jpg" || $extension=="jpeg" ){
				$uploadedfile = $imagefleimagename1_tmp;
				$src = imagecreatefromjpeg($uploadedfile);
			}else if($extension=="png"){
				$uploadedfile = $imagefleimagename1_tmp;
				$src = imagecreatefrompng($uploadedfile);
			}else {
				$src = imagecreatefromgif($uploadedfile);
			}
			list($width,$height)=getimagesize($uploadedfile);
			 $setheight=400;
			 $ratio=0.0;
			 /*if($width>$setwidth){
				$ratio=$setwidth/$width;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				$newheight = $height ;
            	$newwidth = $width ;
			 }*/
			if($height>$setheight){
				$ratio=$setheight/$height;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				  $newheight = $height ;
            	  $newwidth = $width ;
			 }
			 $newfile1=$imagefleimagename1;

			move_uploaded_file($_FILES["image1fleimage"]['tmp_name'], "$ImagePath".$newfile1);
			
			
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight, $width,$height);
			$imageThumbName = $imagefleimagename1;
			$imagefleimagename = "$ImageThumbPath/". $imageThumbName;
				
			imagejpeg($tmp,$imagefleimagename,100);
			imagedestroy($src);
			imagedestroy($tmp);
			

	//////---------------End Image 1 end------------////////////
	}else{
	$newfile1="";
	 $imageThumbName="";
	}


	$sql="insert into  tbl_banner(name,order_number,image,thumb,status) values('$name','$order','$newfile1','$imageThumbName','$status')";
	if(mysqli_query($conn,$sql) or die(mysqli_error($conn)))
	{
		header('Location: ../banner-list.php?m=1');
		//echo "success";
	}
	else
	{
		header('Location: ../banner-list.php?m=0');
		//echo "fail";
	}
} 	
   /*--------Add Banner close-----------------------------------------------*/

   /*--------Delete Banner -----------------------------------------------*/	
   function deleteBanner($conn)
{
	$id =isset($_GET['id'])? $_GET['id'] : "";
	//echo "value is ".$id;
	
	$del =	"delete from tbl_banner where id = '$id' ";

	if(mysqli_query($conn,$del) or die(mysqli_error($conn)))
	{
			
		header('Location: ../banner-list.php?&m=6');
	}
	else
	{
	
		header('Location: ../banner-list.php?m=7');
	}

}
 /*--------Delete Banner close-----------------------------------------------*/
  /*--------Edit Banner close-----------------------------------------------*/

 function editBanner($conn)
{

	$id				    = $_POST['txtid']; 
	
	$name		= mysqli_real_escape_string($conn,$_POST['txtname']);
	$order		 	    = mysqli_real_escape_string($conn,$_POST['txtorder']);  

	
	if(isset($_POST['txtstatus'])){$status=1;}else{$status=0;} 

	$imagefleimagename1 			= $_FILES['image1fleimage']['name']; 
	$imagefleimagename1_tmp 		= $_FILES['image1fleimage']['tmp_name'];

	//------now clear all condtion is good-------------if two image not avale-----
function getExtension($str) {
	$i = strrpos($str,".");
	 if (!$i) { return ""; } 

	 $l = strlen($str) - $i;
	 $ext = substr($str,$i+1,$l);
	 return $ext;
}

// ------------- get all images  name  -------------------------
$sel = mysqli_query($conn,"select * from tbl_banner where id = '$id' ");
$row = mysqli_fetch_assoc($sel);
$Un_OrginalImage1 	= $row['image'];	
$Un_Image1 			= $row['thumb'];

/*--------------insert record varible record------------*/
$InsertImage1 				= $row['image'];	
$InsertImagethumb1 			= $row['thumb'];

/*---------------------------*/
$flagImage1		=0;
$flagImage2		=0;
// ------------- get all images  name  -------------------------	
			$no = rand(1,999);
			$tno = rand(1,999);	
///////--------------Upload Logo Image-----------------////////////
 	global $bannerPath;	
	global $bannerPathThumb;	
	$ImagePath = "$bannerPath/";
	$ImageThumbPath = "$bannerPathThumb/";
//================================ Image 1 ==============================	
if(	$imagefleimagename1!=""){
	$flagImage1		=1;
	//check if image has 2 dot then exit program
			//$catfile = $imagefleimagename1;
			$image = $imagefleimagename1;
			$uploadedfile = $imagefleimagename1;
			$imagefleimagename1 = stripslashes($imagefleimagename1);
			$extension = getExtension($imagefleimagename1);
			$extension = strtolower($extension);
			/*-------------------------------*/
			/*---------------------------------*/
			if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png")) {
					header('Location: ../banner-list.php?m=16&id='.$id);
					exit();
			}
			if($extension=="jpg" || $extension=="jpeg" ){
				$uploadedfile = $imagefleimagename1_tmp;
				$src = imagecreatefromjpeg($uploadedfile);
			}else if($extension=="png"){
				$uploadedfile = $imagefleimagename1_tmp;
				$src = imagecreatefrompng($uploadedfile);
			}else {
				$src = imagecreatefromgif($uploadedfile);
			}
			list($width,$height)=getimagesize($uploadedfile);
			 $setwidth=400;
			 $ratio=0.0;
			 if($width>$setwidth){
				$ratio=$setwidth/$width;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				$newheight = $height ;
            	$newwidth = $width ;
			 }
			/*if($height>$setheight){
				$ratio=$setheight/$height;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				  $newheight =350;
			 }*/
			 

			 $InsertImage1=$imagefleimagename1;

			move_uploaded_file($_FILES["image1fleimage"]['tmp_name'], "$ImagePath".$InsertImage1);
			
			
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight, $width,$height);
			$InsertImagethumb1 = $imagefleimagename1;
			$imagefleimagename = "$ImageThumbPath/". $InsertImagethumb1;
				
			imagejpeg($tmp,$imagefleimagename,100);
			imagedestroy($src);
			imagedestroy($tmp);
	//////---------------End Upload Brand Image------------////////////
}	



	$sqladd = mysqli_query($conn,"update tbl_banner set 
	name='$name',
	order_number='$order',
	image='$InsertImage1',
	thumb='$InsertImagethumb1',
	status='$status'
	 where id = '$id'") or die(mysqli_error($conn));
	if(mysqli_affected_rows($conn) > 0)
	{
		// echo "1";
		header('Location: ../banner-list.php?m=4');
	}
	else
	{
		// echo "0";
		header('Location: ../banner-list.php?m=5');
	}

} 
 /*--------Edit banner close-----------------------------------------------*/
	/*--------Add Category-----------------------------------------------*/

function addCategory($conn)
{  	
	$categoryname		= mysqli_real_escape_string($conn,$_POST['txtname']); 
	$order		 	    = mysqli_real_escape_string($conn,$_POST['txtorder']); 
	$url	            = strtolower(str_replace(" ","-",$categoryname));
	$url	            = strtolower(str_replace("&","and",$url));
	
	if(isset($_POST['txtstatus'])){$status=1;}else{$status=0;}

	$imagefleimagename1 			= $_FILES['image1fleimage']['name']; 
	$imagefleimagename1_tmp 		= $_FILES['image1fleimage']['tmp_name'];

	//---------------------condition--check dots------------------------ 
	$dots=substr_count($imagefleimagename1, '.');
	if($dots>1){header('Location: ../category.php?m=2&n=Rooms Image');exit(0);}
	//------------------------------------------------------------------
		//------now clear all condtion is good-------------if two image not avale-----
	function getExtension($str) {
		$i = strrpos($str,".");
         if (!$i) { return ""; } 

         $l = strlen($str) - $i;
         $ext = substr($str,$i+1,$l);
         return $ext;
	}
			$no = rand(1,999);
			$tno = rand(1,999);	
	///////--------------Upload Logo Image-----------------////////////


	global $categoryPath;	
	global $categoryPathThumb;	
	$ImagePath = "$categoryPath/";
	$ImageThumbPath = "$categoryPathThumb/";
	//================================ Image 1 ==============================	

	if(	$imagefleimagename1!=""){
			//check if image has 2 dot then exit program
			//$catfile = $imagefleimagename1;
			$image = $imagefleimagename1;
			$uploadedfile = $imagefleimagename1;
			$imagefleimagename1 = stripslashes($imagefleimagename1);
			$extension = getExtension($imagefleimagename1);
			$extension = strtolower($extension);
			/*-------------------------------*/
			/*---------------------------------*/
			if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") ) {
					header('Location: ../category.php?m=3');
					exit();
			}
			if($extension=="jpg" || $extension=="jpeg" ){
				$uploadedfile = $imagefleimagename1_tmp;
				$src = imagecreatefromjpeg($uploadedfile);
			}else if($extension=="png"){
				$uploadedfile = $imagefleimagename1_tmp;
				$src = imagecreatefrompng($uploadedfile);
			}else {
				$src = imagecreatefromgif($uploadedfile);
			}
			list($width,$height)=getimagesize($uploadedfile);
			 $setheight=400;
			 $ratio=0.0;
			 /*if($width>$setwidth){
				$ratio=$setwidth/$width;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				$newheight = $height ;
            	$newwidth = $width ;
			 }*/
			if($height>$setheight){
				$ratio=$setheight/$height;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				  $newheight = $height ;
            	  $newwidth = $width ;
			 }
			 $newfile1=$imagefleimagename1;

			move_uploaded_file($_FILES["image1fleimage"]['tmp_name'], "$ImagePath".$newfile1);
			
			
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight, $width,$height);
			$imageThumbName = $imagefleimagename1;
			$imagefleimagename = "../../media/category/thumb/". $imageThumbName;
				
			imagejpeg($tmp,$imagefleimagename,100);
			imagedestroy($src);
			imagedestroy($tmp);
			

	//////---------------End Image 1 end------------////////////
	}else{
	$newfile1="";
	 $imageThumbName="";
	}


	$sql="insert into  tbl_category(name,image,thumb,url,order_number,status) values('$categoryname','$newfile1','$imageThumbName','$url','$order','$status')";
	if(mysqli_query($conn,$sql) or die(mysqli_error($conn)))
	{
		header('Location: ../category-list.php?m=1');
		//echo "success";
	}
	else
	{
		header('Location: ../category-list.php?m=0');
		//echo "fail";
	}
} 	
   /*--------Add Category close-----------------------------------------------*/	

 /*--------Delete Category -----------------------------------------------*/	
   function deleteCategory($conn)
{

	$id =isset($_GET['id'])? $_GET['id'] : "";
	//echo "value is ".$id;
	$sql="SELECT * FROM tbl_subcategory where category_id='$id'";
     $run=mysqli_query($conn,$sql) or die(mysqli_error($conn));
      $row=mysqli_num_rows($run);
	if($row<1)
	{
			$del =	"delete from tbl_category where id = '$id' ";

			if(mysqli_query($conn,$del) or die(mysqli_error($conn)))
			{
				
				header('Location: ../category-list.php?&m=6');
			}
			else
			{
			
				header('Location: ../category-list.php?m=7');
			}
	}
	else
	{
		header('Location: ../category-list.php?m=17');
	}		
}
 /*--------Delete Category close-----------------------------------------------*/

  /*--------Edit Category close-----------------------------------------------*/

 function editCategory($conn)
{

	$id				    = $_POST['txtid']; 
	$categoryname		= mysqli_real_escape_string($conn,$_POST['txtname']); 
	$order		 	    = mysqli_real_escape_string($conn,$_POST['txtorder']); 
	$url	            = strtolower(str_replace(" ","-",$categoryname));
	$url	            = strtolower(str_replace("&","and",$url));
	
	if(isset($_POST['txtstatus'])){$status=1;}else{$status=0;} 

	$imagefleimagename1 			= $_FILES['image1fleimage']['name']; 
	$imagefleimagename1_tmp 		= $_FILES['image1fleimage']['tmp_name'];

	//------now clear all condtion is good-------------if two image not avale-----
function getExtension($str) {
	$i = strrpos($str,".");
	 if (!$i) { return ""; } 

	 $l = strlen($str) - $i;
	 $ext = substr($str,$i+1,$l);
	 return $ext;
}

// ------------- get all images  name  -------------------------
$sel = mysqli_query($conn,"select * from tbl_category where id = '$id' ");
$row = mysqli_fetch_assoc($sel);
$Un_OrginalImage1 	= $row['image'];	
$Un_Image1 			= $row['thumb'];

/*--------------insert record varible record------------*/
$InsertImage1 				= $row['image'];	
$InsertImagethumb1 			= $row['thumb'];

/*---------------------------*/
$flagImage1		=0;
$flagImage2		=0;
// ------------- get all images  name  -------------------------	
			$no = rand(1,999);
			$tno = rand(1,999);	
///////--------------Upload Logo Image-----------------////////////
 	global $categoryPath;	
	global $categoryPathThumb;	
	$ImagePath = "$categoryPath/";
	$ImageThumbPath = "$categoryPathThumb/";
//================================ Image 1 ==============================	
if(	$imagefleimagename1!=""){
	$flagImage1		=1;
	//check if image has 2 dot then exit program
			//$catfile = $imagefleimagename1;
			$image = $imagefleimagename1;
			$uploadedfile = $imagefleimagename1;
			$imagefleimagename1 = stripslashes($imagefleimagename1);
			$extension = getExtension($imagefleimagename1);
			$extension = strtolower($extension);
			/*-------------------------------*/
			/*---------------------------------*/
			if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png")) {
					header('Location: ../category-list.php?m=16&id='.$id);
					exit();
			}
			if($extension=="jpg" || $extension=="jpeg" ){
				$uploadedfile = $imagefleimagename1_tmp;
				$src = imagecreatefromjpeg($uploadedfile);
			}else if($extension=="png"){
				$uploadedfile = $imagefleimagename1_tmp;
				$src = imagecreatefrompng($uploadedfile);
			}else {
				$src = imagecreatefromgif($uploadedfile);
			}
			list($width,$height)=getimagesize($uploadedfile);
			 $setwidth=400;
			 $ratio=0.0;
			 if($width>$setwidth){
				$ratio=$setwidth/$width;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				$newheight = $height ;
            	$newwidth = $width ;
			 }
			/*if($height>$setheight){
				$ratio=$setheight/$height;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				  $newheight =350;
			 }*/
			 

			 $InsertImage1=$imagefleimagename1;

			move_uploaded_file($_FILES["image1fleimage"]['tmp_name'], "$ImagePath".$InsertImage1);
			
			
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight, $width,$height);
			$InsertImagethumb1 = $imagefleimagename1;
			$imagefleimagename = "../../media/category/thumb/". $InsertImagethumb1;
				
			imagejpeg($tmp,$imagefleimagename,100);
			imagedestroy($src);
			imagedestroy($tmp);
	//////---------------End Upload Brand Image------------////////////
}	



	$sqladd = mysqli_query($conn,"update tbl_category set 
	name='$categoryname',
	image='$InsertImage1',
	thumb='$InsertImagethumb1',
	url='$url',
	order_number='$order',
	status='$status'
	 where id = '$id'") or die(mysqli_error($conn));
	if(mysqli_affected_rows($conn) > 0)
	{
		// echo "1";
		header('Location: ../category-list.php?m=4');
	}
	else
	{
		// echo "0";
		header('Location: ../category-list.php?m=5');
	}

} 
 /*--------Edit Category close-----------------------------------------------*/
 	/*--------Add Sub Category-----------------------------------------------*/

function addSubCategory($conn)
{  	
	$category		        = mysqli_real_escape_string($conn,$_POST['selcategory']); 
	$subcategoryname		= mysqli_real_escape_string($conn,$_POST['txtname']); 
	$order		 	        = mysqli_real_escape_string($conn,$_POST['txtorder']); 
	$url	                = strtolower(str_replace(" ","-",$subcategoryname));
	$url	                = strtolower(str_replace("&","and",$url));

	if(isset($_POST['txtstatus'])){$status=1;}else{$status=0;}
		$imagefleimagename1 			= $_FILES['image1fleimage']['name']; 
	$imagefleimagename1_tmp 		= $_FILES['image1fleimage']['tmp_name'];

	//---------------------condition--check dots------------------------ 
	$dots=substr_count($imagefleimagename1, '.');
	if($dots>1){header('Location: ../sub-category.php?m=2&n=Rooms Image');exit(0);}
	//------------------------------------------------------------------
		//------now clear all condtion is good-------------if two image not avale-----
	function getExtension($str) {
		$i = strrpos($str,".");
         if (!$i) { return ""; } 

         $l = strlen($str) - $i;
         $ext = substr($str,$i+1,$l);
         return $ext;
	}
			$no = rand(1,999);
			$tno = rand(1,999);	
	///////--------------Upload Logo Image-----------------////////////


	global $subcategoryPath;	
	global $subcategoryPathThumb;	
	$ImagePath = "$subcategoryPath/";
	$ImageThumbPath = "$subcategoryPathThumb/";
	//================================ Image 1 ==============================	

	if(	$imagefleimagename1!=""){
			//check if image has 2 dot then exit program
			//$catfile = $imagefleimagename1;
			$image = $imagefleimagename1;
			$uploadedfile = $imagefleimagename1;
			$imagefleimagename1 = stripslashes($imagefleimagename1);
			$extension = getExtension($imagefleimagename1);
			$extension = strtolower($extension);
			/*-------------------------------*/
			/*---------------------------------*/
			if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") ) {
					header('Location: ../sub-category.php?m=3');
					exit();
			}
			if($extension=="jpg" || $extension=="jpeg" ){
				$uploadedfile = $imagefleimagename1_tmp;
				$src = imagecreatefromjpeg($uploadedfile);
			}else if($extension=="png"){
				$uploadedfile = $imagefleimagename1_tmp;
				$src = imagecreatefrompng($uploadedfile);
			}else {
				$src = imagecreatefromgif($uploadedfile);
			}
			list($width,$height)=getimagesize($uploadedfile);
			 $setheight=400;
			 $ratio=0.0;
			 /*if($width>$setwidth){
				$ratio=$setwidth/$width;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				$newheight = $height ;
            	$newwidth = $width ;
			 }*/
			if($height>$setheight){
				$ratio=$setheight/$height;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				  $newheight = $height ;
            	  $newwidth = $width ;
			 }
			 $newfile1=$imagefleimagename1;

			move_uploaded_file($_FILES["image1fleimage"]['tmp_name'], "$ImagePath".$newfile1);
			
			
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight, $width,$height);
			$imageThumbName = $imagefleimagename1;
			$imagefleimagename = "../../media/subcategory/thumb/". $imageThumbName;

			// echo $imagefleimagename;
			// die();
				
			imagejpeg($tmp,$imagefleimagename,100);
			imagedestroy($src);
			imagedestroy($tmp);
			

	//////---------------End Image 1 end------------////////////
	}else{
	$newfile1="";
	 $imageThumbName="";
	}
	$sql="insert into  tbl_subcategory(category_id,name,image,thumb,url,order_number,status) values('$category','$subcategoryname','$newfile1','$imageThumbName','$url','$order','$status')";
	if(mysqli_query($conn,$sql) or die(mysqli_error($conn)))
	{
		header('Location: ../sub-category-list.php?m=1');
		//echo "success";
	}
	else
	{
		header('Location: ../sub-category-list.php?m=0');
		//echo "fail";
	}
} 	
   /*--------Add Sub Category close-----------------------------------------------*/	
    /*--------Delete Sub Category -----------------------------------------------*/	
   function deleteSubCategory($conn)
{

	$id =isset($_GET['id'])? $_GET['id'] : "";
	//echo "value is ".$id;
	$sql="SELECT * FROM tbl_product where 	sub_category_id='$id'";
     $run=mysqli_query($conn,$sql) or die(mysqli_error($conn));
      $row=mysqli_num_rows($run);
	if($row<1)
	{
	
			$del =	"delete from tbl_subcategory where id = '$id' ";

			if(mysqli_query($conn,$del) or die(mysqli_error($conn)))
			{
				
				header('Location: ../sub-category-list.php?&m=6');
			}
			else
			{
			
				header('Location: ../sub-category-list.php?m=7');
			}
    }
    else
    {
    	header('Location: ../sub-category-list.php?m=18');
    }
}
 /*--------Delete Sub Category close-----------------------------------------------*/

 /*--------Edit Sub Category close-----------------------------------------------*/

 function editSubCategory($conn)
{

	$id				        = $_POST['txtid']; 
	$category		        = mysqli_real_escape_string($conn,$_POST['selcategory']); 
	$subcategoryname		= mysqli_real_escape_string($conn,$_POST['txtname']); 
	$order		 	        = mysqli_real_escape_string($conn,$_POST['txtorder']); 
	$url	                = strtolower(str_replace(" ","-",$subcategoryname));
	$url	                = strtolower(str_replace("&","and",$url));

	if(isset($_POST['txtstatus'])){$status=1;}else{$status=0;}
	$imagefleimagename1 			= $_FILES['image1fleimage']['name']; 
	$imagefleimagename1_tmp 		= $_FILES['image1fleimage']['tmp_name'];
	//------now clear all condtion is good-------------if two image not avale-----
function getExtension($str) {
	$i = strrpos($str,".");
	 if (!$i) { return ""; } 

	 $l = strlen($str) - $i;
	 $ext = substr($str,$i+1,$l);
	 return $ext;
}

// ------------- get all images  name  -------------------------
$sel = mysqli_query($conn,"select * from tbl_subcategory where id = '$id' ");
$row = mysqli_fetch_assoc($sel);
$Un_OrginalImage1 	= $row['image'];	
$Un_Image1 			= $row['thumb'];

/*--------------insert record varible record------------*/
$InsertImage1 				= $row['image'];	
$InsertImagethumb1 			= $row['thumb'];

/*---------------------------*/
$flagImage1		=0;
$flagImage2		=0;
// ------------- get all images  name  -------------------------	
			$no = rand(1,999);
			$tno = rand(1,999);	
///////--------------Upload Logo Image-----------------////////////
 	global $subcategoryPath;	
	global $subcategoryPathThumb;	
	$ImagePath = "$subcategoryPath/";
	$ImageThumbPath = "$subcategoryPathThumb/";
//================================ Image 1 ==============================	
if(	$imagefleimagename1!=""){
	$flagImage1		=1;
	//check if image has 2 dot then exit program
			//$catfile = $imagefleimagename1;
			$image = $imagefleimagename1;
			$uploadedfile = $imagefleimagename1;
			$imagefleimagename1 = stripslashes($imagefleimagename1);
			$extension = getExtension($imagefleimagename1);
			$extension = strtolower($extension);
			/*-------------------------------*/
			/*---------------------------------*/
			if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png")) {
					header('Location: ../sub-category-list.php?m=16&id='.$id);
					exit();
			}
			if($extension=="jpg" || $extension=="jpeg" ){
				$uploadedfile = $imagefleimagename1_tmp;
				$src = imagecreatefromjpeg($uploadedfile);
			}else if($extension=="png" || $extension=="PNG" ){
				$uploadedfile = $imagefleimagename1_tmp;
				$src = imagecreatefrompng($uploadedfile);
			}else {
				$src = imagecreatefromgif($uploadedfile);
			}
			list($width,$height)=getimagesize($uploadedfile);
			 $setwidth=400;
			 $ratio=0.0;
			 if($width>$setwidth){
				$ratio=$setwidth/$width;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				$newheight = $height ;
            	$newwidth = $width ;
			 }
			/*if($height>$setheight){
				$ratio=$setheight/$height;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				  $newheight =350;
			 }*/
			 

			 $InsertImage1=$imagefleimagename1;

			move_uploaded_file($_FILES["image1fleimage"]['tmp_name'], "$ImagePath".$InsertImage1);
			
			
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight, $width,$height);
			$InsertImagethumb1 = $imagefleimagename1;
			$imagefleimagename = "../../media/subcategory/thumb/". $InsertImagethumb1;
				
			imagejpeg($tmp,$imagefleimagename,100);
			imagedestroy($src);
			imagedestroy($tmp);
	//////---------------End Upload Brand Image------------////////////
}	



	$sqladd = mysqli_query($conn,"update tbl_subcategory set 
	category_id='$category',	
	name='$subcategoryname',
	image='$InsertImage1',
	thumb='$InsertImagethumb1',
	order_number='$order',
	status='$status'
	where id = '$id'") or die(mysqli_error($conn));
	if(mysqli_affected_rows($conn) > 0)
	{
		// echo "1";
		header('Location: ../sub-category-list.php?m=4');
	}
	else
	{
		// echo "0";
		header('Location: ../sub-category-list.php?m=5');
	}

} 
/*--------Edit Sub Category close-----------------------------------------------*/

/*--------Add product-----------------------------------------------*/
function addProduct($conn)
{  
	$category	                = 	mysqli_real_escape_string($conn,$_POST['selcategory']);
	$subcategory	            = 	mysqli_real_escape_string($conn,$_POST['selsubcategory']);
	// $subsubcategory	            = 	mysqli_real_escape_string($conn,$_POST['selsubsubcategory']);
	
	$name	 				    = 	mysqli_real_escape_string($conn,$_POST['txtproductname']); 	
	$url					    = 	strtolower(str_replace(" ","-",$name));
	$url					    = 	strtolower(str_replace("&","and",$url));
	
	$shortdescription		 	= 	mysqli_real_escape_string($conn,$_POST['txtshortdescription']); 
	$longdescription		 	= 	mysqli_real_escape_string($conn,$_POST['txtlongdescription']); 
	$skucode		 			    = 	mysqli_real_escape_string($conn,$_POST['txtskucode']);
	$miqty = 	mysqli_real_escape_string($conn,$_POST['txtmiqty']);
	
	$metakeyword = 	mysqli_real_escape_string($conn,$_POST['txtmetakeyword']);
	$metadescription = 	mysqli_real_escape_string($conn,$_POST['txtmetadescription']);
	$metatitle = mysqli_real_escape_string($conn,$_POST['txtmetatitle']);
	
	 $rand=rand(100000,999999);
	 $productId="LA".$rand;
      $date=date('d/m/Y H:i', time());
     $rand2=rand(100000,999999);
	 $varientId="LZV".$rand2;	
	
	if(isset($_POST['txtstatus'])){$status=1;}else{$status=0;}
	if(isset($_POST['txtfeatured'])){$featured=1;}else{$featured=0;}
	if(isset($_POST['txtlatests'])){$latest=1;}else{$latest=0;}
	if(isset($_POST['txtproductpage'])){$productpage=1;}else{$productpage=0;}
	
	/*-------------------------Image info-----------------------------*/
	//------------------brand logo--------------------------
	$imagefleimagename1 			= $_FILES['image1fleimage']['name']; 
	$imagefleimagename1_tmp 		= $_FILES['image1fleimage']['tmp_name'];
	$imagefleimagename2 			= $_FILES['image2fleimage']['name']; 
	$imagefleimagename2_tmp 		= $_FILES['image2fleimage']['tmp_name'];
	$imagefleimagename3 			= $_FILES['image3fleimage']['name']; 
	$imagefleimagename3_tmp 		= $_FILES['image3fleimage']['tmp_name'];
	$imagefleimagename4 			= $_FILES['image4fleimage']['name']; 
	$imagefleimagename4_tmp 		= $_FILES['image4fleimage']['tmp_name'];
	$imagefleimagename5 			= $_FILES['image5fleimage']['name']; 
	$imagefleimagename5_tmp 		= $_FILES['image5fleimage']['tmp_name'];
	$imagefleimagename6 			= $_FILES['image6fleimage']['name']; 
	$imagefleimagename6_tmp 		= $_FILES['image6fleimage']['tmp_name'];
	//------------------brand img 1--------------------------
	//---------------------condition--check dots------------------------ 
	$dots=substr_count($imagefleimagename1, '.');
	if($dots>1){header('Location: ../product.php?m=2&n=Rooms Image');exit(0);}
	//------------------------------------------------------------------

	//-----------------------check compalsory image-------------------------------------------
	/*if($imagefleimagename1==""){
	header('Location: ../add-image.php?m=3&n=Product Image&id='.$productID);exit(0);
	}
	//----------------------------------------------------------------------------------------

	//-----------------------check compalsory image size--------------------------------------
	list($width1,$height1)=getimagesize($imagefleimagename1_tmp);
	if($width1<1000){
		header('Location: ../add-image.php?m=13&n=1000px Product Image&id=');exit(0);
	}
	//----------------------------------------------------------------------------------------*/
	//------now clear all condtion is good-------------if two image not avale-----
	function getExtension($str) {
		$i = strrpos($str,".");
         if (!$i) { return ""; } 

         $l = strlen($str) - $i;
         $ext = substr($str,$i+1,$l);
         return $ext;
	}
			// $no = rand(1,999);
			// $tno = rand(1,999);	
	///////--------------Upload Logo Image-----------------////////////


	global $productPath;	
	global $productPathThumb;	
	$ImagePath = "$productPath/";
	$ImageThumbPath = "$productPathThumb/";
	//================================ Image 1 ==============================	


	if(	$imagefleimagename1!=""){
			
			$image = $imagefleimagename1;
			$uploadedfile = $imagefleimagename1;
			$imagefleimagename1 = stripslashes($imagefleimagename1);
			$extension = getExtension($imagefleimagename1);
			$extension = strtolower($extension);
			/*-------------------------------*/
			/*---------------------------------*/
			if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") ) {
					header('Location: ../product.php?m=3');
					exit();
			}
			if($extension=="jpg" || $extension=="jpeg" ){
				$uploadedfile = $imagefleimagename1_tmp;
				$src = imagecreatefromjpeg($uploadedfile);
			}else if($extension=="png"){
				$uploadedfile = $imagefleimagename1_tmp;
				$src = imagecreatefrompng($uploadedfile);
			}else {
				$src = $uploadedfile;
			}
			list($width,$height)=getimagesize($uploadedfile);
			 $setheight=400;
			 $ratio=0.0;

			
			if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") ) {
					header('Location: ../product.php?m=3');
					exit();
			}
			if($extension=="jpg" || $extension=="jpeg" ){
				$uploadedfile = $imagefleimagename2_tmp;
				$src = imagecreatefromjpeg($uploadedfile);
			}else if($extension=="png"){
				$uploadedfile = $imagefleimagename2_tmp;
				$src = imagecreatefrompng($uploadedfile);
			}else {
				$src = imagecreatefromgif($uploadedfile);
			}
			list($width,$height)=getimagesize($uploadedfile);
			 $setheight=400;
			 $ratio=0.0;

			
			if($height>$setheight){
				$ratio=$setheight/$height;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				  $newheight = $height ;
            	  $newwidth = $width ;
			 }
			 $newfile2=$imagefleimagename2;

			move_uploaded_file($_FILES["image2fleimage"]['tmp_name'], "$ImagePath".$newfile2);
			
			
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight, $width,$height);
			$image2ThumbName = $imagefleimagename2;
			$imagefleimagename = "$ImageThumbPath/". $image2ThumbName;
				


			imagejpeg($tmp,$imagefleimagename,100);
			imagedestroy($src);
			imagedestroy($tmp);
			

	//////---------------End Image 2 end------------////////////
	}else{
	$newfile2="";
	 $image2ThumbName="";
	}

		//================================ Image 3 ==============================	

	if(	$imagefleimagename3!=""){
			//check if image has 2 dot then exit program
			//$catfile = $imagefleimagename1;
			$image = $imagefleimagename3;
			$uploadedfile = $imagefleimagename3;
			$imagefleimagename3 = stripslashes($imagefleimagename3);
			$extension = getExtension($imagefleimagename3);
			$extension = strtolower($extension);
			/*-------------------------------*/
			/*---------------------------------*/
			if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") ) {
					header('Location: ../product.php?m=3');
					exit();
			}
			if($extension=="jpg" || $extension=="jpeg" ){
				$uploadedfile = $imagefleimagename3_tmp;
				$src = imagecreatefromjpeg($uploadedfile);
			}else if($extension=="png"){
				$uploadedfile = $imagefleimagename3_tmp;
				$src = imagecreatefrompng($uploadedfile);
			}else {
				$src = imagecreatefromgif($uploadedfile);
			}
			list($width,$height)=getimagesize($uploadedfile);
			 $setheight=400;
			 $ratio=0.0;
			 /*if($width>$setwidth){
				$ratio=$setwidth/$width;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				$newheight = $height ;
            	$newwidth = $width ;
			 }*/
			if($height>$setheight){
				$ratio=$setheight/$height;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				  $newheight = $height ;
            	  $newwidth = $width ;
			 }
			 $newfile3=$imagefleimagename3;

			move_uploaded_file($_FILES["image3fleimage"]['tmp_name'], "$ImagePath".$newfile3);
			
			
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight, $width,$height);
			$image3ThumbName = $imagefleimagename3;
			$imagefleimagename = "$ImageThumbPath/". $image3ThumbName;
				
			imagejpeg($tmp,$imagefleimagename,100);
			imagedestroy($src);
			imagedestroy($tmp);
			

	//////---------------End Image 3 end------------////////////
	}else{
	$newfile3="";
	 $image3ThumbName="";
	}
			//================================ Image 4 ==============================	

	if(	$imagefleimagename4!=""){
			//check if image has 2 dot then exit program
			//$catfile = $imagefleimagename1;
			$image = $imagefleimagename4;
			$uploadedfile = $imagefleimagename4;
			$imagefleimagename4 = stripslashes($imagefleimagename4);
			$extension = getExtension($imagefleimagename4);
			$extension = strtolower($extension);
			/*-------------------------------*/
			/*---------------------------------*/
			if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") ) {
					header('Location: ../product.php?m=3');
					exit();
			}
			if($extension=="jpg" || $extension=="jpeg" ){
				$uploadedfile = $imagefleimagename4_tmp;
				$src = imagecreatefromjpeg($uploadedfile);
			}else if($extension=="png"){
				$uploadedfile = $imagefleimagename4_tmp;
				$src = imagecreatefrompng($uploadedfile);
			}else {
				$src = imagecreatefromgif($uploadedfile);
			}
			list($width,$height)=getimagesize($uploadedfile);
			 $setheight=400;
			 $ratio=0.0;
			 /*if($width>$setwidth){
				$ratio=$setwidth/$width;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				$newheight = $height ;
            	$newwidth = $width ;
			 }*/
			if($height>$setheight){
				$ratio=$setheight/$height;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				  $newheight = $height ;
            	  $newwidth = $width ;
			 }
			 $newfile4=$imagefleimagename4;

			move_uploaded_file($_FILES["image4fleimage"]['tmp_name'], "$ImagePath".$newfile4);
			
			
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight, $width,$height);
			$image4ThumbName = $imagefleimagename4;
			$imagefleimagename = "$ImageThumbPath/". $image4ThumbName;
				
			imagejpeg($tmp,$imagefleimagename,100);
			imagedestroy($src);
			imagedestroy($tmp);
			

	//////---------------End Image 4 end------------////////////
	}else{
	$newfile4="";
	 $image4ThumbName="";
	}

			//================================ Image 5 ==============================	

	if(	$imagefleimagename5!=""){
			//check if image has 2 dot then exit program
			//$catfile = $imagefleimagename1;
			$image = $imagefleimagename5;
			$uploadedfile = $imagefleimagename5;
			$imagefleimagename5 = stripslashes($imagefleimagename5);
			$extension = getExtension($imagefleimagename5);
			$extension = strtolower($extension);
			/*-------------------------------*/
			/*---------------------------------*/
			if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") ) {
					header('Location: ../product.php?m=3');
					exit();
			}
			if($extension=="jpg" || $extension=="jpeg" ){
				$uploadedfile = $imagefleimagename5_tmp;
				$src = imagecreatefromjpeg($uploadedfile);
			}else if($extension=="png"){
				$uploadedfile = $imagefleimagename5_tmp;
				$src = imagecreatefrompng($uploadedfile);
			}else {
				$src = imagecreatefromgif($uploadedfile);
			}
			list($width,$height)=getimagesize($uploadedfile);
			 $setheight=400;
			 $ratio=0.0;
			 /*if($width>$setwidth){
				$ratio=$setwidth/$width;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				$newheight = $height ;
            	$newwidth = $width ;
			 }*/
			if($height>$setheight){
				$ratio=$setheight/$height;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				  $newheight = $height ;
            	  $newwidth = $width ;
			 }
			 $newfile5=$imagefleimagename5;

			move_uploaded_file($_FILES["image5fleimage"]['tmp_name'], "$ImagePath".$newfile5);
			
			
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight, $width,$height);
			$image5ThumbName = $imagefleimagename5;
			$imagefleimagename = "$ImageThumbPath/". $image5ThumbName;
				
			imagejpeg($tmp,$imagefleimagename,100);
			imagedestroy($src);
			imagedestroy($tmp);
			

	//////---------------End Image 5 end------------////////////
	}else{
	$newfile5="";
	 $image5ThumbName="";
	}

			//================================ Image 6 ==============================	

	if(	$imagefleimagename6!=""){
			//check if image has 2 dot then exit program
			//$catfile = $imagefleimagename1;
			$image = $imagefleimagename6;
			$uploadedfile = $imagefleimagename6;
			$imagefleimagename6 = stripslashes($imagefleimagename6);
			$extension = getExtension($imagefleimagename6);
			$extension = strtolower($extension);
			/*-------------------------------*/
			/*---------------------------------*/
			if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") ) {
					header('Location: ../product.php?m=3');
					exit();
			}
			if($extension=="jpg" || $extension=="jpeg" ){
				$uploadedfile = $imagefleimagename6_tmp;
				$src = imagecreatefromjpeg($uploadedfile);
			}else if($extension=="png"){
				$uploadedfile = $imagefleimagename6_tmp;
				$src = imagecreatefrompng($uploadedfile);
			}else {
				$src = imagecreatefromgif($uploadedfile);
			}
			list($width,$height)=getimagesize($uploadedfile);
			 $setheight=400;
			 $ratio=0.0;
			 /*if($width>$setwidth){
				$ratio=$setwidth/$width;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				$newheight = $height ;
            	$newwidth = $width ;
			 }*/
			if($height>$setheight){
				$ratio=$setheight/$height;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				  $newheight = $height ;
            	  $newwidth = $width ;
			 }
			 $newfile6=$imagefleimagename6;

			move_uploaded_file($_FILES["image6fleimage"]['tmp_name'], "$ImagePath".$newfile6);
			
			
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight, $width,$height);
			$image6ThumbName = $imagefleimagename6;
			$imagefleimagename = "$ImageThumbPath/". $image6ThumbName;
				
			
			imagejpeg($tmp,$imagefleimagename,100);
			imagedestroy($src);
			imagedestroy($tmp);
			

	//////---------------End Image 6 end------------////////////
	}else{
	$newfile6="";
	 $image6ThumbName="";
	}



       
       // insert in product          

	$sql="insert into tbl_product(category_id,sub_category_id,productname,productid,varient_id,url,skucode,short_description,image1,thumb1,image2,thumb2,image3,thumb3,image4,thumb4,image5,thumb5,image6,thumb6,status,productDate,long_description,	minorderqty,metakeyword,metadescription,metatitle) 
	values('$category','$subcategory','$name','$productId','$varientId','$url','$skucode','$shortdescription','$newfile1','$imageThumbName','$newfile2','$image2ThumbName','$newfile3','$image3ThumbName','$newfile4','$image4ThumbName','$newfile5','$image5ThumbName','$newfile6','$image6ThumbName','$status','$date','$longdescription','$miqty','$metakeyword','$metadescription','$metatitle')";
 			
	
	

	die();
			if(mysqli_query($conn,$sql) or die(mysqli_error($conn)))
			{
	   // $del=mysqli_query($conn,"delete from tbl_product_price where weight='0'");
    // 	$del=mysqli_query($conn,"delete from tbl_product_stock where weight='0'");
				// header('Location: ../product-list.php?m=1');
				// echo "suucess";
					// insert in price 
        for($i=0;$i<=8;$i++)
            {
        
          
          $size[$i]	 = 	mysqli_real_escape_string($conn,$_POST['size'][$i]);
          $unit[$i]	 = 	mysqli_real_escape_string($conn,$_POST['unit'][$i]);
          $price[$i] = 	mysqli_real_escape_string($conn,$_POST['price'][$i]);
          $mrp[$i] = 	mysqli_real_escape_string($conn,$_POST['listprice'][$i]);
        $stock[$i] = 	mysqli_real_escape_string($conn,$_POST['stock'][$i]);
            
          
            
                if($price[$i]!='')
                {
                    $query=mysqli_query($conn,"insert into tbl_product_price (productId,varient_id,psize,punit,pprice,pmrp,pdate,status,pqty) values ('$productId','$varientId','$size[$i]','$unit[$i]','$price[$i]','$mrp[$i]','$date','$status','$stock[$i]')");
                    
                    $del=mysqli_query($conn,"delete from tbl_product_price where pprice='0' or pprice=''");
                 	// $del=mysqli_query($conn,"delete from tbl_product_stock where weight='0' or weight=''");

                     header('Location: ../product-list.php?m=1');
                }

             }
				
			}
			else
			{
								//echo "fail";
				header('Location: ../product-list.php?m=0');
				
			}


} 

/*--------Add product close-----------------------------------------------*/	
/*--------Delete Product -----------------------------------------------*/	
   function deleteProduct($conn)
{

	$id =isset($_GET['id'])? $_GET['id'] : "";
	//echo "value is ".$id;
	$sql=mysqli_query($conn,"select * from tbl_product where id='$id'")or die(mysqli_error($conn));
       $row1=mysqli_fetch_assoc($sql);
       $productid=$row1['productid'];      

    if($sql>0) 
    {
    
    	$del = mysqli_query($conn,"delete from tbl_product_price where productId = '$productid'");

		   $del2 = "delete from tbl_product where productid = '$productid' ";

			if(mysqli_query($conn,$del2) or die(mysqli_error($conn)))
			{

				header('Location: ../product-list.php?&m=6');
			}
			else
			{
			
				header('Location: ../product-list.php?m=7');
			}
    } 
    else
		    {
		    	header('Location: ../product-list.php?m=7');
		    }  
	

}
 /*--------Delete Product close-----------------------------------------------*/

  /*--------Edit Product -----------------------------------------------*/

 function editProduct($conn)
{ 

	$id	           =	$_POST['txtid']; 
	$txtproductid  =	$_POST['txtproductid'];	
	$txtvarientid  =  $_POST['txtvarientid'];         
    $category      = 	mysqli_real_escape_string($conn,$_POST['selcategory']);
	$subcategory   = 	mysqli_real_escape_string($conn,$_POST['selsubcategory']);
	
	$name          = 	mysqli_real_escape_string($conn,$_POST['txtproductname']); 	
	$url		   = 	strtolower(str_replace(" ","-",$name));
	$url	       = 	strtolower(str_replace("&","and",$url));
	
 $shortdescription = mysqli_real_escape_string($conn,$_POST['txtshortdescription']); 
 	$longdescription		 	= 	mysqli_real_escape_string($conn,$_POST['txtlongdescription']); 
	$skucode       = 	mysqli_real_escape_string($conn,$_POST['txtskucode']);
		$ordernumber          = 	mysqli_real_escape_string($conn,$_POST['txtordernumber']); 
			$miqty = 	mysqli_real_escape_string($conn,$_POST['txtmiqty']);
			
			$metakeyword = 	mysqli_real_escape_string($conn,$_POST['txtmetakeyword']);
	$metadescription = 	mysqli_real_escape_string($conn,$_POST['txtmetadescription']);
	$metatitle = mysqli_real_escape_string($conn,$_POST['txtmetatitle']);
	
	$date=date('d/m/Y H:i', time());

if(isset($_POST['txtstatus'])){$status=1;}else{$status=0;}
if(isset($_POST['txtfeatured'])){$featured=1;}else{$featured=0;}
	if(isset($_POST['txtlatests'])){$latest=1;}else{$latest=0;}
	if(isset($_POST['txtproductpage'])){$productpage=1;}else{$productpage=0;}
	/*-------------------------Image info-----------------------------*/
	//------------------brand logo--------------------------
	$imagefleimagename1 			= $_FILES['image1fleimage']['name']; 
	$imagefleimagename1_tmp 		= $_FILES['image1fleimage']['tmp_name'];
	$imagefleimagename2 			= $_FILES['image2fleimage']['name']; 
	$imagefleimagename2_tmp 		= $_FILES['image2fleimage']['tmp_name'];
	$imagefleimagename3 			= $_FILES['image3fleimage']['name']; 
	$imagefleimagename3_tmp 		= $_FILES['image3fleimage']['tmp_name'];
	$imagefleimagename4 			= $_FILES['image4fleimage']['name']; 
	$imagefleimagename4_tmp 		= $_FILES['image4fleimage']['tmp_name'];
	$imagefleimagename5 			= $_FILES['image5fleimage']['name']; 
	$imagefleimagename5_tmp 		= $_FILES['image5fleimage']['tmp_name'];
	$imagefleimagename6 			= $_FILES['image6fleimage']['name']; 
	$imagefleimagename6_tmp 		= $_FILES['image6fleimage']['tmp_name'];
	//------------------brand img 1--------------------------
//------now clear all condtion is good-------------if two image not avale-----
function getExtension($str) {
	$i = strrpos($str,".");
	 if (!$i) { return ""; } 

	 $l = strlen($str) - $i;
	 $ext = substr($str,$i+1,$l);
	 return $ext;
}

// ------------- get all images  name  -------------------------
$sel = mysqli_query($conn,"select * from tbl_product where id = '$id' ");
$row = mysqli_fetch_assoc($sel);
$Un_OrginalImage1 	= $row['image1'];	
$Un_Image1 			= $row['thumb1'];
$Un_OrginalImage2 	= $row['image2'];
$Un_Image2 			= $row['thumb2'];	
$Un_OrginalImage3 	= $row['image3'];
$Un_Image3 			= $row['thumb3'];	
$Un_OrginalImage4 	= $row['image4'];
$Un_Image4 			= $row['thumb4'];
$Un_OrginalImage5 	= $row['image5'];
$Un_Image5 			= $row['thumb5'];
$Un_OrginalImage6 	= $row['image6'];
$Un_Image6 			= $row['thumb6'];
/*--------------insert record varible record------------*/
$InsertImage1 				= $row['image1'];	
$InsertImagethumb1 			= $row['thumb1'];
$InsertImage2 				= $row['image2'];	
$InsertImagethumb2			= $row['thumb2'];
$InsertImage3 				= $row['image3'];	
$InsertImagethumb3			= $row['thumb3'];
$InsertImage4 				= $row['image4'];	
$InsertImagethumb4			= $row['thumb4'];
$InsertImage5 				= $row['image5'];	
$InsertImagethumb5			= $row['thumb5'];
$InsertImage6 				= $row['image6'];	
$InsertImagethumb6			= $row['thumb6'];
	
	
/*---------------------------*/
$flagImage1		=0;
$flagImage2		=0;
$flagImage3		=0;
$flagImage4		=0;
$flagImage5		=0;
$flagImage6		=0;
// ------------- get all images  name  -------------------------	
			$no = rand(1,999);
			$tno = rand(1,999);	
///////--------------Upload Logo Image-----------------////////////
    global $productPath;	
	global $productPathThumb;	
	$ImagePath = "$productPath/";
	$ImageThumbPath = "$productPathThumb/";
//================================ Image 1 ==============================	
if(	$imagefleimagename1!=""){
	$flagImage1		=1;
	//check if image has 2 dot then exit program
			//$catfile = $imagefleimagename1;
			$image = $imagefleimagename1;
			$uploadedfile = $imagefleimagename1;
			$imagefleimagename1 = stripslashes($imagefleimagename1);
			$extension = getExtension($imagefleimagename1);
			$extension = strtolower($extension);
			/*-------------------------------*/
			/*---------------------------------*/
			if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png")) {
					header('Location: ../product-list.php?m=16&id='.$id);
					exit();
			}
			if($extension=="jpg" || $extension=="jpeg" ){
				$uploadedfile = $imagefleimagename1_tmp;
				$src = imagecreatefromjpeg($uploadedfile);
			}else if($extension=="png"){
				$uploadedfile = $imagefleimagename1_tmp;
				$src = imagecreatefrompng($uploadedfile);
			}else {
				$src = imagecreatefromgif($uploadedfile);
			}
			list($width,$height)=getimagesize($uploadedfile);
			 $setwidth=400;
			 $ratio=0.0;
			 if($width>$setwidth){
				$ratio=$setwidth/$width;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				$newheight = $height ;
            	$newwidth = $width ;
			 }

			/*if($height>$setheight){
				$ratio=$setheight/$height;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				  $newheight =350;
			 }*/
			 

			 $InsertImage1=$imagefleimagename1;

			move_uploaded_file($_FILES["image1fleimage"]['tmp_name'], "$ImagePath".$InsertImage1);
			
			
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight, $width,$height);
			$InsertImagethumb1 = $imagefleimagename1;
			$imagefleimagename = "$ImageThumbPath/". $InsertImagethumb1;
				
			imagejpeg($tmp,$imagefleimagename,100);
			imagedestroy($src);
			imagedestroy($tmp);
	//////---------------End Upload Brand Image------------////////////
}	
// ======================= image 2 =========================
if(	$imagefleimagename2!=""){
	$flagImage2		=2;
	//check if image has 2 dot then exit program
			//$catfile = $imagefleimagename1;
			$image = $imagefleimagename2;
			$uploadedfile = $imagefleimagename2;
			$imagefleimagename2 = stripslashes($imagefleimagename2);
			$extension = getExtension($imagefleimagename2);
			$extension = strtolower($extension);
			/*-------------------------------*/
			/*---------------------------------*/
			if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png")) {
					header('Location: ../product-list.php?m=16&id='.$id);
					exit();
			}
			if($extension=="jpg" || $extension=="jpeg" ){
				$uploadedfile = $imagefleimagename2_tmp;
				$src = imagecreatefromjpeg($uploadedfile);
			}else if($extension=="png"){
				$uploadedfile = $imagefleimagename2_tmp;
				$src = imagecreatefrompng($uploadedfile);
			}else {
				$src = imagecreatefromgif($uploadedfile);
			}
			list($width,$height)=getimagesize($uploadedfile);
			 $setwidth=400;
			 $ratio=0.0;
			 if($width>$setwidth){
				$ratio=$setwidth/$width;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				$newheight = $height ;
            	$newwidth = $width ;
			 }
			/*if($height>$setheight){
				$ratio=$setheight/$height;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				  $newheight =350;
			 }*/
			 

			 $InsertImage2=$imagefleimagename2;

			move_uploaded_file($_FILES["image2fleimage"]['tmp_name'], "$ImagePath".$InsertImage2);
			
			
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight, $width,$height);
			$InsertImagethumb2 = $imagefleimagename2;
			$imagefleimagename = "$ImageThumbPath/". $InsertImagethumb2;
				
			imagejpeg($tmp,$imagefleimagename,100);
			imagedestroy($src);
			imagedestroy($tmp);
	//////---------------End Upload Brand Image------------////////////
}	
//================================ Image 2 End==============================
/*----------------------------------------------*/

// ======================= image 3 =========================
if(	$imagefleimagename3!=""){
	$flagImage3	=3;
	//check if image has 2 dot then exit program
			//$catfile = $imagefleimagename1;
			$image = $imagefleimagename3;
			$uploadedfile = $imagefleimagename3;
			$imagefleimagename3 = stripslashes($imagefleimagename3);
			$extension = getExtension($imagefleimagename3);
			$extension = strtolower($extension);
			/*-------------------------------*/
			/*---------------------------------*/
			if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png")) {
					header('Location: ../product-list.php?m=16&id='.$id);
					exit();
			}
			if($extension=="jpg" || $extension=="jpeg" ){
				$uploadedfile = $imagefleimagename3_tmp;
				$src = imagecreatefromjpeg($uploadedfile);
			}else if($extension=="png"){
				$uploadedfile = $imagefleimagename3_tmp;
				$src = imagecreatefrompng($uploadedfile);
			}else {
				$src = imagecreatefromgif($uploadedfile);
			}
			list($width,$height)=getimagesize($uploadedfile);
			 $setwidth=400;
			 $ratio=0.0;
			 if($width>$setwidth){
				$ratio=$setwidth/$width;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				$newheight = $height ;
            	$newwidth = $width ;
			 }
			/*if($height>$setheight){
				$ratio=$setheight/$height;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				  $newheight =350;
			 }*/
			 

			 $InsertImage3=$imagefleimagename3;

			move_uploaded_file($_FILES["image3fleimage"]['tmp_name'], "$ImagePath".$InsertImage3);
			
			
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight, $width,$height);
			$InsertImagethumb3 = $imagefleimagename3;
			$imagefleimagename = "$ImageThumbPath/". $InsertImagethumb3;
				
			imagejpeg($tmp,$imagefleimagename,100);
			imagedestroy($src);
			imagedestroy($tmp);
	//////---------------End Upload Brand Image------------////////////
}	
//================================ Image 3 End==============================

// ======================= image 4 =========================
if(	$imagefleimagename4!=""){
	$flagImage4	=4;
	//check if image has 2 dot then exit program
			//$catfile = $imagefleimagename1;
			$image = $imagefleimagename4;
			$uploadedfile = $imagefleimagename4;
			$imagefleimagename4 = stripslashes($imagefleimagename4);
			$extension = getExtension($imagefleimagename4);
			$extension = strtolower($extension);
			/*-------------------------------*/
			/*---------------------------------*/
			if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png")) {
					header('Location: ../product-list.php?m=16&id='.$id);
					exit();
			}
			if($extension=="jpg" || $extension=="jpeg" ){
				$uploadedfile = $imagefleimagename4_tmp;
				$src = imagecreatefromjpeg($uploadedfile);
			}else if($extension=="png"){
				$uploadedfile = $imagefleimagename4_tmp;
				$src = imagecreatefrompng($uploadedfile);
			}else {
				$src = imagecreatefromgif($uploadedfile);
			}
			list($width,$height)=getimagesize($uploadedfile);
			 $setwidth=400;
			 $ratio=0.0;
			 if($width>$setwidth){
				$ratio=$setwidth/$width;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				$newheight = $height ;
            	$newwidth = $width ;
			 }
			/*if($height>$setheight){
				$ratio=$setheight/$height;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				  $newheight =350;
			 }*/
			 

			 $InsertImage4=$imagefleimagename4;

			move_uploaded_file($_FILES["image4fleimage"]['tmp_name'], "$ImagePath".$InsertImage4);
			
			
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight, $width,$height);
			$InsertImagethumb4 = $imagefleimagename4;
			$imagefleimagename = "$ImageThumbPath/". $InsertImagethumb4;
				
			imagejpeg($tmp,$imagefleimagename,100);
			imagedestroy($src);
			imagedestroy($tmp);
	//////---------------End Upload Brand Image------------////////////
}	
//================================ Image 4 End==============================

// ======================= image 5 =========================
if(	$imagefleimagename5!=""){
	$flagImage5	=5;
	//check if image has 2 dot then exit program
			//$catfile = $imagefleimagename1;
			$image = $imagefleimagename5;
			$uploadedfile = $imagefleimagename5;
			$imagefleimagename5 = stripslashes($imagefleimagename5);
			$extension = getExtension($imagefleimagename5);
			$extension = strtolower($extension);
			/*-------------------------------*/
			/*---------------------------------*/
			if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png")) {
					header('Location: ../product-list.php?m=16&id='.$id);
					exit();
			}
			if($extension=="jpg" || $extension=="jpeg" ){
				$uploadedfile = $imagefleimagename5_tmp;
				$src = imagecreatefromjpeg($uploadedfile);
			}else if($extension=="png"){
				$uploadedfile = $imagefleimagename5_tmp;
				$src = imagecreatefrompng($uploadedfile);
			}else {
				$src = imagecreatefromgif($uploadedfile);
			}
			list($width,$height)=getimagesize($uploadedfile);
			 $setwidth=400;
			 $ratio=0.0;
			 if($width>$setwidth){
				$ratio=$setwidth/$width;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				$newheight = $height ;
            	$newwidth = $width ;
			 }
			/*if($height>$setheight){
				$ratio=$setheight/$height;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				  $newheight =350;
			 }*/
			 

			 $InsertImage5=$imagefleimagename5;

			move_uploaded_file($_FILES["image5fleimage"]['tmp_name'], "$ImagePath".$InsertImage5);
			
			
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight, $width,$height);
			$InsertImagethumb5 = $imagefleimagename5;
			$imagefleimagename = "$ImageThumbPath/". $InsertImagethumb5;
				
			imagejpeg($tmp,$imagefleimagename,100);
			imagedestroy($src);
			imagedestroy($tmp);
	//////---------------End Upload Brand Image------------////////////
}	
//================================ Image 5 End==============================
// ======================= image 6 =========================
if(	$imagefleimagename6!=""){
	$flagImage6	=6;
	//check if image has 2 dot then exit program
			//$catfile = $imagefleimagename1;
			$image = $imagefleimagename6;
			$uploadedfile = $imagefleimagename6;
			$imagefleimagename6 = stripslashes($imagefleimagename6);
			$extension = getExtension($imagefleimagename6);
			$extension = strtolower($extension);
			/*-------------------------------*/
			/*---------------------------------*/
			if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png")) {
					header('Location: ../product-list.php?m=16&id='.$id);
					exit();
			}
			if($extension=="jpg" || $extension=="jpeg" ){
				$uploadedfile = $imagefleimagename6_tmp;
				$src = imagecreatefromjpeg($uploadedfile);
			}else if($extension=="png"){
				$uploadedfile = $imagefleimagename6_tmp;
				$src = imagecreatefrompng($uploadedfile);
			}else {
				$src = imagecreatefromgif($uploadedfile);
			}
			list($width,$height)=getimagesize($uploadedfile);
			 $setwidth=400;
			 $ratio=0.0;
			 if($width>$setwidth){
				$ratio=$setwidth/$width;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				$newheight = $height ;
            	$newwidth = $width ;
			 }
			/*if($height>$setheight){
				$ratio=$setheight/$height;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				  $newheight =350;
			 }*/
			 

			 $InsertImage6=$imagefleimagename6;

			move_uploaded_file($_FILES["image6fleimage"]['tmp_name'], "$ImagePath".$InsertImage6);
			
			
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight, $width,$height);
			$InsertImagethumb6 = $imagefleimagename6;
			$imagefleimagename = "$ImageThumbPath/". $InsertImagethumb6;
				
			imagejpeg($tmp,$imagefleimagename,100);
			imagedestroy($src);
			imagedestroy($tmp);
	//////---------------End Upload Brand Image------------////////////
}	
//================================ Image 6 End==============================


/*----------------------------------------------*/


$sqladd = mysqli_query($conn,"update tbl_product set 
category_id='$category',
sub_category_id='$subcategory',
productname='$name',
url='$url',
skucode='$skucode',
short_description='$shortdescription',
image1='$InsertImage1',
thumb1='$InsertImagethumb1',
image2='$InsertImage2',
thumb2='$InsertImagethumb2',
image3='$InsertImage3',
thumb3='$InsertImagethumb3',
image4='$InsertImage4',
thumb4='$InsertImagethumb4',
image5='$InsertImage5',
thumb5='$InsertImagethumb5',
image6='$InsertImage6',
thumb6='$InsertImagethumb6',
status='$status',
ordernumber='$ordernumber',
long_description='$longdescription',
minorderqty='$miqty',
metakeyword='$metakeyword',
metadescription='$metadescription',
metatitle='$metatitle'
where id = '$id'") or die(mysqli_error($conn));

		// Delete product price and stock
		//$del= mysqli_query($conn,"delete from tbl_product_stock where productId = '$txtproductid'");
    	$del = mysqli_query($conn,"delete from tbl_product_price where productId = '$txtproductid'");
     
    	// Delete product price and stock close



 if(mysqli_affected_rows($conn) > 0)
	{
		if($flagImage1==1){
			if($Un_OrginalImage1!=""){
				unlink($ImagePath.$Un_OrginalImage1);
				unlink($ImageThumbPath.$Un_Image1);
			}
		}
		if($flagImage2==2){
			if($Un_OrginalImage2!=""){
				unlink($ImagePath.$Un_OrginalImage2);
				unlink($ImageThumbPath.$Un_Image2);
			}
		}
		if($flagImage3==3){
			if($Un_OrginalImage3!=""){
				unlink($ImagePath.$Un_OrginalImage3);
				unlink($ImageThumbPath.$Un_Image3);
			}
		}
		if($flagImage4==4){
			if($Un_OrginalImage4!=""){
				unlink($ImagePath.$Un_OrginalImage4);
				unlink($ImageThumbPath.$Un_Image4);
			}
		}
		if($flagImage5==5){
			if($Un_OrginalImage5!=""){
				unlink($ImagePath.$Un_OrginalImage5);
				unlink($ImageThumbPath.$Un_Image5);
			}
		}
		if($flagImage6==6){
			if($Un_OrginalImage6!=""){
				unlink($ImagePath.$Un_OrginalImage6);
				unlink($ImageThumbPath.$Un_Image6);
			}
		}


					// insert in price 
         for($i=0;$i<=8;$i++)
            {

             $size[$i]	 = 	mysqli_real_escape_string($conn,$_POST['size'][$i]);
          $unit[$i]	 = 	mysqli_real_escape_string($conn,$_POST['unit'][$i]);
          $price[$i] = 	mysqli_real_escape_string($conn,$_POST['price'][$i]);
          $mrp[$i] = 	mysqli_real_escape_string($conn,$_POST['listprice'][$i]);
        $stock[$i] = 	mysqli_real_escape_string($conn,$_POST['stock'][$i]);
       
       
                
            $query99=mysqli_query($conn,"insert into tbl_product_price (productId,varient_id,psize,punit,pprice,pmrp,pdate,status,pqty) values ('$txtproductid','$txtvarientid','$size[$i]','$unit[$i]','$price[$i]','$mrp[$i]','$date','$status','$stock[$i]')");
            
        $del=mysqli_query($conn,"delete from tbl_product_price where pprice='0' or pprice=''");

	 // header('Location: ../cartupdate.php?id='.$id);
		// echo "success";
		header('Location: ../product-list.php?m=4');
	}

	// header('Location: ../product-list.php?m=4');
}

	else
	{
		header('Location: ../product-list.php?m=5');
	}
} 


	/*--------Add Gallery-----------------------------------------------*/

function addGallery($conn)
{  	
	$name		= mysqli_real_escape_string($conn,$_POST['txtname']); 

	
	if(isset($_POST['txtstatus'])){$status=1;}else{$status=0;}

	$imagefleimagename1 			= $_FILES['image1fleimage']['name']; 
	$imagefleimagename1_tmp 		= $_FILES['image1fleimage']['tmp_name'];

	//---------------------condition--check dots------------------------ 
	$dots=substr_count($imagefleimagename1, '.');
	if($dots>1){header('Location: ../gallery.php?m=2&n=Rooms Image');exit(0);}
	//------------------------------------------------------------------
		//------now clear all condtion is good-------------if two image not avale-----
	function getExtension($str) {
		$i = strrpos($str,".");
         if (!$i) { return ""; } 

         $l = strlen($str) - $i;
         $ext = substr($str,$i+1,$l);
         return $ext;
	}
			$no = rand(1,999);
			$tno = rand(1,999);	
	///////--------------Upload Logo Image-----------------////////////


	global $galleryPath;	
	global $galleryPathThumb;	
	$ImagePath = "$galleryPath/";
	$ImageThumbPath = "$galleryPathThumb/";
	//================================ Image 1 ==============================	

	if(	$imagefleimagename1!=""){
			//check if image has 2 dot then exit program
			//$catfile = $imagefleimagename1;
			$image = $imagefleimagename1;
			$uploadedfile = $imagefleimagename1;
			$imagefleimagename1 = stripslashes($imagefleimagename1);
			$extension = getExtension($imagefleimagename1);
			$extension = strtolower($extension);
			/*-------------------------------*/
			/*---------------------------------*/
			if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") ) {
					header('Location: ../category.php?m=3');
					exit();
			}
			if($extension=="jpg" || $extension=="jpeg" ){
				$uploadedfile = $imagefleimagename1_tmp;
				$src = imagecreatefromjpeg($uploadedfile);
			}else if($extension=="png"){
				$uploadedfile = $imagefleimagename1_tmp;
				$src = imagecreatefrompng($uploadedfile);
			}else {
				$src = imagecreatefromgif($uploadedfile);
			}
			list($width,$height)=getimagesize($uploadedfile);
			 $setheight=400;
			 $ratio=0.0;
			 /*if($width>$setwidth){
				$ratio=$setwidth/$width;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				$newheight = $height ;
            	$newwidth = $width ;
			 }*/
			if($height>$setheight){
				$ratio=$setheight/$height;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				  $newheight = $height ;
            	  $newwidth = $width ;
			 }
			 $newfile1=$imagefleimagename1;

			move_uploaded_file($_FILES["image1fleimage"]['tmp_name'], "$ImagePath".$newfile1);
			
			
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight, $width,$height);
			$imageThumbName = $imagefleimagename1;
			$imagefleimagename = "$ImageThumbPath/". $imageThumbName;
				
			imagejpeg($tmp,$imagefleimagename,100);
			imagedestroy($src);
			imagedestroy($tmp);
			

	//////---------------End Image 1 end------------////////////
	}else{
	$newfile1="";
	 $imageThumbName="";
	}


	$sql="insert into  tbl_gallery(name,image,thumb,status) values('$name','$newfile1','$imageThumbName','$status')";
	if(mysqli_query($conn,$sql) or die(mysqli_error($conn)))
	{
		header('Location: ../gallery-list.php?m=1');
		//echo "success";
	}
	else
	{
		header('Location: ../gallery-list.php?m=0');
		//echo "fail";
	}
} 	
   /*--------Add Gallery close-----------------------------------------------*/

   /*--------Delete Gallery -----------------------------------------------*/	
   function deleteGallery($conn)
{
	$id =isset($_GET['id'])? $_GET['id'] : "";
	//echo "value is ".$id;
	
	$del =	"delete from tbl_gallery where id = '$id' ";

	if(mysqli_query($conn,$del) or die(mysqli_error($conn)))
	{
			
		header('Location: ../gallery-list.php?&m=6');
	}
	else
	{
	
		header('Location: ../gallery-list.php?m=7');
	}

}
 /*--------Delete Gallery close-----------------------------------------------*/
  /*--------Edit Gallery close-----------------------------------------------*/

 function editGallery($conn)
{

	$id				    = $_POST['txtid']; 
	$name		= mysqli_real_escape_string($conn,$_POST['txtname']); 
	
	if(isset($_POST['txtstatus'])){$status=1;}else{$status=0;} 

	$imagefleimagename1 			= $_FILES['image1fleimage']['name']; 
	$imagefleimagename1_tmp 		= $_FILES['image1fleimage']['tmp_name'];

	//------now clear all condtion is good-------------if two image not avale-----
function getExtension($str) {
	$i = strrpos($str,".");
	 if (!$i) { return ""; } 

	 $l = strlen($str) - $i;
	 $ext = substr($str,$i+1,$l);
	 return $ext;
}

// ------------- get all images  name  -------------------------
$sel = mysqli_query($conn,"select * from tbl_gallery where id = '$id' ");
$row = mysqli_fetch_assoc($sel);
$Un_OrginalImage1 	= $row['image'];	
$Un_Image1 			= $row['thumb'];

/*--------------insert record varible record------------*/
$InsertImage1 				= $row['image'];	
$InsertImagethumb1 			= $row['thumb'];

/*---------------------------*/
$flagImage1		=0;
$flagImage2		=0;
// ------------- get all images  name  -------------------------	
			$no = rand(1,999);
			$tno = rand(1,999);	
///////--------------Upload Logo Image-----------------////////////
 	global $galleryPath;	
	global $galleryPathThumb;	
	$ImagePath = "$galleryPath/";
	$ImageThumbPath = "$galleryPathThumb/";
//================================ Image 1 ==============================	
if(	$imagefleimagename1!=""){
	$flagImage1		=1;
	//check if image has 2 dot then exit program
			//$catfile = $imagefleimagename1;
			$image = $imagefleimagename1;
			$uploadedfile = $imagefleimagename1;
			$imagefleimagename1 = stripslashes($imagefleimagename1);
			$extension = getExtension($imagefleimagename1);
			$extension = strtolower($extension);
			/*-------------------------------*/
			/*---------------------------------*/
			if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png")) {
					header('Location: ../category-list.php?m=16&id='.$id);
					exit();
			}
			if($extension=="jpg" || $extension=="jpeg" ){
				$uploadedfile = $imagefleimagename1_tmp;
				$src = imagecreatefromjpeg($uploadedfile);
			}else if($extension=="png"){
				$uploadedfile = $imagefleimagename1_tmp;
				$src = imagecreatefrompng($uploadedfile);
			}else {
				$src = imagecreatefromgif($uploadedfile);
			}
			list($width,$height)=getimagesize($uploadedfile);
			 $setwidth=400;
			 $ratio=0.0;
			 if($width>$setwidth){
				$ratio=$setwidth/$width;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				$newheight = $height ;
            	$newwidth = $width ;
			 }
			/*if($height>$setheight){
				$ratio=$setheight/$height;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				  $newheight =350;
			 }*/
			 

			 $InsertImage1=$imagefleimagename1;

			move_uploaded_file($_FILES["image1fleimage"]['tmp_name'], "$ImagePath".$InsertImage1);
			
			
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight, $width,$height);
			$InsertImagethumb1 = $imagefleimagename1;
			$imagefleimagename = "$ImageThumbPath/". $InsertImagethumb1;
				
			imagejpeg($tmp,$imagefleimagename,100);
			imagedestroy($src);
			imagedestroy($tmp);
	//////---------------End Upload Brand Image------------////////////
}	



	$sqladd = mysqli_query($conn,"update tbl_gallery set 
	name='$name',
	image='$InsertImage1',
	thumb='$InsertImagethumb1',
	status='$status'
	 where id = '$id'") or die(mysqli_error($conn));
	if(mysqli_affected_rows($conn) > 0)
	{
		// echo "1";
		header('Location: ../gallery-list.php?m=4');
	}
	else
	{
		// echo "0";
		header('Location: ../gallery-list.php?m=5');
	}

} 
 /*--------Edit Gallery close-----------------------------------------------*/
 /*--------Add Blogs-----------------------------------------------*/

function addBlog($conn)
{  	
	$name		= mysqli_real_escape_string($conn,$_POST['txtname']); 
	$desc		= mysqli_real_escape_string($conn,$_POST['txtdescription']);

	
	if(isset($_POST['txtstatus'])){$status=1;}else{$status=0;}

	$imagefleimagename1 			= $_FILES['image1fleimage']['name']; 
	$imagefleimagename1_tmp 		= $_FILES['image1fleimage']['tmp_name'];

	//---------------------condition--check dots------------------------ 
	$dots=substr_count($imagefleimagename1, '.');
	if($dots>1){header('Location: ../blog.php?m=2&n=Rooms Image');exit(0);}
	//------------------------------------------------------------------
		//------now clear all condtion is good-------------if two image not avale-----
	function getExtension($str) {
		$i = strrpos($str,".");
         if (!$i) { return ""; } 

         $l = strlen($str) - $i;
         $ext = substr($str,$i+1,$l);
         return $ext;
	}
			$no = rand(1,999);
			$tno = rand(1,999);	
	///////--------------Upload Logo Image-----------------////////////


	global $blogPath;	
	global $blogPathThumb;	
	$ImagePath = "$blogPath/";
	$ImageThumbPath = "$blogPathThumb/";
	//================================ Image 1 ==============================	

	if(	$imagefleimagename1!=""){
			//check if image has 2 dot then exit program
			//$catfile = $imagefleimagename1;
			$image = $imagefleimagename1;
			$uploadedfile = $imagefleimagename1;
			$imagefleimagename1 = stripslashes($imagefleimagename1);
			$extension = getExtension($imagefleimagename1);
			$extension = strtolower($extension);
			/*-------------------------------*/
			/*---------------------------------*/
			if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") ) {
					header('Location: ../blog.php?m=3');
					exit();
			}
			if($extension=="jpg" || $extension=="jpeg" ){
				$uploadedfile = $imagefleimagename1_tmp;
				$src = imagecreatefromjpeg($uploadedfile);
			}else if($extension=="png"){
				$uploadedfile = $imagefleimagename1_tmp;
				$src = imagecreatefrompng($uploadedfile);
			}else {
				$src = imagecreatefromgif($uploadedfile);
			}
			list($width,$height)=getimagesize($uploadedfile);
			 $setheight=400;
			 $ratio=0.0;
			 /*if($width>$setwidth){
				$ratio=$setwidth/$width;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				$newheight = $height ;
            	$newwidth = $width ;
			 }*/
			if($height>$setheight){
				$ratio=$setheight/$height;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				  $newheight = $height ;
            	  $newwidth = $width ;
			 }
			 $newfile1=$imagefleimagename1;

			move_uploaded_file($_FILES["image1fleimage"]['tmp_name'], "$ImagePath".$newfile1);
			
			
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight, $width,$height);
			$imageThumbName = $imagefleimagename1;
			$imagefleimagename = "$ImageThumbPath/". $imageThumbName;
				
			imagejpeg($tmp,$imagefleimagename,100);
			imagedestroy($src);
			imagedestroy($tmp);
			

	//////---------------End Image 1 end------------////////////
	}else{
	$newfile1="";
	 $imageThumbName="";
	}


	$sql="insert into  tbl_blog(name,description,image,thumb,date,status) values('$name','$desc','$newfile1','$imageThumbName',now(),'$status')";
	if(mysqli_query($conn,$sql) or die(mysqli_error($conn)))
	{
		header('Location: ../blog-list.php?m=1');
		//echo "success";
	}
	else
	{
		header('Location: ../blog-list.php?m=0');
		//echo "fail";
	}
} 	
   /*--------Add Blog close-----------------------------------------------*/

   /*--------Delete Blog -----------------------------------------------*/	
   function deleteBlog($conn)
{
	$id =isset($_GET['id'])? $_GET['id'] : "";
	//echo "value is ".$id;
	
	$del =	"delete from tbl_blog where id = '$id' ";

	if(mysqli_query($conn,$del) or die(mysqli_error($conn)))
	{
			
		header('Location: ../blog-list.php?&m=6');
	}
	else
	{
	
		header('Location: ../blog-list.php?m=7');
	}

}
 /*--------Delete Blog close-----------------------------------------------*/
  /*--------Edit Blog close-----------------------------------------------*/

 function editBlog($conn)
{

	$id				    = $_POST['txtid']; 
	$name		= mysqli_real_escape_string($conn,$_POST['txtname']); 
	$desc		= mysqli_real_escape_string($conn,$_POST['txtdescription']);
	
	if(isset($_POST['txtstatus'])){$status=1;}else{$status=0;} 

	$imagefleimagename1 			= $_FILES['image1fleimage']['name']; 
	$imagefleimagename1_tmp 		= $_FILES['image1fleimage']['tmp_name'];

	//------now clear all condtion is good-------------if two image not avale-----
function getExtension($str) {
	$i = strrpos($str,".");
	 if (!$i) { return ""; } 

	 $l = strlen($str) - $i;
	 $ext = substr($str,$i+1,$l);
	 return $ext;
}

// ------------- get all images  name  -------------------------
$sel = mysqli_query($conn,"select * from tbl_blog where id = '$id' ");
$row = mysqli_fetch_assoc($sel);
$Un_OrginalImage1 	= $row['image'];	
$Un_Image1 			= $row['thumb'];

/*--------------insert record varible record------------*/
$InsertImage1 				= $row['image'];	
$InsertImagethumb1 			= $row['thumb'];

/*---------------------------*/
$flagImage1		=0;
$flagImage2		=0;
// ------------- get all images  name  -------------------------	
			$no = rand(1,999);
			$tno = rand(1,999);	
///////--------------Upload Logo Image-----------------////////////
 	global $blogPath;	
	global $blogPathThumb;	
	$ImagePath = "$blogPath/";
	$ImageThumbPath = "$blogPathThumb/";
//================================ Image 1 ==============================	
if(	$imagefleimagename1!=""){
	$flagImage1		=1;
	//check if image has 2 dot then exit program
			//$catfile = $imagefleimagename1;
			$image = $imagefleimagename1;
			$uploadedfile = $imagefleimagename1;
			$imagefleimagename1 = stripslashes($imagefleimagename1);
			$extension = getExtension($imagefleimagename1);
			$extension = strtolower($extension);
			/*-------------------------------*/
			/*---------------------------------*/
			if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png")) {
					header('Location: ../blog-list.php?m=16&id='.$id);
					exit();
			}
			if($extension=="jpg" || $extension=="jpeg" ){
				$uploadedfile = $imagefleimagename1_tmp;
				$src = imagecreatefromjpeg($uploadedfile);
			}else if($extension=="png"){
				$uploadedfile = $imagefleimagename1_tmp;
				$src = imagecreatefrompng($uploadedfile);
			}else {
				$src = imagecreatefromgif($uploadedfile);
			}
			list($width,$height)=getimagesize($uploadedfile);
			 $setwidth=400;
			 $ratio=0.0;
			 if($width>$setwidth){
				$ratio=$setwidth/$width;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				$newheight = $height ;
            	$newwidth = $width ;
			 }
			/*if($height>$setheight){
				$ratio=$setheight/$height;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				  $newheight =350;
			 }*/
			 

			 $InsertImage1=$imagefleimagename1;

			move_uploaded_file($_FILES["image1fleimage"]['tmp_name'], "$ImagePath".$InsertImage1);
			
			
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight, $width,$height);
			$InsertImagethumb1 = $imagefleimagename1;
			$imagefleimagename = "$ImageThumbPath/". $InsertImagethumb1;
				
			imagejpeg($tmp,$imagefleimagename,100);
			imagedestroy($src);
			imagedestroy($tmp);
	//////---------------End Upload Brand Image------------////////////
}	



	$sqladd = mysqli_query($conn,"update tbl_blog set 
	name='$name',
	description='$desc',
	image='$InsertImage1',
	thumb='$InsertImagethumb1',
	status='$status'
	 where id = '$id'") or die(mysqli_error($conn));
	if(mysqli_affected_rows($conn) > 0)
	{
		// echo "1";
		header('Location: ../blog-list.php?m=4');
	}
	else
	{
		// echo "0";
		header('Location: ../blog-list.php?m=5');
	}

} 
 /*--------Edit Blog close-----------------------------------------------*/
    /*--------Delete ContactEnquiry -----------------------------------------------*/	
   function deleteContactEnquiry($conn)
{
	$id =isset($_GET['id'])? $_GET['id'] : "";
	//echo "value is ".$id;
	
	$del =	"delete from tbl_contact where id = '$id' ";

	if(mysqli_query($conn,$del) or die(mysqli_error($conn)))
	{
			
		header('Location: ../contact-enquiry-list.php?&m=6');
	}
	else
	{
	
		header('Location: ../contact-enquiry-list.php?m=7');
	}

}
 /*--------Delete ContactEnquiry close-----------------------------------------------*/
      /*--------Delete Suggestions -----------------------------------------------*/	
   function deleteSuggestion($conn)
{
	$id =isset($_GET['id'])? $_GET['id'] : "";
	//echo "value is ".$id;
	
	$del =	"delete from tbl_suggestion where id = '$id' ";

	if(mysqli_query($conn,$del) or die(mysqli_error($conn)))
	{
			
		header('Location: ../suggestion-list.php?&m=6');
	}
	else
	{
	
		header('Location: ../suggestion-list.php?m=7');
	}

}
 /*--------Delete suggestion list close-----------------------------------------------*/
   /*--------Add Offer-----------------------------------------------*/

function addOffer($conn)
{  	
	$name		= mysqli_real_escape_string($conn,$_POST['txtname']); 

	
	if(isset($_POST['txtstatus'])){$status=1;}else{$status=0;}

	$imagefleimagename1 			= $_FILES['image1fleimage']['name']; 
	$imagefleimagename1_tmp 		= $_FILES['image1fleimage']['tmp_name'];

	//---------------------condition--check dots------------------------ 
	$dots=substr_count($imagefleimagename1, '.');
	if($dots>1){header('Location: ../offer.php?m=2&n=Rooms Image');exit(0);}
	//------------------------------------------------------------------
		//------now clear all condtion is good-------------if two image not avale-----
	function getExtension($str) {
		$i = strrpos($str,".");
         if (!$i) { return ""; } 

         $l = strlen($str) - $i;
         $ext = substr($str,$i+1,$l);
         return $ext;
	}
			$no = rand(1,999);
			$tno = rand(1,999);	
	///////--------------Upload Logo Image-----------------////////////


	global $offerPath;	
	global $offerPathThumb;	
	$ImagePath = "$offerPath/";
	$ImageThumbPath = "$offerPathThumb/";
	//================================ Image 1 ==============================	

	if(	$imagefleimagename1!=""){
			//check if image has 2 dot then exit program
			//$catfile = $imagefleimagename1;
			$image = $imagefleimagename1;
			$uploadedfile = $imagefleimagename1;
			$imagefleimagename1 = stripslashes($imagefleimagename1);
			$extension = getExtension($imagefleimagename1);
			$extension = strtolower($extension);
			/*-------------------------------*/
			/*---------------------------------*/
			if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") ) {
					header('Location: ../offer.php?m=3');
					exit();
			}
			if($extension=="jpg" || $extension=="jpeg" ){
				$uploadedfile = $imagefleimagename1_tmp;
				$src = imagecreatefromjpeg($uploadedfile);
			}else if($extension=="png"){
				$uploadedfile = $imagefleimagename1_tmp;
				$src = imagecreatefrompng($uploadedfile);
			}else {
				$src = imagecreatefromgif($uploadedfile);
			}
			list($width,$height)=getimagesize($uploadedfile);
			 $setheight=400;
			 $ratio=0.0;
			 /*if($width>$setwidth){
				$ratio=$setwidth/$width;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				$newheight = $height ;
            	$newwidth = $width ;
			 }*/
			if($height>$setheight){
				$ratio=$setheight/$height;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				  $newheight = $height ;
            	  $newwidth = $width ;
			 }
			 $newfile1=$imagefleimagename1;

			move_uploaded_file($_FILES["image1fleimage"]['tmp_name'], "$ImagePath".$newfile1);
			
			
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight, $width,$height);
			$imageThumbName = $imagefleimagename1;
			$imagefleimagename = "$ImageThumbPath/". $imageThumbName;
				
			imagejpeg($tmp,$imagefleimagename,100);
			imagedestroy($src);
			imagedestroy($tmp);
			

	//////---------------End Image 1 end------------////////////
	}else{
	$newfile1="";
	 $imageThumbName="";
	}


	$sql="insert into  tbl_offer(name,image,thumb,status) values('$name','$newfile1','$imageThumbName','$status')";
	if(mysqli_query($conn,$sql) or die(mysqli_error($conn)))
	{
		header('Location: ../offer-list.php?m=1');
		//echo "success";
	}
	else
	{
		header('Location: ../offer-list.php?m=0');
		//echo "fail";
	}
} 	
   /*--------Add Offer close-----------------------------------------------*/

   /*--------Delete Offer -----------------------------------------------*/	
   function deleteOffer($conn)
{
	$id =isset($_GET['id'])? $_GET['id'] : "";
	//echo "value is ".$id;
	
	$del =	"delete from tbl_offer where id = '$id' ";

	if(mysqli_query($conn,$del) or die(mysqli_error($conn)))
	{
			
		header('Location: ../offer-list.php?&m=6');
	}
	else
	{
	
		header('Location: ../offer-list.php?m=7');
	}

}
 /*--------Delete Offer close-----------------------------------------------*/
  /*--------Edit Banner close-----------------------------------------------*/

 function editOffer($conn)
{

	$id				    = $_POST['txtid']; 
	
	$name		= mysqli_real_escape_string($conn,$_POST['txtname']); 

	
	if(isset($_POST['txtstatus'])){$status=1;}else{$status=0;} 

	$imagefleimagename1 			= $_FILES['image1fleimage']['name']; 
	$imagefleimagename1_tmp 		= $_FILES['image1fleimage']['tmp_name'];

	//------now clear all condtion is good-------------if two image not avale-----
function getExtension($str) {
	$i = strrpos($str,".");
	 if (!$i) { return ""; } 

	 $l = strlen($str) - $i;
	 $ext = substr($str,$i+1,$l);
	 return $ext;
}

// ------------- get all images  name  -------------------------
$sel = mysqli_query($conn,"select * from tbl_offer where id = '$id' ");
$row = mysqli_fetch_assoc($sel);
$Un_OrginalImage1 	= $row['image'];	
$Un_Image1 			= $row['thumb'];

/*--------------insert record varible record------------*/
$InsertImage1 				= $row['image'];	
$InsertImagethumb1 			= $row['thumb'];

/*---------------------------*/
$flagImage1		=0;
$flagImage2		=0;
// ------------- get all images  name  -------------------------	
			$no = rand(1,999);
			$tno = rand(1,999);	
///////--------------Upload Logo Image-----------------////////////
 	global $offerPath;	
	global $offerPathThumb;	
	$ImagePath = "$offerPath/";
	$ImageThumbPath = "$offerPathThumb/";
//================================ Image 1 ==============================	
if(	$imagefleimagename1!=""){
	$flagImage1		=1;
	//check if image has 2 dot then exit program
			//$catfile = $imagefleimagename1;
			$image = $imagefleimagename1;
			$uploadedfile = $imagefleimagename1;
			$imagefleimagename1 = stripslashes($imagefleimagename1);
			$extension = getExtension($imagefleimagename1);
			$extension = strtolower($extension);
			/*-------------------------------*/
			/*---------------------------------*/
			if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png")) {
					header('Location: ../banner-list.php?m=16&id='.$id);
					exit();
			}
			if($extension=="jpg" || $extension=="jpeg" ){
				$uploadedfile = $imagefleimagename1_tmp;
				$src = imagecreatefromjpeg($uploadedfile);
			}else if($extension=="png"){
				$uploadedfile = $imagefleimagename1_tmp;
				$src = imagecreatefrompng($uploadedfile);
			}else {
				$src = imagecreatefromgif($uploadedfile);
			}
			list($width,$height)=getimagesize($uploadedfile);
			 $setwidth=400;
			 $ratio=0.0;
			 if($width>$setwidth){
				$ratio=$setwidth/$width;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				$newheight = $height ;
            	$newwidth = $width ;
			 }
			/*if($height>$setheight){
				$ratio=$setheight/$height;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				  $newheight =350;
			 }*/
			 

			 $InsertImage1=$imagefleimagename1;

			move_uploaded_file($_FILES["image1fleimage"]['tmp_name'], "$ImagePath".$InsertImage1);
			
			
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight, $width,$height);
			$InsertImagethumb1 = $imagefleimagename1;
			$imagefleimagename = "$ImageThumbPath/". $InsertImagethumb1;
				
			imagejpeg($tmp,$imagefleimagename,100);
			imagedestroy($src);
			imagedestroy($tmp);
	//////---------------End Upload Brand Image------------////////////
}	



	$sqladd = mysqli_query($conn,"update tbl_offer set 
	name='$name',
	image='$InsertImage1',
	thumb='$InsertImagethumb1',
	status='$status'
	 where id = '$id'") or die(mysqli_error($conn));
	if(mysqli_affected_rows($conn) > 0)
	{
		// echo "1";
		header('Location: ../offer-list.php?m=4');
	}
	else
	{
		// echo "0";
		header('Location: ../offer-list.php?m=5');
	}

} 
 /*--------Edit offer close-----------------------------------------------*/
     /*--------Delete Order offer -----------------------------------------------*/	
   function deleteOrder($conn)
{
	$orderid =isset($_GET['orderid'])? $_GET['orderid'] : "";
	//echo "value is ".$id;
	
	$del =	"delete from order_master where orderId = '$orderid'";

	if(mysqli_query($conn,$del) or die(mysqli_error($conn)))
	{
			
		header('Location: ../order-list.php?&m=6');
	}
	else
	{
	
		header('Location: ../order-list.php?m=7');
	}

}
 /*--------Delete order close-----------------------------------------------*/

   /*--------Add Promo code-----------------------------------------------*/

function addPromocode($conn)
{  	
	$couponcode		= mysqli_real_escape_string($conn,$_POST['txtcouponcode']); 
	$couponvalue		= mysqli_real_escape_string($conn,$_POST['txtcouponvalue']); 
	$mincartvalue		= mysqli_real_escape_string($conn,$_POST['txtmincartvalue']);
	$short_description		= mysqli_real_escape_string($conn,$_POST['txtshortdescription']);

	$date=date('d/m/Y H:i', time());	 
	
	if(isset($_POST['txtstatus'])){$status=1;}else{$status=0;}


	$sql="insert into  tbl_coupon_master(coupon_code,coupon_value,short_description,date,cart_min_value,status) values('$couponcode','$couponvalue','$short_description','$date','$mincartvalue','$status')";

	if(mysqli_query($conn,$sql) or die(mysqli_error($conn)))
	{
		header('Location: ../promocode-list.php?m=1');
		//echo "success";
	}
	else
	{
		header('Location: ../promocode-list.php?m=0');
		//echo "fail";
	}
} 
   /*--------Add promocode close-----------------------------------------------*/	

 /*--------Delete deletePromocode -----------------------------------------------*/	
   function deletePromocode($conn)
{

	$id =isset($_GET['id'])? $_GET['id'] : "";
	//echo "value is ".$id;
			$del =	"delete from tbl_coupon_master where id = '$id' ";

			if(mysqli_query($conn,$del) or die(mysqli_error($conn)))
			{
				
				header('Location: ../promocode-list.php?&m=6');
			}
			else
			{
			
				header('Location: ../promocode-list.php?m=7');
			}
			
}
 /*--------promocode.php close-----------------------------------------------*/

  /*--------Edit editPromocode-----------------------------------------------*/

 function editPromocode($conn)
{

	$id				    = $_POST['txtid']; 
	$couponcode		= mysqli_real_escape_string($conn,$_POST['txtcouponcode']); 
	$couponvalue		= mysqli_real_escape_string($conn,$_POST['txtcouponvalue']); 
	$mincartvalue		= mysqli_real_escape_string($conn,$_POST['txtmincartvalue']);
	$short_description		= mysqli_real_escape_string($conn,$_POST['txtshortdescription']);
	
	if(isset($_POST['txtstatus'])){$status=1;}else{$status=0;} 

	$sqladd = mysqli_query($conn,"update tbl_coupon_master set 
	coupon_code='$couponcode',
	coupon_value='$couponvalue',
	short_description='$short_description',
	cart_min_value='$mincartvalue',
	status='$status'
	 where id = '$id'") or die(mysqli_error($conn));
	if(mysqli_affected_rows($conn) > 0)
	{
		// echo "1";
		header('Location: ../promocode-list.php?m=4');
	}
	else
	{
		// echo "0";
		header('Location: ../promocode-list.php?m=5');
	}

} 
 /*--------Edit promocode close-----------------------------------------------*/
      /*--------Delete promocode user -----------------------------------------------*/	
   function deletePromoCodeUser($conn)
{
	$id =isset($_GET['id'])? $_GET['id'] : "";
	//echo "value is ".$id;
	
	$del =	"delete from tbl_coupon_user where id = '$id' ";

	if(mysqli_query($conn,$del) or die(mysqli_error($conn)))
	{
			
		header('Location: ../promocode-user-list.php?&m=6');
	}
	else
	{
	
		header('Location: ../promocode-user-list.php?m=7');
	}

}
 /*--------Delete promocode user close-----------------------------------------------*/
 	      /*--------Delete Review -----------------------------------------------*/	
   function DeleteReview($conn)
{
	$id =isset($_GET['id'])? $_GET['id'] : "";
	//echo "value is ".$id;
	
	$del =	"delete from tbl_review where id = '$id' ";

	if(mysqli_query($conn,$del) or die(mysqli_error($conn)))
	{
			
		header('Location: ../review-list.php?&m=6');
	}
	else
	{
	
		header('Location: ../review-list.php?m=7');
	}

}
 /*--------Delete Review list close-----------------------------------------------*/
 	  /*--------Active Review -----------------------------------------------*/	
   function ActiveReview($conn)
{

	$id =isset($_GET['id'])? $_GET['id'] : "";
	//echo "value is ".$id;
	
	$del =	"update tbl_review set active_status='1' where id = '$id'";

	if(mysqli_query($conn,$del) or die(mysqli_error($conn)))
	{	
		
		header('Location: ../review-list.php?&m=6');
	}
	else
	{
	
		header('Location: ../review-list.php?m=7');
	}

}
 /*--------Active Review close-----------------------------------------------*/
   /*--------Deactive Review -----------------------------------------------*/	
   function DeactiveReview($conn)
{

	$id =isset($_GET['id'])? $_GET['id'] : "";
	//echo "value is ".$id;
	
	$del =	"update tbl_review set active_status='0' where id = '$id'";

	if(mysqli_query($conn,$del) or die(mysqli_error($conn)))
	{
		
		header('Location: ../review-list.php?&m=6');
	}
	else
	{
	
		header('Location: ../review-list.php?m=7');
	}

}
 /*--------Deactive Review close-----------------------------------------------*/
   	/*--------Add Invoice-----------------------------------------------*/

function addInvoice($conn)
{  	
	$name		  = mysqli_real_escape_string($conn,$_POST['txtname']);
	$address		  = mysqli_real_escape_string($conn,$_POST['txtaddress']); 
	$pincode		  = mysqli_real_escape_string($conn,$_POST['txtpincode']);  
	$mobile		  = mysqli_real_escape_string($conn,$_POST['txtmobile']); 
	$order_date		  = mysqli_real_escape_string($conn,$_POST['txtorderdate']); 
	$email		  = mysqli_real_escape_string($conn,$_POST['txtemail']); 
	$payment_method		  = mysqli_real_escape_string($conn,$_POST['selpaymentmethod']);
	$rand=rand(100000,999999);
	$tempinvoiceid="TEMP".$rand;
	$date=date('d/m/Y H:i', time());
	$rand2=rand(100000,999999);
    $invoice_number="KIRA".$rand2;

    $sql="insert into tbl_invoice(temp_invoiceid,name,email,mobile,pincode,invoice_number,order_date,date,status,payment_method,address) values('$tempinvoiceid','$name','$email','$mobile','$pincode','$invoice_number','$order_date','$date','1','$payment_method','$address')";

	if(mysqli_query($conn,$sql) or die(mysqli_error($conn)))
	{	
		 for($i=0;$i<=5;$i++)
            {
           
              $productname[$i]	 = 	mysqli_real_escape_string($conn,$_POST['productname'][$i]);
              $price[$i] = 	mysqli_real_escape_string($conn,$_POST['price'][$i]);
              $size[$i] = 	mysqli_real_escape_string($conn,$_POST['size'][$i]);
              $mrp[$i] = 	mysqli_real_escape_string($conn,$_POST['mrp'][$i]);
              $qty[$i]	 = 	mysqli_real_escape_string($conn,$_POST['qty'][$i]);
               
                if($productname[$i]!='')
                {
                     $query=mysqli_query($conn,"insert into tbl_invoice_product(invoice_id,invoice_number,product_name,size,qty,unit_price,mrp) values ('$tempinvoiceid','$invoice_number','$productname[$i]','$size[$i]','$qty[$i]','$price[$i]','$mrp[$i]')");

                    $del=mysqli_query($conn,"delete from tbl_invoice_product where product_name='0' or product_name=''");
 
                    header('Location: ../invoice-generate-list.php?m=1');
                }

             }
		
		//echo "success";
	}
	else
	{
		header('Location: ../invoice-generate-list.php?m=0');
		//echo "fail";
	}
} 	
   /*--------Add Invoice close-----------------------------------------------*/	
    /*--------Delete Invoice -----------------------------------------------*/	
   function deleteInvoice($conn)
{

	$id =isset($_GET['id'])? $_GET['id'] : "";
	$tempinvoiceid =isset($_GET['tempinvoiceid'])? $_GET['tempinvoiceid'] : "";
	//echo "value is ".$id;

			$del =	"delete from tbl_invoice where id = '$id' ";

			if(mysqli_query($conn,$del) or die(mysqli_error($conn)))
			{
				$del =	"delete from tbl_invoice_product where invoice_id = '$tempinvoiceid'";
				if(mysqli_query($conn,$del) or die(mysqli_error($conn)))
					{
						header('Location: ../invoice-generate-list.php?&m=6');
					}
				else{
					header('Location: ../invoice-generate-list.php?m=7');
				}	
				
			}
			else
			{
			
				header('Location: ../invoice-generate-list.php?m=7');
			}
  
}
 /*--------Delete Invoice close-----------------------------------------------*/

 /*--------Edit Invoice close-----------------------------------------------*/

 function editInvoice($conn)
{

	$id				        = $_POST['txtid']; 
	$tempinvoiveid  =	$_POST['txttempinvoiveid'];	
	$name		  = mysqli_real_escape_string($conn,$_POST['txtname']);
	$address		  = mysqli_real_escape_string($conn,$_POST['txtaddress']); 
	$pincode		  = mysqli_real_escape_string($conn,$_POST['txtpincode']);  
	$mobile		  = mysqli_real_escape_string($conn,$_POST['txtmobile']); 
	$order_date		  = mysqli_real_escape_string($conn,$_POST['txtorderdate']); 
	$email		  = mysqli_real_escape_string($conn,$_POST['txtemail']); 
	$payment_method		  = mysqli_real_escape_string($conn,$_POST['selpaymentmethod']);

	$sqladd = mysqli_query($conn,"update tbl_invoice set 
	name='$name',	
	email='$email',
	address='$address',
	pincode='$pincode',
	mobile='$mobile',
	payment_method='$payment_method',
	order_date='$order_date'
	where id = '$id'") or die(mysqli_error($conn));

	// Delete product in invoice
		$del= mysqli_query($conn,"delete from tbl_invoice_product where invoice_id = '$tempinvoiveid'");
    	
	if(mysqli_affected_rows($conn) > 0)
	{
		for($i=0;$i<=5;$i++)
            {
           
              $productname[$i]	 = 	mysqli_real_escape_string($conn,$_POST['productname'][$i]);
              $price[$i] = 	mysqli_real_escape_string($conn,$_POST['price'][$i]);
              $size[$i] = 	mysqli_real_escape_string($conn,$_POST['size'][$i]);
              $qty[$i]	 = 	mysqli_real_escape_string($conn,$_POST['qty'][$i]);
              $mrp[$i]	 = 	mysqli_real_escape_string($conn,$_POST['mrp'][$i]);
               
                if($productname[$i]!='')
                {
                     $query=mysqli_query($conn,"insert into tbl_invoice_product(invoice_id,product_name,size,qty,unit_price,mrp) values ('$tempinvoiveid','$productname[$i]','$size[$i]','$qty[$i]','$price[$i]','$mrp[$i]')");

                    
                    $del=mysqli_query($conn,"delete from tbl_invoice_product where product_name='0' or product_name=''");
 
                    header('Location: ../invoice-generate-list.php?m=4');
                }

             }
	}
	else
	{
		// echo "0";
		header('Location: ../invoice-generate-list.php?m=5');
	}

} 
/*--------Edit Invoice close-----------------------------------------------*/
	/*--------Add  COLOR-----------------------------------------------*/

function addColor($conn)
{  	

	$name		     = mysqli_real_escape_string($conn,$_POST['txtname']); 
	$colorcode		     = mysqli_real_escape_string($conn,$_POST['txtcolorcode']); 

	if(isset($_POST['txtstatus'])){$status=1;}else{$status=0;}

	$sql="insert into  tbl_color(name,status,color_code) values('$name','$status','$colorcode')";

	if(mysqli_query($conn,$sql) or die(mysqli_error($conn)))
	{
		header('Location: ../color-list.php?m=1');
		//echo "success";
	}
	else
	{
		header('Location: ../color-list.php?m=0');
		//echo "fail";
	}
} 	
   /*--------Add Color close-----------------------------------------------*/	
    /*--------Delete Color -----------------------------------------------*/	
   function deleteColor($conn)
{

	$id =isset($_GET['id'])? $_GET['id'] : "";
	//echo "value is ".$id;

			$del =	"delete from tbl_color where id = '$id' ";

			if(mysqli_query($conn,$del) or die(mysqli_error($conn)))
			{
				
				header('Location: ../color-list.php?&m=6');
			}
			else
			{
			
				header('Location: ../color-list.php?m=7');
			}
  
}
 /*--------Delete Color close-----------------------------------------------*/

 /*--------Edit Color close-----------------------------------------------*/

 function editColor($conn)
{

	$id				        = $_POST['txtid']; 
	$name		= mysqli_real_escape_string($conn,$_POST['txtname']);
	$colorcode		     = mysqli_real_escape_string($conn,$_POST['txtcolorcode']);  
	

	if(isset($_POST['txtstatus'])){$status=1;}else{$status=0;}
	
	$sqladd = mysqli_query($conn,"update tbl_color set 
	name='$name',
	status='$status',
	color_code='$colorcode'
	where id = '$id'") or die(mysqli_error($conn));
	if(mysqli_affected_rows($conn) > 0)
	{
		// echo "1";
		header('Location: ../color-list.php?m=4');
	}
	else
	{
		// echo "0";
		header('Location: ../color-list.php?m=5');
	}

} 
/*--------Edit Color close-----------------------------------------------*/
/*--------Add product Varient-----------------------------------------------*/
function addProductVarient($conn)
{  
	$varientId	                = 	mysqli_real_escape_string($conn,$_POST['txtvarientid']);
	$category	                = 	mysqli_real_escape_string($conn,$_POST['selcategory']);
	$subcategory	            = 	mysqli_real_escape_string($conn,$_POST['selsubcategory']);
		$subsubcategory	            = 	mysqli_real_escape_string($conn,$_POST['selsubsubcategory']);
	$color	            = 	mysqli_real_escape_string($conn,$_POST['selcolor']);
	$name	 				    = 	mysqli_real_escape_string($conn,$_POST['txtproductname']); 	
	$url					    = 	strtolower(str_replace(" ","-",$name));
	$url					    = 	strtolower(str_replace("&","and",$url));
  		
	$shortdescription		 	= 	mysqli_real_escape_string($conn,$_POST['txtshortdescription']); 
	$skucode		 			    = 	mysqli_real_escape_string($conn,$_POST['txtskucode']);
	 $rand=rand(100000,999999);
	 $productId="LZ".$rand;
      $date=date('d/m/Y H:i', time());
  //    $rand2=rand(100000,999999);
	 // $varientId="SHV".$rand2;	
	
	if(isset($_POST['txtstatus'])){$status=1;}else{$status=0;}
	if(isset($_POST['txtfeatured'])){$featured=1;}else{$featured=0;}
	if(isset($_POST['txtlatests'])){$latest=1;}else{$latest=0;}
		if(isset($_POST['txtproductpage'])){$productpage=1;}else{$productpage=0;}
	
	/*-------------------------Image info-----------------------------*/
	//------------------brand logo--------------------------
	$imagefleimagename1 			= $_FILES['image1fleimage']['name']; 
	$imagefleimagename1_tmp 		= $_FILES['image1fleimage']['tmp_name'];
	$imagefleimagename2 			= $_FILES['image2fleimage']['name']; 
	$imagefleimagename2_tmp 		= $_FILES['image2fleimage']['tmp_name'];
	$imagefleimagename3 			= $_FILES['image3fleimage']['name']; 
	$imagefleimagename3_tmp 		= $_FILES['image3fleimage']['tmp_name'];
	$imagefleimagename4 			= $_FILES['image4fleimage']['name']; 
	$imagefleimagename4_tmp 		= $_FILES['image4fleimage']['tmp_name'];
	$imagefleimagename5 			= $_FILES['image5fleimage']['name']; 
	$imagefleimagename5_tmp 		= $_FILES['image5fleimage']['tmp_name'];
	$imagefleimagename6 			= $_FILES['image6fleimage']['name']; 
	$imagefleimagename6_tmp 		= $_FILES['image6fleimage']['tmp_name'];
	//------------------brand img 1--------------------------
	//---------------------condition--check dots------------------------ 
	$dots=substr_count($imagefleimagename1, '.');
	if($dots>1){header('Location: ../product.php?m=2&n=Rooms Image');exit(0);}
	//------------------------------------------------------------------

	//-----------------------check compalsory image-------------------------------------------
	/*if($imagefleimagename1==""){
	header('Location: ../add-image.php?m=3&n=Product Image&id='.$productID);exit(0);
	}
	//----------------------------------------------------------------------------------------

	//-----------------------check compalsory image size--------------------------------------
	list($width1,$height1)=getimagesize($imagefleimagename1_tmp);
	if($width1<1000){
		header('Location: ../add-image.php?m=13&n=1000px Product Image&id=');exit(0);
	}
	//----------------------------------------------------------------------------------------*/
	//------now clear all condtion is good-------------if two image not avale-----
	function getExtension($str) {
		$i = strrpos($str,".");
         if (!$i) { return ""; } 

         $l = strlen($str) - $i;
         $ext = substr($str,$i+1,$l);
         return $ext;
	}
			$no = rand(1,999);
			$tno = rand(1,999);	
	///////--------------Upload Logo Image-----------------////////////


	global $productPath;	
	global $productPathThumb;	
	$ImagePath = "$productPath/";
	$ImageThumbPath = "$productPathThumb/";
	//================================ Image 1 ==============================	

	if(	$imagefleimagename1!=""){
			//check if image has 2 dot then exit program
			//$catfile = $imagefleimagename1;
			$image = $imagefleimagename1;
			$uploadedfile = $imagefleimagename1;
			$imagefleimagename1 = stripslashes($imagefleimagename1);
			$extension = getExtension($imagefleimagename1);
			$extension = strtolower($extension);
			/*-------------------------------*/
			/*---------------------------------*/
			if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") ) {
					header('Location: ../product.php?m=3');
					exit();
			}
			if($extension=="jpg" || $extension=="jpeg" ){
				$uploadedfile = $imagefleimagename1_tmp;
				$src = imagecreatefromjpeg($uploadedfile);
			}else if($extension=="png"){
				$uploadedfile = $imagefleimagename1_tmp;
				$src = imagecreatefrompng($uploadedfile);
			}else {
				$src = imagecreatefromgif($uploadedfile);
			}
			list($width,$height)=getimagesize($uploadedfile);
			 $setheight=400;
			 $ratio=0.0;
			 /*if($width>$setwidth){
				$ratio=$setwidth/$width;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				$newheight = $height ;
            	$newwidth = $width ;
			 }*/
			if($height>$setheight){
				$ratio=$setheight/$height;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				  $newheight = $height ;
            	  $newwidth = $width ;
			 }
			 $newfile1=$imagefleimagename1;

			move_uploaded_file($_FILES["image1fleimage"]['tmp_name'], "$ImagePath".$newfile1);
			
			
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight, $width,$height);
			$imageThumbName = $imagefleimagename1;
			$imagefleimagename = "$ImageThumbPath/". $imageThumbName;
				
			imagejpeg($tmp,$imagefleimagename,100);
			imagedestroy($src);
			imagedestroy($tmp);
			

	//////---------------End Image 1 end------------////////////
	}else{
	$newfile1="";
	 $imageThumbName="";
	}

		//================================ Image 2 ==============================	

	if(	$imagefleimagename2!=""){
			//check if image has 2 dot then exit program
			//$catfile = $imagefleimagename1;
			$image = $imagefleimagename2;
			$uploadedfile = $imagefleimagename2;
			$imagefleimagename2 = stripslashes($imagefleimagename2);
			$extension = getExtension($imagefleimagename2);
			$extension = strtolower($extension);
			/*-------------------------------*/
			/*---------------------------------*/
			if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") ) {
					header('Location: ../product.php?m=3');
					exit();
			}
			if($extension=="jpg" || $extension=="jpeg" ){
				$uploadedfile = $imagefleimagename2_tmp;
				$src = imagecreatefromjpeg($uploadedfile);
			}else if($extension=="png"){
				$uploadedfile = $imagefleimagename2_tmp;
				$src = imagecreatefrompng($uploadedfile);
			}else {
				$src = imagecreatefromgif($uploadedfile);
			}
			list($width,$height)=getimagesize($uploadedfile);
			 $setheight=400;
			 $ratio=0.0;
			 /*if($width>$setwidth){
				$ratio=$setwidth/$width;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				$newheight = $height ;
            	$newwidth = $width ;
			 }*/
			if($height>$setheight){
				$ratio=$setheight/$height;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				  $newheight = $height ;
            	  $newwidth = $width ;
			 }
			 $newfile2=$imagefleimagename2;

			move_uploaded_file($_FILES["image2fleimage"]['tmp_name'], "$ImagePath".$newfile2);
			
			
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight, $width,$height);
			$image2ThumbName = $imagefleimagename2;
			$imagefleimagename = "$ImageThumbPath/". $image2ThumbName;
				
			imagejpeg($tmp,$imagefleimagename,100);
			imagedestroy($src);
			imagedestroy($tmp);
			

	//////---------------End Image 2 end------------////////////
	}else{
	$newfile2="";
	 $image2ThumbName="";
	}

		//================================ Image 3 ==============================	

	if(	$imagefleimagename3!=""){
			//check if image has 2 dot then exit program
			//$catfile = $imagefleimagename1;
			$image = $imagefleimagename3;
			$uploadedfile = $imagefleimagename3;
			$imagefleimagename3 = stripslashes($imagefleimagename3);
			$extension = getExtension($imagefleimagename3);
			$extension = strtolower($extension);
			/*-------------------------------*/
			/*---------------------------------*/
			if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") ) {
					header('Location: ../product.php?m=3');
					exit();
			}
			if($extension=="jpg" || $extension=="jpeg" ){
				$uploadedfile = $imagefleimagename3_tmp;
				$src = imagecreatefromjpeg($uploadedfile);
			}else if($extension=="png"){
				$uploadedfile = $imagefleimagename3_tmp;
				$src = imagecreatefrompng($uploadedfile);
			}else {
				$src = imagecreatefromgif($uploadedfile);
			}
			list($width,$height)=getimagesize($uploadedfile);
			 $setheight=400;
			 $ratio=0.0;
			 /*if($width>$setwidth){
				$ratio=$setwidth/$width;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				$newheight = $height ;
            	$newwidth = $width ;
			 }*/
			if($height>$setheight){
				$ratio=$setheight/$height;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				  $newheight = $height ;
            	  $newwidth = $width ;
			 }
			 $newfile3=$imagefleimagename3;

			move_uploaded_file($_FILES["image3fleimage"]['tmp_name'], "$ImagePath".$newfile3);
			
			
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight, $width,$height);
			$image3ThumbName = $imagefleimagename3;
			$imagefleimagename = "$ImageThumbPath/". $image3ThumbName;
				
			imagejpeg($tmp,$imagefleimagename,100);
			imagedestroy($src);
			imagedestroy($tmp);
			

	//////---------------End Image 3 end------------////////////
	}else{
	$newfile3="";
	 $image3ThumbName="";
	}
			//================================ Image 4 ==============================	

	if(	$imagefleimagename4!=""){
			//check if image has 2 dot then exit program
			//$catfile = $imagefleimagename1;
			$image = $imagefleimagename4;
			$uploadedfile = $imagefleimagename4;
			$imagefleimagename4 = stripslashes($imagefleimagename4);
			$extension = getExtension($imagefleimagename4);
			$extension = strtolower($extension);
			/*-------------------------------*/
			/*---------------------------------*/
			if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") ) {
					header('Location: ../product.php?m=3');
					exit();
			}
			if($extension=="jpg" || $extension=="jpeg" ){
				$uploadedfile = $imagefleimagename4_tmp;
				$src = imagecreatefromjpeg($uploadedfile);
			}else if($extension=="png"){
				$uploadedfile = $imagefleimagename4_tmp;
				$src = imagecreatefrompng($uploadedfile);
			}else {
				$src = imagecreatefromgif($uploadedfile);
			}
			list($width,$height)=getimagesize($uploadedfile);
			 $setheight=400;
			 $ratio=0.0;
			 /*if($width>$setwidth){
				$ratio=$setwidth/$width;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				$newheight = $height ;
            	$newwidth = $width ;
			 }*/
			if($height>$setheight){
				$ratio=$setheight/$height;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				  $newheight = $height ;
            	  $newwidth = $width ;
			 }
			 $newfile4=$imagefleimagename4;

			move_uploaded_file($_FILES["image4fleimage"]['tmp_name'], "$ImagePath".$newfile4);
			
			
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight, $width,$height);
			$image4ThumbName = $imagefleimagename4;
			$imagefleimagename = "$ImageThumbPath/". $image4ThumbName;
				
			imagejpeg($tmp,$imagefleimagename,100);
			imagedestroy($src);
			imagedestroy($tmp);
			

	//////---------------End Image 4 end------------////////////
	}else{
	$newfile4="";
	 $image4ThumbName="";
	}

			//================================ Image 5 ==============================	

	if(	$imagefleimagename5!=""){
			//check if image has 2 dot then exit program
			//$catfile = $imagefleimagename1;
			$image = $imagefleimagename5;
			$uploadedfile = $imagefleimagename5;
			$imagefleimagename5 = stripslashes($imagefleimagename5);
			$extension = getExtension($imagefleimagename5);
			$extension = strtolower($extension);
			/*-------------------------------*/
			/*---------------------------------*/
			if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") ) {
					header('Location: ../product.php?m=3');
					exit();
			}
			if($extension=="jpg" || $extension=="jpeg" ){
				$uploadedfile = $imagefleimagename5_tmp;
				$src = imagecreatefromjpeg($uploadedfile);
			}else if($extension=="png"){
				$uploadedfile = $imagefleimagename5_tmp;
				$src = imagecreatefrompng($uploadedfile);
			}else {
				$src = imagecreatefromgif($uploadedfile);
			}
			list($width,$height)=getimagesize($uploadedfile);
			 $setheight=400;
			 $ratio=0.0;
			 /*if($width>$setwidth){
				$ratio=$setwidth/$width;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				$newheight = $height ;
            	$newwidth = $width ;
			 }*/
			if($height>$setheight){
				$ratio=$setheight/$height;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				  $newheight = $height ;
            	  $newwidth = $width ;
			 }
			 $newfile5=$imagefleimagename5;

			move_uploaded_file($_FILES["image5fleimage"]['tmp_name'], "$ImagePath".$newfile5);
			
			
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight, $width,$height);
			$image5ThumbName = $imagefleimagename5;
			$imagefleimagename = "$ImageThumbPath/". $image5ThumbName;
				
			imagejpeg($tmp,$imagefleimagename,100);
			imagedestroy($src);
			imagedestroy($tmp);
			

	//////---------------End Image 5 end------------////////////
	}else{
	$newfile5="";
	 $image5ThumbName="";
	}

			//================================ Image 6 ==============================	

	if(	$imagefleimagename6!=""){
			//check if image has 2 dot then exit program
			//$catfile = $imagefleimagename1;
			$image = $imagefleimagename6;
			$uploadedfile = $imagefleimagename6;
			$imagefleimagename6 = stripslashes($imagefleimagename6);
			$extension = getExtension($imagefleimagename6);
			$extension = strtolower($extension);
			/*-------------------------------*/
			/*---------------------------------*/
			if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") ) {
					header('Location: ../product.php?m=3');
					exit();
			}
			if($extension=="jpg" || $extension=="jpeg" ){
				$uploadedfile = $imagefleimagename6_tmp;
				$src = imagecreatefromjpeg($uploadedfile);
			}else if($extension=="png"){
				$uploadedfile = $imagefleimagename6_tmp;
				$src = imagecreatefrompng($uploadedfile);
			}else {
				$src = imagecreatefromgif($uploadedfile);
			}
			list($width,$height)=getimagesize($uploadedfile);
			 $setheight=400;
			 $ratio=0.0;
			 /*if($width>$setwidth){
				$ratio=$setwidth/$width;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				$newheight = $height ;
            	$newwidth = $width ;
			 }*/
			if($height>$setheight){
				$ratio=$setheight/$height;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				  $newheight = $height ;
            	  $newwidth = $width ;
			 }
			 $newfile6=$imagefleimagename6;

			move_uploaded_file($_FILES["image6fleimage"]['tmp_name'], "$ImagePath".$newfile6);
			
			
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight, $width,$height);
			$image6ThumbName = $imagefleimagename6;
			$imagefleimagename = "$ImageThumbPath/". $image6ThumbName;
				
			imagejpeg($tmp,$imagefleimagename,100);
			imagedestroy($src);
			imagedestroy($tmp);
			

	//////---------------End Image 6 end------------////////////
	}else{
	$newfile6="";
	 $image6ThumbName="";
	}



       
       // insert in product          

	$sql="insert into tbl_product(category_id,sub_category_id,sub_sub_category_id,productname,productid,varient_id,url,skucode,short_description,image1,thumb1,image2,thumb2,image3,thumb3,image4,thumb4,image5,thumb5,image6,thumb6,status,featured,latest,productpage,productDate,color) 
	values('$category','$subcategory','$subsubcategory','$name','$productId','$varientId','$url','$skucode','$shortdescription','$newfile1','$imageThumbName','$newfile2','$image2ThumbName','$newfile3','$image3ThumbName','$newfile4','$image4ThumbName','$newfile5','$image5ThumbName','$newfile6','$image6ThumbName','$status','$featured','$latest','$productpage','$date','$color')";
 				
			if(mysqli_query($conn,$sql) or die(mysqli_error($conn)))
			{
	   // $del=mysqli_query($conn,"delete from tbl_product_price where weight='0'");
    // 	$del=mysqli_query($conn,"delete from tbl_product_stock where weight='0'");
				// header('Location: ../product-list.php?m=1');
				// echo "suucess";
					// insert in price 
        for($i=0;$i<=8;$i++)
            {
        
           $size[$i]	 = 	mysqli_real_escape_string($conn,$_POST['size'][$i]);
          $unit[$i]	 = 	mysqli_real_escape_string($conn,$_POST['unit'][$i]);
          $price[$i] = 	mysqli_real_escape_string($conn,$_POST['price'][$i]);
          $mrp[$i] = 	mysqli_real_escape_string($conn,$_POST['listprice'][$i]);
        $stock[$i] = 	mysqli_real_escape_string($conn,$_POST['stock'][$i]);
          
            
                if($price[$i]!='')
                {
                    $query=mysqli_query($conn,"insert into tbl_product_price (productId,varient_id,psize,punit,pprice,pmrp,pdate,status,pqty) values ('$productId','$varientId','$size[$i]','$unit[$i]','$price[$i]','$mrp[$i]','$date','$status','$stock[$i]')");

                    
                    $del=mysqli_query($conn,"delete from tbl_product_price where pprice='0' or pprice=''");
                 	// $del=mysqli_query($conn,"delete from tbl_product_stock where weight='0' or weight=''");

                     header('Location: ../product-varient-list.php?m=1&varientid='.$varientId);
                }

             }
				
			}
			else
			{
								//echo "fail";
				header('Location: ../product-varient-list.php?m=0&varientid='.$varientId);
				
			}


} 

/*--------Add product Varient close-----------------------------------------------*/	
/*--------Delete Product Varient -----------------------------------------------*/	
   function deleteProductVarient($conn)
{

	$id =isset($_GET['id'])? $_GET['id'] : "";
	$varientId =isset($_GET['varientid'])? $_GET['varientid'] : "";
	//echo "value is ".$id;
	$sql=mysqli_query($conn,"select * from tbl_product where id='$id'")or die(mysqli_error($conn));
       $row1=mysqli_fetch_assoc($sql);
       $productid=$row1['productid'];      

    if($sql>0) 
    {
    
    	$del = mysqli_query($conn,"delete from tbl_product_price where productId = '$productid'");

		   $del2 = "delete from tbl_product where productid = '$productid' ";

			if(mysqli_query($conn,$del2) or die(mysqli_error($conn)))
			{

				header('Location: ../product-varient-list.php?&m=6&varientid='.$varientId);
			}
			else
			{
			
				header('Location: ../product-varient-list.php?m=7&varientid='.$varientId);
			}
    } 
    else
		    {
		    	header('Location: ../product-varient-list.php?m=7&varientid='.$varientId);
		    }  
	

}
 /*--------Delete Product Varient close-----------------------------------------------*/

  /*--------Edit Product Varient -----------------------------------------------*/

 function editProductVarient($conn)
{ 

	$id	           =	$_POST['txtid']; 
	$txtproductid  =	$_POST['txtproductid'];
	$varientId	                = 	mysqli_real_escape_string($conn,$_POST['txtvarientid']);
	$varientid	                = 	mysqli_real_escape_string($conn,$_POST['txtvarientid']);	
    $category      = 	mysqli_real_escape_string($conn,$_POST['selcategory']);
	$subcategory   = 	mysqli_real_escape_string($conn,$_POST['selsubcategory']);
	$subsubcategory	  = mysqli_real_escape_string($conn,$_POST['selsubsubcategory']);
	$color	            = 	mysqli_real_escape_string($conn,$_POST['selcolor']);
	$name          = 	mysqli_real_escape_string($conn,$_POST['txtproductname']); 	
	$url		   = 	strtolower(str_replace(" ","-",$name));
	$url	       = 	strtolower(str_replace("&","and",$url));	
 $shortdescription = mysqli_real_escape_string($conn,$_POST['txtshortdescription']); 
	$skucode       = 	mysqli_real_escape_string($conn,$_POST['txtskucode']);
	$date=date('d/m/Y H:i', time());

if(isset($_POST['txtstatus'])){$status=1;}else{$status=0;}
if(isset($_POST['txtfeatured'])){$featured=1;}else{$featured=0;}
	if(isset($_POST['txtlatests'])){$latest=1;}else{$latest=0;}
	if(isset($_POST['txtproductpage'])){$productpage=1;}else{$productpage=0;}
	/*-------------------------Image info-----------------------------*/
	//------------------brand logo--------------------------
	$imagefleimagename1 			= $_FILES['image1fleimage']['name']; 
	$imagefleimagename1_tmp 		= $_FILES['image1fleimage']['tmp_name'];
	$imagefleimagename2 			= $_FILES['image2fleimage']['name']; 
	$imagefleimagename2_tmp 		= $_FILES['image2fleimage']['tmp_name'];
	$imagefleimagename3 			= $_FILES['image3fleimage']['name']; 
	$imagefleimagename3_tmp 		= $_FILES['image3fleimage']['tmp_name'];
	$imagefleimagename4 			= $_FILES['image4fleimage']['name']; 
	$imagefleimagename4_tmp 		= $_FILES['image4fleimage']['tmp_name'];
	$imagefleimagename5 			= $_FILES['image5fleimage']['name']; 
	$imagefleimagename5_tmp 		= $_FILES['image5fleimage']['tmp_name'];
	$imagefleimagename6 			= $_FILES['image6fleimage']['name']; 
	$imagefleimagename6_tmp 		= $_FILES['image6fleimage']['tmp_name'];
	//------------------brand img 1--------------------------
//------now clear all condtion is good-------------if two image not avale-----
function getExtension($str) {
	$i = strrpos($str,".");
	 if (!$i) { return ""; } 

	 $l = strlen($str) - $i;
	 $ext = substr($str,$i+1,$l);
	 return $ext;
}

// ------------- get all images  name  -------------------------
$sel = mysqli_query($conn,"select * from tbl_product where id = '$id' ");
$row = mysqli_fetch_assoc($sel);
$Un_OrginalImage1 	= $row['image1'];	
$Un_Image1 			= $row['thumb1'];
$Un_OrginalImage2 	= $row['image2'];
$Un_Image2 			= $row['thumb2'];	
$Un_OrginalImage3 	= $row['image3'];
$Un_Image3 			= $row['thumb3'];	
$Un_OrginalImage4 	= $row['image4'];
$Un_Image4 			= $row['thumb4'];
$Un_OrginalImage5 	= $row['image5'];
$Un_Image5 			= $row['thumb5'];
$Un_OrginalImage6 	= $row['image6'];
$Un_Image6 			= $row['thumb6'];
/*--------------insert record varible record------------*/
$InsertImage1 				= $row['image1'];	
$InsertImagethumb1 			= $row['thumb1'];
$InsertImage2 				= $row['image2'];	
$InsertImagethumb2			= $row['thumb2'];
$InsertImage3 				= $row['image3'];	
$InsertImagethumb3			= $row['thumb3'];
$InsertImage4 				= $row['image4'];	
$InsertImagethumb4			= $row['thumb4'];
$InsertImage5 				= $row['image5'];	
$InsertImagethumb5			= $row['thumb5'];
$InsertImage6 				= $row['image6'];	
$InsertImagethumb6			= $row['thumb6'];
	
	
/*---------------------------*/
$flagImage1		=0;
$flagImage2		=0;
$flagImage3		=0;
$flagImage4		=0;
$flagImage5		=0;
$flagImage6		=0;
// ------------- get all images  name  -------------------------	
			$no = rand(1,999);
			$tno = rand(1,999);	
///////--------------Upload Logo Image-----------------////////////
    global $productPath;	
	global $productPathThumb;	
	$ImagePath = "$productPath/";
	$ImageThumbPath = "$productPathThumb/";
//================================ Image 1 ==============================	
if(	$imagefleimagename1!=""){
	$flagImage1		=1;
	//check if image has 2 dot then exit program
			//$catfile = $imagefleimagename1;
			$image = $imagefleimagename1;
			$uploadedfile = $imagefleimagename1;
			$imagefleimagename1 = stripslashes($imagefleimagename1);
			$extension = getExtension($imagefleimagename1);
			$extension = strtolower($extension);
			/*-------------------------------*/
			/*---------------------------------*/
			if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png")) {
					header('Location: ../product-list.php?m=16&id='.$id);
					exit();
			}
			if($extension=="jpg" || $extension=="jpeg" ){
				$uploadedfile = $imagefleimagename1_tmp;
				$src = imagecreatefromjpeg($uploadedfile);
			}else if($extension=="png"){
				$uploadedfile = $imagefleimagename1_tmp;
				$src = imagecreatefrompng($uploadedfile);
			}else {
				$src = imagecreatefromgif($uploadedfile);
			}
			list($width,$height)=getimagesize($uploadedfile);
			 $setwidth=400;
			 $ratio=0.0;
			 if($width>$setwidth){
				$ratio=$setwidth/$width;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				$newheight = $height ;
            	$newwidth = $width ;
			 }
			/*if($height>$setheight){
				$ratio=$setheight/$height;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				  $newheight =350;
			 }*/
			 

			 $InsertImage1=$imagefleimagename1;

			move_uploaded_file($_FILES["image1fleimage"]['tmp_name'], "$ImagePath".$InsertImage1);
			
			
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight, $width,$height);
			$InsertImagethumb1 = $imagefleimagename1;
			$imagefleimagename = "$ImageThumbPath/". $InsertImagethumb1;
				
			imagejpeg($tmp,$imagefleimagename,100);
			imagedestroy($src);
			imagedestroy($tmp);
	//////---------------End Upload Brand Image------------////////////
}	
// ======================= image 2 =========================
if(	$imagefleimagename2!=""){
	$flagImage2		=2;
	//check if image has 2 dot then exit program
			//$catfile = $imagefleimagename1;
			$image = $imagefleimagename2;
			$uploadedfile = $imagefleimagename2;
			$imagefleimagename2 = stripslashes($imagefleimagename2);
			$extension = getExtension($imagefleimagename2);
			$extension = strtolower($extension);
			/*-------------------------------*/
			/*---------------------------------*/
			if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png")) {
					header('Location: ../product-list.php?m=16&id='.$id);
					exit();
			}
			if($extension=="jpg" || $extension=="jpeg" ){
				$uploadedfile = $imagefleimagename2_tmp;
				$src = imagecreatefromjpeg($uploadedfile);
			}else if($extension=="png"){
				$uploadedfile = $imagefleimagename2_tmp;
				$src = imagecreatefrompng($uploadedfile);
			}else {
				$src = imagecreatefromgif($uploadedfile);
			}
			list($width,$height)=getimagesize($uploadedfile);
			 $setwidth=400;
			 $ratio=0.0;
			 if($width>$setwidth){
				$ratio=$setwidth/$width;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				$newheight = $height ;
            	$newwidth = $width ;
			 }
			/*if($height>$setheight){
				$ratio=$setheight/$height;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				  $newheight =350;
			 }*/
			 

			 $InsertImage2=$imagefleimagename2;

			move_uploaded_file($_FILES["image2fleimage"]['tmp_name'], "$ImagePath".$InsertImage2);
			
			
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight, $width,$height);
			$InsertImagethumb2 = $imagefleimagename2;
			$imagefleimagename = "$ImageThumbPath/". $InsertImagethumb2;
				
			imagejpeg($tmp,$imagefleimagename,100);
			imagedestroy($src);
			imagedestroy($tmp);
	//////---------------End Upload Brand Image------------////////////
}	
//================================ Image 2 End==============================
/*----------------------------------------------*/

// ======================= image 3 =========================
if(	$imagefleimagename3!=""){
	$flagImage3	=3;
	//check if image has 2 dot then exit program
			//$catfile = $imagefleimagename1;
			$image = $imagefleimagename3;
			$uploadedfile = $imagefleimagename3;
			$imagefleimagename3 = stripslashes($imagefleimagename3);
			$extension = getExtension($imagefleimagename3);
			$extension = strtolower($extension);
			/*-------------------------------*/
			/*---------------------------------*/
			if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png")) {
					header('Location: ../product-list.php?m=16&id='.$id);
					exit();
			}
			if($extension=="jpg" || $extension=="jpeg" ){
				$uploadedfile = $imagefleimagename3_tmp;
				$src = imagecreatefromjpeg($uploadedfile);
			}else if($extension=="png"){
				$uploadedfile = $imagefleimagename3_tmp;
				$src = imagecreatefrompng($uploadedfile);
			}else {
				$src = imagecreatefromgif($uploadedfile);
			}
			list($width,$height)=getimagesize($uploadedfile);
			 $setwidth=400;
			 $ratio=0.0;
			 if($width>$setwidth){
				$ratio=$setwidth/$width;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				$newheight = $height ;
            	$newwidth = $width ;
			 }
			/*if($height>$setheight){
				$ratio=$setheight/$height;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				  $newheight =350;
			 }*/
			 

			 $InsertImage3=$imagefleimagename3;

			move_uploaded_file($_FILES["image3fleimage"]['tmp_name'], "$ImagePath".$InsertImage3);
			
			
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight, $width,$height);
			$InsertImagethumb3 = $imagefleimagename3;
			$imagefleimagename = "$ImageThumbPath/". $InsertImagethumb3;
				
			imagejpeg($tmp,$imagefleimagename,100);
			imagedestroy($src);
			imagedestroy($tmp);
	//////---------------End Upload Brand Image------------////////////
}	
//================================ Image 3 End==============================

// ======================= image 4 =========================
if(	$imagefleimagename4!=""){
	$flagImage4	=4;
	//check if image has 2 dot then exit program
			//$catfile = $imagefleimagename1;
			$image = $imagefleimagename4;
			$uploadedfile = $imagefleimagename4;
			$imagefleimagename4 = stripslashes($imagefleimagename4);
			$extension = getExtension($imagefleimagename4);
			$extension = strtolower($extension);
			/*-------------------------------*/
			/*---------------------------------*/
			if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png")) {
					header('Location: ../product-list.php?m=16&id='.$id);
					exit();
			}
			if($extension=="jpg" || $extension=="jpeg" ){
				$uploadedfile = $imagefleimagename4_tmp;
				$src = imagecreatefromjpeg($uploadedfile);
			}else if($extension=="png"){
				$uploadedfile = $imagefleimagename4_tmp;
				$src = imagecreatefrompng($uploadedfile);
			}else {
				$src = imagecreatefromgif($uploadedfile);
			}
			list($width,$height)=getimagesize($uploadedfile);
			 $setwidth=400;
			 $ratio=0.0;
			 if($width>$setwidth){
				$ratio=$setwidth/$width;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				$newheight = $height ;
            	$newwidth = $width ;
			 }
			/*if($height>$setheight){
				$ratio=$setheight/$height;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				  $newheight =350;
			 }*/
			 

			 $InsertImage4=$imagefleimagename4;

			move_uploaded_file($_FILES["image4fleimage"]['tmp_name'], "$ImagePath".$InsertImage4);
			
			
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight, $width,$height);
			$InsertImagethumb4 = $imagefleimagename4;
			$imagefleimagename = "$ImageThumbPath/". $InsertImagethumb4;
				
			imagejpeg($tmp,$imagefleimagename,100);
			imagedestroy($src);
			imagedestroy($tmp);
	//////---------------End Upload Brand Image------------////////////
}	
//================================ Image 4 End==============================

// ======================= image 5 =========================
if(	$imagefleimagename5!=""){
	$flagImage5	=5;
	//check if image has 2 dot then exit program
			//$catfile = $imagefleimagename1;
			$image = $imagefleimagename5;
			$uploadedfile = $imagefleimagename5;
			$imagefleimagename5 = stripslashes($imagefleimagename5);
			$extension = getExtension($imagefleimagename5);
			$extension = strtolower($extension);
			/*-------------------------------*/
			/*---------------------------------*/
			if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png")) {
					header('Location: ../product-list.php?m=16&id='.$id);
					exit();
			}
			if($extension=="jpg" || $extension=="jpeg" ){
				$uploadedfile = $imagefleimagename5_tmp;
				$src = imagecreatefromjpeg($uploadedfile);
			}else if($extension=="png"){
				$uploadedfile = $imagefleimagename5_tmp;
				$src = imagecreatefrompng($uploadedfile);
			}else {
				$src = imagecreatefromgif($uploadedfile);
			}
			list($width,$height)=getimagesize($uploadedfile);
			 $setwidth=400;
			 $ratio=0.0;
			 if($width>$setwidth){
				$ratio=$setwidth/$width;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				$newheight = $height ;
            	$newwidth = $width ;
			 }
			/*if($height>$setheight){
				$ratio=$setheight/$height;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				  $newheight =350;
			 }*/
			 

			 $InsertImage5=$imagefleimagename5;

			move_uploaded_file($_FILES["image5fleimage"]['tmp_name'], "$ImagePath".$InsertImage5);
			
			
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight, $width,$height);
			$InsertImagethumb5 = $imagefleimagename5;
			$imagefleimagename = "$ImageThumbPath/". $InsertImagethumb5;
				
			imagejpeg($tmp,$imagefleimagename,100);
			imagedestroy($src);
			imagedestroy($tmp);
	//////---------------End Upload Brand Image------------////////////
}	
//================================ Image 5 End==============================
// ======================= image 6 =========================
if(	$imagefleimagename6!=""){
	$flagImage6	=6;
	//check if image has 2 dot then exit program
			//$catfile = $imagefleimagename1;
			$image = $imagefleimagename6;
			$uploadedfile = $imagefleimagename6;
			$imagefleimagename6 = stripslashes($imagefleimagename6);
			$extension = getExtension($imagefleimagename6);
			$extension = strtolower($extension);
			/*-------------------------------*/
			/*---------------------------------*/
			if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png")) {
					header('Location: ../product-list.php?m=16&id='.$id);
					exit();
			}
			if($extension=="jpg" || $extension=="jpeg" ){
				$uploadedfile = $imagefleimagename6_tmp;
				$src = imagecreatefromjpeg($uploadedfile);
			}else if($extension=="png"){
				$uploadedfile = $imagefleimagename6_tmp;
				$src = imagecreatefrompng($uploadedfile);
			}else {
				$src = imagecreatefromgif($uploadedfile);
			}
			list($width,$height)=getimagesize($uploadedfile);
			 $setwidth=400;
			 $ratio=0.0;
			 if($width>$setwidth){
				$ratio=$setwidth/$width;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				$newheight = $height ;
            	$newwidth = $width ;
			 }
			/*if($height>$setheight){
				$ratio=$setheight/$height;
				$newheight = $height * $ratio;    // Reset height to match scaled image
            	$newwidth = $width * $ratio; 
			 }else{
				  $newheight =350;
			 }*/
			 

			 $InsertImage6=$imagefleimagename6;

			move_uploaded_file($_FILES["image6fleimage"]['tmp_name'], "$ImagePath".$InsertImage6);
			
			
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight, $width,$height);
			$InsertImagethumb6 = $imagefleimagename6;
			$imagefleimagename = "$ImageThumbPath/". $InsertImagethumb6;
				
			imagejpeg($tmp,$imagefleimagename,100);
			imagedestroy($src);
			imagedestroy($tmp);
	//////---------------End Upload Brand Image------------////////////
}	
//================================ Image 6 End==============================


/*----------------------------------------------*/


$sqladd = mysqli_query($conn,"update tbl_product set 
category_id='$category',
sub_category_id='$subcategory',
sub_sub_category_id='$subsubcategory',
productname='$name',
url='$url',
skucode='$skucode',
short_description='$shortdescription',
image1='$InsertImage1',
thumb1='$InsertImagethumb1',
image2='$InsertImage2',
thumb2='$InsertImagethumb2',
image3='$InsertImage3',
thumb3='$InsertImagethumb3',
image4='$InsertImage4',
thumb4='$InsertImagethumb4',
image5='$InsertImage5',
thumb5='$InsertImagethumb5',
image6='$InsertImage6',
thumb6='$InsertImagethumb6',
status='$status',
featured='$featured',
latest='$latest',
productpage='$productpage',
color='$color'
where id = '$id'") or die(mysqli_error($conn));

		// Delete product price and stock
		//$del= mysqli_query($conn,"delete from tbl_product_stock where productId = '$txtproductid'");
    	$del = mysqli_query($conn,"delete from tbl_product_price where productId = '$txtproductid'");
     
    	// Delete product price and stock close



 if(mysqli_affected_rows($conn) > 0)
	{
		if($flagImage1==1){
			if($Un_OrginalImage1!=""){
				unlink($ImagePath.$Un_OrginalImage1);
				unlink($ImageThumbPath.$Un_Image1);
			}
		}
		if($flagImage2==2){
			if($Un_OrginalImage2!=""){
				unlink($ImagePath.$Un_OrginalImage2);
				unlink($ImageThumbPath.$Un_Image2);
			}
		}
		if($flagImage3==3){
			if($Un_OrginalImage3!=""){
				unlink($ImagePath.$Un_OrginalImage3);
				unlink($ImageThumbPath.$Un_Image3);
			}
		}
		if($flagImage4==4){
			if($Un_OrginalImage4!=""){
				unlink($ImagePath.$Un_OrginalImage4);
				unlink($ImageThumbPath.$Un_Image4);
			}
		}
		if($flagImage5==5){
			if($Un_OrginalImage5!=""){
				unlink($ImagePath.$Un_OrginalImage5);
				unlink($ImageThumbPath.$Un_Image5);
			}
		}
		if($flagImage6==6){
			if($Un_OrginalImage6!=""){
				unlink($ImagePath.$Un_OrginalImage6);
				unlink($ImageThumbPath.$Un_Image6);
			}
		}


					// insert in price 
         for($i=0;$i<=8;$i++)
            {

          $size[$i]     =  mysqli_real_escape_string($conn,$_POST['size'][$i]);
          $unit[$i]  =  mysqli_real_escape_string($conn,$_POST['unit'][$i]);
          $price[$i] =  mysqli_real_escape_string($conn,$_POST['price'][$i]);
          $mrp[$i] =    mysqli_real_escape_string($conn,$_POST['listprice'][$i]);
        $stock[$i] =    mysqli_real_escape_string($conn,$_POST['stock'][$i]);
       
       
                
            $query99=mysqli_query($conn,"insert into tbl_product_price (productId,varient_id,psize,punit,pprice,pmrp,pdate,status,pqty) values ('$txtproductid','$varientId','$size[$i]','$unit[$i]','$price[$i]','$mrp[$i]','$date','$status','$stock[$i]')");
            
        $del=mysqli_query($conn,"delete from tbl_product_price where pprice='0' or pprice=''");

	  // header('Location: ../cartupdate.php?id='.$id);
		// echo "success";
		header('Location: ../product-varient-list.php?m=4&varientid='.$varientId);
	}

	// header('Location: ../product-list.php?m=4');
}

	else
	{
		header('Location: ../product-varient-list.php?m=5&varientid='.$varientId);
	}
} 


	/*--------Edit Product Varient-----------------------------------------------*/
?>		

MMCT - 2023