<?php 
require('includes/header_pemohon.php');  

$ladang_List = [];
$ladang_List[] = array('ruminan', 'Ladang Ruminan');
$ladang_List[] = array('tenusu', 'Ladang Tenusu');
$ladang_List[] = array('babi', 'Ladang Babi');
$ladang_List[] = array('aneka', 'Ladang Aneka Haiwan');
$dz_myID = 'temp_'.$my_details->usr_id;
?>	

<!--begin::Content-->
<div class="content d-flex flex-column flex-column-fluid" id="kt_content">
	<!--begin::Subheader-->
	<div class="subheader py-2 py-lg-4 subheader-solid" id="kt_subheader">
		<div class="container-fluid d-flex align-items-center justify-content-between flex-wrap flex-sm-nowrap">
			<!--begin::Info-->
			<div class="d-flex align-items-center flex-wrap mr-2">
				<!--begin::Page Title-->
				<h5 class="text-dark font-weight-bold mt-2 mb-2 mr-5">Borang Maklumat Penternak</h5>
				<!--end::Page Title-->
				<!--begin::Actions-->
				<div class="subheader-separator subheader-separator-ver mt-2 mb-2 mr-4 bg-gray-200"></div>
			</div>
			<!--end::Info-->
		</div>
	</div>
	<!--end::Subheader-->
	<!--begin::Entry-->
	<div class="d-flex flex-column-fluid">
		<!--begin::Container-->
		<div class="container">
			<div class="card card-custom">
				<div class="card-body p-0">
					<div class="col-xl-12 col-xxl-12">
						<input type="hidden" id="dz_myID" value="<?=$dz_myID?>">
						<form id="daftarForm">
							<?php
								require('daftar_general.php');
								createModal('pengguna-modal');
								
								echo '<div class="col-md-10 form-group row">';
									echo '<label class="col-md-3 col-form-label">Muat Naik Fail:</label>';
									echo '<div class="col-md-9">
											<div class="dropzone dropzone-default" id="daftar_dz">
												<div class="dropzone-msg dz-message needsclick">
													<h3 class="dropzone-msg-title">Dokumen Permohonan</h3>
													<span class="dropzone-msg-desc">Sila Muat Naik Dokumen Di Sini.</span>
												</div>
											</div>
											*Klik pada ruangan diatas untuk muatnaik dokumen (hanya format gambar/pdf sahaja)
										</div>';
								echo '</div>';
								
								echo '<div class="col-md-10 form-group row" id="jenis_ladang_div">';
									echo '<label class="col-md-3 col-form-label" id="jenis_ladang_label">Jenis Ladang</label>';
									echo '<div class="col-md-6">';
										echo '<div class="checkbox-list">';
											foreach($ladang_List as $key => $menu) 
											{
												echo '<label class="checkbox">';
													echo '<input type="checkbox" id="t_'.$menu[0].'" name="t_'.$menu[0].'" onclick="showTab(\''.$menu[0].'\')">';
													echo '<span></span>';
													echo $menu[1];
												echo '</label>';
											}
										echo '</div>';
									echo '</div>';
								echo '</div>';
								
								
							?>
							<hr>
							<div style="text-align:center;padding-bottom:20px">
								<button type="button" class="btn btn-primary" id="daftarSimpanBtn">Simpan</button>
							</div>
							<hr>
						</form>
						<?php
							echo '<ul class="nav nav-tabs" role="tablist">';
								foreach($ladang_List as $key => $menu) 
								{
									echo '<li class="nav-item" id="li_'.$menu[0].'" style="display:none">';
										echo '<a class="nav-link" data-toggle="tab" id="nav_'.$menu[0].'" href="#tab_'.$menu[0].'">';
											echo '<span class="nav-text">'.$menu[1].'</span>';
										echo '</a>';
									echo '</li>';
								}
							echo '</ul>';
							
							echo '<div class="tab-content">';
								foreach($ladang_List as $key => $menu) 
								{
									require('daftar_'.$menu[0].'.php');
								}
							echo '</div>';
						?>
					</div>
				</div>
				<!--end::Wizard-->
			</div>
		</div>
		<!--end::Container-->
	</div>
	<!--end::Entry-->
