-
Notifications
You must be signed in to change notification settings - Fork 0
/
messages.php
124 lines (80 loc) · 2.53 KB
/
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
107
108
109
110
111
112
113
114
<?php
include("includes/header.php");
$message_obj = new Message($con, $userLoggedIn);
if (isset($_GET['u'])) {
$user_to = $_GET['u']; // get the username to send message to
} else {
$user_to = $message_obj->getMostRecentUser();
if ($user_to == false) {
$user_to = 'new'; // this is the first message/conversation
}
}
// create user obj of the user to send message to
if ($user_to != 'new') {
$user_to_obj = new User($con, $user_to);
}
// when post message button is pressed
if (isset($_POST['post_message'])) {
if (isset($_POST['message_body'])) {
$body = mysqli_real_escape_string($con, $_POST['message_body']);
$date = date("Y-m-d H:i:s");
// send the message
$message_obj->sendMessage($user_to, $body, $date);
}
}
?>
<div class="user_details column">
<a href=" <?php echo $data['username'] ?> "><img src=" <?php echo $data['profile_pic'] ?> "></a>
<div class="user_details_left_right">
<a href=" <?php echo $data['username'] ?> ">
<?php
echo $data['first_name'] . " " . $data['last_name'];
?>
</a>
<?php
echo "Posts: " . $data['num_posts'] . "<br>";
echo "Likes: " . $data['num_likes'];
?>
</div>
</div>
<div class="main_column column" id="main_column">
<?php
if ($user_to != 'new') {
echo "<h4>You and <a href='$user_to'>" . $user_to_obj->getFirstAndLastName() . "</a></h4><hr><br>";
echo "<div class='loaded_messages' id='scroll_message'>";
echo $message_obj->getMessages($user_to);
echo "</div>";
} else {
echo "<h4>New Message</h4>";
}
?>
<div class="message_post">
<form action="" method="POST">
<?php
if ($user_to == "new") {
echo "Select the friend you would like to message <br><br>";
?>
To: <input type='text' onkeyup='getUser(this.value, "<?php echo $userLoggedIn; ?>")' name='q' placeholder='Name' autocomplete='off' id='search_text_input'>
<?php
echo "<div class='results'></div>";
} else {
echo "<textarea name='message_body' id='message_textarea' placeholder='Write you message..'></textarea>";
echo "<input type='submit' name='post_message' class='info' id='message_submit' value='Send'>";
}
?>
</form>
</div>
<script>
// to scroll to the latest message
var div = document.getElementById("scroll_message");
div.scrollTop = div.scrollHeight;
</script>
</div>
<div class="user_details column" id="conversations">
<h4>Conversations</h4>
<div class="loaded_conversations">
<?php echo $message_obj->getConvos(); ?>
</div>
<br>
<a href="messages.php?u=new">New Message</a>
</div>