-
Notifications
You must be signed in to change notification settings - Fork 4
/
my-messages.php
106 lines (93 loc) · 3.55 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
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
include('./classes/DB.php');
include('./classes/Login.php');
if (Login::isLoggedIn()) {
$userid = Login::isLoggedIn();
$username="";
$username=DB::query('SELECT username FROM users WHERE id=:userid', array(':userid'=>$userid))[0]['username'];
} 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 `read`=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 AND users.id = messages.sender', array(':receiver'=>$userid));
foreach ($messages as $message) {
if (strlen($message['body']) > 10) {
$m = substr($message['body'], 0, 10)." ...";
} else {
$m = $message['body'];
}
if ($message['read'] == 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 />';
}
}
?>
<link href="chat/style.css" rel="stylesheet">
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="chat/script.js"></script>
<div class="msg_box" style="right:290px">
<div class="msg_head">My Messages
</div>
<div class="msg_wrap">
<div class="msg_body">
<div class="msg_a"><?php
$messages = DB::query('SELECT messages.*, users.username FROM messages, users WHERE receiver=:receiver AND users.id = messages.sender', array(':receiver'=>$userid));
foreach ($messages as $message) {
if (strlen($message['body']) > 10) {
$m = substr($message['body'], 0, 10)." ...";
} else {
$m = $message['body'];
}
if ($message['read'] == 0) {
echo "<a href='my-messages.php?receiver=".$message['sender']."'><strong>".$m."</strong></a> sent by ".$message['username'].'<hr />';
} else {
echo "<a href='my-messages.php?receiver=".$message['sender']."'>".$m."</a> sent by ".$message['username'].'<br />';
}
}
}
?>
</div>
</div>
</div>
</div>
<?php
if (!isset($_GET['mid'])) {
?>
<div class="chat_box">
<div class="chat_head"> <?php echo $username?></div>
<div class="chat_body">
<?php
$usrs = DB::query('SELECT users.* FROM users,followers WHERE follower_id=:followerid AND users.id=followers.user_id',array(':followerid'=>$userid));
foreach ($usrs as $usr) {
$m = $usr['username'];
if($m!=$username){
echo "<div class='user'>";
echo"<a href='send-message.php?receiver=".$usr['id']."'>".$m."</a>".'<br />';
echo "</div>";
}
}?>
</div>
</div>
<?php
} ?>