<?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 `date_range`,`banner`,`title`,`sub_title`,`title_3` FROM `screen_winners` WHERE `status`='ACT' ORDER BY rand() LIMIT 1 ");

      

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