<?php

$env = "";
if (isset($_SERVER['HTTP_HOST']) && $_SERVER['HTTP_HOST'] == 'boasearch' ) {
    $env = "dev";
}

if ((!isset($_REQUEST['qt']) || empty($_REQUEST['qt'])) &&
    (!isset($_REQUEST['status']) || empty($_REQUEST['status'])) &&
    (!isset($_REQUEST['type']) || empty($_REQUEST['type']))    ) {
    echo '';
    exit;
}
$qt = htmlspecialchars(stripslashes(trim($_REQUEST['qt'])));
$status = htmlspecialchars(stripslashes(trim($_REQUEST['status'])));
$type = htmlspecialchars(stripslashes(trim($_REQUEST['type'])));
//$email = urldecode($_REQUEST['email']);

require_once '../lib/Licensees.php';
$ldb = new Licensees($env);
$licenseesData = $ldb->fetchLicensees($qt, $status, strtolower($type));

//print_r($licenseesData);
echo json_encode(generateJsonData($licenseesData));




function generateJsonData($licensees) {
    global $qt;
//print_r($licensees);
    $returnArray = array();
    foreach ((array)$licensees as $l) {
        $license = new stdClass();
        $license->type = ucwords($l['type']);
        $license->license = $l['license_no'];
        $license->name = $l['name1'];
        $license->status = ucwords(strtolower($l['status']));
        $license->complaints = $l['complaints'];
        if (empty($l['state']) || empty($l['city'])) {
            $license->address = ucwords(strtolower($l['city'])) . " " . $l['state'] . "<br />" .$l['zip'];
        } else {
            $license->address = ucwords(strtolower($l['city'])) . ", " . $l['state'] . "<br />" .$l['zip'];
        }
        $license->expires = $l['date_expires'];

        if (!empty($license->name))
            array_push($returnArray, $license);

    }
    return $returnArray;
}