<?php

include_once ("includes/setup.inc.php");
//Header("Content-type: application/xml");
Header("Cache-Control: no-cache");

$num_errors = 0;
$id = fetch_postget_val("id", $_POST, $_GET);
$dateTimeNow = dateTimeNow();

try
{
	$PASS_COUNTER = 0; //COUNTER FOR DOUBLE CONFIRM
	$PASS_VALUE = 1; //NUMBER OF QUERY TO EXECUTE. IMPORTANT FOR CHECKING!!

	//PDO INIT
	$PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
	$PDO->beginTransaction();

	$indicator_Array = array();
	$indicator_Array[] = array('tkh_buka', formatDate(fetch_postget_val("tkh_buka", $_POST, $_GET), "Y-m-d"), PDO::PARAM_STR);
	$indicator_Array[] = array('tkh_tutup', formatDate(fetch_postget_val("tkh_tutup", $_POST, $_GET), "Y-m-d"), PDO::PARAM_STR);
	$indicator_Array[] = array('aktif', fetch_postget_val("aktif", $_POST, $_GET), PDO::PARAM_INT);
	$indicator_Array[] = array('flag_khairat', fetch_postget_val("flag_khairat", $_POST, $_GET), PDO::PARAM_INT);
	$indicator_Array[] = array('flag_aktifmohon', fetch_postget_val("flag_aktifmohon", $_POST, $_GET), PDO::PARAM_INT);
	$indicator_Array[] = array('tahun_bayaran_tunai', fetch_postget_val("tahun_bayaran_tunai", $_POST, $_GET), PDO::PARAM_INT);
	$indicator_Array[] = array('id_bayaranfasa_tunai', fetch_postget_val("id_bayaranfasa_tunai", $_POST, $_GET), PDO::PARAM_INT);
	$indicator_Array[] = array('tkh_cutoff_tunai', formatDate(fetch_postget_val("tkh_cutoff_tunai", $_POST, $_GET), "Y-m-d"), PDO::PARAM_STR);
	$indicator_Array[] = array('tahun_bayaran_EFT', fetch_postget_val("tahun_bayaran_EFT", $_POST, $_GET), PDO::PARAM_INT);
	$indicator_Array[] = array('id_bayaranfasa_EFT', fetch_postget_val("id_bayaranfasa_EFT", $_POST, $_GET), PDO::PARAM_INT);
	$indicator_Array[] = array('tkh_cutoff_EFT', formatDate(fetch_postget_val("tkh_cutoff_EFT", $_POST, $_GET), "Y-m-d"), PDO::PARAM_STR);
	$indicator_Array[] = array('tkh_cutoff_sah_EFT', formatDate(fetch_postget_val("tkh_cutoff_sah_EFT", $_POST, $_GET), "Y-m-d"), PDO::PARAM_STR);
	$indicator_Array[] = array('tkh_cutoff_aktifmohon', formatDate(fetch_postget_val("tkh_cutoff_aktifmohon", $_POST, $_GET), "Y-m-d"), PDO::PARAM_STR);
	$indicator_Array[] = array('id_kemaskini', $my_details->usr_id, PDO::PARAM_INT);
	$indicator_Array[] = array('tkh_kemaskini', $dateTimeNow, PDO::PARAM_STR);
	$whereCondition = "WHERE id_kawalan = $id";
	$PASS_COUNTER += PDO_UPDATE_INDIKATOR_AUDIT($PDO, 'i_kawalan', $id, $indicator_Array, $whereCondition, $my_details->usr_id, $my_details->user_level, $dateTimeNow);

	//*****************************************
	//COMMIT if PASS_COUNTER == PASS_VALUE
	//*****************************************
	if ($PASS_COUNTER == $PASS_VALUE)
	{
		$PDO->commit();
		echo $PASS_COUNTER;
	}
	else
	{
		$PDO->rollBack();
		echo -1;
	}
}
catch (Exception $e) 
{
	$PDO->rollBack();
	echo "Failed: " . $e->getMessage();
}

?>