<?php

require_once($_SERVER['DOCUMENT_ROOT'] . '/sys/db.php');

foreach ($_POST as $paramName => $paramValue) {
  if ($paramName == "selectid")
    $ad_id = $paramValue;
}

$dal = new DAL();

if ($ad_id > 0) {

  $sql = "SELECT AD.id, " . 
         "(CASE WHEN OCA.organizationcontact_id IS NULL THEN 0 ELSE OCA.organizationcontact_id END) AS organizationcontact_id, " .
         "'' AS organizationcontact_id_text, " .
         "AD.suite,                   '' AS suite_text, " .
//         "OCA.addresstype_id,         '' AS addresstype_id_text, " .
         "AD.careof,                  '' AS careof_text, " .
         "AD.pobox,                   '' AS pobox_text, " .
         "AD.station,                 '' AS station_text, " .
         "AD.streetno,                '' AS streetno_text, " .
         "AD.streetname,              '' AS streetname_text, " .
         "AD.streetype,               '' AS streetype_text, " .
         "AD.streetdir,               '' AS streetdir_text, " .
         "AD.ruralroute,              '' AS ruralroute_text, " .
         "AD.city,                    '' AS city_text, " .
         "AD.province,                '' AS province_text, " .
         "AD.postcode,                '' AS postcode_text, " .
         "AD.country,                 '' AS country_text " .
         "FROM address AD " .
         "LEFT JOIN organizationcontactaddress OCA ON OCA.address_id = AD.id " .
         "WHERE AD.id = $ad_id   " .
         "LIMIT 1 ";
  $result = $dal->query($sql);
}

echo json_encode($result);

?>

