From f3f892ed0d20609fe501a428df2e7c4aebc001e3 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Mon, 4 Aug 2025 20:12:43 +0500 Subject: feat: show room messages --- web/index.php | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 90 insertions(+), 3 deletions(-) (limited to 'web/index.php') diff --git a/web/index.php b/web/index.php index b71e61b..b6657c5 100644 --- a/web/index.php +++ b/web/index.php @@ -4,8 +4,52 @@ include_once $_SERVER['DOCUMENT_ROOT'] . '/config.php'; $db = new PDO(DB_URL, DB_USER, DB_PASS); $room = $_GET['r'] ?: null; +$date = $_GET['d'] ?: null; -if (isset($room)) { +$limit = min(abs(intval($_GET['l'] ?? '500')), 500); +$page = abs(intval($_GET['p'] ?? '1') - 1); +$offset = $limit * $page; + +if (isset($room, $date)) { + $room = urldecode($room); + $date = urldecode($date); + $stmt = $db->prepare('SELECT id, `name`, joined_at, departed_at FROM rooms WHERE `name` = ?'); + $stmt->execute([$room]); + + $room = $stmt->fetch(PDO::FETCH_ASSOC) ?: null; + if (!$room) { + http_response_code(404); + exit("No room found."); + } + $room['encoded'] = urlencode($room['name']); + + $stmt = $db->prepare("SELECT m.id, u.nick, m.command, m.params, m.tags, m.sent_at + FROM messages m + JOIN rooms r ON r.id = m.room_id + JOIN users u ON u.id = m.user_id + WHERE m.room_id = ? + AND m.sent_at BETWEEN ? AND DATE_ADD(?, INTERVAL 1 DAY) + ORDER BY sent_at DESC + LIMIT $limit OFFSET $offset + "); + $stmt->execute([$room['id'], $date, $date]); + $messages = $stmt->fetchAll(PDO::FETCH_ASSOC); + + // searching for previous message day + $stmt = $db->prepare('SELECT m.sent_at AS d + FROM messages m + JOIN rooms r ON r.id = m.room_id + JOIN users u ON u.id = m.user_id + WHERE m.room_id = ? + AND DATE(m.sent_at) = ( + SELECT MAX(DATE(sent_at)) + FROM messages + WHERE DATE(sent_at) < ? + ) + '); + $stmt->execute([$room['id'], $date]); + $previous_day = $stmt->fetch(PDO::FETCH_ASSOC) ?: null; +} else if (isset($room)) { $room = urldecode($room); $stmt = $db->prepare('SELECT id, `name`, joined_at, departed_at FROM rooms WHERE `name` = ?'); $stmt->execute([$room]); @@ -56,7 +100,9 @@ if (isset($room)) { - + + <?= sprintf('Log for %s, %s - %s', $room['name'], $date, INSTANCE_NAME) ?> + <?= $room['name'] ?> - <?= INSTANCE_NAME ?> Index - <?= INSTANCE_NAME ?> @@ -66,7 +112,30 @@ if (isset($room)) { - + +

+ +

No messages.

+ +

Showing messages on Page

+ + + + + + + + + + + + + +
TimeNickMessage
+
+ +

- Index of

$months): ?> @@ -135,4 +204,22 @@ if (isset($room)) { + + + + \ No newline at end of file -- cgit v1.2.3