-
Notifications
You must be signed in to change notification settings - Fork 2
/
my-messages.php
44 lines (44 loc) · 1.72 KB
/
my-messages.php
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
<?php
include ('./classes/DB.php');
include ('./classes/Login.php');
if (Login::isLoggedIn()) {
$userid = Login::isLoggedIn();
} else {
die('Not logged in');
}
if (isset($_GET['mid'])) {
$message = DB::query('SELECT * FROM messages WHERE id=:mid AND (receiver=:receiver OR sender=:sender)', array(':mid' => $_GET['mid'], ':receiver' => $userid, ':sender' => $userid)) [0];
echo '<h1>View Message</h1>';
echo htmlspecialchars($message['body']);
echo '<hr />';
if ($message['sender'] == $userid) {
$id = $message['receiver'];
} else {
$id = $message['sender'];
}
DB::query('UPDATE messages SET `seen`=1 WHERE id=:mid', array(':mid' => $_GET['mid']));
?>
<form action="send-message.php?receiver=<?php echo $id; ?>" method="post">
<textarea name="body" rows="8" cols="80"></textarea>
<input type="submit" name="send" value="Send Message">
</form>
<?php
} else {
?>
<h1>My Messages</h1>
<?php
$messages = DB::query('SELECT messages.*, users.username FROM messages, users WHERE (receiver=:receiver OR sender=:sender) AND users.id = messages.sender', array(':receiver' => $userid, ':sender' => $userid));
foreach ($messages as $message) {
if (strlen($message['body']) > 10) {
$m = substr($message['body'], 0, 10) . " ...";
} else {
$m = $message['body'];
}
if ($message['seen'] == 0) {
echo "<a href='my-messages.php?mid=" . $message['id'] . "'><strong>" . $m . "</strong></a> sent by " . $message['username'] . '<hr />';
} else {
echo "<a href='my-messages.php?mid=" . $message['id'] . "'>" . $m . "</a> sent by " . $message['username'] . '<hr />';
}
}
}
?>