<?php
session_start();

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

foreach ($_POST as $paramName => $paramValue) {
  if ($paramName == "summaryid")
    $id = $paramValue;
  else if ($paramName == "field")
    $field = $paramValue;
}

if ($field == 'sumFieldProjects') {

  $_SESSION['fieldproject'] = $id;
    
  if ($id > 0) {
    $dal = new DAL();

    $sql = "SELECT PW.id, PR.name AS Project, PR.refno AS 'Ref No', " .
           "PA.name AS Parcel, LO.username as Login, WO.textdate AS Workday, " .
           "CONCAT (PW.startime, '-', PW.stoptime) AS Time "  .
           "FROM project PR, projectparcel PP,  parcel PA, " .
           "projectworkevent PW, workday WO,  login LO " .
           "WHERE PR.id = $id AND PP.project_id = PR.id " .
           "AND PA.id = PP.parcel_id AND PW.projectparcel_id = PP.id " .
           "AND WO.id = PW.workday_id AND LO.id = PW.login_id " .
           "ORDER BY WO.date DESC";
    $result = $dal->query($sql);
  }
}

echo json_encode($result);
?>
