<?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.*, B.nama_pemohon, C.desk_audit, D.nama, E.desk_peranan, F.desk_daerah, G.desk_dun, H.desk_dun AS dun_pemohon, I.desk_parlimen
				  FROM s_auditlog A
				  LEFT JOIN m_pemohon B ON A.id_pemohon = B.id_pemohon
				  LEFT JOIN i_audit C ON A.id_audit = C.id_audit
				  LEFT JOIN t_pengguna D ON A.id_keyin = D.id_pengguna
				  LEFT JOIN t_peranan E ON A.id_peranan = E.id_peranan
				  LEFT JOIN i_daerah F ON A.id_daerah = F.id_daerah
				  LEFT JOIN i_dun G ON A.id_dun = G.id_dun
				  LEFT JOIN i_dun H ON B.id_dun = H.id_dun
				  LEFT JOIN i_parlimen I ON A.id_parlimen = I.id_parlimen
				  WHERE A.id_pemohon = ?
				  AND A.id_program NOT IN (5,6)
				  ORDER BY A.id_auditlog 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 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>Pemohon</th>
								<th>Tindakan</th>
								<th>Log Oleh</th>
								<th>Tarikh Log</th>
								<th>Peranan</th>
								<th>Parlimen</th>
								<th>DUN</th>
								<th>Daerah</th>
								<th>Ulasan</th>
							</tr>
						</thead>
						<tbody>	
						<?php
							for($num = 0; $num < count($log_List); $num++)
							{	
								$keyin = $log_List[$num]['nama'];
								$dun = $log_List[$num]['desk_dun'];
								$daerah = $log_List[$num]['desk_daerah'];
								$parlimen = $log_List[$num]['desk_parlimen'];
								if($log_List[$num]['id_peranan'] == 10)
								{									
									$keyin = $log_List[$num]['nama_pemohon'];
									$dun = $log_List[$num]['dun_pemohon'];
									$daerah = '';
									$parlimen = '';
								}
								
								echo '<tr>';
									echo '<td>'.($num + 1).'</td>';
									echo '<td>'.$log_List[$num]['nama_pemohon'].'</td>';
									echo '<td>'.$log_List[$num]['desk_audit'].'</td>';
									echo '<td>'.$keyin.'</td>';
									echo '<td>'.$log_List[$num]['tkh_keyin'].'</td>';
									echo '<td>'.$log_List[$num]['desk_peranan'].'</td>';
									echo '<td>'.$parlimen.'</td>';
									echo '<td>'.$dun.'</td>';
									echo '<td>'.$daerah.'</td>';
									echo '<td>'.$log_List[$num]['ulasan'].'</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>