<?php

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

foreach ($_POST as $paramName => $paramValue) {
  if ($paramName == "summaryid")
    $oc_id = $paramValue;
}

$dal = new DAL();
$sql = "SELECT AT.id AS id, " .
       "(CASE WHEN OCA.id IS NULL THEN 0 ELSE OCA.id END) AS fky1, " .
       "(CASE WHEN OCA.id IS NULL THEN 0 ELSE OCA.address_id END) AS fky2, " .
       "AT.descr as text " .
       "FROM addresstype AT " .
       "LEFT JOIN organizationcontactaddress OCA " .
       "ON (OCA.organizationcontact_id = $oc_id AND AT.id = OCA.addresstype_id) " .
       "WHERE AT.active = 1 " ;
$result = $dal->query($sql);

echo json_encode($result);

?>

