summaryrefslogtreecommitdiff
path: root/inbox.php
blob: 9932802656f7ea90ec2bb8bd5723a6ccf2c7d1dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
include_once "{$_SERVER['DOCUMENT_ROOT']}/lib/accounts.php";
include_once "{$_SERVER['DOCUMENT_ROOT']}/lib/config.php";
include_once "{$_SERVER['DOCUMENT_ROOT']}/lib/partials.php";
include_once "{$_SERVER['DOCUMENT_ROOT']}/lib/utils.php";

if (!authorize_user(true)) {
    exit;
}

$db = new PDO(CONFIG['database']['url'], CONFIG['database']['user'], CONFIG['database']['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 - <?= CONFIG['instance']['name'] ?></title>
    <link rel="stylesheet" href="/static/style.css">
    <link rel="shortcut icon" href="/static/favicon.ico" type="image/x-icon">
</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>