<?php

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

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

$dal = new DAL();

$sql = "SELECT PWP.id, " .
       "CASE WHEN " .
         "(LENGTH(surname) < 10 && LENGTH(firstname) < 10) " . 
           "THEN CONCAT(surname,', ',firstname) " . 
           "ELSE CONCAT(surname,', ',SUBSTRING(firstname,1,1)) " . 
       "END AS text " .
       "FROM personnel PE, projectworkdaypersonnel PWP, projectworkdayoperationpersonnel POP " .
       "WHERE POP.projectworkdayoperation_id = $pwo_id " .
       "AND PWP.id = POP.projectworkdaypersonnel_id AND PE.id = PWP.personnel_id " .
       "ORDER BY text ";
$result = $dal->query($sql);

echo json_encode($result);

?>

