	<?php
	/**
	* Created by PhpStorm.
	* User: ahmad
	* Date: 20/08/2019
	* Time: 11:48 AM
	*/

	require_once("../connection.php");
	
	$key=mysqli_real_escape_string($connect, $_GET['key']);
	$id=mysqli_real_escape_string($connect, $_GET['id']);

	$getusers = mysqli_query($connect,"SELECT * FROM users WHERE id_session='$key'");
	$u	      = mysqli_fetch_array($getusers);
	$count   = mysqli_num_rows($getusers);

	if ($count > 0){
	
	$data=mysqli_fetch_array(mysqli_query($connect,"SELECT img FROM product WHERE id_product='$id'"));
	if ($data['img']!=''){
		
	 mysqli_query($connect,"UPDATE product SET showing		 = '1'
								WHERE id_product 	 = '$id'");
     unlink("$_SERVER[DOCUMENT_ROOT]/geten/images/$data[gbr]");  
	 
	}
	else{
	 
	 mysqli_query($connect,"UPDATE product SET showing		 = '1'
								WHERE id_product 	 = '$id'");
	 
	}


	$json = array(
    'status' 	=> 'true',
    'errCode' 	=> '01',
	'msg' 		=> 'Success'
	);

    echo json_encode($json);

	}else{
	
	
 $json = array(
    'status' 	=> 'true',
    'errCode' 	=> '00',
	'msg' 		=> 'User Not Found'
   );

    echo json_encode($json);	
	}
	?>