-
Notifications
You must be signed in to change notification settings - Fork 4
/
friends.php
175 lines (131 loc) · 6.97 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
<?php
/**
* https://09source.kicks-ass.net:8443/svn/installer09/
* Licence Info: GPL
* Copyright (C) 2010 Installer09 v.1
* A bittorrent tracker source based on TBDev.net/tbsource/bytemonsoon.
* Project Leaders: Mindless,putyn,kidvision.
**/
require_once(dirname(__FILE__).DIRECTORY_SEPARATOR.'include'.DIRECTORY_SEPARATOR.'bittorrent.php');
require_once(INCL_DIR.'user_functions.php');
dbconn(false);
loggedinorreturn();
$lang = array_merge( load_language('global'), load_language('friends') );
parked();
$userid = isset($_GET['id']) ? (int)$_GET['id'] : $CURUSER['id'];
$action = isset($_GET['action']) ? $_GET['action'] : '';
if (!is_valid_id($userid))
stderr($lang['friends_error'], $lang['friends_invalid_id']);
if ($userid != $CURUSER["id"])
stderr($lang['friends_error'], $lang['friends_no_access']);
if ($action == 'add')
{
$targetid = 0+$_GET['targetid'];
$type = $_GET['type'];
if (!is_valid_id($targetid))
stderr($lang['friends_error'], $lang['friends_invalid_id']);
if ($type == 'friend')
{
$table_is = $frag = 'friends';
$field_is = 'friendid';
}
elseif ($type == 'block')
{
$table_is = $frag = 'blocks';
$field_is = 'blockid';
}
else
stderr($lang['friends_error'], $lang['friends_unknown']);
$r = mysql_query("SELECT id FROM $table_is WHERE userid=$userid AND $field_is=$targetid") or sqlerr(__FILE__, __LINE__);
if (mysql_num_rows($r) == 1)
stderr($lang['friends_error'], sprintf($lang['friends_already'], htmlspecialchars($table_is)));
mysql_query("INSERT INTO $table_is VALUES (0,$userid, $targetid)") or sqlerr(__FILE__, __LINE__);
header("Location: {$TBDEV['baseurl']}/friends.php?id=$userid#$frag");
die;
}
if ($action == 'delete')
{
$targetid = (int)$_GET['targetid'];
$sure = isset($_GET['sure']) ? htmlspecialchars($_GET['sure']) : false;
$type = isset($_GET['type']) ? ($_GET['type'] == 'friend' ? 'friend' : 'block') : stderr($lang['friends_error'], 'LoL');
if (!is_valid_id($targetid))
stderr($lang['friends_error'], $lang['friends_invalid_id']);
if (!$sure)
stderr("{$lang['friends_delete']} $type", sprintf($lang['friends_sure'], $type, $userid, $type, $targetid) );
if ($type == 'friend')
{
mysql_query("DELETE FROM friends WHERE userid=$userid AND friendid=$targetid") or sqlerr(__FILE__, __LINE__);
if (mysql_affected_rows() == 0)
stderr($lang['friends_error'], $lang['friends_no_friend']);
$frag = "friends";
}
elseif ($type == 'block')
{
mysql_query("DELETE FROM blocks WHERE userid=$userid AND blockid=$targetid") or sqlerr(__FILE__, __LINE__);
if (mysql_affected_rows() == 0)
stderr($lang['friends_error'], $lang['friends_no_block']);
$frag = "blocks";
}
else
stderr($lang['friends_error'], $lang['friends_unknown']);
header("Location: {$TBDEV['baseurl']}/friends.php?id=$userid#$frag");
die;
}
$res = mysql_query("SELECT * FROM users WHERE id=$userid") or sqlerr(__FILE__, __LINE__);
$user = mysql_fetch_assoc($res) or stderr($lang['friends_error'], $lang['friends_no_user']);
$HTMLOUT = '';
$res = mysql_query("SELECT f.friendid as id, u.username AS name, u.username, u.class, u.avatar, u.title, u.leechwarn, u.chatpost, u.pirate, u.king, u.donor, u.warned, u.enabled, u.last_access FROM friends AS f LEFT JOIN users as u ON f.friendid = u.id WHERE userid=$userid ORDER BY name") or sqlerr(__FILE__, __LINE__);
$count = mysql_num_rows($res);
$friends = '';
if( !$count)
{
$friends = "<em>{$lang['friends_friends_empty']}.</em>";
}
else
{
while ($friend = mysql_fetch_assoc($res))
{
$title = $friend["title"];
if (!$title)
$title = get_user_class_name($friend["class"]);
$userlink = "<a href='userdetails.php?id={$friend['id']}'><b></b></a>";
$userlink .= format_username($friend) . " ($title)<br />{$lang['friends_last_seen']} " . get_date( $friend['last_access'],'');
$delete = "<span class='btn'><a href='friends.php?id=$userid&action=delete&type=friend&targetid={$friend['id']}'>{$lang['friends_remove']}</a></span>";
$pm = " <span class='btn'><a href='sendmessage.php?receiver={$friend['id']}'>{$lang['friends_pm']}</a></span>";
$avatar = ($CURUSER["avatars"] == "yes" ? htmlspecialchars($friend["avatar"]) : "");
if (!$avatar)
$avatar = "{$TBDEV['pic_base_url']}default_avatar.gif";
$friends .= "<div style='border: 1px solid black;padding:5px;'>".($avatar ? "<img width='50px' src='$avatar' style='float:right;' alt='' />" : ""). "<p >{$userlink}<br /><br />{$delete}{$pm}</p></div><br />";
}
}
$res = mysql_query("SELECT b.blockid as id, u.username AS name, u.username, u.class, u.donor, u.warned, u.leechwarn, u.chatpost, u.pirate, u.king, 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__);
$blocks = '';
if(mysql_num_rows($res) == 0)
{
$blocks = "{$lang['friends_blocks_empty']}<em>.</em>";
}
else
{
while ($block = mysql_fetch_assoc($res))
{
$blocks .= "<div style='border: 1px solid black;padding:5px;'>";
$blocks .= "<span class='btn' style='float:center;'><a href='friends.php?id=$userid&action=delete&type=block&targetid={$block['id']}'>{$lang['friends_delete']}</a></span><br />";
$blocks .= "<p><a href='userdetails.php?id={$block['id']}'><b></b></a>";
$blocks .= format_username($block) . "</p></div><br />";
}
}
$HTMLOUT .= "<div style='border: 1px solid black;padding:5px;'><span class='btn' style='float:right;'>{$lang['friends_personal']} ".htmlspecialchars($user['username'])."</span>";
$HTMLOUT .= "<table class='main' width='739' border='0' cellspacing='0' cellpadding='0'>
<tr>
<td class='colhead'><h2 style='width:50%; text-align:left;'><a name='friends'>{$lang['friends_friends_list']}</a></h2></td>
<td class='colhead'><h2 style='width:50%; text-align:left; vertical-align:top;'><a name='blocks'>{$lang['friends_blocks_list']}</a></h2></td>
</tr>
<tr>
<td style='padding:10px;background:#ECE9D8;width:50%;'>$friends</td>
<td style='padding:10px;background:#ECE9D8 vertical-align:top;'>$blocks</td>
</tr>
</table>";
$HTMLOUT .= "<p><a href='users.php'><b>{$lang['friends_user_list']}</b></a></p>";
$HTMLOUT .= "</div>";
print stdhead("{$lang['friends_stdhead']} {$user['username']}") . $HTMLOUT . stdfoot();
?>