diff options
| -rw-r--r-- | database.sql | 10 | ||||
| -rw-r--r-- | public/inbox.php | 76 | ||||
| -rw-r--r-- | public/static/img/icons/inbox/0.png | bin | 0 -> 587 bytes | |||
| -rw-r--r-- | public/static/img/icons/inbox/1.png | bin | 0 -> 781 bytes | |||
| -rw-r--r-- | public/static/img/icons/inbox/2.png | bin | 0 -> 641 bytes | |||
| -rw-r--r-- | src/partials.php | 15 |
6 files changed, 101 insertions, 0 deletions
diff --git a/database.sql b/database.sql index ec59cf8..15c73e8 100644 --- a/database.sql +++ b/database.sql @@ -55,4 +55,14 @@ CREATE TABLE IF NOT EXISTS ratings ( emote_id INTEGER NOT NULL REFERENCES emotes(id), rate INTEGER NOT NULL, rated_at TIMESTAMP NOT NULL DEFAULT UTC_TIMESTAMP +); + +CREATE TABLE IF NOT EXISTS inbox_messages ( + id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, + recipient_id INTEGER NOT NULL REFERENCES users(id), + message_type INTEGER NOT NULL, + contents TEXT NOT NULL, + link TEXT, + sent_at TIMESTAMP NOT NULL DEFAULT UTC_TIMESTAMP, + has_read BOOLEAN NOT NULL DEFAULT false );
\ No newline at end of file diff --git a/public/inbox.php b/public/inbox.php new file mode 100644 index 0000000..878bfe4 --- /dev/null +++ b/public/inbox.php @@ -0,0 +1,76 @@ +<?php +include_once "../src/accounts.php"; +include_once "../src/config.php"; +include_once "../src/partials.php"; +include_once "../src/utils.php"; + +if (!authorize_user(true)) { + exit; +} + +$db = new PDO(DB_URL, DB_USER, DB_PASS); + +$stmt = $db->prepare("SELECT * FROM inbox_messages WHERE recipient_id = ? ORDER BY sent_at DESC"); +$stmt->execute([$_SESSION["user_id"]]); + +$messages = $stmt->fetchAll(PDO::FETCH_ASSOC); + +$stmt = $db->prepare("UPDATE inbox_messages SET has_read = true WHERE recipient_id = ?"); +$stmt->execute([$_SESSION["user_id"]]); + +?> + +<html> + +<head> + <title>Inbox - alright.party</title> + <link rel="stylesheet" href="/static/style.css"> +</head> + +<body> + <div class="container"> + <div class="wrapper"> + <?php html_navigation_bar() ?> + <section class="content"> + <section class="box" style="width: 50%;"> + <section class="box navtab"> + Inbox + </section> + <section class="box content"> + <table> + <tr> + <th style="width: 16px;"></th> + <th>Contents</th> + <th style="min-width: 96px;"></th> + </tr> + <?php + foreach ($messages as $message) { + echo '<tr'; + if (!$message["has_read"]) { + echo ' style="background-color: yellow;"'; + } + echo '>'; + + echo '<td><img src="/static/img/icons/inbox/' . $message["message_type"] . '.png"></td>'; + echo '<td>' . $message["contents"]; + echo ' <span style="font-size:12px; color: gray;">(' . format_timestamp(time() - strtotime($message["sent_at"])) . ' ago)</span>'; + echo '</td>'; + + echo '<td style="text-align:center;">'; + if ($message["link"]) { + echo '<a href="' . $message["link"] . '">[ View ]</a>'; + } + echo '</td>'; + + echo '</tr>'; + } + ?> + </table> + </section> + </section> + </section> + </div> + </div> +</body> + +</html>
\ No newline at end of file diff --git a/public/static/img/icons/inbox/0.png b/public/static/img/icons/inbox/0.png Binary files differnew file mode 100644 index 0000000..c149c2b --- /dev/null +++ b/public/static/img/icons/inbox/0.png diff --git a/public/static/img/icons/inbox/1.png b/public/static/img/icons/inbox/1.png Binary files differnew file mode 100644 index 0000000..89c8129 --- /dev/null +++ b/public/static/img/icons/inbox/1.png diff --git a/public/static/img/icons/inbox/2.png b/public/static/img/icons/inbox/2.png Binary files differnew file mode 100644 index 0000000..7348aed --- /dev/null +++ b/public/static/img/icons/inbox/2.png diff --git a/src/partials.php b/src/partials.php index 71f4f63..174b1d3 100644 --- a/src/partials.php +++ b/src/partials.php @@ -12,6 +12,21 @@ function html_navigation_bar() <a href="/users.php" class="button">Users</a> <a href="/emotes/upload.php" class="button">Upload</a> <a href="/account" class="button">Account</a> + <?php + if (isset($_SESSION["user_id"])) { + $db = new PDO(DB_URL, DB_USER, DB_PASS); + $stmt = $db->prepare("SELECT COUNT(*) FROM inbox_messages WHERE recipient_id = ? AND has_read = false"); + $stmt->execute([$_SESSION["user_id"]]); + $unread_count = intval($stmt->fetch()[0]); + echo '' ?> + <a href="/inbox.php" class="button"> + Inbox <?php echo $unread_count > 0 ? "($unread_count)" : "" ?> + </a> + <?php ; + $stmt = null; + $db = null; + } + ?> </div> <?php if (isset($_SESSION["user_id"])) { |
