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

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

?>
<div class="modal-header">
	<h5 class="modal-title">Cipta Aduan</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, 'Program', 'i_program', 'id_program', '', 'Pilih Program', 7, 3, 12, $readonly);
					//createDropDown($PDO, 'DUN', 'i_dun', 'id_dun', '', 'Pilih DUN', 7, 3, 12, $readonly);
					createDropDown($PDO, 'Jenis Aduan', 'i_jenisaduan', 'id_jenisaduan', '', 'Pilih Jenis Aduan', 7, 3, 12, $readonly);
					createTextBox('Tajuk', 'tajuk', 'Tajuk', '', 3, $readonly, 7, 12, '', 'text', 'Sila masukkan tajuk aduan');
					createTextArea('Keterangan', 'laporan', 'Sila nyatakan keterangan aduan', '', 0, 3, 7, 12, '', 10);			
				?>
			</div>
		</div>
	</form>
</div>
<div class="modal-footer">
	<?php
		echo '<button type="button" class="btn btn-secondary" data-dismiss="modal">Tutup</button>';
		echo '<button type="button" class="btn btn-primary" id="indicator_simpanBtn">Simpan</button>';
	?>
</div>

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

	$('.select2').select2({ width: '100%' });
	
	$('.myDatePicker').datepicker({
		autoclose: true,
		clearBtn: true,
		format: "dd M yyyy",
		todayHighlight: true,
		orientation: "bottom left",
		templates: {
			leftArrow: '<i class="la la-angle-left"></i>',
			rightArrow: '<i class="la la-angle-right"></i>'
		}
	});
	
	$('#indicator_simpanBtn').click(function() {
		var indicator_list = [[]];
		//indicator_list.push(['id_program', 'Program', 'dd']);
		indicator_list.push(['id_dun', 'DUN', 'dd']);
		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 = $('#indicator_form').serialize();
			$.ajax({
				type: "POST", 
				url: "in_ad-tambah_insert.php", 
				data: param+ '&id=' + "<?=$myID?>"+ '&temp=' + "<?=$temp?>",

				success: function(res){
					if(res > 0)
					{
						swal.fire({
							text: "Berjaya cipta aduan",
							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>
