<?php
include('../sys/phpcore.inc');
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/x-www-form-urlencoded");


$key 		= $conn->real_escape_string($_POST['key']);
$id 		= $conn->real_escape_string($_POST['id']);
$member 	= $_POST['member'];
$batch_no 	= date('ymdhis');



if($key!="-_mAsdS90121+0182*"){
		echo "INVALID";
		return false;
	}






$row = count($member);
for($i=0;$i<$row;$i++){


	$member_name		= $conn->real_escape_string($member[$i]['member_name']);
	$member_phone		= $conn->real_escape_string($member[$i]['member_phone']);
	$member_date		= $conn->real_escape_string($member[$i]['member_date']);
	$member_outlet		= $conn->real_escape_string($member[$i]['member_outlet']);



	$sqlchk = "SELECT COUNT(*) as num FROM mst_member WHERE member_phone = '$member_phone'";
	$dcon_chk = $conn->query($sqlchk) or die($sqlchk);
	$rschk = $dcon_chk->fetch_assoc();
	$check = $rschk['num']+0;


$sqldetail  = "INSERT INTO mst_member 
				(member_phone,member_name,member_dateregister,member_outlet) 
				VALUES 
				('$member_phone','$member_name','$member_date','$member_outlet')";
				if($check==0){
				$conn->query($sqldetail) or die($sqldetail);
				}

}


$n_member = array();
$sqldetail = "SELECT * FROM mst_member";
$dcond = mysqli_query($conn,$sqldetail) or die($sqldetail);
while($rs = mysqli_fetch_array($dcond)){

	//header//	
	$member_phone 		= $rs['member_phone'];
	$member_name 		= ($rs['member_name']);
	$member_date 		= ($rs['member_dateregister']);
	$member_outlet 		= ($rs['member_outlet']);

	
	
	$n_member[]  = array(
					"member_phone"  => $member_phone,
					"member_name" => $member_name,
					"member_date" => $member_date,
					"member_outlet" => $member_outlet,

	);

}



echo  json_encode($n_member);
	//echo "<br><h4>".$jml." Transaksi Penjualan Berhasil Dikirim</h4>";
?>