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

$indicator_Query = "SELECT A.*
				  FROM i_hubungi A
				  WHERE A.id_hubungi = ?";
$PDO_stmt = $PDO->prepare($indicator_Query);
$PDO_stmt->bindValue(1, 1, PDO::PARAM_INT);
$PDO_stmt->execute();
$indicator_List = $PDO_stmt->fetch(PDO::FETCH_ASSOC);
?>	

<!--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">Pengurusan Maklumat Hubungi Kami</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">
			<form action="javascript:;" class="form-horizontal" name="indicator_form" id="indicator_form">
				<div class="form-body">
					<!--begin::Row-->
					<div class="row">
						<?php
							createTextBox('Nama Pegawai', 'nama', 'Nama Pegawai', $indicator_List['nama'], 3, $readonly, 7, 12, '', 'text');
							createTextBox('No Telefon', 'no_tel', 'No Telefon', $indicator_List['no_tel'], 3, $readonly, 7, 12, '', 'text');
							createTextBox('No Faks', 'no_faks', 'No Faks', $indicator_List['no_faks'], 3, $readonly, 7, 12, '', 'text');
							createTextArea('Alamat', 'alamat', 'Alamat', $indicator_List['alamat'], 0, 3, 7, 12, '', 10);		
						?>
						
					</div>
					<div class="row">
						<button type="button" class="btn btn-primary" id="indicator_simpanBtn">Kemaskini Maklumat</button>						
					</div>
					<!--end::Row-->
				</div>
			</form>
		</div>
		<!--end::Container-->
	</div>
	<!--end::Entry-->
</div>
<!--end::Content-->
					
<?php 
require('includes/footer.php');
?>

<script>
$(document).ready(function(){  

	$('.select2').select2({ width: '100%' }); 
	
	$('#indicator_simpanBtn').click(function() {
		var indicator_list = [[]];
		indicator_list.push(['nama', 'Nama Pegawai', 'tb']);
		indicator_list.push(['no_tel', 'No Telefon', 'tb']);
		indicator_list.push(['no_faks', 'No Faks', 'tb']);
		indicator_list.push(['alamat', 'Alamat', 'tb']);
		
		if (checkInput(indicator_list))
		{
			$(this).prop("disabled",true);
			var param = $('#indicator_form').serialize();
			$.ajax({
				type: "POST", 
				url: "in_hubungi-insert.php", 
				data: param,

				success: function(res){
					if(res > 0)
					{
						swal.fire({
							text: "Berjaya Kemaskini Maklumat Hubungi Kami",
							icon: "success",
							buttonsStyling: false,
							confirmButtonText: "OK!",
							customClass: {
								confirmButton: "btn font-weight-bold btn-light-primary"
							}
						}).then(function() {
								window.location = "in_hubungi.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>