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

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

if ($pw_id > 0) {
  $dal = new DAL();

  $sql = "SELECT PW.workday_id AS wo_id, PW.projectparcel_id as pp_id, " .
         "LW.id AS lw_id, PP.project_id AS pr_id " .
         "FROM projectworkevent PW, loginworkday LW, projectparcel PP " .
         "WHERE PW.id = $pw_id AND PW.login_id = LW.login_id AND " . 
         "PW.workday_id = LW.workday_id AND PP.id = PW.projectparcel_id LIMIT 1 "; 
  $workdays = $dal->query($sql); 

// form values 
  $sql = "SELECT PW.id,        PR.id as fkid, " .
         "PA.project_id,       CONCAT (PR.refno, ': ', PR.name) AS project_id_text, " .
         "PW.projectparcel_id, PA.name AS parcel_id_text, " .
         "WO.date,             WO.textdate AS date_text, " .
         "PW.startime,         PW.startime AS startime_text, " . 
         "PW.stoptime,         PW.stoptime AS stoptime_text, " .
         "PW.breakdur,         PW.breakdur AS breakdur_text,  " .
         "PW.note,             '' AS note_text  " .
         "FROM projectworkevent PW, projectparcel PP, " .
         "parcel PA, project PR, workday WO " .
         "WHERE PW.id = $pw_id AND PP.id = PW.projectparcel_id " .
         "AND PA.id = PP.parcel_id AND PR.id = PP.project_id " .
         "AND WO.id = PW.workday_id LIMIT 1";
  $result = $dal->query($sql);

  $_SESSION['fieldproject'] = $workdays->pr_id;
  $_SESSION['projectparcel'] = $workdays->pp_id;
  $_SESSION['workday'] = $workdays->wo_id;
  $_SESSION['loginworkday'] = $workdays->lw_id;
  $_SESSION['projectworkevent'] = $pw_id;
}

else {
  $_SESSION['fieldproject'] = 0;
  $_SESSION['projectparcel'] = 0;
  $_SESSION['workday'] = 0;
  $_SESSION['loginworkday'] = 0;
  $_SESSION['projectworkevent'] = 0;
}

$_SESSION['definedoperation'] = 0;
$_SESSION['dailyoperation'] = 0;
$_SESSION['propertypart'] = 0;
$_SESSION['sitedefinition'] = 0;

echo json_encode($result);

?>

