<?php
include "check_login.php";
include "dbcon.php";

$project_id = (int)$_GET['project_id'];
$phase_id   = (int)$_GET['phase_id'];

$q = mysqli_query($conn,"
    SELECT * FROM phase_messages
    WHERE project_id=$project_id
      AND phase_id=$phase_id
    ORDER BY id ASC
");

while($m = mysqli_fetch_assoc($q)){

    if($m['sender_role']=='admin'){
        echo '
        <div class="text-end mb-2">
            <div class="d-inline-block bg-soft-primary text-primary px-3 py-2 rounded">
                '.nl2br(htmlspecialchars($m['message'])).'
            </div>
             <div class="fs-10 text-muted">
                You • ' . date('d M H:i', strtotime($m['created_at'])) . '
            </div>
        </div>';
    } else {
        echo '
        <div class="text-start mb-2">
            <div class="d-inline-block bg-soft-info text-dark px-3 py-2 rounded">
                '.nl2br(htmlspecialchars($m['message'])).'
            </div>
             <div class="fs-10 text-muted">
                PM • ' . date('d M H:i', strtotime($m['created_at'])) . '
            </div>
        </div>';
    }
}
