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

	require_once("../connection.php");
	
	$key=mysqli_real_escape_string($connect, $_POST['key']);
	$email=mysqli_real_escape_string($connect, $_POST['email']);
	$telpon=mysqli_real_escape_string($connect, $_POST['telephone']);
	$nama_supplier=mysqli_real_escape_string($connect, $_POST['name_supplier']);
	$alamat=mysqli_real_escape_string($connect, $_POST['address']);
	$id=mysqli_real_escape_string($connect, $_POST['id']);

	$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";
  
  $lokasi_file 		= $_FILES['img']['tmp_name'];
  $tipe_file   		= $_FILES['img']['type'];
  $nama_file   		= $_FILES['img']['name'];
  $acak        		= rand(1,99);
  $nama_file_unik	= $acak.$nama_file; 
  
  
	if (empty($lokasi_file)){
	mysqli_query($connect,"UPDATE supplier SET name_supplier       = '$nama_supplier',
								 address				 = '$alamat',
								 email				 = '$email',
								 telephone				 = '$telpon'
                             WHERE id_supplier       = '$id'");
							 
							 }else{
	    UploadImage($nama_file_unik);
	mysqli_query($connect,"UPDATE supplier SET name_supplier       = '$nama_supplier',
								 address				 = '$alamat',
								 email				 = '$email',
								 telephone				 = '$telpon',
								 img		     	 = '$nama_file_unik'
                             WHERE id_supplier       = '$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);	
	}
	?>