</div>
<!--end::Content-->
					
<?php 
require('includes/footer.php');
?>


<script>
var uploadPath = 'upload_daftar_pemohon';
var myDZ_pengguna = new Dropzone("div#daftar_dz", {
	acceptedFiles: "image/jpg,image/jpeg,image/png,image/bmp,application/pdf",
	//maxFiles: 1,
	maxFilesize: 2,//max file size in MB,
	url: "general-photo_upload.php",
	paramName: "uploadfile",
	dictDefaultMessage : '<span style="font-style:italic"><h1>Drop files to upload</h1><h3>(or click)</h3></span>',
	init: function() {
		$.get("general-photo_upload.php", {uploadId:$('#dz_myID').val(), generalName:"", uploadFolder:uploadPath}, function(data) {
			$.each(data, function(key,value){
				var mockFile = { name: value.name, size: value.size };				
				myDZ_pengguna.emit("addedfile", mockFile);
				if(value.name.trim().endsWith(".pdf"))
				{
					myDZ_pengguna.emit("thumbnail", mockFile, uploadPath + "/pdf.jpg");
				}
				else
				{
					myDZ_pengguna.emit("thumbnail", mockFile, uploadPath + "/" + $('#dz_myID').val() + "/" + value.name);
				}
				myDZ_pengguna.emit("complete", mockFile);
				myDZ_pengguna.files.push(mockFile);
			});
		});
	}
});

myDZ_pengguna.on("error", function(file, errorMessage) {
	alert("ERROR " + errorMessage);
	myDZ_pengguna.removeFile(file);
});

myDZ_pengguna.on("success", function(file, photoPath) {
	file.previewElement.querySelector("[data-dz-name]").innerHTML = photoPath;
	console.log(photoPath);
	console.log(photoPath.trim().endsWith(".pdf"));
	if(photoPath.trim().endsWith(".pdf"))
	{
		myDZ_pengguna.emit("thumbnail", file, uploadPath + "/pdf.jpg");
	}
	else
	{
		myDZ_pengguna.emit("thumbnail", file, uploadPath + "/" + $('#dz_myID').val() + "/" + photoPath);
	}
});

myDZ_pengguna.on("sending", function(file, xhr, formData){
	formData.append("uploadId", $('#dz_myID').val());
	//formData.append("generalName", "banner.jpg");
	formData.append("uploadFolder", uploadPath);
	//myDropzone.removeAllFiles(); //remove all 1st
});
	
myDZ_pengguna.on("dictRemoveFileConfirmation", function(file, xhr, formData){
	formData.append("uploadId", $('#dz_myID').val());
});

myDZ_pengguna.on("addedfile", function(file) {
	var deleted = false;
	if(deleted == false)
	{
		file.previewElement.addEventListener("click", function() {
			var filesrc = uploadPath + "/" + $('#dz_myID').val() + "/" + file.previewElement.querySelector('[data-dz-name]').innerHTML.trim();
			if(filesrc.endsWith(".pdf"))
			{
				window.open(filesrc);
			}
			else
			{
				loadMyModal('general-photo_view.php?src="' + filesrc + '"', '#pengguna-modal');
			}
		});
		
		// Create the remove button
		var removeButton = Dropzone.createElement('<a class="btn btn-xs red"><i class="fa fa-trash-o"></i>Remove Image</a>');

		// Listen to the click event
		removeButton.addEventListener("click", function(e) {
			e.preventDefault();
			e.stopPropagation();

			var deleteFileName = file.previewElement.querySelector('[data-dz-name]').innerHTML;
			x = confirm("Are you sure to delete " + deleteFileName + "?");
			if(!x)  return false;
			var name = deleteFileName;                
			$.ajax({
				type: "POST",
				url: "general-photo_delete.php",
				data: "uploadId=" + $('#dz_myID').val() + "&filename="+name+ "&uploadFolder=" + uploadPath,
				dataType: "html"
			});
			myDZ_pengguna.removeFile(file);
		});

		file.previewElement.appendChild(removeButton);
	}
	
});

