<?php
class Fadtn
{
    /* static function ping($host, $port, $timeout) { 
        $fP = fSockOpen($host, $port, $errno, $errstr, $timeout); 
        if (!$fP) { return false; } 
        return true;
    } */
    static function query($imm){
        //if(!self::ping("41.226.255.80",8085, 5)) return null;
        //$uu=file_get_contents("http://41.226.255.80:8085/?imm=".urlencode($imm));
        $uu=file_get_contents("https://api.".app::$dom."/public/fad/?imm=".urlencode($imm));
        return json_decode($uu,true);
    }
}
api::getfad(function($data){
	if(!empty($data["ref"])){
		$key = "ref";
	}elseif(!empty($data["vin"])){
		$key = "vin";
	}elseif(!empty($data["imm"])){
		$key = "imm";
	}
	// return ["data" => ["res"=>[]]];
	$ctx = stream_context_create(array('http'=>
		array(
			'timeout' => 5,  //1200 Seconds is 20 Minutes
		)
	));
	$rep = file_get_contents("https://api.".app::$dom."/public/fad/?$key=".urlencode($data[$key]), false, $ctx);
	$fad=json_decode($rep,true);
	if($fad!=null) return $fad;
	else return ["data" => ["res"=>null]];
});