<?php 
require('includes/header.php');  
$myID = fetch_postget_val('appointment',$_POST, $_GET);
?>	

<!--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 Temu Janji</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">
				<div class="card-header" id="headingThree8">
					<div class="card-title" style="margin-bottom:0px">
						<div class="card-label">													
							<span class="svg-icon svg-icon-primary menu-icon">
								<?=$Tapisanhome_svg?>
							</span>Maklumat Pemilik & Haiwan Peliharaan</div>
					</div>
				</div>
				<div class="card-body" style="padding-top:20px">
				<?php
					include_once ("general-appointment_detail.php");
				?>
				</div>
			</div>
			<!--begin::Row-->
			<div class="row">
				<?php
					$tbColumn = array();
					$tbColumn[] = array('Bil', 5);
					$tbColumn[] = array('Ubat', 20);
					$tbColumn[] = array('Quantity', 20);
					$tbColumn[] = array('Remarks', 20);
					$tbColumn[] = array('Tindakan', 0);
					
					$userBtn = '';
					$userBtn = '<a class="btn btn-primary font-weight-bolder" onclick="loadTambah()"><span class="svg-icon svg-icon-md">'.$tambahBtnSvg.'</span>Tambah Ubat</a>';						
					
					createTable('indicator_table', $tbColumn, 'Pengurusan Temu Janji Klinik', 'Senarai Temu Janji', 0, $userBtn, 'ajax-modal', 12);
				?>
				
				
			</div>
			<div class="card">
				<div class="card-body" style="padding-top:20px">
					<?php
						createTextArea('Maklumat Teliti', 'check_result', 'Maklumat Teliti (Jika Berkenaan)', '', 0, 2, 10, 12, '', 10);
					?>
					<div class="col-md-12" style="text-align:center">
						<button type="button" class="btn btn-primary" id="confirmBtn">Done Checking</button>
					</div>
				</div>
			</div>
			
			<!--end::Row-->
		</div>
		<!--end::Container-->
	</div>
	<!--end::Entry-->
</div>
<!--end::Content-->
					
<?php 
require('includes/footer.php');
?>


<script>
var ajaxUrl = "pht_listjanji-check_result_ajax.php";
function getData()
{
	return {
		sqlOnly: 0,
		appointment: "<?=$myID?>",
	};
}

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

function loadTambah()
{
	loadMyModal('pht_listjanji-check_result_tambah.php?appointment=' + "<?=$myID?>", '#ajax-modal');
}

$(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);
	reloadTable();
	
	$('#confirmBtn').click(function() {

			$(this).prop("disabled",true);
			//var param = $('#indicator_form').serialize();
			$.ajax({
				type: "POST", 
				url: "pht_listjanji-check_result_insert.php", 
				data: 'check_result=' + $('#check_result').val() + '&id=' + "<?=$myID?>",

				success: function(res){
					
					$(this).prop("disabled",false);
					if(res > 0)
					{
						swal.fire({
							text: "Done Checking",
							icon: "success",
							buttonsStyling: false,
							confirmButtonText: "OK!",
							customClass: {
								confirmButton: "btn font-weight-bold btn-light-primary"
							}
						}).then(function() {
							window.location.href = 'pht_listjanji.php';
						});
					}
					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>
