<?php
include_once("../../../../db.php");
include_once("db.php");
include_once("../../../config.php");
$ldb = new database();

$q = strtolower($_GET["q"]);
if (!$q)
    return;

# get suggestion from database
mysql_query("SET NAMES 'utf8'");
//Licenece
$licence_key    = LICENCE_KEY;
$inventory_code = INVENTORY_CODE;


//Find Active Inventory
$activeinventory   = "SELECT inventory_id FROM inventory WHERE inve_active = '1' ";
$resultinventory   = $ldb->returnArray($activeinventory);
$inventory_code_rb = $resultinventory['0']['inventory_id'];

if (sizeof($resultinventory) > 0) {
    $sql        = "SELECT element_name, image_path, ota_id, ota_priority, element_type, element_id, state_province_code, country_code from approved_inventory WHERE microsite_inventory_code = '$inventory_code_rb' AND active = '1' AND publish = '1' AND deleted = '0' AND element_name like '%" . $_GET["q"] . "%' ORDER BY element_type DESC ";
    $result_obj = $ldb->returnArray($sql);
    #echo out the suggestion
    for ($a = 0; $a < sizeof($result_obj); $a++) {
        $elementid            = "" . $result_obj[$a]['ota_id'] . "";
        $firstelement         = $result_obj[$a]['element_name'] . "||RESERVALO||" . $elementid;
        $nombrecompletostring = $result_obj[$a]['element_name'];
        $codigopais           = $result_obj[$a]['country_code'];
        $stringpaisestado     = $result_obj[$a]['country_code'];
        if (($codigopais == 'US') || ($codigopais == 'CA') || ($codigopais == 'AU')) {
            $stringpaisestado = $result_obj[$a]['state_province_code'] . ', ' . $result_obj[$a]['country_code'];
        }
        $nombrecompletostring = $result_obj[$a]['element_name'] . ', ' . $stringpaisestado;
        echo $nombrecompletostring . "||==||" . PATH . "" . $result_obj[$a]['image_path'] . "||==||" . $result_obj[$a]['ota_id'] . "||==||" . $result_obj[$a]['ota_priority'] . "||==||" . $result_obj[$a]['element_type'] . "||==||" . $result_obj[$a]['element_id'] . "\n";
    }
}
?>