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

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


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

try {
  global $dbutil;

$logger->info("data>>", $data['data']);
  $cnt = 0;
  $detail = $data['data'][0];
  insertUpdateAxm99($detail, $dbutil, $logger );

  $dbutil->commit();
} 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 {
  $logger->info("response", $response );
  print( json_encode($response) );
}

$logger->info("=== af999x_updata_end ===");

//axm99
function insertUpdateAxm99($data, $dbutil, $logger) {
  global $stringUtil;

  $valueData['hnm'] = $data['hnm'];
  $valueData['hzip'] = $data['hzip'];
  $valueData['hadd'] = $data['hadd'];
  $valueData['hadd2'] = $data['hadd2'];
  $valueData['htel'] = $data['htel'];
  $valueData['hfax'] = $data['hfax'];
  $valueData['hcd'] = $data['hcd'];
  $valueData['frdat'] = $data['frdat'];
  $valueData['fgicd'] = $data['fgicd'];
  $valueData['fsicd'] = $data['fsicd'];
  $valueData['fnm'] = $data['fnm'];
  $valueData['fknmk'] = $data['fknmk'];
  $valueData['fkcd'] = $data['fkcd'];
  $valueData['fyocd'] = $data['fyocd'];
  $valueData['fkocd'] = $data['fkocd'];
  $valueData['fgicd2'] = $data['fgicd2'];
  $valueData['fsicd2'] = $data['fsicd2'];
  $valueData['fnm2'] = $data['fnm2'];
  $valueData['fknmk2'] = $data['fknmk2'];
  $valueData['fyocd2'] = $data['fyocd2'];
  $valueData['fkocd2'] = $data['fkocd2'];
  $valueData['fgicd3'] = $data['fgicd3'];
  $valueData['fsicd3'] = $data['fsicd3'];
  $valueData['fnm3'] = $data['fnm3'];
  $valueData['fknmk3'] = $data['fknmk3'];
  $valueData['fyocd3'] = $data['fyocd3'];
  $valueData['fkocd3'] = $data['fkocd3'];
  $valueData['ktktcd'] = $_SESSION[$GLOBALS['SYSTEM_NAME_EN']]["LGKTKTCD"];

  $logger->info("valuData",$valueData);
  //更新
  $sql = file_get_contents("./sql/update.sql");
  $result = $dbutil->update($sql, $valueData);
  $logger->info("did_update",$result);
}

?>
