<?php

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

foreach ($_POST as $paramName => $paramValue) {
  if ($paramName == "optionsid")
    $co_id = $paramValue;
}

$dal = new DAL();
$sql = "SELECT OC.id,  " .
       "(CASE WHEN " .
         "(LENGTH(CO.surname) < 10 && LENGTH(CO.firstname) < 10) " . 
           "THEN CONCAT(CO.surname,', ',CO.firstname) " . 
           "ELSE CONCAT(CO.surname,', ',SUBSTRING(CO.firstname,1,1)) " . 
       "END) AS text " .
       "FROM organizationcontact OC, contact CO, organizationcontact OC1 " .
       "WHERE OC1.id = $oc_id AND OC.organization_id = OC1.organization_id " .
       "AND CO.id = OC.contact_id " ;
$result = $dal->query($sql);

echo json_encode($result);

?>

