<?php

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

$num_errors = 0;
$dateTimeNow = dateTimeNow();

/*$indicator_Query = "SELECT t_pemohon.*
				  FROM t_pemohon
				  WHERE emel = ?";
$PDO_stmt = $PDO->prepare($indicator_Query);
$PDO_stmt->bindValue(1, fetch_postget_val("emel", $_POST, $_GET), PDO::PARAM_STR);
$PDO_stmt->execute();
$indicator_List2 = $PDO_stmt->fetch(PDO::FETCH_ASSOC);

if($indicator_List2['id_pemohon'] > 0)
{
	echo -777;
	exit(0);
}*/

$active_ruminan = fetch_postget_val("active_ruminan", $_POST, $_GET);
$active_tenusu = fetch_postget_val("active_tenusu", $_POST, $_GET);
$active_babi = fetch_postget_val("active_babi", $_POST, $_GET);
$active_aneka = fetch_postget_val("active_aneka", $_POST, $_GET);
$ruminan_id = 0;
$tenusu_id = 0;
$babi_id = 0;
$aneka_id = 0;

$indicator_Query = "SELECT *
				  FROM i_dun
				  WHERE id_dun = ?";
$PDO_stmt = $PDO->prepare($indicator_Query);
$PDO_stmt->bindValue(1, fetch_postget_val("dun_premis", $_POST, $_GET), PDO::PARAM_STR);
$PDO_stmt->execute();
$dun_List = $PDO_stmt->fetch(PDO::FETCH_ASSOC);

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

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

	$kpbaru = fetch_postget_val("kpbaru_pemilik", $_POST, $_GET);
	$year = ((substr($kpbaru, 0, 2) <= date("y"))?'20':'19').substr($kpbaru, 0, 2);
	$tkh_lahir = $year."-".substr($kpbaru, 2, 2)."-".substr($kpbaru, 4, 2);
	$id_jantina = (substr($kpbaru, -1) % 2 == 0 ? 2 : 1);
	
	$indicator_Array = array();
	$indicator_Array[] = array('nama_pemilik', fetch_postget_val("nama_pemilik", $_POST, $_GET), PDO::PARAM_STR);
	$indicator_Array[] = array('kpbaru_pemilik', fetch_postget_val("kpbaru_pemilik", $_POST, $_GET), PDO::PARAM_STR);
	$indicator_Array[] = array('tkhlahir_pemilik', $tkh_lahir, PDO::PARAM_STR);
	$indicator_Array[] = array('id_jantina', $id_jantina, PDO::PARAM_STR);
	$indicator_Array[] = array('id_bangsa', fetch_postget_val("bangsa_pemilik", $_POST, $_GET), PDO::PARAM_STR);
	$indicator_Array[] = array('tel_pemilik', fetch_postget_val("tel_pemilik", $_POST, $_GET), PDO::PARAM_STR);
	$indicator_Array[] = array('alamat_pemilik', fetch_postget_val("alamat_pemilik", $_POST, $_GET), PDO::PARAM_STR);
	$indicator_Array[] = array('id_jenispemilik', 2, PDO::PARAM_INT);
	
	$indicator_Array[] = array('id_insert', $my_details->usr_id, PDO::PARAM_INT);
	$indicator_Array[] = array('tkh_insert', $dateTimeNow, PDO::PARAM_STR);
	
	$PASS_COUNTER += PDO_INSERT($PDO, 'm_pemilik', $indicator_Array);
	$pemilik_id = $PDO->lastInsertId();

	$indicator_Array2 = array();
	$indicator_Array2[] = array('id_pemilik', $pemilik_id, PDO::PARAM_INT);
	$indicator_Array2[] = array('id_premis', fetch_postget_val("id_premis", $_POST, $_GET), PDO::PARAM_STR,1);
	$indicator_Array2[] = array('alamat_ladang', fetch_postget_val("alamat_premis", $_POST, $_GET), PDO::PARAM_STR);
	$indicator_Array2[] = array('nama_penternak', fetch_postget_val("nama_penternak", $_POST, $_GET), PDO::PARAM_STR);
	$indicator_Array2[] = array('gps_ladang_lat', fetch_postget_val("gps_lat", $_POST, $_GET), PDO::PARAM_STR);
	$indicator_Array2[] = array('gps_ladang_long', fetch_postget_val("gps_long", $_POST, $_GET), PDO::PARAM_STR);
	$indicator_Array2[] = array('id_negeri', 11, PDO::PARAM_STR); //hardcode to penang
	$indicator_Array2[] = array('id_daerah', $dun_List['id_daerah'], PDO::PARAM_STR);
	$indicator_Array2[] = array('id_mukim', 0, PDO::PARAM_STR); //what is this?
	$indicator_Array2[] = array('id_parlimen', $dun_List['id_parlimen'], PDO::PARAM_STR);
	$indicator_Array2[] = array('id_dun', fetch_postget_val("dun_premis", $_POST, $_GET), PDO::PARAM_STR);
	$indicator_Array2[] = array('id_status_ladang', fetch_postget_val("status_ladang_premis", $_POST, $_GET), PDO::PARAM_STR);
	$indicator_Array2[] = array('id_projek_kerajaan', fetch_postget_val("projek_kerajaan_premis", $_POST, $_GET), PDO::PARAM_STR);
	$indicator_Array2[] = array('id_katpemilik', fetch_postget_val("katpemilik_premis", $_POST, $_GET), PDO::PARAM_STR);
	$indicator_Array2[] = array('id_status_lesen', fetch_postget_val("status_lesen_premis", $_POST, $_GET), PDO::PARAM_STR);
	$indicator_Array2[] = array('id_sistem_pemeliharaan', fetch_postget_val("sistem_pemeliharaan_premis", $_POST, $_GET), PDO::PARAM_STR);
	$indicator_Array2[] = array('id_hakmilik', fetch_postget_val("hakmilik_premis", $_POST, $_GET), PDO::PARAM_STR);
	$indicator_Array2[] = array('id_kategori_tanah', fetch_postget_val("kategori_tanah_premis", $_POST, $_GET), PDO::PARAM_STR);
	$indicator_Array2[] = array('id_syarat_nyata_tanah', fetch_postget_val("syarat_nyata_tanah_premis", $_POST, $_GET), PDO::PARAM_STR);


	$indicator_Array2[] = array('id_insert', $my_details->usr_id, PDO::PARAM_INT);
	$indicator_Array2[] = array('tkh_insert', $dateTimeNow, PDO::PARAM_STR);
	
	$PASS_COUNTER += PDO_INSERT($PDO, 'm_ladang', $indicator_Array2);
	$ladang_id = $PDO->lastInsertId();
	
	if($active_ruminan > 0)
	{
		$myid = "ruminan";
		$indicator_Array3 = array();
		$indicator_Array3[] = array('id_ladang', $ladang_id, PDO::PARAM_INT);
		$indicator_Array3[] = array('lr_luas_kandang', fetch_postget_val('luas_kandang_' . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array3[] = array('lr_luas_fodder', fetch_postget_val('luas_fodder_' . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array3[] = array('lr_luas_ragutan', fetch_postget_val('luas_ragutan_' . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array3[] = array('lr_kapasiti_pedaging', fetch_postget_val('kapasiti_pedaging_' . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array3[] = array('lr_kapasiti_fidlot', fetch_postget_val('kapasiti_fidlot_' . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array3[] = array('lr_kapasiti_kambing', fetch_postget_val('kapasiti_kambing_' . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array3[] = array('lr_kapasiti_bebiri', fetch_postget_val('kapasiti_bebiri_' . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array3[] = array('lr_kapasiti_kerbau', fetch_postget_val('kapasiti_kerbau_' . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array3[] = array('id_kategori_ladang_lembu', fetch_postget_val('kategori_ladang_lembu_' . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array3[] = array('id_kategori_ladang_kambing', fetch_postget_val('kategori_ladang_kambing_' . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array3[] = array('id_kategori_ladang_kerbau', fetch_postget_val('kategori_ladang_kerbau_' . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array3[] = array('lr_bt_lembu_kk_baka', fetch_postget_val('lembu_kk_baka_' . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array3[] = array('lr_bt_lembu_kk_jurusan', fetch_postget_val('lembu_kk_jurusan_' . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array3[] = array('lr_bt_lembu_kk_j1', fetch_postget_val('lembu_kk_j1_' . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array3[] = array('lr_bt_lembu_kk_j2', fetch_postget_val('lembu_kk_j2_' . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array3[] = array('lr_bt_lembu_kk_j3', fetch_postget_val('lembu_kk_j3_' . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array3[] = array('lr_bt_lembu_kk_b1', fetch_postget_val('lembu_kk_b1_' . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array3[] = array('lr_bt_lembu_kk_b2', fetch_postget_val('lembu_kk_b2_' . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array3[] = array('lr_bt_lembu_kk_b3', fetch_postget_val('lembu_kk_b3_' . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array3[] = array('lr_bt_lembu_kacukan_baka', fetch_postget_val('lembu_kacukan_baka_' . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array3[] = array('lr_bt_lembu_kacukan_jurusan', fetch_postget_val('lembu_kacukan_jurusan_' . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array3[] = array('lr_bt_lembu_kacukan_j1', fetch_postget_val('lembu_kacukan_j1_' . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array3[] = array('lr_bt_lembu_kacukan_j2', fetch_postget_val('lembu_kacukan_j2_' . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array3[] = array('lr_bt_lembu_kacukan_j3', fetch_postget_val('lembu_kacukan_j3_' . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array3[] = array('lr_bt_lembu_kacukan_b1', fetch_postget_val('lembu_kacukan_b1_' . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array3[] = array('lr_bt_lembu_kacukan_b2', fetch_postget_val('lembu_kacukan_b2_' . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array3[] = array('lr_bt_lembu_kacukan_b3', fetch_postget_val('lembu_kacukan_b3_' . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array3[] = array('lr_bt_kerbau_baka', fetch_postget_val('kerbau_baka_' . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array3[] = array('lr_bt_kerbau_jurusan', fetch_postget_val('kerbau_jurusan_' . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array3[] = array('lr_bt_kerbau_j1', fetch_postget_val('kerbau_j1_' . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array3[] = array('lr_bt_kerbau_j2', fetch_postget_val('kerbau_j2_' . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array3[] = array('lr_bt_kerbau_j3', fetch_postget_val('kerbau_j3_' . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array3[] = array('lr_bt_kerbau_b1', fetch_postget_val('kerbau_b1_' . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array3[] = array('lr_bt_kerbau_b2', fetch_postget_val('kerbau_b2_' . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array3[] = array('lr_bt_kerbau_b3', fetch_postget_val('kerbau_b3_' . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array3[] = array('lr_bt_kambing_baka', fetch_postget_val('kambing_baka_' . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array3[] = array('lr_bt_kambing_jurusan', fetch_postget_val('kambing_jurusan_' . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array3[] = array('lr_bt_kambing_j1', fetch_postget_val('kambing_j1_' . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array3[] = array('lr_bt_kambing_j2', fetch_postget_val('kambing_j2_' . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array3[] = array('lr_bt_kambing_b1', fetch_postget_val('kambing_b1_' . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array3[] = array('lr_bt_kambing_b2', fetch_postget_val('kambing_b2_' . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array3[] = array('lr_bt_bebiri_baka', fetch_postget_val('bebiri_baka_' . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array3[] = array('lr_bt_bebiri_jurusan', fetch_postget_val('bebiri_jurusan_' . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array3[] = array('lr_bt_bebiri_j1', fetch_postget_val('bebiri_j1_' . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array3[] = array('lr_bt_bebiri_j2', fetch_postget_val('bebiri_j2_' . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array3[] = array('lr_bt_bebiri_b1', fetch_postget_val('bebiri_b1_' . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array3[] = array('lr_bt_bebiri_b2', fetch_postget_val('bebiri_b2_' . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array3[] = array('lr_bil_jual_lembu', fetch_postget_val('bil_jual_lembu_' . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array3[] = array('lr_nilai_jualan_lembu', fetch_postget_val('nilai_jual_lembu_' . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array3[] = array('lr_bil_jual_kerbau', fetch_postget_val('bil_jual_kerbau_' . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array3[] = array('lr_nilai_jualan_kerbau', fetch_postget_val('nilai_jual_kerbau_' . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array3[] = array('lr_bil_jual_kambing', fetch_postget_val('bil_jual_kambing_' . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array3[] = array('lr_nilai_jualan_kambing', fetch_postget_val('nilai_jual_kambing_' . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array3[] = array('lr_bil_jual_bebiri', fetch_postget_val('bil_jual_bebiri_' . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array3[] = array('lr_nilai_jualan_bebiri', fetch_postget_val('nilai_jual_bebiri_' . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array3[] = array('id_insert', $my_details->usr_id, PDO::PARAM_INT);
		$indicator_Array3[] = array('tkh_insert', $dateTimeNow, PDO::PARAM_STR);
		
		$PASS_VALUE += 1;
		$PASS_COUNTER += PDO_INSERT($PDO, 'm_ladang_ruminan', $indicator_Array3);
		$ruminan_id = $PDO->lastInsertId();
	}
	
	if($active_tenusu > 0)
	{
		$myid = "tenusu";
		$indicator_Array4 = array();
		$indicator_Array4[] = array('id_ladang', $ladang_id, PDO::PARAM_INT);
		$indicator_Array4[] = array("lt_luas_kandang", fetch_postget_val("luas_kandang_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array4[] = array("lt_luas_fodder", fetch_postget_val("luas_fodder_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array4[] = array("lt_luas_ragutan", fetch_postget_val("luas_ragutan_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array4[] = array("lt_kapasiti_lembu", fetch_postget_val("kapasiti_lembu_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array4[] = array("lt_kapasiti_kerbau", fetch_postget_val("kapasiti_kerbau_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array4[] = array("lt_kapasiti_kambing", fetch_postget_val("kapasiti_kambing_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array4[] = array("lt_kapasiti_bebiri", fetch_postget_val("kapasiti_bebiri_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array4[] = array("id_kategori_ladang_tenusu", fetch_postget_val("kategori_ladang_tenusu_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array4[] = array("lt_bt_lembu_baka", fetch_postget_val("lembu_baka_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array4[] = array("lt_bt_lembu_j1", fetch_postget_val("lembu_j1_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array4[] = array("lt_bt_lembu_j2", fetch_postget_val("lembu_j2_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array4[] = array("lt_bt_lembu_j3", fetch_postget_val("lembu_j3_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array4[] = array("lt_bt_lembu_b1", fetch_postget_val("lembu_b1_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array4[] = array("lt_bt_lembu_b2", fetch_postget_val("lembu_b2_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array4[] = array("lt_bt_lembu_b3", fetch_postget_val("lembu_b3_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array4[] = array("lt_bt_kerbau_baka", fetch_postget_val("kerbau_baka_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array4[] = array("lt_bt_kerbau_j1", fetch_postget_val("kerbau_j1_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array4[] = array("lt_bt_kerbau_j2", fetch_postget_val("kerbau_j2_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array4[] = array("lt_bt_kerbau_j3", fetch_postget_val("kerbau_j3_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array4[] = array("lt_bt_kerbau_b1", fetch_postget_val("kerbau_b1_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array4[] = array("lt_bt_kerbau_b2", fetch_postget_val("kerbau_b2_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array4[] = array("lt_bt_kerbau_b3", fetch_postget_val("kerbau_b3_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array4[] = array("lt_bt_kambing_baka", fetch_postget_val("kambing_baka_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array4[] = array("lt_bt_kambing_j1", fetch_postget_val("kambing_j1_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array4[] = array("lt_bt_kambing_j2", fetch_postget_val("kambing_j2_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array4[] = array("lt_bt_kambing_b1", fetch_postget_val("kambing_b1_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array4[] = array("lt_bt_kambing_b2", fetch_postget_val("kambing_b2_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array4[] = array("lt_bil_jual_ternakan", fetch_postget_val("bil_jual_ternakan_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array4[] = array("lt_nilai_jualan_ternakan", fetch_postget_val("nilai_jual_ternakan_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array4[] = array("lt_nilai_jualan_ternakan_tahunan", fetch_postget_val("nilai_jual_ternakan_tahunan_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array4[] = array("lt_jumlah_susu_sehari_lembu", fetch_postget_val("susu_sehari_lembu_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array4[] = array("lt_nilai_jualan_susu_lembu", fetch_postget_val("nilai_jual_susu_lembu_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array4[] = array("lt_nilai_jualan_susu_tahunan_lembu", fetch_postget_val("nilai_jual_susu_tahunan_lembu_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array4[] = array("lt_jumlah_susu_sehari_kambing", fetch_postget_val("susu_sehari_kambing_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array4[] = array("lt_nilai_jualan_susu_kambing", fetch_postget_val("nilai_jual_susu_kambing_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array4[] = array("lt_nilai_jualan_susu_tahunan_kambing", fetch_postget_val("nilai_jual_susu_tahunan_kambing_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array4[] = array('id_insert', $my_details->usr_id, PDO::PARAM_INT);
		$indicator_Array4[] = array('tkh_insert', $dateTimeNow, PDO::PARAM_STR);
		
		$PASS_VALUE += 1;
		$PASS_COUNTER += PDO_INSERT($PDO, 'm_ladang_tenusu', $indicator_Array4);
		$tenusu_id = $PDO->lastInsertId();
	}
	
	if($active_babi > 0)
	{
		$myid = "babi";
		$indicator_Array5 = array();
		$indicator_Array5[] = array('id_ladang', $ladang_id, PDO::PARAM_INT);
		$indicator_Array5[] = array("lb_luas_ladang", fetch_postget_val("luas_ladang_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array5[] = array("lb_kapasiti_ladang", fetch_postget_val("kapasiti_ladang_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array5[] = array("lb_baka_babi", fetch_postget_val("baka_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array5[] = array("lb_bil_kandang_tertutup", fetch_postget_val("bil_kandang_tutup_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array5[] = array("lb_bil_kandang_semi_terbuka", fetch_postget_val("bil_kandang_semi_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array5[] = array("lb_bil_kandang_terbuka", fetch_postget_val("bil_kandang_buka_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array5[] = array("lb_bil_sisa_kumbahan", fetch_postget_val("bil_sisa_kumbahan_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array5[] = array("id_pengolahan_sisa_kumbahan", fetch_postget_val("pengolahan_sisa_kumbahan_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array5[] = array("lb_exist_zon_penampan", fetch_postget_val("zon_penampan_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array5[] = array("lb_exist_gahp", fetch_postget_val("gahp_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array5[] = array("lb_exist_homemixer", fetch_postget_val("homemixer_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array5[] = array("lb_jumlah_spesis_boar", fetch_postget_val("jumlah_spesis_boar_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array5[] = array("lb_jumlah_spesis_induk", fetch_postget_val("jumlah_spesis_induk_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array5[] = array("lb_jumlah_spesis_lain", fetch_postget_val("jumlah_spesis_lain_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array5[] = array("lb_jumlah_spesis_spp", fetch_postget_val("jumlah_spesis_spp_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array5[] = array("lb_bil_jualan", fetch_postget_val("bil_jualan_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array5[] = array("lb_nilai_jualan", fetch_postget_val("nilai_jualan_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array5[] = array("lb_jumlah_jualan", fetch_postget_val("jumlah_jualan_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array5[] = array('id_insert', $my_details->usr_id, PDO::PARAM_INT);
		$indicator_Array5[] = array('tkh_insert', $dateTimeNow, PDO::PARAM_STR);
		
		$PASS_VALUE += 1;
		$PASS_COUNTER += PDO_INSERT($PDO, 'm_ladang_babi', $indicator_Array5);
		$babi_id = $PDO->lastInsertId();
	}
	
	if($active_aneka > 0)
	{
		$myid = "aneka";
		$indicator_Array6 = array();
		$indicator_Array6[] = array('id_ladang', $ladang_id, PDO::PARAM_INT);
		$indicator_Array6[] = array("la_bil_kandang", fetch_postget_val("bil_kandang_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array6[] = array("la_kapasiti_kandang", fetch_postget_val("kapasiti_kandang_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array6[] = array("la_luas_pengeluaran", fetch_postget_val("luas_pengeluaran_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array6[] = array("la_luas_ladang", fetch_postget_val("luas_ladang_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array6[] = array("la_bt_arnab_pedaging", fetch_postget_val("bil_arnab_pedaging_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array6[] = array("la_bt_arnab_pet", fetch_postget_val("bil_arnab_pet_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array6[] = array("la_bt_rusa_pedaging_j", fetch_postget_val("bil_rusa_pedaging_j_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array6[] = array("la_bt_rusa_pedaging_b", fetch_postget_val("bil_rusa_pedaging_b_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array6[] = array("la_bt_rusa_rekreasi_j", fetch_postget_val("bil_rusa_rekreasi_j_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array6[] = array("la_bt_rusa_rekreasi_b", fetch_postget_val("bil_rusa_rekreasi_b_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array6[] = array("la_bt_kuda_pembiakan_j", fetch_postget_val("bil_kuda_biakan_j_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array6[] = array("la_bt_kuda_pembiakan_b", fetch_postget_val("bil_kuda_biakan_b_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array6[] = array("la_bt_kuda_rekreasi_j", fetch_postget_val("bil_kuda_rekreasi_j_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array6[] = array("la_bt_kuda_rekreasi_g", fetch_postget_val("bil_kuda_rekreasi_g_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array6[] = array("la_bt_kuda_rekreasi_b", fetch_postget_val("bil_kuda_rekreasi_b_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array6[] = array("la_bt_katak", fetch_postget_val("bil_katak_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array6[] = array("la_bt_angsa", fetch_postget_val("bil_angsa_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array6[] = array("la_bt_piru", fetch_postget_val("bil_piru_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array6[] = array("la_bt_ostrich", fetch_postget_val("bil_ostrich_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array6[] = array("la_bt_selasih", fetch_postget_val("bil_selasih_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array6[] = array("la_bt_mutiara", fetch_postget_val("bil_mutiara_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array6[] = array("la_bt_parrot", fetch_postget_val("bil_parrot_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array6[] = array("la_bil_jualan", fetch_postget_val("bil_jualan_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array6[] = array("la_nilai_jualan", fetch_postget_val("nilai_jualan_" . $myid, $_POST, $_GET), PDO::PARAM_STR);
		$indicator_Array6[] = array('id_insert', $my_details->usr_id, PDO::PARAM_INT);
		$indicator_Array6[] = array('tkh_insert', $dateTimeNow, PDO::PARAM_STR);
		
		$PASS_VALUE += 1;
		$PASS_COUNTER += PDO_INSERT($PDO, 'm_ladang_aneka', $indicator_Array6);
		$aneka_id = $PDO->lastInsertId();
	}
	
	$indicator_Array7 = array();
	$indicator_Array7[] = array('id_ladang_ruminan', $ruminan_id, PDO::PARAM_INT);
	$indicator_Array7[] = array('id_ladang_tenusu', $tenusu_id, PDO::PARAM_INT);
	$indicator_Array7[] = array('id_ladang_babi', $babi_id, PDO::PARAM_INT);
	$indicator_Array7[] = array('id_ladang_aneka', $aneka_id, PDO::PARAM_INT);
	
	$PASS_VALUE += 1;
	$whereCondition = "WHERE id_ladang = $ladang_id";
	$PASS_COUNTER += PDO_UPDATE($PDO, 'm_ladang', $indicator_Array7, $whereCondition);


	//*****************************************
	//COMMIT if PASS_COUNTER == PASS_VALUE
	//*****************************************
	if ($PASS_COUNTER == $PASS_VALUE)
	{
		$PDO->commit();
		echo $PASS_COUNTER;
		
		rename('upload_daftar_pemohon/temp_'.$my_details->usr_id, 'upload_borang/'.$ladang_id);
	}
	else
	{
		$PDO->rollBack();
		echo -1;
	}
}
catch (Exception $e) 
{
	$PDO->rollBack();
	echo "Failed: " . $e->getMessage();
}

?>