<?php

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

$key=mysqli_real_escape_string($connect, $_POST['key']);
$nama_toko=mysqli_real_escape_string($connect, $_POST['name_store']);
$email=mysqli_real_escape_string($connect, $_POST['email']);
$alamat=mysqli_real_escape_string($connect, $_POST['address']);
$pajak=mysqli_real_escape_string($connect, $_POST['tax']);
$service_charge=mysqli_real_escape_string($connect, $_POST['service_charge']);
$nohp=mysqli_real_escape_string($connect, $_POST['nohp']);
$id=mysqli_real_escape_string($connect, $_POST['id']);
$currency=mysqli_real_escape_string($connect, $_POST['currency']);
$footer=mysqli_real_escape_string($connect, $_POST['footer']);
$shift=mysqli_real_escape_string($connect, $_POST['shift']);

$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"); 
  
  $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;
   
  $folder = date("m-d-y-H");
	  if (empty($lokasi_file)){
	mysqli_query($connect,"UPDATE store SET name_store   	       = '$nama_toko',
								 address			   	   = '$alamat',
								 email				   = '$email',
								 tax				   = '$pajak',
								 service_charge		   = '$service_charge',
								 currency		   	= '$currency',
								 footer		   			= '$footer',
								 shift		   			= '$shift',
								 nohp			       = '$nohp'
                             WHERE id_store 	           = '$id'");
	}else{
	    UploadLogo($nama_file_unik);
		
	mysqli_query($connect,"UPDATE store SET name_store   	       = '$nama_toko',
								 address			   	   = '$alamat',
								 email				   = '$email',
								 tax				   = '$pajak',
								 service_charge		   = '$service_charge',
								 currency		   	= '$currency',
								 footer		   			= '$footer',
								 shift		   			= '$shift',
								 img		   			= '$folder/$nama_file_unik',
								 nohp			       = '$nohp'
                             WHERE id_store 	           = '$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);	
}
?>
