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 ++++++++++++++++++++++++++++++++++++++++++++++++++-- web/static/style.css | 44 ++++++++++++++++++------- 2 files changed, 123 insertions(+), 14 deletions(-) (limited to 'web') 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 diff --git a/web/static/style.css b/web/static/style.css index 47bf506..a84bdc6 100644 --- a/web/static/style.css +++ b/web/static/style.css @@ -1,6 +1,7 @@ :root { --primary-color: #e2e9d9; - --calendar-border: black; + --table-border: #a8a8a8; + --message-alt-background: #eeeeee; } * { @@ -8,6 +9,10 @@ padding: 0; } +body { + padding: 8px; +} + .calendar-wrapper { display: flex; flex-direction: row; @@ -15,31 +20,48 @@ gap: 16px; } -.calendar { - border: var(--calendar-border) solid 1px; +table { + border: var(--table-border) solid 1px; border-spacing: 0; } -.calendar>caption { - border: var(--calendar-border) solid 1px; +table caption { + border: var(--table-border) solid 1px; border-bottom: none; background: var(--primary-color); } -.calendar td, -.calendar th { - border: var(--calendar-border) solid 1px; +table td, +table th { + border: var(--table-border) solid 1px; border-left: unset; border-top: unset; padding: 2px; +} + +table.calendar td, +table.calendar th { text-align: center; } -.calendar td:last-child, -.calendar th:last-child { +table td:last-child, +table th:last-child { border-right: unset; } -.calendar tr:last-child td { +table tr:last-child td { border-bottom: unset; +} + +.message { + font-size: 16px; + font-family: monospace; +} + +.message:nth-child(even) { + background: var(--message-alt-background); +} + +.message .nick { + text-align: right; } \ No newline at end of file -- cgit v1.2.3