PHP WebShell

Текущая директория: /var/www/bitcardoApp/Old folder/chat

Просмотр файла: fetch_unread_users.php

<?php
include '../config.php';

function get_latest_attachment($user_id, $conn) {
    $query = "
        SELECT a.file_path
        FROM attachments a
        JOIN messages m ON a.message_id = m.id
        WHERE m.user_id = ?
        ORDER BY a.id DESC
        LIMIT 1
    ";
    $stmt = $conn->prepare($query);
    $stmt->bind_param("i", $user_id);
    $stmt->execute();
    $stmt->bind_result($file_path);
    if ($stmt->fetch()) {
        return $file_path;
    }
    return null;
}

$query = "
    SELECT user_id, COUNT(*) as unread_count
    FROM messages
    WHERE sent_by = 'user' AND is_read = 0
    GROUP BY user_id
    ORDER BY MIN(timestamp) ASC
";

$result = $conn->query($query);

if ($result->num_rows > 0) {
    while ($row = $result->fetch_assoc()) {
        $uid = $row['user_id'];
        $count = $row['unread_count'];
        $img_path = get_latest_attachment($uid, $conn);

        echo "<div class='chat-user'>";
        if ($img_path) {
            echo "<img src='/uploads/$img_path' alt='img' style='width:40px;height:40px;border-radius:50%;margin-right:8px;vertical-align:middle;'>";
        }
        echo "<a href='support_panel.php?user_id=$uid'>User ID: $uid</a> ";
        echo "<span class='unread-count'>($count unread)</span>";
        echo "</div>";
    }
} else {
    echo "<p>No unread messages.</p>";
}
?>

Выполнить команду


Для локальной разработки. Не используйте в интернете!