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

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

$dal = new DAL();
// Get ids to store in Session
$sql = "SELECT PW.workday_id AS wo_id, PW.parcel_id as pa_id, " .
       "LW.id AS lw_id, PA.project_id AS pr_id " .
       "FROM projectworkday PW, loginworkday LW, parcel PA " .
       "WHERE PW.id = $pw_id AND PW.login_id = LW.login_id AND " . 
       "PW.workday_id = LW.workday_id AND PA.id = PW.parcel_id LIMIT 1 "; 
$workdays = $dal->query($sql); 

$sql = "SELECT PW.id, PR.name AS project_name, PR.id AS rowproject_name, " .
       "parcel_id AS parcel_id, date, start_time, end_time, break_dur " .
       "FROM projectworkday PW, workday WO, parcel PA, project PR " .
       "WHERE PW.id = $pw_id AND PW.parcel_id = PA.id " .
       "AND PW.workday_id = WO.id AND PA.project_id = PR.id LIMIT 1";
$result = $dal->query($sql);

$_SESSION['project'] = $workdays->pr_id;
$_SESSION['parcel'] = $workdays->pa_id;
$_SESSION['workday'] = $workdays->wo_id;
$_SESSION['loginworkday'] = $workdays->lw_id;
$_SESSION['projectworkday'] = $pw_id;

echo json_encode($result);

?>

