<?php
//共通
require_once '../../base/common.php';
$logger = new logger(basename(__FILE__));
$logger->info("===chkChgpas_start===");

$response["status"] = "NG";

try {
  global $dbutil;
  $valutil = new getValueUtil();

  $requestBody = file_get_contents('php://input');
  $logger->info("data", $requestBody );
  $data = json_decode($requestBody, true);

  $logger->info("data", $data );

  // SQL実行
  $whereParams["chgcd"] = $header["chgcd"];
  $whereParams["precycl"] = $header["precycl"];
  $whereParams["chgpas"] = $header["chgpas"];
  $sql = file_get_contents("./sql/chkChgpas.sql");
  $result = $dbutil->select($sql, $whereParams);

  if ( $result != null && $result["errcode"] < 0) {
    $retData["msg"]     = $result["errnm"];
    $response["status"] = "NG";
    $response["data"]   = $retData;
  } else if( $result != null && $result[0]["cnt"] != null) {  //データ有
    $response["status"] = "OK";
    $response["data"]   = json_encode($result[0], JSON_PARTIAL_OUTPUT_ON_ERROR);
  }

} catch(userException $ue) {
  $retData["code"]  = $ue->getErrorCode();
  $retData["msg"]   = $ue->getErrorMessage();

  $response["status"] = "NG";
  $response["data"]   = $retData;

  $dbutil->rollback();
} catch(Exception $e) {
  $response["status"] = "NG";
  $response["data"]   = $e->getMessage();

  $dbutil->rollback();

} finally {
  print(json_encode($response));
}


$logger->info("=== chkChgpas_end ===", $response);

?>
