<?php 
include_once ("includes/setup.inc.php");

$script_base = 'in_tempattunai';
$myID = fetch_postget_val('id',$_POST, $_GET);
$readonly = fetch_postget_val('readonly',$_POST, $_GET);
$temp = ($my_details->usr_id).'_'.time();

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

?>
<div class="modal-header">
	<h5 class="modal-title">Tambah / Kemaskini Maklumat Tempat Pembayaran Tunai</h5>
	<button type="button" class="close" data-dismiss="modal" aria-label="Close" id="closeBtn" name="closeBtn" ></button>
</div>
<div class="modal-body">
	<form action="javascript:;" class="form-horizontal" name="indicator_form" id="indicator_form">
		<div class="form-body">
			<div class="row">
				<?php
					createDropDown($PDO, 'Daerah', 'i_daerah', 'id_daerah', $indicator_List['id_daerah'], 'Sila Pilih', 6, 3, 12, $readonly);
					//createTextBox('Alamat', 'alamat_tempattunai', 'Sebab Tunai', $indicator_List['alamat_tempattunai'], 3, $readonly, 7, 12, '', 'text');
					createTextArea('Alamat', 'alamat_tempattunai', 'Alamat', $indicator_List['alamat_tempattunai'], 0, 3, 7, 12, '', 10);
					createTextBox('Susunan', 'susunan', 'Susunan', $indicator_List['susunan'], 3, $readonly, 7, 12, '', 'text');
					
					$flag_aktif = 1;
					if($myID > 0)
					{
						$flag_aktif = $indicator_List['aktif'];						
					}					
					$myArray = [];
					$myArray[] = array(1, 'YA');
					createDropDown_Array('Aktif', $myArray, 'aktif', $flag_aktif, 'TIDAK', 4, 3, 12, $readonly);
				?>
			</div>
		</div>
	</form>
</div>
<div class="modal-footer">
	<?php
		echo '<button type="button" class="btn btn-secondary" data-dismiss="modal">Tutup</button>';
		if($readonly == 0)
		{
			echo '<button type="button" class="btn btn-primary" id="indicator_simpanBtn">Simpan</button>';
		}
	?>
</div>

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

	$('.select2').select2({ width: '100%' }); 
	
	$('#indicator_simpanBtn').click(function() {
		var indicator_list = [[]];
		indicator_list.push(['id_daerah', 'Daerah', 'dd']);
		indicator_list.push(['alamat_tempattunai', 'Alamat', 'tb']);
		
		if (checkInput(indicator_list))
		{
			$(this).prop("disabled",true);
			var param = $('#indicator_form').serialize();
			$.ajax({
				type: "POST", 
				url: "<?=$script_base?>-tambah_insert.php", 
				data: param+ '&id=' + "<?=$myID?>",

				success: function(res){
					if(res > 0)
					{
						swal.fire({
							text: "Berjaya Tambah/Kemaskini Maklumat",
							icon: "success",
							buttonsStyling: false,
							confirmButtonText: "OK!",
							customClass: {
								confirmButton: "btn font-weight-bold btn-light-primary"
							}
						}).then(function() {
							window.parent.reloadTable();
							$("#closeBtn").click();
						});
					}
					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>