<?php
require_once('config.php');

$error_message;
$valid = true;

$json = file_get_contents('php://input');

// Converts it into a PHP object
$data = json_decode($json, true);

$site_cd = $data['site_cd'];
$EmpID = $data['EmpID'];
$ROW_ID = $data['RowID'];
$LOGINID = $data['LOGINID'];

$wko_det_work_grp = $data['wko_det_work_grp'];
$wko_det_numeric2 = $data['wko_det_numeric2'];
$wko_det_numeric3 = $data['wko_det_numeric3'];


$Is_checked = $data['wko_det_safety'];


$sql = "UPDATE	wko_det 
SET		wko_det_safety =?,
		wko_det_work_grp=?,
		wko_det_numeric2=?,
		wko_det_numeric3=?,		
		wko_det.audit_user =?,						
		wko_det.audit_date=GETDATE()
WHERE	wko_det.site_cd =?
AND		wko_det.mst_RowID = ?";								
								
$params_wko_det = array($Is_checked,$wko_det_work_grp,$wko_det_numeric2,$wko_det_numeric3,$LOGINID,$site_cd,$ROW_ID);				
$stmt_wko_det = sqlsrv_query( $conn, $sql,$params_wko_det);

if( !$stmt_wko_det ) {
	$error_message = "Error insert table (UPDATE Table wko_det)";
	returnError($error_message);
	die( print_r( sqlsrv_errors(), true));
}	
sqlsrv_free_stmt( $stmt_wko_det);	




if ($valid) {	
	sqlsrv_commit( $conn );
	sqlsrv_close( $conn);	
	returnData();	
}
 
function returnData(){
	$returnData = array(
	'status' => 'SUCCESS',	
	'message' => 'Update Successfully');

	echo json_encode($returnData);
}

function returnError($error_message){	
	
	$returnData = array(
	'status' => 'ERROR',
	'message' => $error_message);	
	echo json_encode($returnData);
	exit();
}




?>