<?php

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

foreach ($_POST as $paramName => $paramValue) {
  if ($paramName == "fkeyid")
    $pw_id = $paramValue;
  else if ($paramName == "selectid")
    $pwo_id = $paramValue;
}

$dal = new DAL();

$sql = "SELECT POB.id, " .
       "CASE WHEN " .
         "(LENGTH(surname) < 10 && LENGTH(firstname) < 10) " . 
           "THEN CONCAT(surname,', ',firstname) " . 
         "ELSE CONCAT(surname,', ',SUBSTRING(firstname,1,1)) " . 
       "END AS text " .
       "FROM (contact CO, projectworkdayobserver POB) " . 
       "LEFT JOIN projectworkdayoperationobserver POO " .
       "ON (POO.projectworkdayobserver_id = POB.id AND POO.projectworkdayoperation_id = $pwo_id) " .
       "WHERE POB.projectworkday_id = $pw_id AND CO.id = POB.contact_id " .
       "AND POO.id IS NULL " .
       "ORDER BY text ";
$result = $dal->query($sql);

echo json_encode($result);

?>

