<?php

include('config.php');
include('function.php');
include('countrycodes.php');

date_default_timezone_set('UTC');

define('GX_PATH', realpath(__DIR__.'/'));
define('GX_LIB', GX_PATH.'/lib/');

require 'autoload.php';
new Db();

$q = Db::result("SELECT `id` FROM `hitstat` WHERE `id` > '{$_GET['last_id']}' ");
$n = Db::$num_rows;

$lastq = Db::result("SELECT `id` FROM `hitstat` ORDER BY `id` DESC LIMIT 1  ");
$last_id = $lastq[0]->id;

header("Content-type:application/json");

if( $n > 0 ) {
    $today = date("Y-m-d");
    $data = Db::result("SELECT * FROM `hitstat` WHERE `id` > '{$_GET['last_id']}' ORDER BY `id` ASC");
    // $lastData = Db::result("SELECT * FROM `lead_report` WHERE `id` > '{$_GET['last_id']}' ");
    $result = array(
        'last_id' => $last_id,
        'result' => true,
        'data' => $data
        // 'lastData' => $lastData
    );

    echo json_encode($result);
} else {
    $result = array(
        'last_id' => $_GET['last_id'],
        'result' => false
    );

    echo json_encode($result);
}