-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfriends.php
278 lines (243 loc) · 8.83 KB
/
friends.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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
<?php
require "include/bittorrent.php";
loggedinorreturn();
if($usergroups['canfriendslist'] != 'yes') ug();
parked();
$userid = $_GET['id'];
$action = isset($_POST['action']) ? $_POST['action'] : (isset($_GET['action']) ? $_GET['action'] : 'flist');
if (!$userid)
$userid = $CURUSER['id'];
if (!is_valid_id($userid))
stderr("Error", "Invalid ID $userid.");
if ($userid != $CURUSER["id"])
stderr("Error", "Access denied.");
$res = sql_query("SELECT * FROM users WHERE id=$userid") or sqlerr(__FILE__, __LINE__);
$user = mysql_fetch_array($res) or stderr("Error", "No user with ID $userid.");
// action: add -------------------------------------------------------------
if ($action == 'add')
{
$targetid = $_GET['targetid'];
$type = $_GET['type'];
if (!is_valid_id($targetid))
stderr("Error", "Invalid ID $$targetid.");
if ($type == 'friend')
{
$table_is = $frag = 'friends';
$field_is = 'friendid';
}
elseif ($type == 'block')
{
$table_is = $frag = 'blocks';
$field_is = 'blockid';
}
else
stderr("Error", "Unknown type $type");
$r = sql_query("SELECT id FROM $table_is WHERE userid=$userid AND $field_is=$targetid") or sqlerr(__FILE__, __LINE__);
if (mysql_num_rows($r) == 1)
stderr("Error", "User ID $targetid is already in your $table_is list.");
sql_query("INSERT INTO $table_is VALUES (0,$userid, $targetid)") or sqlerr(__FILE__, __LINE__);
header("Location: $BASEURL/friends.php");
die;
}
// action: delete ----------------------------------------------------------
if ($action == 'delete')
{
$targetid = $_GET['targetid'];
$sure = $_GET['sure'];
$type = $_GET['type'];
if (!is_valid_id($targetid))
stderr("Error", "Invalid ID $userid.");
if (!$sure)
stderr("Delete $type","Do you really want to delete a $type? Click\n" .
"<a href=?id=$userid&action=delete&type=$type&targetid=$targetid&sure=1>here</a> if you are sure.",false);
if ($type == 'friend')
{
sql_query("DELETE FROM friends WHERE userid=$userid AND friendid=$targetid") or sqlerr(__FILE__, __LINE__);
if (mysql_affected_rows() == 0)
stderr("Error", "No friend found with ID $targetid");
$frag = "friends";
}
elseif ($type == 'block')
{
sql_query("DELETE FROM blocks WHERE userid=$userid AND blockid=$targetid") or sqlerr(__FILE__, __LINE__);
if (mysql_affected_rows() == 0)
stderr("Error", "No block found with ID $targetid");
$frag = "blocks";
}
else
stderr("Error", "Unknown type $type");
header("Location: $BASEURL/friends.php");
die;
}
// main body -----------------------------------------------------------------
if($action == 'flist') {
stdhead("Personal lists for " . $user['username']);
if ($user["donor"] == "yes") $donor = "<td class=embedded><img src=pic/starbig.gif alt='Donor' style='margin-left: 4pt'></td>";
if ($user["warned"] == "yes") $warned = "<td class=embedded><img src=pic/warnedbig.gif alt='Warned' style='margin-left: 4pt'></td>";
fmenu();
print("<table class=main width=100% border=0 cellspacing=0 cellpadding=0><tr><td class=embedded>");
print("<h2 align=left><a name=\"friends\">Friends list for $CURUSER[username]</a></h2>\n");
print("<table width=100% border=1 cellspacing=0 cellpadding=5>");
$i = 0;
$dt = gmtime() - 180;
$dt = sqlesc(get_date_time($dt));
$res = sql_query("SELECT f.friendid as id, u.username AS name, u.class, u.avatar, u.title, u.donor, u.warned, u.enabled, u.last_access, u.gender FROM friends AS f LEFT JOIN users as u ON f.friendid = u.id WHERE userid=$userid ORDER BY name") or sqlerr(__FILE__, __LINE__);
if(mysql_num_rows($res) <= 0)
echo "<em>No frieds yet</em>";
else
while ($friend = mysql_fetch_array($res))
{
$avatar = ($CURUSER["avatars"] == "yes" ? htmlspecialchars($friend["avatar"]) : "");
if (!$avatar)
$avatar = "pic/default_avatar.gif";
?>
<tr>
<td>
<div>
<div style="border-right: 1px dotted black; float: left; margin-right: 3px;">
<a href="friends.php?id=<?=$CURUSER['id']?>&action=delete&type=friend&targetid=<?=$friend['id'];?>"><img src="pic/friends/remove.gif" alt="" border="0"></a>
<br><a href="sendmessage.php?receiver=<?=$friend['id']?>"><img src="pic/friends/pm.png" alt="" border="0"></a>
</div>
<div style="float: right;">
<img src="<?=$avatar;?>" height="40" width="40">
</div>
<?if($friend['gender'] == 'N/A') {?>
N/A
<?php }?>
<?php if($friend['gender'] == 'Male') {?>
<img src="pic/friends/Male.png" alt="Male" title="Male" border="0">
<?php }?>
<?php if($friend['gender'] == 'Female') {?>
<img src="pic/friends/Female.png" alt="Male" title="Male" border="0">
<?php }?>
<?='<a href=userdetails.php?id='.$friend['id'].'>'.get_style($friend['class'],$friend['name']).'</a>'?> (<?
if(!empty($friend['title']))
echo $friend['title'];
else
echo get_user_class_name($friend['class']);
?>)
<br>
<?php
if($friend['last_access']>$dt)
$status = 'online.png';
else
$status = 'offline.png';
?>
<img src="pic/friends/<?=$status?>" border="0">
<strong><?php
echo 'Last Seen - '.$friend['last_access'] .
"(" . get_elapsed_time(sql_timestamp_to_unix_timestamp($friend[last_access])) . " ago)"
?></strong>
</div>
</td>
</tr>
<?php
}
if ($i % 2 == 1)
print($friends);
print("</td></tr>\n");
print("</table></table>");
stdfoot();
die;
}
elseif($action == 'added') {
stdhead();
fmenu();
print("<table class=main width=100% border=0 cellspacing=0 cellpadding=0><tr><td class=embedded>");
print("<h2 align=left><a name=\"friendsadded\">Added you to friendslist</a></h2>\n");
print("<table width=100% border=1 cellspacing=0 cellpadding=5>");
$i = 0;
$friendadd = sql_query("SELECT f.userid AS id, u.username AS name, u.id AS uid, u.class, u.avatar, u.title, u.donor, u.warned, u.enabled, u.last_access, u.gender FROM friends AS f LEFT JOIN users AS u ON f.userid = u.id WHERE friendid = $CURUSER[id] ORDER BY name") or sqlerr(__FILE__, __LINE__);
if(mysql_num_rows($friendadd) == 0)
$friendsno = "<em>No friends yet</em>";
else
while ($friend = mysql_fetch_array($friendadd))
{
$title = $friend["title"];
if (!$title)
$title = get_user_class_name($friend["class"]);
$avatar = ($CURUSER["avatars"] == "yes" ? htmlspecialchars($friend["avatar"]) : "");
if (!$avatar)
$avatar = "pic/default_avatar.gif";
?>
<tr>
<td>
<div>
<div style="border-right: 1px dotted black; float: left; margin-right: 3px;">
<a href="sendmessage.php?receiver=<?=$friend['id']?>"><img src="pic/friends/pm.png" alt="" border="0"></a>
</div>
<div style="float: right;">
<img src="<?=$avatar;?>" height="40" width="40">
</div>
<?php if($friend['gender'] == 'N/A') {?>
N/A
<?php }?>
<?php if($friend['gender'] == 'Male') {?>
<img src="pic/friends/Male.png" alt="Male" title="Male" border="0">
<?php }?>
<?php if($friend['gender'] == 'Female') {?>
<img src="pic/friends/Female.png" alt="Female" title="Female" border="0">
<?php }?>
<?='<a href=userdetails.php?id='.$friend['id'].'>'.get_style($friend['class'],$friend['name']).'</a>'?> (<?
if(!empty($friend['title']))
echo $friend['title'];
else
echo get_user_class_name($friend['class']);
?>)
<br>
<?php
if($friend['last_access']>$dt)
$status = 'online.png';
else
$status = 'offline.png';
?>
<img src="pic/friends/<?=$status?>" border="0">
<strong><?php
echo 'Last Seen - '.$friend['last_access'] .
"(" . get_elapsed_time(sql_timestamp_to_unix_timestamp($friend[last_access])) . " ago)"
?></strong>
</div>
</td>
</tr>
<?php
}
if ($i % 2 == 1)
print("<td class=bottom width=50%> </td></tr></table>\n");
print($friendsno);
print("</td></tr></table></table><br>\n");
stdfoot();
die;
}
elseif($action == 'blocked') {
stdhead();
fmenu();
$res = sql_query("SELECT b.blockid as id, u.username AS name, u.donor, u.warned, u.enabled, u.last_access FROM blocks AS b LEFT JOIN users as u ON b.blockid = u.id WHERE userid=$userid ORDER BY name") or sqlerr(__FILE__, __LINE__);
if(mysql_num_rows($res) == 0)
$blocks = "<em>Your blocked userlist is empty</em>";
else {
$i = 0;
$blocks = "<table width=100% cellspacing=0 cellpadding=0>";
while ($block = mysql_fetch_array($res))
{
if ($i % 6 == 0)
$blocks .= "<tr>";
$blocks .= "<td style='border: none; padding: 4px; spacing: 0px;'>[<font class=small><a href=friends.php?id=$userid&action=delete&type=block&targetid=" .
$block['id'] . ">D</a></font>] <a href=userdetails.php?id=" . $block['id'] . "><b>" . $block['name'] . "</b></a>" .
get_user_icons($block) . "</td>";
if ($i % 6 == 5)
$blocks .= "</tr>";
$i++;
}
print("</table>\n");
}
print("<table class=main width=100% border=0 cellspacing=0 cellpadding=5><tr><td class=embedded>");
print("<h2 align=left><a name=\"blocks\">Blocked Users</a></h2></td></tr>");
print("<tr class=tableb><td style='padding: 10px;'>");
print("$blocks\n");
print("</td></tr></table>\n");
print("<p><a href=page.php?type=users><b>Find user/browse users list</b></a></p>");
stdfoot();
}
else {
die; }
?>