<?php
include 'config.php';
include 'fungsi.php';

$response = array("error" => FALSE);

$email = mysqli_real_escape_string($con,$_POST['email']);
$grup = mysqli_real_escape_string($con,$_POST['grup']);
	
$query = mysqli_query($con,"SELECT ID FROM prospek WHERE email='$email'");
	$check = mysqli_fetch_array($query,MYSQLI_NUM);
	if (isset($check[0])) {
		
		$id = $check[0];
		$query = mysqli_query($con,"SELECT id FROM gtm WHERE id_member='$id' and id_grup='$grup' ORDER BY id asc LIMIT 0,1");	
		$nextitem = mysqli_fetch_array($query,MYSQLI_NUM);
		if (isset($nextitem[0])) {
		    $idgtm = $nextitem[0];
		    mysqli_query($con,"update gtm set status=2 where id='".$idgtm."'");
		} 
		
		$response["error"] = FALSE;
        $response["pesan"] = 'Sukses mengaktifkan email menjadi buyer';
        echo json_encode($response);
		
		
	}else{
		$response["error"] = TRUE;
        $response["pesan"] = 'gagal mengaktifkan email jadi buyer';
        echo json_encode($response);
	}
?>	