var autogenerate = true;
var activeLadang = [];
function showTab(ladang)
{
	if($('#t_' + ladang).is(":checked"))
	{
		$('.tab-pane').removeClass('active');
		$('#li_' + ladang).show();
		$('#tab_' + ladang).addClass( "active show" );
		$('#nav_' + ladang).click();
		activeLadang[ladang] = 1;
	}
	else
	{
		$('#li_' + ladang).hide();
		$('#tab_' + ladang).removeClass( "active show" );
		delete activeLadang[ladang];
		
		for (const ladang in activeLadang) {
		  $('#nav_' + ladang).click();
		  break;
		}
	}
}

var ajaxUrl = $('#script_base_name').val() + "-ajax.php";
function getData()
{
	return {
		sqlOnly: 0,
		daerah: $('#daerah_sc').val(),
		dun: $('#dun_sc').val(),
	};
}

function deleteFunction(id, desk)
{
	Swal.fire({
        title: "Pastikah Anda?",
        text: "Pastikah untuk selesaikan '" + desk + "' ?",
        icon: "warning",
        showCancelButton: true,
        confirmButtonText: "Ya",
		cancelButtonText: "Tidak",
    }).then(function(result) {
		if (result.value) {
			$.ajax({
			   type: "POST",
			   url: $('#script_base_name').val() + "-aktif.php",
			   data: 'id=' + id,
			   
			   success: function(res){
					swal.fire({
						text: "Berjaya selesaikan " + desk + ".",
						icon: "success",
						buttonsStyling: false,
						confirmButtonText: "OK!",
						customClass: {
							confirmButton: "btn font-weight-bold btn-light-primary"
						}
					}).then(function() {
						reloadTable();
					});
			   
			   }
		   });  //end ajax
		}
	});
}

function reloadTable()
{
	reinitTable($('#table_name').val(), this.ajaxUrl, this.getData(), 1, 0);
}

