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

$myID = fetch_postget_val('id',$_POST, $_GET);
$id_program = fetch_postget_val('program',$_POST, $_GET);
$readonly = fetch_postget_val('readonly',$_POST, $_GET);

$indicator_Query = "SELECT A.*,B.desk_program
				  FROM m_pemohon A
				  LEFT JOIN i_program B ON B.id_program = A.id_program
				  WHERE A.id_pemohon = ?";
$PDO_stmt = $PDO->prepare($indicator_Query); 
$PDO_stmt->bindValue(1, $myID, PDO::PARAM_INT);
$PDO_stmt->execute();
$info_List = $PDO_stmt->fetch(PDO::FETCH_ASSOC);
							
$indicator_Query = "SELECT A.*
				  FROM s_boranglog A
				  WHERE A.id_pemohon = ?
				  ORDER BY A.id_boranglog DESC";
$PDO_stmt = $PDO->prepare($indicator_Query);
$PDO_stmt->bindValue(1, $myID, PDO::PARAM_INT);
$PDO_stmt->execute();

$log_List = array();
while($result = $PDO_stmt->fetch(PDO::FETCH_ASSOC))
{
	$log_List[] = $result;
}

?>
<div class="modal-header">
	<h5 class="modal-title"><b>LOG BORANG PERMOHONAN</b><br>Pemohon : <b><?=$info_List['nama_pemohon']?></b></h5>
	<button type="button" class="close" data-dismiss="modal" aria-label="Close" id="closeBtn" name="closeBtn" ></button>
</div>
<div class="modal-body">
	<div class="row">
		<div class="col-md-12">		
			<!--begin::Card-->
			<div class="card card-custom gutter-b example-hover">
				<div class="card-body">	
					<table class="table table-separate table-head-custom table-checkable" id="kt_datatable2">
						<thead>
							<tr>
								<th>Bil</th>
								<th>Aktiviti</th>
								<th>Table</th>
								<th>ID</th>
								<th>Nama Field</th>
								<th>Asal</th>
								<th>Baru</th>
								<th>Tkh. Kemaskini</th>
							</tr>
						</thead>
						<tbody>	
						<?php
							for($num = 0; $num < count($log_List); $num++)
							{				
								$aktiviti = 'INSERT';
								if($log_List[$num]['aktiviti'] == 'U')
								{
									$aktiviti = 'UPDATE';
								}	
								
								$asal = $log_List[$num]['makl_asal'];
								if($log_List[$num]['makl_asal'] == '' || $log_List[$num]['makl_asal'] == 0)
								{
									$asal = '-';
								}
								
								echo '<tr>';
									echo '<td>'.($num + 1).'</td>';
									echo '<td>'.$aktiviti.'</td>';
									echo '<td>'.$log_List[$num]['nama_table'].'</td>';
									echo '<td>'.$log_List[$num]['id_table'].'</td>';
									echo '<td>'.$log_List[$num]['nama_field'].'</td>';
									echo '<td>'.$asal.'</td>';
									echo '<td>'.$log_List[$num]['makl_baru'].'</td>';
									echo '<td>'.formatDate($log_List[$num]['tkh_keyin'],'d M Y H:i:s').'</td>';
								echo '</tr>';
							}							
						?>
						</tbody>
					</table>					
				</div>
			</div>
			<!--end::Card-->										
		</div>
	</div>
</div>
<div class="modal-footer">
	<?php
		echo '<button type="button" class="btn btn-secondary" data-dismiss="modal">Tutup</button>';
	?>
</div>
<script src="assets/plugins/custom/datatables/datatables.bundle.js"></script>
<script>
"use strict";
var KTDatatablesBasicScrollable = function() {

    var initTable2 = function() {
        var table = $('#kt_datatable2');

        // begin second table
        table.DataTable({
            scrollY: '50vh',
            scrollX: true,
            scrollCollapse: true,
        });
    };

    return {

        //main function to initiate the module
        init: function() {
            initTable2();
        },

    };

}();

jQuery(document).ready(function() {
    KTDatatablesBasicScrollable.init();
});
</script>