Mini Shell
<?php
session_start();
require_once 'config/config.php';
if (!isset($_GET['complaint_id'])) {
echo '<p style="text-align: center; color: #666;">No complaint selected.</p>';
exit;
}
$complaintId = mysqli_real_escape_string($conn, $_GET['complaint_id']);
// Fetch all responses from responce_trend table with user details
$query = "SELECT rt.*,
aa.Full_Name as UserName, aa.Position as UserPosition,
from_admin.Full_Name as FromUserName, from_admin.Position as FromPosition
FROM responce_trend rt
LEFT JOIN admin_accounts aa ON rt.UserID = aa.id
LEFT JOIN admin_accounts from_admin ON rt.`From` = from_admin.id
WHERE rt.ComplaintID = '$complaintId'
ORDER BY rt.Responce_TrendID DESC";
$result = mysqli_query($conn, $query);
if (!$result || mysqli_num_rows($result) == 0) {
echo '<p style="text-align: center; color: #666;"><i class="fa fa-info-circle"></i> No file trail records found for this file.</p>';
exit;
}
$allRecords = [];
while ($row = mysqli_fetch_assoc($result)) {
$allRecords[] = $row;
}
?>
<table class="file-trail-table">
<thead>
<th>#</th>
<th>Date</th>
<th>From (Forwarded By)</th>
<th>To (Assigned To)</th>
<th>Response</th>
<th>Remarks</th>
<th>Status</th>
<th>Attachment</th>
</tr>
</thead>
<tbody>
<?php
$counter = 1;
foreach ($allRecords as $record):
// Format user name and position
$userName = $record['UserName'] ?? '';
$userPosition = $record['UserPosition'] ?? '';
$formattedUserName = '';
if (!empty($userName)) {
$formattedUserName = '<span class="user-name">' . htmlspecialchars($userName) . '</span>';
if (!empty($userPosition)) {
$formattedUserName .= '<span class="user-position">' . htmlspecialchars($userPosition) . '</span>';
}
} elseif (!empty($record['UserID'])) {
$nameQuery = "SELECT Full_Name, Position FROM admin_accounts WHERE id = '" . $record['UserID'] . "'";
$nameResult = mysqli_query($conn, $nameQuery);
if ($nameResult && mysqli_num_rows($nameResult) > 0) {
$nameData = mysqli_fetch_assoc($nameResult);
$formattedUserName = '<span class="user-name">' . htmlspecialchars($nameData['Full_Name']) . '</span>';
if (!empty($nameData['Position'])) {
$formattedUserName .= '<span class="user-position">' . htmlspecialchars($nameData['Position']) . '</span>';
}
} else {
$formattedUserName = '<span class="user-name">Unknown User</span>';
}
} else {
$formattedUserName = '<span class="user-name">System</span>';
}
// Format forwarded from info
$fromName = $record['FromUserName'] ?? '';
$fromPosition = $record['FromPosition'] ?? '';
$formattedFromName = '';
if (!empty($fromName)) {
$formattedFromName = '<span class="user-name">' . htmlspecialchars($fromName) . '</span>';
if (!empty($fromPosition)) {
$formattedFromName .= '<span class="user-position">' . htmlspecialchars($fromPosition) . '</span>';
}
} elseif (!empty($record['From'])) {
$fromQuery = "SELECT Full_Name, Position FROM admin_accounts WHERE id = '" . $record['From'] . "'";
$fromResult = mysqli_query($conn, $fromQuery);
if ($fromResult && mysqli_num_rows($fromResult) > 0) {
$fromData = mysqli_fetch_assoc($fromResult);
$formattedFromName = '<span class="user-name">' . htmlspecialchars($fromData['Full_Name']) . '</span>';
if (!empty($fromData['Position'])) {
$formattedFromName .= '<span class="user-position">' . htmlspecialchars($fromData['Position']) . '</span>';
}
} else {
$formattedFromName = '<span class="user-name">System</span>';
}
} else {
$formattedFromName = '<span class="user-name">System</span>';
}
// Format status with appropriate class
$status = $record['Status'] ?? '';
$statusClass = 'status-pending-small';
if (strtolower($status) == 'open' || strtolower($status) == 'new') {
$statusClass = 'status-open-small';
} elseif (strpos(strtolower($status), 'progress') !== false || strtolower($status) == 'in progress') {
$statusClass = 'status-progress-small';
} elseif (strtolower($status) == 'closed' || strtolower($status) == 'completed') {
$statusClass = 'status-closed-small';
}
// Format date
$responseDate = !empty($record['Responce_Date']) ? date('Y-m-d H:i:s', strtotime($record['Responce_Date'])) : 'N/A';
// Check if there's an attachment
$hasAttachment = !empty($record['Attachment']);
?>
<tr>
<td style="text-align: center; width: 40px;"><?php echo $counter++; ?></td>
<td class="date-time"><?php echo htmlspecialchars($responseDate); ?></td>
<td><?php echo $formattedFromName; ?></td>
<td><?php echo $formattedUserName; ?></td>
<td class="response-text">
<?php
$response = $record['Responce'] ?? '';
if (!empty($response)) {
echo nl2br(htmlspecialchars(substr($response, 0, 200)));
if (strlen($response) > 200) {
echo '...';
}
} else {
echo '<span style="color: #95a5a6;">No response</span>';
}
?>
</td>
<td class="remarks-text">
<?php
$remarks = $record['Remarks'] ?? '';
if (!empty($remarks)) {
echo nl2br(htmlspecialchars(substr($remarks, 0, 150)));
if (strlen($remarks) > 150) {
echo '...';
}
} else {
echo '<span style="color: #95a5a6;">-</span>';
}
?>
</td>
<td>
<span class="status-badge-small <?php echo $statusClass; ?>">
<?php echo htmlspecialchars($status ?: 'N/A'); ?>
</span>
</td>
<td>
<?php if ($hasAttachment): ?>
<a href="Uploads/<?php echo htmlspecialchars($record['Attachment']); ?>" target="_blank" class="attachment-link">
<i class="fa fa-download"></i> Download
</a>
<?php else: ?>
<span style="color: #95a5a6;">-</span>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>