<?php
session_start();
$lo_id = $_SESSION['login'];

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

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

$dal = new DAL();

$sql = "SELECT OW.id, PR.name AS Project, PR.refno AS RefNo, " .
       "PA.name AS Parcel, " .
       "(CASE WHEN TE.name IS NULL THEN 'Not selected' ELSE TE.name END) AS Role, " . 
       "OW.duration AS Duration, " .
       "(CASE WHEN OW.billable = 1 THEN 'Yes' ELSE 'No' END) AS Billable, " .
       "OW.note AS Note " .
       "FROM (workday WO, officeworkrole OW, projectparcel PP, parcel PA, project PR) " .
       "LEFT JOIN teamrole TE ON TE.id = OW.teamrole_id " . 
       "WHERE WO.id = '$wo_id' AND OW.workday_id = WO.id " .
       "AND OW.login_id = $lo_id AND PP.id = OW.projectparcel_id " .
       "AND PA.id = PP.parcel_id AND PR.id = PP.project_id " .
       "ORDER BY OW.startime DESC ";
$result = $dal->query($sql);

echo json_encode($result);

?>
