<?php
header("Access-Control-Allow-Origin: *"); //enable resourse sharing(allows this resource to be shared with "all[*]" requesting clients

define("MAIN_DB_USERNAME", "initia19_localization");
define("MAIN_DB_PASSWORD", "queritel_localization");
define("MAIN_DB_NAME", "initia19_localization");

include("../includes/localization-classes-v1.php");
include("../includes/localization-miscellaneous-v1.php");

$db = new Database(MAIN_DB_USERNAME, MAIN_DB_PASSWORD, MAIN_DB_NAME);


$ip_address = clean($_REQUEST["ip"]);

if (!empty($ip_address)){
    $client = new HostInfoLocalization($db);


    $client->setIp_address($ip_address);

    $result["ip_address"] = $client->getIp_address();
    $result["country_name"] = $client->getCountry_name();
    $result["country_code"] = $client->getCountry_code();
    $result["country_flag"] = "https://api.queritel.com/api/localization/resources/flags/" . stringCase($client->getCountry_code(),STRING_CASE_LOWER) . ".svg";

    echo json_encode($result);

}
else{
    $client = new HostInfoLocalization($db);

    $result["ip_address"] = $client->getIp_address();
    $result["country_name"] = $client->getCountry_name();
    $result["country_code"] = $client->getCountry_code();
    $result["country_flag"] = "https://api.queritel.com/api/localization/resources/flags/" . stringCase($client->getCountry_code(),STRING_CASE_LOWER) . ".svg";

    echo json_encode($result);
}



/*if (isset($_REQUEST["ip"])){
    $client = new HostInfo($db);


    $ip = $_REQUEST["ip"];
    if($ip != "my_ip"){
        $client->setIp_address($ip);
    }

    $result["ip_address"] = $client->getIp_address();
    $result["country_name"] = $client->getCountry_name();
    $result["country_code"] = $client->getCountry_code();
    $result["country_flag"] = "https://api.queritel.com/api/test-lab/hernandez/flags/" . stringCase($client->getCountry_code(),STRING_CASE_LOWER) . ".svg";


    echo json_encode($result);


}*/


