<?php

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

$num_errors = 0;
$id_bayaran = fetch_postget_val('id_bayaran',$_POST, $_GET);
$id_pemohon = fetch_postget_val('id_pemohon',$_POST, $_GET);
$id_program = fetch_postget_val('id_program',$_POST, $_GET);
$mbayar_table = fetch_postget_val('mbayar_table',$_POST, $_GET);
$mbayar_table_id = fetch_postget_val('mbayar_table_id',$_POST, $_GET);
$catatan = fetch_postget_val("catatan", $_POST, $_GET);
$dateTimeNow = dateTimeNow();

try
{
	$indicator_Query = "SELECT A.*
					  FROM $mbayar_table A
					  WHERE A.$mbayar_table_id = ?";
	$PDO_stmt = $PDO->prepare($indicator_Query);
	$PDO_stmt->bindValue(1, $id_bayaran, PDO::PARAM_INT);
	$PDO_stmt->execute();
	$anakemas_List = $PDO_stmt->fetch(PDO::FETCH_ASSOC);

	$PASS_COUNTER = 0; //COUNTER FOR DOUBLE CONFIRM
	$PASS_VALUE = 0; //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('id_bayarankat', fetch_postget_val("id_bayarankat", $_POST, $_GET), PDO::PARAM_STR);
	$indicator_Array[] = array('catatan', $catatan, PDO::PARAM_STR,1);
	$indicator_Array[] = array('id_kemaskini', $my_details->usr_id, PDO::PARAM_INT);
	$indicator_Array[] = array('tkh_kemaskini', $dateTimeNow, PDO::PARAM_STR);
	$PASS_VALUE += 1;
	$whereCondition = "WHERE $mbayar_table_id = $id_bayaran";
	$PASS_COUNTER += PDO_UPDATE($PDO, $mbayar_table, $indicator_Array, $whereCondition);
		
	$PASS_VALUE += 1;
	$PASS_COUNTER += PDO_INSERT_ACTION_AUDIT($PDO, $id_pemohon, 41, $my_details->usr_id, $my_details->user_level, $dateTimeNow, $my_details->user_jab, $my_details->user_dun, $my_details->user_daerah, $catatan, '', '', $my_details->user_parlimen, $id_program);

	//*****************************************
	//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();
}

?>