<?php
if($_COOKIE['sejahtera_role'] == 10)
{
	include_once ("includes/setup_pemohon.inc.php");
}
else
{
	include_once ("includes/setup.inc.php");
}
//include_once ("includes/setup_pemohon.inc.php");
//Header("Content-type: application/xml");
Header("Cache-Control: no-cache");

$num_errors = 0;
$id = fetch_postget_val("id", $_POST, $_GET);
$part = fetch_postget_val("part", $_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();
	
	if($part == 1)
	{
		$indicator_Array[] = array('id_kahwin', fetch_postget_val("id_kahwin", $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array[] = array('id_jantina', fetch_postget_val("id_jantina", $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array[] = array('id_bangsa', fetch_postget_val("id_bangsa", $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array[] = array('id_tarafpendidikan', fetch_postget_val("id_tarafpendidikan", $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array[] = array('id_dun', fetch_postget_val("id_dun", $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array[] = array('id_parlimen', fetch_postget_val("id_parlimen", $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array[] = array('id_daerah', fetch_postget_val("id_daerah", $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array[] = array('id_katmilik', fetch_postget_val("id_katmilik", $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array[] = array('luas_kandang', fetch_postget_val("luas_kandang", $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array[] = array('luas_fodder', fetch_postget_val("luas_fodder", $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array[] = array('luas_ragutan', fetch_postget_val("luas_ragutan", $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array[] = array('id_hakmilik', fetch_postget_val("id_hakmilik", $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array[] = array('id_projekerajaan', fetch_postget_val("id_projekerajaan", $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array[] = array('id_statuskandang', fetch_postget_val("id_statuskandang", $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array[] = array('no_lesen', fetch_postget_val("no_lesen", $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array[] = array('no_salt', fetch_postget_val("no_salt", $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array[] = array('syarat_tanah', fetch_postget_val("syarat_tanah", $_POST, $_GET), PDO::PARAM_STR);
	}
	else if($part == 2)
	{
		$indicator_Array[] = array('le_daging', fetch_postget_val("le_daging", $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array[] = array('le_fidlot', fetch_postget_val("le_fidlot", $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array[] = array('le_tenusu', fetch_postget_val("le_tenusu", $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array[] = array('kerbau', fetch_postget_val("kerbau", $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array[] = array('kambing', fetch_postget_val("kambing", $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array[] = array('kambing_tenusu', fetch_postget_val("kambing_tenusu", $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array[] = array('bebiri', fetch_postget_val("bebiri", $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array[] = array('babi', fetch_postget_val("babi", $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array[] = array('ayam_piru', fetch_postget_val("ayam_piru", $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array[] = array('puyuh_pembiak', fetch_postget_val("puyuh_pembiak", $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array[] = array('ay_daging', fetch_postget_val("ay_daging", $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array[] = array('ay_telur', fetch_postget_val("ay_telur", $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array[] = array('ay_kampung', fetch_postget_val("ay_kampung", $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array[] = array('ay_pembiak_dg', fetch_postget_val("ay_pembiak_dg", $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array[] = array('ay_pembiak_kg', fetch_postget_val("ay_pembiak_kg", $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array[] = array('it_daging', fetch_postget_val("it_daging", $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array[] = array('it_telur', fetch_postget_val("it_telur", $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array[] = array('it_pembiak', fetch_postget_val("it_pembiak", $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array[] = array('pu_daging', fetch_postget_val("pu_daging", $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array[] = array('pu_telur', fetch_postget_val("pu_telur", $_POST, $_GET), 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_pemohon = $id";
	$PASS_COUNTER += PDO_UPDATE($PDO, 'm_borang', $indicator_Array, $whereCondition);

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

?>