<?php

require_once("../connection.php");

$key=mysqli_real_escape_string($connect, $_POST['key']);
$full_name=mysqli_real_escape_string($connect, $_POST['full_name']);
$address=mysqli_real_escape_string($connect, $_POST['address']);
$email=mysqli_real_escape_string($connect, $_POST['email']);

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

	$masterakun = mysqli_query($connect,"SELECT * FROM users WHERE phone_number='$u[master]'");
	$m=mysqli_fetch_array($masterakun);


if ($jumlah > 0){
	
	include "../fungsi_thumb.php";
	
	$folder = date("m-d-y-H");
  
  $file_location 		= $_FILES['img']['tmp_name'];
  $tipe_file   		= $_FILES['img']['type'];
  $file_name   		= $_FILES['img']['name'];
  $acak        		= rand(1,99);
  $file_name_unique	= $acak.$file_name; 
  	
	

  
  
	if (empty($file_location)){
	mysqli_query($connect,"UPDATE users SET full_name   	   = '$full_name',
								  address			   = '$address',
								  email				   = '$email'
                             WHERE id_session 	       = '$key'");
	}else{
	    UploadFoto($file_name_unique);
	mysqli_query($connect,"UPDATE users SET full_name         = '$full_name',
								  address			   = '$address',
								  img			   	   = '$folder/small_$file_name_unique',
								  email				   = '$email'
                             WHERE id_session 	       = '$key'");
	}

	$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);	
}
?>