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

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

$dal = new DAL();

$sql = "SELECT LC.id,    LC.lot_id AS fkid, " .
       "composition_id,  '' AS composition_id_text, " . 
       "munselcolour_id, '' AS munselcolour_id_text, " . 
       "compaction_id,   '' AS compaction_id_text, " . 
       "(CASE WHEN SE.id IS NULL THEN 0 ELSE SE.texture_id END) AS texture_id, " .
       "(CASE WHEN SE.id IS NULL THEN '' ELSE '' END) AS texture_id_text, " .
       "(CASE WHEN SE.id IS NULL THEN 0 ELSE SE.sphericity_id END) AS sphericity_id, " .
       "(CASE WHEN SE.id IS NULL THEN '' ELSE '' END) AS sphericity_id_text, " .
       "(CASE WHEN SE.id IS NULL THEN 0 ELSE SE.rounding_id END) AS rounding_id, " .
       "(CASE WHEN SE.id IS NULL THEN '' ELSE '' END) AS rounding_id_text, " .
       "note,            '' AS note_text " .
       "FROM lotcomposition LC " .
       "LEFT JOIN sediment SE ON SE.lotcomposition_id = LC.id " .
       "WHERE LC.id = $lc_id LIMIT 1 " ; 
$result = $dal->query($sql);

$_SESSION['lotdefinition'] = $lc_id;
 
echo json_encode($result);

?>

