<?php

/*CONEXAO COM O BANCO*/
include "../Connections/config.php";
/*********************/

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

if ($_REQUEST["a"]) {
    $started = microtime(true);
    $api = [];
    $res = $db->query("SELECT * FROM theme");
    while ($row = $res->fetch_array()) {
        $api[] = ["name" => $row["name"], "url" => $row["url"]];
    }
    $new = json_encode($api);
    $new = str_replace("\\/", "/", $new);
    $api2 = [];
    $res2 = $db->query("SELECT * FROM advert");
    while ($row2 = $res2->fetch_array()) {
        $api2[] = ["title" => $row2["title"], "description" => $row2["description"], "url" => $row2["url"]];
    }
    if ($api2 == NULL || $api2 == "") {
        $new2 = "[{\"title\":\"BoxBR Flix IPTV\",\"description\":\"Best Media Player in the world.\",\"url\":\"https:\\/\\/flixapp.org\\/public\\/upload\\/1604854505.png\"}]";
    } else {
        $new2 = json_encode($api2);
        $new2 = str_replace("\\/", "/", $new2);
    }
    $end = microtime(true);
    $difference = $end - $started;
    $queryTime = number_format($difference, 16);
    echo "{\"themes\":" . $new . ",\n\"adverts\":" . $new2 . ",\"app_type\":\"android\",\"use_agent\":\"mozilla/5.0 (windows nt 10.0; win64; x64) applewebkit/537.36 (khtml, like gecko) chrome/88.0.4324.104 safari/537.36\",\"total_execution_time\":" . $queryTime . "}";
} else {
    header("Location: ../lock.php");
}

?>