<?php

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

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

$dal = new DAL();

$sql = "SELECT PWP.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  (personnel PE, projectworkdaypersonnel PWP) " .
       "LEFT JOIN projectworkdayoperationpersonnel POP " .
       "ON (POP.projectworkdaypersonnel_id = PWP.id AND POP.projectworkdayoperation_id  = $pwo_id) " .
       "WHERE PWP.projectworkday_id = $pw_id AND PE.id = PWP.personnel_id AND POP.id IS NULL " .
       "ORDER BY text ";
$result = $dal->query($sql);

echo json_encode($result);

?>