$(document).ready(function(){  

	$('#ajax-modal').on('shown.bs.modal', function () {  // this is to clear modal cache each time modal load
	 $(this).removeData('bs.modal');
	}); 
	
	//initTable($('#table_name').val(), ajaxUrl, getData(), 1, 0);
	
	//print function
	$('#printExcel, #printPdf').click(function() {
		printFunc($('#table_name').val(), $(this).attr("value"), "normalPrint.php", $('#script_base_name').val(), $('#table_title').val(), $('#table_header').val());
	});
	
	$('#daerah_sc,#dun_sc').change(function(){
		reloadTable();
	});
						
	if(autogenerate)
	{
		var randomY = Math.floor(Math.random() * 90) + 10;
		var randomM = Math.floor(Math.random() * 9) + 1;
		var randomD = Math.floor(Math.random() * 15) + 10;
		
		var dddd = Date.now();
		var randomkp = randomY + "0" + randomM + randomD + dddd.toString().substring(7, 13);
		$('#nama_pemilik').val('nama_' + dddd);
		$('#kpbaru_pemilik').val(randomkp);
		$('#bangsa_pemilik').val(Math.floor(Math.random() * 6)).trigger('change');
		$('#tel_pemilik').val("60" + dddd);
		$('#alamat_pemilik').val('alamat_' + dddd);
		
		$('#id_premis').val('premis_' + dddd);
		$('#nama_penternak').val('penternak_' + dddd);
		$('#alamat_premis').val('alamatpremis_' + dddd);
		$('#gps_lat').val((Math.random() * 4 + 1.00).toFixed(4));
		$('#gps_long').val((Math.random() * 100 + 1.00).toFixed(4));
		
		$('#dun_premis').val(Math.floor(Math.random() * 40) + 1).trigger('change');
		$('#status_ladang_premis').val(1).trigger('change');
		$('#projek_kerajaan_premis').val(Math.floor(Math.random() * 3) + 1).trigger('change');
		$('#katpemilik_premis').val(Math.floor(Math.random() * 3) + 1).trigger('change');
		$('#status_lesen_premis').val(Math.floor(Math.random() * 3) + 1).trigger('change');
		$('#sistem_pemeliharaan_premis').val(Math.floor(Math.random() * 3) + 1).trigger('change');
		$('#hakmilik_premis').val(Math.floor(Math.random() * 3) + 1).trigger('change');
		$('#kategori_tanah_premis').val(Math.floor(Math.random() * 3) + 1).trigger('change');
		$('#syarat_nyata_tanah_premis').val(Math.floor(Math.random() * 3) + 1).trigger('change');
		
		//ruminan
		var myid = 'ruminan';
		$('#luas_kandang_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#luas_fodder_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#luas_ragutan_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#kapasiti_pedaging_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#kapasiti_fidlot_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#kapasiti_kambing_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#kapasiti_bebiri_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#kapasiti_kerbau_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#kategori_ladang_lembu_' + myid).val(Math.floor(Math.random() * 3) + 1).trigger('change');
		$('#kategori_ladang_kambing_' + myid).val(Math.floor(Math.random() * 3) + 1).trigger('change');
		$('#kategori_ladang_kerbau_' + myid).val(Math.floor(Math.random() * 3) + 1).trigger('change');
		$('#lembu_kk_baka_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#lembu_kk_jurusan_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#lembu_kk_j1_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#lembu_kk_j2_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#lembu_kk_j3_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#lembu_kk_b1_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#lembu_kk_b2_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#lembu_kk_b3_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#lembu_kacukan_baka_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#lembu_kacukan_jurusan_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#lembu_kacukan_j1_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#lembu_kacukan_j2_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#lembu_kacukan_j3_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#lembu_kacukan_b1_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#lembu_kacukan_b2_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#lembu_kacukan_b3_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#kerbau_baka_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#kerbau_jurusan_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#kerbau_j1_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#kerbau_j2_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#kerbau_j3_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#kerbau_b1_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#kerbau_b2_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#kerbau_b3_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#kambing_baka_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#kambing_jurusan_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#kambing_j1_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#kambing_j2_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#kambing_b1_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#kambing_b2_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#bebiri_baka_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#bebiri_jurusan_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#bebiri_j1_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#bebiri_j2_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#bebiri_b1_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#bebiri_b2_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#bil_jual_lembu_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#nilai_jual_lembu_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#bil_jual_kerbau_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#nilai_jual_kerbau_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#bil_jual_kambing_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#nilai_jual_kambing_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#bil_jual_bebiri_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#nilai_jual_bebiri_' + myid).val(Math.floor(Math.random() * 100) + 1);
		
		//tenusu
		myid = 'tenusu';
		$('#luas_kandang_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#luas_fodder_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#luas_ragutan_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#kapasiti_lembu_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#kapasiti_kerbau_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#kapasiti_kambing_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#kapasiti_bebiri_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#kategori_ladang_tenusu_' + myid).val(Math.floor(Math.random() * 3) + 1).trigger('change');
		$('#lembu_baka_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#lembu_j1_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#lembu_j2_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#lembu_j3_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#lembu_b1_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#lembu_b2_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#lembu_b3_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#kerbau_baka_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#kerbau_j1_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#kerbau_j2_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#kerbau_j3_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#kerbau_b1_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#kerbau_b2_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#kerbau_b3_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#kambing_baka_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#kambing_j1_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#kambing_j2_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#kambing_b1_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#kambing_b2_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#bil_jual_ternakan_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#nilai_jual_ternakan_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#nilai_jual_ternakan_tahunan_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#susu_sehari_lembu_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#nilai_jual_susu_lembu_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#nilai_jual_susu_tahunan_lembu_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#susu_sehari_kambing_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#nilai_jual_susu_kambing_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#nilai_jual_susu_tahunan_kambing_' + myid).val(Math.floor(Math.random() * 100) + 1);
		
		//babi
		myid = 'babi';
		$('#luas_ladang_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#kapasiti_ladang_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#baka_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#bil_kandang_tutup_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#bil_kandang_semi_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#bil_kandang_buka_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#bil_sisa_kumbahan_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#pengolahan_sisa_kumbahan_' + myid).val(Math.floor(Math.random() * 3) + 1).trigger('change');
		$('#zon_penampan_' + myid).val(Math.floor(Math.random() * 2) + 1).trigger('change');
		$('#gahp_' + myid).val(Math.floor(Math.random() * 2) + 1).trigger('change');
		$('#homemixer_' + myid).val(Math.floor(Math.random() * 2) + 1).trigger('change');
		$('#jumlah_spesis_boar_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#jumlah_spesis_induk_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#jumlah_spesis_lain_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#jumlah_spesis_spp_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#bil_jualan_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#nilai_jualan_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#jumlah_jualan_' + myid).val(Math.floor(Math.random() * 100) + 1);
		
		//aneka
		myid = 'aneka';
		$('#bil_kandang_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#kapasiti_kandang_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#luas_pengeluaran_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#luas_ladang_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#bil_arnab_pedaging_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#bil_arnab_pet_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#bil_rusa_pedaging_j_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#bil_rusa_pedaging_b_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#bil_rusa_rekreasi_j_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#bil_rusa_rekreasi_b_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#bil_kuda_biakan_j_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#bil_kuda_biakan_b_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#bil_kuda_rekreasi_j_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#bil_kuda_rekreasi_g_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#bil_kuda_rekreasi_b_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#bil_katak_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#bil_angsa_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#bil_piru_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#bil_ostrich_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#bil_selasih_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#bil_mutiara_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#bil_parrot_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#bil_jualan_' + myid).val(Math.floor(Math.random() * 100) + 1);
		$('#nilai_jualan_' + myid).val(Math.floor(Math.random() * 100) + 1);
	}
	
	$('#daftarSimpanBtn').click(function() {
		var indicator_list = [[]];
		indicator_list.push(['nama_pemilik', 'Nama Pemilik', 'tb']);
		//indicator_list.push(['id_jenisaduan', 'Jenis Aduan', 'dd']);
		//indicator_list.push(['tajuk', 'Tajuk', 'tb']);
		//indicator_list.push(['laporan', 'Keterangan aduan', 'tb']);
		
		//if (checkInput(indicator_list))
		{
			//$(this).prop("disabled",true);
			var param = $('#daftarForm').serialize();
			console.log(activeLadang);
			for (const ladang in activeLadang) {
			  console.log(ladang);
			  param += "&active_" + ladang + "=1";
			  param += "&" + $('#daftarForm_' + ladang).serialize();
			}
			console.log(param);
			
			$.ajax({
				type: "POST", 
				url: "general-borangternak_insert.php", 
				data: param,

				success: function(res){
					if(res > 0)
					{
						swal.fire({
							text: "Berjaya daftar",
							icon: "success",
							buttonsStyling: false,
							confirmButtonText: "OK!",
							customClass: {
								confirmButton: "btn font-weight-bold btn-light-primary"
							}
						}).then(function() {
							window.location.reload();
						});
					}
					else
					{
						swal.fire({
							text: "Error. " + res,
							icon: "error",
							buttonsStyling: false,
							confirmButtonText: "OK!",
							customClass: {
								confirmButton: "btn font-weight-bold btn-light-primary"
							}
						}).then(function() {
							$(this).prop("disabled",false);										
						});
					}
					
				} 
			});  //end ajax
			
		}
	});		
});
</script>