<?php

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

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

if ($fkeyId == 3) 
  $where = "status_id > 0";
else
  $where = "status_id = $fkeyId";

$dal = new DAL();


$sql = "SELECT id, CONCAT (lastname, ', ', firstname) AS hint " .
       "FROM personnel " .
       "WHERE $where " .
       "AND (lastname LIKE '%$pattern%' OR firstname LIKE '%$pattern%') " ;
$result = $dal->query($sql);

echo json_encode ($result);


