<?php

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

foreach ($_POST as $paramName => $paramValue) {
  if ($paramName == "currid")
    $date = $paramValue;
  if ($paramName == "baseid")
    $lo_id  = $paramValue;
}

$dal = new DAL();

$sql = "SELECT PTR.id, PR.name AS project, PR.refno AS ref_no, " .
       "PA.name AS parcel, TR.name AS role, PTR.moduration, " .
       "CASE WHEN PTR.billable = 1 THEN 'Yes' ELSE 'No' END AS billable, " .
       "PTR.note " .
       "FROM workday WO, projectworkday PW, projectworkdaypersonnel PWP, " .
       "parcel PA, project PR, projectteamrole PTR, teamrole TR " . 
       "WHERE WO.date = '$date' AND PW.workday_id = WO.id " .
       "AND PW.login_id = $lo_id AND PWP.projectworkday_id = PW.id " .
       "AND PTR.projectworkdaypersonnel_id = PWP.id " .
       "AND TR.id = PTR.teamrole_id AND PA.id = PW.parcel_id " .
       "AND PR.id = PA.project_id ORDER BY PTR.start_time DESC ";
$result = $dal->query($sql);

echo json_encode($result);

?>
