<?php

include_once ("includes/setup.inc.php");
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('desk_bank', fetch_postget_val("desk_bank", $_POST, $_GET), PDO::PARAM_STR);
	$indicator_Array[] = array('kod_bank', fetch_postget_val("kod_bank", $_POST, $_GET), PDO::PARAM_STR,1);
	$indicator_Array[] = array('digit_bank', fetch_postget_val("digit_bank", $_POST, $_GET), PDO::PARAM_STR);
	$indicator_Array[] = array('kod_rentas', fetch_postget_val("kod_rentas", $_POST, $_GET), PDO::PARAM_STR);
	$indicator_Array[] = array('alamat1', fetch_postget_val("alamat1", $_POST, $_GET), PDO::PARAM_STR);
	$indicator_Array[] = array('alamat2', fetch_postget_val("alamat2", $_POST, $_GET), PDO::PARAM_STR);
	$indicator_Array[] = array('susunan', fetch_postget_val("susunan", $_POST, $_GET), PDO::PARAM_STR);
	$indicator_Array[] = array('aktif', fetch_postget_val("aktif", $_POST, $_GET), PDO::PARAM_STR);

	if($id == 0)
	{
		$indicator_Array[] = array('id_keyin', $my_details->usr_id, PDO::PARAM_INT);
		$indicator_Array[] = array('tkh_keyin', $dateTimeNow, PDO::PARAM_STR);
		$PASS_COUNTER += PDO_INSERT($PDO, 'i_bank', $indicator_Array);
	}
	else
	{
		$indicator_Array[] = array('id_kemaskini', $my_details->usr_id, PDO::PARAM_INT);
		$indicator_Array[] = array('tkh_kemaskini', $dateTimeNow, PDO::PARAM_STR);
		$whereCondition = "WHERE id_bank = $id";
		//$PASS_COUNTER += PDO_UPDATE($PDO, 'i_bank', $indicator_Array, $whereCondition);
		$PASS_COUNTER += PDO_UPDATE_INDIKATOR_AUDIT($PDO, 'i_bank', $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();
}

?>