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

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

$gInit_array = array( //初期値
  "scls1" => "",
  "scls2" => "",
  "scls3" => "",
  "scls4" => "",
  "scls5" => "",
  "scls6" => "",
  "scls7" => "",
  "scls8" => "",
  "scls9" => "",
  "snum1" => "",
  "snum2" => "",
  "snum3" => "",
  "nm" => "",
  "nm2" => "",
  "nm3" => "",
  "nm4" => "",
);

$assign_var["hasPopAf04m"] = "1";

try {
  global $dbutil;

  $requestBody = file_get_contents('php://input');
  $data = json_decode($requestBody, true);

  $logger->info($data);

  // SQL実行
  $header = $data["header"];

  $ret_array = array(); //return用
  $ret_detail = array();  //データ用
  
  // sqlの条件を設定する
  $whereParams = array();
  $whereParams["mhno"] = $header["mhno"];
  $sql = file_get_contents("./sql/search.sql");
  $logger->info("whereParams",$whereParams);
  $result = $dbutil->select($sql, $whereParams);

  if ($result == null) {
    $ret = "1";
    $cnt = 0;
    $ret_detail = $gInit_array;
    $ret_detail["cls"] = $header["cls"];
  } else {
    $ret = "0";
    $ret_detail = $result;

    $cnt = 0;
    foreach($ret_detail as $key => $val) {
      $cnt++;
    }

  }

  $ret_array["ret"] = $ret;
  $ret_array["ret_array"] = $ret_detail;
  $ret_array["cnt"] = $cnt;
  $result = $ret_array;

  $logger->info('getDetail_ret',$result );
  $response["status"] = "OK";
  $response["data"]   = json_encode($result, true);

} 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("=== getDetail_end ===", $response);

?>
