From ab2fa2aad371eb803c0e52c326075907a3583b8b Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Mon, 4 Aug 2025 16:07:48 +0500 Subject: feat: show room log timestamps --- web/index.php | 109 ++++++++++++++++++++++++++++++++++++++++++++++++--- web/static/style.css | 45 +++++++++++++++++++++ 2 files changed, 148 insertions(+), 6 deletions(-) create mode 100644 web/static/style.css (limited to 'web') diff --git a/web/index.php b/web/index.php index fd5246a..b71e61b 100644 --- a/web/index.php +++ b/web/index.php @@ -3,21 +3,118 @@ include_once $_SERVER['DOCUMENT_ROOT'] . '/config.php'; $db = new PDO(DB_URL, DB_USER, DB_PASS); -$stmt = $db->query('SELECT name FROM rooms ORDER BY joined_at, departed_at DESC'); -$stmt->execute(); -$rooms = $stmt->fetchAll(PDO::FETCH_ASSOC); +$room = $_GET['r'] ?: null; + +if (isset($room)) { + $room = urldecode($room); + $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 YEAR(sent_at) AS msg_year, + MONTH(sent_at) AS msg_month, + DAY(sent_at) AS msg_day, + COUNT(*) AS msg_count + FROM messages + WHERE room_id = ? + GROUP BY YEAR(sent_at), MONTH(sent_at), DAY(sent_at) + ORDER BY YEAR(sent_at) DESC, MONTH(sent_at) DESC, DAY(sent_at) DESC + '); + $stmt->execute([$room['id']]); + $raw_dates = $stmt->fetchAll(PDO::FETCH_ASSOC); + $dates = []; + + foreach ($raw_dates as $rm) { + $y = $rm['msg_year']; + $m = $rm['msg_month']; + $d = $rm['msg_day']; + $c = $rm['msg_count']; + if (!array_key_exists($y, $dates)) { + $dates[$y] = []; + } + if (!array_key_exists($m, $dates[$y])) { + $dates[$y][$m] = []; + } + if (!array_key_exists($d, $dates[$y][$m])) { + $dates[$y][$m] = []; + } + $dates[$y][$m][$d] = $c; + } +} else { + $stmt = $db->query('SELECT name FROM rooms ORDER BY joined_at, departed_at DESC'); + $stmt->execute(); + $rooms = $stmt->fetchAll(PDO::FETCH_ASSOC); +} ?> - Index - <?= INSTANCE_NAME ?> + + <?= $room['name'] ?> - <?= INSTANCE_NAME ?> + + Index - <?= INSTANCE_NAME ?> + - + +

- Index of

+
+ $months): ?> + $days): ?> + format('t'); + $sw = (int) $fd->format('N'); + $ms = $fd->format('M'); + ?> + + + + + + + + + + + + + '; + + for ($day = 1; $day <= $dm; $day++) { + echo ''; + if ((($day + $sw - 1) % 7) == 0 && $day != $dm) + echo ''; + } + + $remainingdays = (7 - (($dm + $sw - 1) % 7)) % 7; + for ($i = 0; $i < $remainingdays; $i++) + echo ''; + ?> + +
MoTuWeThFrSaSu
'; + if (array_key_exists($day, $days) && $days[$day] > 0) { + echo "$day"; + } else { + echo $day; + } + echo '
+ + +
+

Index of

There are no rooms. Add one!

@@ -29,7 +126,7 @@ $rooms = $stmt->fetchAll(PDO::FETCH_ASSOC); - + diff --git a/web/static/style.css b/web/static/style.css new file mode 100644 index 0000000..47bf506 --- /dev/null +++ b/web/static/style.css @@ -0,0 +1,45 @@ +:root { + --primary-color: #e2e9d9; + --calendar-border: black; +} + +* { + margin: 0; + padding: 0; +} + +.calendar-wrapper { + display: flex; + flex-direction: row; + flex-wrap: wrap; + gap: 16px; +} + +.calendar { + border: var(--calendar-border) solid 1px; + border-spacing: 0; +} + +.calendar>caption { + border: var(--calendar-border) solid 1px; + border-bottom: none; + background: var(--primary-color); +} + +.calendar td, +.calendar th { + border: var(--calendar-border) solid 1px; + border-left: unset; + border-top: unset; + padding: 2px; + text-align: center; +} + +.calendar td:last-child, +.calendar th:last-child { + border-right: unset; +} + +.calendar tr:last-child td { + border-bottom: unset; +} \ No newline at end of file -- cgit v1.2.3