<?php

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

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

$dal = new DAL();
$sql = "SELECT OC.id, " .
       "CONCAT (CO.firstname, ' ' , CO.surname, ': ', OZ.name) AS hint " .
       "FROM organizationcontact OC, organization OZ, contact CO " .
       "WHERE (OZ.name LIKE '%$pattern%' OR CO.surname LIKE '%$pattern%' " .
       "OR CO.firstname LIKE '%$pattern%') " .
       "AND OC.contact_id = CO.id AND OC.organization_id = OZ.id " ;
$result = $dal->query($sql);

echo json_encode ($result);

?>

