<?php
include 'config.php';
$user_token = $_COOKIE['user_token'];

$zaman = time()-259200;

$myUser = $db->query("SELECT * FROM kullanicilar WHERE user_token = '$user_token'")->fetch(PDO::FETCH_ASSOC);

$user_id = $myUser['user_id'];

$sehir = $myUser['user_sehir'];	

$cinsiyet = $myUser['user_cinsiyet'];

if($cinsiyet == "erkek"){
    $cins = "kadin";
}elseif($cinsiyet == "kadin"){
    $cins = "erkek";
}

if($_GET['type']=='finder'){
    if($user_id == 663793) {
        $statement = $db->prepare("SELECT * FROM kullanicilar WHERE user_cinsiyet = '{$cins}' AND user_picture = 'assets/img/no-avatar.png' AND user_deaktif = 0 AND user_songiris >= $zaman ORDER BY RAND() LIMIT 10");
    } else {
        $statement = $db->prepare("SELECT * FROM kullanicilar WHERE user_cinsiyet = '{$cins}' AND user_picture != 'assets/img/no-avatar.png' AND user_deaktif = 0 AND user_songiris >= $zaman ORDER BY RAND() LIMIT 10");
    }
}elseif($_POST['type']=='kesfet'){
    if($user_id == 663793) {
        $statement = $db->prepare("SELECT * FROM kullanicilar WHERE user_cinsiyet = '{$cins}' AND user_picture = 'assets/img/no-avatar.png' AND user_deaktif = 0 AND user_songiris >= $zaman ORDER BY RAND() LIMIT 20");
    } else {
        $statement = $db->prepare("SELECT * FROM kullanicilar WHERE user_cinsiyet = '{$cins}' AND user_deaktif = 0 AND user_songiris >= $zaman ORDER BY RAND() LIMIT 20");
    }
}

$statement->execute();
$results = $statement->fetchAll(PDO::FETCH_ASSOC);
echo $json = json_encode($results);
?>


