<?php

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

foreach ($_POST as $paramName => $paramValue) {
  if ($paramName == "sumid")
    $or_id = $paramValue;
}

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

echo json_encode($result);

?>

