<?php
require_once(dirname(__FILE__). '/inc/db.class.php');
require_once(dirname(__FILE__). '/inc/config.php');

if($_SERVER['REMOTE_ADDR'] == '112.200.103.149'){
    sleep(10);
}

$db = new db();
$db->load($db_info);
$phone = !empty($_GET['phone'])? $_GET['phone'] : null;
if(!$phone)
{
	$ret = array('status' => 0, 'message' => 'Record Not Found for invalid '. $phone);
	echo json_encode($ret);
	die();
}
$data = null;
$res = $db->select('*')->from('company')->where('phone', $phone)->get();
if($res->count == 1)
{
	$d = $res->result();
	$value = $d[0];
	$value->owner = getOwner($value->id);
	$data = new stdClass();
	$data->map_link = "https://maps.google.com/maps?q=". $value->adress . '+' . $value->city . '+' . $value->state . '+' . $value->zip;
	$data->address = new stdClass();
	$data->address->full = $value->adress.' '. $value->city . ', '. $value->state .' '. $value->zip;
	$data->address->address = $value->adress;
	$data->address->city = $value->city;
	$data->address->state = $value->state;
	$data->address->zip = $value->zip;
	if(strlen($data->address->zip) < 5)
	{
		while (strlen($data->address->zip) < 5) $data->address->zip = '0' . $data->address->zip;
	}
	
	$data->company = new stdClass();
	$data->company->name = $value->name;
	$data->company->phone = $value->phone;
	$data->company->tagline = $value->tagline;
	$data->company->notes = $value->notes;
	
	if($value->owner)
	{
		$data->owner = $value->owner;
	}
}


if($data == null)
{
	$ret = array('status' => 0, 'message' => 'Record Not Found in db for '. $phone);
	echo json_encode($ret);
	die();
}

$ret = array('status' => 1, 'message' => 'Records Found for '. $phone, 'data' => $data);
echo json_encode($ret);
die();

?>