-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathinvite.php
More file actions
282 lines (227 loc) · 10.8 KB
/
invite.php
File metadata and controls
282 lines (227 loc) · 10.8 KB
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
279
280
281
282
<?php
/**
**************************
** FreeTSP Version: 1.0 **
**************************
** http://www.freetsp.info
** https://github.com/Krypto/FreeTSP
** Licence Info: GPL
** Copyright (C) 2010 FreeTSP v1.0
** A bittorrent tracker source based on TBDev.net/tbsource/bytemonsoon.
** Project Leaders: Krypto, Fireknight.
**/
require_once(dirname(__FILE__).DIRECTORY_SEPARATOR.'functions'.DIRECTORY_SEPARATOR.'function_main.php');
require_once(FUNC_DIR.'function_user.php');
require_once(FUNC_DIR.'function_vfunctions.php');
db_connect(true);
logged_in();
$do = (isset($_GET["do"]) ? $_GET["do"] : (isset($_POST["do"]) ? $_POST["do"] : ''));
$valid_actions = array('create_invite', 'delete_invite', 'confirm_account', 'view_page');
$do = (($do && in_array($do,$valid_actions,true)) ? $do : '') or header("Location: ?do=view_page");
//-- Show The Default Fist Page --//
if ($do == 'view_page')
{
$query = sql_query("SELECT *
FROM users
WHERE invitedby = ".sqlesc($CURUSER['id'])) or sqlerr(__FILE__, __LINE__);
$rows = mysql_num_rows($query);
site_header('Invites');
echo("<table border='1' width='81%' cellspacing='0' cellpadding='5'>");
echo("<tr><td class='colhead' align='center' colspan='7'><strong>Invited Users</strong></td></tr>");
if(!$rows)
{
echo("<tr><td class='rowhead' align='center' colspan='7'>No Invitees yet.</td></tr>");
}
else
{
echo ("<tr>
<td class='rowhead' align='center'><strong>Username</strong></td>
<td class='rowhead' align='center'><strong>Uploaded</strong></td>
<td class='rowhead' align='center'><strong>Downloaded</strong></td>
<td class='rowhead' align='center'><strong>Ratio</strong></td>
<td class='rowhead' align='center'><strong>Status</strong></td>
<td class='rowhead' align='center'><strong>Confirm</strong></td>
</tr>");
for ($i = 0; $i < $rows; ++$i)
{
$arr = mysql_fetch_assoc($query);
if ($arr['status'] == 'pending')
{
$user = "".htmlspecialchars($arr['username'])."";
}
else
{
$user = "<a href='userdetails.php?id=$arr[id]'>".htmlspecialchars($arr['username'])."</a>
".($arr["warned"] == "yes" ?" <img src='".$image_dir."warned.png' border='0' width='16' height='16' alt='Warned' title='Warned'>" : "")."
".($arr["enabled"] == "no" ?" <img src='".$image_dir."disabled.png' border='0' width='16' height='16' alt='Disabled' title='Disabled'>" : "")."
".($arr["donor"] == "yes" ?"<img src='".$image_dir."star.png' width='16' height='16' border='0' alt='Donor' title='Donor'>" : "")." ";
}
if ($arr['downloaded'] > 0)
{
$ratio = number_format($arr['uploaded'] / $arr['downloaded'], 3);
$ratio = "<font color='".get_ratio_color($ratio)."'>".$ratio."</font>";
}
else
{
if ($arr['uploaded'] > 0)
{
$ratio = 'Inf.';
}
else
{
$ratio = '---';
}
}
if ($arr["status"] == 'confirmed')
{
$status = "<font color='#1f7309'>Confirmed</font>";
}
else
{
$status = "<font color='#ca0226'>Pending</font>";
}
echo ("<tr>
<td class='rowhead'align='center'>".$user."</td>
<td class='rowhead'align='center'>".mksize($arr['uploaded'])."</td>
<td class='rowhead'align='center'>".mksize($arr['downloaded'])."</td>
<td class='rowhead'align='center'>".$ratio."</td>
<td class='rowhead'align='center'>".$status."</td>");
if ($arr['status'] == 'pending')
{
echo("<td class='rowhead' align='center'><a href='?do=confirm_account&userid=".$arr['id']."&sender=".$CURUSER['id']."'><img src='".$image_dir."rep.png' width='24' height='25' border='0' alt='Confirm Invite' title='Confirm Invite' /></a></td>");
}
else
{
echo("<td class='rowhead' align='center'>---</td>");
}
}
echo("</tr>");
echo("</table><br />");
}
$select = sql_query("SELECT *
FROM invite_codes
WHERE sender = ".$CURUSER['id'].
AND status = 'Pending'") or sqlerr(__FILE__, __LINE__);
$num_row = mysql_num_rows($select);
echo("<table border='1' width='81%' cellspacing='0' cellpadding='5'>");
echo("<tr><td class='colhead' align='center' colspan='6'><strong>Created Invite Codes</strong></td></tr>");
if (!$num_row)
{
echo("<tr><td class='rowhead' align='center' colspan='6'>You have No Created Invite Codes at the moment!</td></tr>");
}
else
{
echo("<tr>
<td class='rowhead' align='center'><strong>Invite Code</strong></td>
<td class='rowhead' align='center'><strong>Created Date</strong></td>
<td class='rowhead' align='center'><strong>Delete</strong></td>
<td class='rowhead' align='center'><strong>Status</strong></td>
</tr>");
for ($i = 0; $i < $num_row; ++$i)
{
$fetch_assoc = mysql_fetch_assoc($select);
echo("<tr>
<td class='rowhead' align='center'>".$fetch_assoc['code']."</td>
<td class='rowhead' align='center'>".get_elapsed_time(sql_timestamp_to_unix_timestamp($fetch_assoc['invite_added']))." ago</td>");
echo("<td class='rowhead' align='center'><a href='?do=delete_invite&id=".$fetch_assoc['id']."&sender=".$CURUSER['id']."'><img src='images/button_delete2.gif' width-'12' height='14' border='0' alt='Delete' title='Delete' /></a></td>
<td class='rowhead' align='center'>".$fetch_assoc['status']."</td>
</tr>");
}
}
echo("<tr>
<td class='rowhead' align='center' colspan='7'>
<form action='?do=create_invite' method='post'><input type='submit' class='btn' value='Create Invite Code' style='height: 20px' /></form>
</td>
</tr>");
echo '</table>';
site_footer();
die();
}
//-- Create The Invite --//
if ($do =='create_invite')
{
if ($CURUSER['invites'] <= 0)
{
error_message_center("error", "Error", "No Invites!");
}
if ($CURUSER["invite_rights"] == 'no')
{
error_message_center("error","Error", "Your Invite Sending Privileges has been Disabled by the Staff!");
}
$res = sql_query("SELECT COUNT(*)
FROM users") or sqlerr(__FILE__, __LINE__);
$arr = mysql_fetch_row($res);
if ($arr[0] >= $invites)
{
error_message_center("error", "Error", "Sorry, User Limit Reached. Please try again later.");
}
$invite = md5(mksecret());
sql_query("INSERT INTO invite_codes (sender, invite_added, code)
VALUES (".sqlesc((int)$CURUSER['id']).", ".sqlesc(get_date_time()).", ".sqlesc($invite).")") or sqlerr(__FILE__, __LINE__);
sql_query("UPDATE users
SET invites = invites - 1
WHERE id = ".sqlesc($CURUSER['id'])) or sqlerr(__FILE__, __LINE__);
header("Location: ?do=view_page");
}
//-- Delete The Invite --//
if ($do =='delete_invite')
{
$id = (isset($_GET["id"]) ? (int)$_GET["id"] : (isset($_POST["id"]) ? (int)$_POST["id"] : ''));
$query = sql_query('SELECT *
FROM invite_codes
WHERE id = '.sqlesc($id).
AND sender = '.sqlesc($CURUSER['id']).
AND status = "Pending"') or sqlerr(__FILE__, __LINE__);
$assoc = mysql_fetch_assoc($query);
if (!$assoc)
{
error_message_center("error", "Error", "This Invite Code Does Not Exist.");
}
isset($_GET['sure']) && $sure = htmlentities($_GET['sure']);
if (!$sure)
{
error_message_center("info", "Sanity Check", "Are you sure you want to Delete this Invite Code?
Click <a href='".$_SERVER['PHP_SELF']."?do=delete_invite&id=".$id."&sender=".$CURUSER['id']."&sure=yes'>HERE</a>
to Delete it or Click <a href='?do=view_page'>HERE</a> to go back.");
}
sql_query("DELETE FROM invite_codes
WHERE id = ".sqlesc($id).
AND sender = ".sqlesc($CURUSER['id'].
AND status = 'Pending'")) or sqlerr(__FILE__, __LINE__);
sql_query("UPDATE users
SET invites = invites + 1
WHERE id = ".sqlesc($CURUSER['id'])) or sqlerr(__FILE__, __LINE__);
header("Location: ?do=view_page");
}
//-- Confirm The Invite --//
if ($do ='confirm_account')
{
$userid = (isset($_GET["userid"]) ? (int)$_GET["userid"] : (isset($_POST["userid"]) ? (int)$_POST["userid"] : ''));
if (!is_valid_id($userid))
{
error_message_center("error", "Error", "Invalid ID.");
}
$select = sql_query("SELECT id, username
FROM users
WHERE id = ".sqlesc($userid).
AND invitedby = ".sqlesc($CURUSER['id'])) or sqlerr(__FILE__, __LINE__);
$assoc = mysql_fetch_assoc($select);
if (!$assoc)
{
error_message_center("error", "Error", "No User with this ID!");
}
isset($_GET['sure']) && $sure = htmlentities($_GET['sure']);
if (!$sure)
{
error_message_center("info" , "Confirm Account", "Are you sure you want to Confirm ".htmlspecialchars($assoc['username'])." 's Account?<br />
Click <a href='?do=confirm_account&userid=".$userid."&sender=".$CURUSER['id']."&sure=yes'>HERE</a> to Confirm it.<br />
Or Click <a href='?do=view_page'>HERE</a> to go back.");
}
sql_query("UPDATE users
SET status = 'confirmed'
WHERE id = ".sqlesc($userid).
AND invitedby = ".sqlesc($CURUSER['id']).
AND status='pending'") or sqlerr(__FILE__, __LINE__);
header("Location: ?do=view_page");
}
?>