<?php 
require('includes/header.php');  
?>	

<!--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">Senarai Pemilik Haiwan Peliharaan</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">
						<form id="carianForm">
							<h5 class="text-dark font-weight-bold mt-5 mb-2 mr-5">Carian Pemilik</h5>
							<hr>
							<?php
								createTextBox('Nama Pemilik', 'carian_nama_pemilik', 'Nama Pemilik', $info_List['nama_pemilik'], 3, $readonly, 6, 10);
								createTextBox('No. KP Baru', 'carian_kpbaru_pemilik', 'KP Baru', $info_List['kpbaru_pemilik'], 3, $readonly, 6, 10);
								createTextBox('No. Telefon', 'carian_tel_pemilik', 'No. Telefon', $info_List['tel_pemilik'], 3, $readonly, 6, 10);
							?>
							<hr>
							<div style="text-align:center;padding-bottom:20px">
								<button type="button" class="btn btn-primary" id="semakBtn">Semak</button>
							</div>
							<hr>
						</form>
					</div>
				</div>
				<!--end::Wizard-->
			</div>
			<!--begin::Row-->
			<div class="row">
				<?php
					$tbColumn = array();
					$tbColumn[] = array('Bil', 5);
					$tbColumn[] = array('Nama', 20);
					$tbColumn[] = array('No KP Baru', 20);
					$tbColumn[] = array('No Tel', 20);
					$tbColumn[] = array('Haiwan Ternakan', 20);
					$tbColumn[] = array('Tindakan', 0);
					
					$userBtn = '';
					$userBtn = '<a class="btn btn-primary font-weight-bolder" onclick="loadMyModal(\''.$base_name.'-tambah.php?id=0\', \'#ajax-modal\')"><span class="svg-icon svg-icon-md">'.$tambahBtnSvg.'</span>Daftar Pemilik Baru</a>';						
					
					createTable('indicator_table', $tbColumn, 'Pengurusan Pemilik Haiwan Peliharaan', 'Senarai Pemilik Haiwan Peliharaan', 0, $userBtn, 'ajax-modal', 12);
				?>
				
			</div>
			<!--end::Row-->
		</div>
		<!--end::Container-->
	</div>
	<!--end::Entry-->
</div>
<!--end::Content-->
					
<?php 
require('includes/footer.php');
?>


<script>
var ajaxUrl = $('#script_base_name').val() + "-ajax.php";
function getData()
{
	return {
		sqlOnly: 0,
		daerah: $('#daerah_sen').val(),
		ladang: $('#ladang_sen').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
	$('#printPdf').click(function() {
		printFunc($('#table_name').val(), $(this).attr("value"), "normalPrint-landscape.php", $('#script_base_name').val(), $('#table_title').val(), $('#table_header').val());
	});
	
	$('#printExcel').click(function() {
		printFunc($('#table_name').val(), $(this).attr("value"), "sen_penternak-excel.php", $('#script_base_name').val(), $('#table_title').val(), $('#table_header').val());
	});
	
	$('#daerah_sen,#ladang_sen').change(function(){
		reloadTable();
	});
});
</script>