<?php
include "../db/dBase.php";
$dbase = new dBase();
$tcon = $dbase->con;
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
header("Access-Control-Allow-Methods: POST");
header("Access-Control-Max-Age: 3600");
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");

$response = array('status' => 'fail', 'message' => 'Something went wrong Please try again','list'=>[]);

$data = json_decode(file_get_contents("php://input"));
if (isset($data->API_KEY)) {
    $key_ = mysqli_real_escape_string($tcon, $data->API_KEY);
    $key = md5($key_);



    // check API Validity
    $api_n = $dbase->countQuery("SELECT `id` FROM `access_log` WHERE `token`='$key' ");
    if ($api_n == 1) {


        if (isset($data->filter)) {
            $filter = json_decode($data->filter);
        }





        $agent_while = $dbase->queryToWhile_2("SELECT user.name,user.userID,user.dp,agent.short,user.social_status,user.gender FROM `user` LEFT JOIN `agent` ON agent.userID = user.userID WHERE user.status=0 AND user.userID <> 'as12if34222' AND user.userID <> 'r1y86b8907nt' ORDER BY  RAND(user.id) ");

      

        $response = array('list'=>array_filter($agent_while),'status'=>'success');
    }
}
echo json_encode(array_filter($response));
