<?php

include 'config.php';

$ip = $_POST['ip'];

$player_id = $_POST['onesignal'];
$useragent = $_POST['useragent'];
$usertoken = $_POST['token'];

$suan = time();



if(!empty($player_id)){





$query = $db->query("SELECT * FROM kullanicilar WHERE user_token = '$usertoken'", PDO::FETCH_ASSOC);
if ( $query->rowCount() ){


$query = $db->prepare("UPDATE kullanicilar SET
user_songiris = :bir,
user_agent = :dort,
user_ip = :uc,
user_onesignal = :bes
WHERE user_token = :iki");
$update = $query->execute(array(
     "bir" => $suan,
     "dort" => $useragent,
     "uc" => $ip,
     "bes" => $player_id,
     "iki" => $usertoken
));

if($update){
	echo '{"result":"1"}';

}else{
	echo '{"result":"0"}';

}





}else{
	//echo '{"result":"0"}';



$coPlayer2 = $db->query("SELECT * FROM nokullanici WHERE player_id = '{$player_id}'")->fetch(PDO::FETCH_ASSOC);


if($coPlayer2){

//echo "DAHA ÖNCEDEN DE VAR<br />";
	echo '{"result":"1"}';

}else{


$query = $db->prepare("INSERT INTO nokullanici SET
player_id = ?,
songiris = ?");
$insert = $query->execute(array(
     $player_id, $suan
));

if($insert){
	echo '{"result":"1"}';
}else{
	echo '{"result":"0"}';
}

//ECHO "YOKMUS EKLEDİK<br />";

}




}












}