-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmessages.php
108 lines (83 loc) · 2.51 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
<?php
include("includes/header.php");
$message_obj = new Message($con, $userLoggedIn);
if(isset($_GET['u']))
$user_to = $_GET['u'];
else {
$user_to = $message_obj->getMostRecentUser();
if($user_to == false)
$user_to = 'new';
}
if($user_to != "new")
$user_to_obj = new User($con, $user_to);
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");
$message_obj->sendMessage($user_to, $body, $date);
}
}
?>
<div class="user_details column">
<a href="<?php echo $userLoggedIn; ?>"> <img src="<?php echo $user['profile_pic']; ?>"> </a>
<div class="user_details_left_right">
<a href="<?php echo $userLoggedIn; ?>">
<?php
echo $user['first_name'] . " " . $user['last_name'];
?>
</a>
<br>
<?php echo "Posts: " . $user['num_posts']. "<br>";
echo "Likes: " . $user['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_messages'>";
echo $message_obj->getMessages($user_to);
echo "</div>";
}
else {
echo "<h4>New Message</h4>";
}
?>
<script>
function getUsers(value, user) {
$.post("includes/handlers/ajax_friend_search.php", {query:value, userLoggedIn:user}, function(data) {
$(".results").html(data);
});
}
</script>
<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' name='q' onkeyup='getUsers(this.value, "<?php echo $userLoggedIn?>")' 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 your message ...'></textarea>";
echo "<input type='submit' name='post_message' class='info' id='message_submit' value='Send'>";
}
?>
</form>
</div>
<script>
var div = document.getElementById("scroll_messages");
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>