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

$myID = fetch_postget_val("id", $_POST, $_GET);

$aduanList = [];
$indicator_Query = "SELECT A.*, B.nama, C.desk_peranan
				  FROM m_aduanmbls A
				  LEFT JOIN t_pengguna B ON B.id_pengguna = A.id_keyin
				  LEFT JOIN t_peranan C ON C.id_peranan = B.id_peranan
				  WHERE A.id_aduan = ?
				  ORDER BY A.tkh_keyin ASC";
$PDO_stmt = $PDO->prepare($indicator_Query);
$PDO_stmt->bindValue(1, $myID, PDO::PARAM_INT);
$PDO_stmt->execute();
while($result = $PDO_stmt->fetch(PDO::FETCH_ASSOC))
{
	$aduanList[] = $result;
}

echo '<table class="table table-striped" width="100%">';
	echo '<tbody>';
	if(count($aduanList) > 0)
	{
		for($num = 0; $num < count($aduanList); $num++)
		{
			$nama = $aduanList[$num]['nama'];
			$peranan = $aduanList[$num]['desk_peranan'];
			if($aduanList[$num]['id_peranan'] == 10)
			{		
				$indicator_Query = "SELECT *
					  FROM m_aduan
					  WHERE id_aduan = ?";
				$PDO_stmt = $PDO->prepare($indicator_Query); 
				$PDO_stmt->bindValue(1, $myID, PDO::PARAM_INT);
				$PDO_stmt->execute();
				$aduan = $PDO_stmt->fetch(PDO::FETCH_ASSOC);
				
				$nama = $aduan['nama_pengadu'];
				$peranan = 'PENGADU';				
			}
			
			echo '<tr>';
				echo '<td style="width:80%"><span style="font-size:12px"><b>'.$nama.' ('.$peranan.')</b></span><br>'.str_replace("\n", '<br>', $aduanList[$num]['maklumbalas']).'</td>';
				echo '<td style="width:20%;text-align:right;font-size:12px">'.formatDate($aduanList[$num]['tkh_keyin'], 'M d, Y H:i A').'</td>';
			echo '</tr>';
		}
	}
	else
	{
		echo '<tr>';
			echo '<td style="text-align:center">Tiada maklumbalas</td>';
		echo '</tr>';
	}
	echo '</tbody>';
echo '</table>';
?>