/
my_messages.php
255 lines (207 loc) · 6.58 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
<?php
error_reporting(0);
include("./inc/header.inc.php");
if($username){
echo '<div style="height:40px; width:100%;"></div>';
}
else{
echo '<div style="height:40px; width:100%;"></div>';
die ("You must be logged in to view this page!");
}
?>
<?php
//include("./inc/header.inc.php");
//echo '<div style="height:40px; width:100%;"></div>';
//grab the messages for the logged in user
?>
<div class="message_content_body">
<div class="read_unread_messages">
<h2>My Unread Messages:</h2><p />
<?php
$grab_messages = mysql_query("SELECT * FROM pvt_messages WHERE user_to='$username' && opened='no' && deleted='no'");
$numrows=mysql_numrows($grab_messages);
if($numrows != 0){
while($get_msg = mysql_fetch_assoc($grab_messages)){
$id = $get_msg['id'];
$user_from = $get_msg['user_from'];
$user_to = $get_msg['user_to'];
$msg_title = $get_msg['msg_title'];
$msg_body = $get_msg['msg_body'];
date_default_timezone_set('Asia/Calcutta');
$date = $get_msg['date'];
$opened = $get_msg['opened'];
$deleted = $get_msg['deleted'];
?>
<script language="javascript">
function toggle<?php echo $id; ?>(){
var ele = document.getElementById("toggleText<?php echo $id;?>");
var text = document.getElementById("displayText<?php echo $id;?>");
if(ele.style.display == "block"){
ele.style.display = "none";
}
else{
ele.style.display = "block";
}
}
</script>
<?php
$users_query = mysql_query("SELECT first_name, last_name FROM users WHERE username='$user_from'");
$full_name = mysql_fetch_assoc($users_query);
$firstname = $full_name['first_name'];
$lastname = $full_name['last_name'];
?>
<?php
if(strlen($msg_title) > 150){
$msg_title = substr($msg_title, 0, 50)." ...";
}
else
$msg_title = $msg_title;
if(strlen($msg_body) > 150){
$msg_body = substr($msg_body, 0, 50)." ...";
}
else
$msg_body = $msg_body;
if(@$_POST['setopened_' . $id . '']){
//update the private messages table
$setopened_query = mysql_query("UPDATE pvt_messages SET opened='yes' WHERE id='$id'");
//header("Location: my_messages.php");
echo "<meta http-equiv=\"refresh\" content=\"0; url=my_messages.php\">";
}
if(@$_POST['reply_' . $id . '']){
//header("Location: msg_reply.php?u=$user_from");
echo "<meta http-equiv=\"refresh\" content=\"0; url=send_msg.php?m=$user_from\">";
}
echo "
<form method='POST' action='my_messages.php' name='$msg_title'>
<b><a href='$user_from'>$firstname $lastname:</a></b>
<input type='button' name='openmsg' value='$msg_title' onClick='javascript:toggle$id()'>
<input type='submit' name='reply_$id' value=\"Reply\">
<input type='submit' name='setopened_$id' value=\"I've read this\">
</form>
<div id='toggleText$id' style='display: none;'>
<br />$msg_body
</div>
<hr /><br />
";
}
}
else{
echo "You haven't read any messages yet.";
}
?>
<h2>My Read Messages:</h2><p />
<?php
$grab_messages = mysql_query("SELECT * FROM pvt_messages WHERE user_to='$username' && opened='yes' && deleted='no'");
$numrows_read = mysql_numrows($grab_messages);
if($numrows_read != 0){
while($get_msg = mysql_fetch_assoc($grab_messages)){
$id = $get_msg['id'];
$user_from = $get_msg['user_from'];
$user_to = $get_msg['user_to'];
$msg_title = $get_msg['msg_title'];
$msg_body = $get_msg['msg_body'];
date_default_timezone_set('Asia/Calcutta');
$date = $get_msg['date'];
$opened = $get_msg['opened'];
$deleted = $get_msg['deleted'];
?>
<script language="javascript">
function toggle<?php echo $id; ?>(){
var ele = document.getElementById("toggleText<?php echo $id;?>");
var text = document.getElementById("displayText<?php echo $id;?>");
if(ele.style.display == "block"){
ele.style.display = "none";
}
else{
ele.style.display = "block";
}
}
</script>
<?php
$users_query = mysql_query("SELECT first_name, last_name FROM users WHERE username='$user_from'");
$full_name = mysql_fetch_assoc($users_query);
$firstname = $full_name['first_name'];
$lastname = $full_name['last_name'];
?>
<?php
if(strlen($msg_body) > 150){
$msg_body = substr($msg_body, 0, 150)." ...";
}
else
$msg_body = $msg_body;
if(@$_POST['delete_' . $id . '']){
$delete_msg_query = mysql_query("UPDATE pvt_messages SET deleted='yes' WHERE id='$id'");
//header("Location: my_messages.php");
echo "<meta http-equiv=\"refresh\" content=\"0; url=my_messages.php\">";
}
if(@$_POST['reply_' . $id . '']){
//header("Location: msg_reply.php?u=$user_from");
echo "<meta http-equiv=\"refresh\" content=\"0; url=send_msg.php?m=$user_from\">";
}
echo "<form method='POST' action='my_messages.php' name='$msg_title'>
<b><a href='$user_from'>$firstname $lastname:</a></b>
<input type='button' name='openmsg' value='$msg_title' onClick='javascript:toggle$id()'>
<input type='submit' name='reply_$id' value=\"Reply\">
<input type='submit' name='delete_$id' value=\"X\" title='delete message'>
</form>
<div id='toggleText$id' style='display: none;'>
<br />$msg_body
</div>
<hr /><br />
";
}
}
?>
</div>
<div class="online_friends">
<h2>Online Friends:</h2>
<?php
//friend lists
$friendsArray = "";
$countFriends = "";
$friendsArray12 = "";
$addAsFriend = "";
$selectFriendsQuery = mysql_query("SELECT friend_array FROM users WHERE username='$username'");
$friendRow = mysql_fetch_assoc($selectFriendsQuery);
$friendArray = $friendRow['friend_array'];
if($friendArray!= ""){
$friendArray = explode(",",$friendArray);
$countFriends = count($friendArray);
$friendArray12 = array_slice($friendArray, 0, 12);
$i = 0;
}
?>
<ul class="onlinefriends">
<?php
if($countFriends != 0){
foreach ($friendArray12 as $key => $value){
$i++;
$getFriendQuery = mysql_query("SELECT * FROM users WHERE username = '$value' AND online= 1 LIMIT 1");
$getFriendRow = mysql_fetch_assoc($getFriendQuery);
$friendUsername = $getFriendRow['username'];
if($friendUsername == ''){
}
else{
$users_query = mysql_query("SELECT first_name, last_name FROM users WHERE username='$friendUsername'");
$full_name = mysql_fetch_assoc($users_query);
$first_name1 = $full_name['first_name'];
$last_name1 = $full_name['last_name'];
echo"<li>";
echo"<a href='send_msg.php?m=$friendUsername'>".$first_name1." ".$last_name1."<img src='img/green_dot.png' height='15' width='15'></a>";
echo"</li>";
}
//$friendProfilePic = $getFriendRow['profile_pic'];
//if($friendProfilePic == ""){
//echo " <a href='$friendUsername'><img src='img/default_pic.png' alt=\"$first_name1 $last_name1's Profile\" title=\"$first_name1 $last_name1's Profile\" height='55' width='45' style='padding-left:5px;'></a>";
//}
//else{
//echo " <a href='$friendUsername'><img src='userdata/profile_pics/$friendProfilePic' alt=\"$first_name1 $last_name1's Profile\" title=\"$first_name1 $last_name1's Profile\" height='55' width='45' style='padding-left:5px;'></a>";
//}
}
}
else
echo "you have no friends yet!";
?>
</ul>
</div>
<div>