-
Notifications
You must be signed in to change notification settings - Fork 4
/
invite.php
282 lines (208 loc) · 12.1 KB
/
invite.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
279
280
281
282
<?php
/**
* http://btdev.net:1337/svn/test/Installer09_Beta
* Licence Info: GPL
* Copyright (C) 2010 BTDev Installer v.1
* A bittorrent tracker source based on TBDev.net/tbsource/bytemonsoon.
* Project Leaders: Mindless,putyn.
**/
/*
+------------------------------------------------
| $Date$
| $Revision$ 09 Final
| $Invite
| $Author$ Neptune,Bigjoos
| $URL$
+------------------------------------------------
*/
require_once(dirname(__FILE__).DIRECTORY_SEPARATOR.'include'.DIRECTORY_SEPARATOR.'bittorrent.php');
require_once(INCL_DIR.'user_functions.php');
require_once(INCL_DIR.'password_functions.php');
dbconn();
loggedinorreturn();
$HTMLOUT ='';
$sure ='';
$lang = array_merge( load_language('global'), load_language('invite_code') );
$do = (isset($_GET["do"]) ? $_GET["do"] : (isset($_POST["do"]) ? $_POST["do"] : ''));
$valid_actions = array('create_invite', 'delete_invite', 'confirm_account', 'view_page', 'send_email');
$do = (($do && in_array($do,$valid_actions,true)) ? $do : '') or header("Location: ?do=view_page");
/**
* @action Main 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);
$HTMLOUT ='';
$HTMLOUT .= "
<table border='1' width='750' cellspacing='0' cellpadding='5'>
<tr class='table'>
<td colspan='7' class='colhead'><b>{$lang['invites_users']}</b></td></tr>";
if(!$rows){
$HTMLOUT .= "<tr><td colspan='7' class='colhead'>{$lang['invites_nousers']}</td></tr>";
} else {
$HTMLOUT .= "<tr class='tableb'>
<td align='center'><b>{$lang['invites_username']}</b></td>
<td align='center'><b>{$lang['invites_uploaded']}</b></td>
<td align='center'><b>{$lang['invites_downloaded']}</b></td>
<td align='center'><b>{$lang['invites_ratio']}</b></td>
<td align='center'><b>{$lang['invites_status']}</b></td>
<td align='center'><b>{$lang['invites_confirm']}</b></td>
</tr>";
for ($i = 0; $i < $rows; ++$i) {
$arr = mysql_fetch_assoc($query);
if ($arr['status'] == 'pending')
$user = "<td align='center'>" . htmlspecialchars($arr['username']) . "</td>";
else
$user = "<td align='center'><a href='{$TBDEV['baseurl']}/userdetails.php?id=$arr[id]'>" . htmlspecialchars($arr['username']) . "</a>" .($arr["warned"] == "yes" ? " <img src='{$TBDEV['pic_base_url']}warned.gif' border='0' alt='Warned' />" : "")." " .($arr["enabled"] == "no" ? " <img src='{$TBDEV['pic_base_url']}disabled.gif' border='0' alt='Disabled' />" : "")." " .($arr["donor"] == "yes" ? "<img src='{$TBDEV['pic_base_url']}star.gif' border='0' alt='Donor' />" : "")."</td>";
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'>{$lang['invites_confirm1']}</font>";
else
$status = "<font color='#ca0226'>{$lang['invites_pend']}</font>";
$HTMLOUT .= "<tr class='tableb'>".$user."<td align='center'>" . mksize($arr['uploaded']) . "</td><td align='center'>" . mksize($arr['downloaded']) . "</td><td align='center'>".$ratio."</td><td align='center'>".$status."</td>";
if ($arr['status'] == 'pending') {
$HTMLOUT .= "<td align='center'><a href='?do=confirm_account&userid=".$arr['id']."&sender=".$CURUSER['id']."'><img src='{$TBDEV['pic_base_url']}confirm.png' alt='confirm' title='Confirm' border='0' /></a></td></tr>";
}
else
$HTMLOUT .= "<td align='center'>---</td></tr>";
}
}
$HTMLOUT .= "</table><br />";
$select = sql_query("SELECT * FROM invite_codes WHERE sender = ".$CURUSER['id']." AND status = 'Pending'") or sqlerr();
$num_row = mysql_num_rows($select);
$HTMLOUT .= "<table border='1' width='750' cellspacing='0' cellpadding='5'>"."<tr class='tabletitle'><td colspan='6' class='colhead'><b>{$lang['invites_codes']}</b></td></tr>";
if(!$num_row) {
$HTMLOUT.= "<tr class='tableb'><td colspan='1'>{$lang['invites_nocodes']}</td></tr>";
} else {
$HTMLOUT .= "<tr class='tableb'><td><b>{$lang['invites_send_code']}</b></td><td><b>{$lang['invites_date']}</b></td><td><b>{$lang['invites_delete']}</b></td><td><b>{$lang['invites_status']}</b></td></tr>";
for ($i = 0; $i < $num_row; ++$i)
{
$fetch_assoc = mysql_fetch_assoc($select);
$HTMLOUT .= "<tr class='tableb'>
<td>".$fetch_assoc['code']." <a href='?do=send_email&id=".(int)$fetch_assoc['id']."'><img src='{$TBDEV['pic_base_url']}email.gif' border='0' alt='Email' title='Send Email' /></a></td>
<td>" . get_date($fetch_assoc['invite_added'], '', 0,1)."</td>";
$HTMLOUT .= "<td><a href='?do=delete_invite&id=".$fetch_assoc['id']."&sender=".$CURUSER['id']."'><img src='{$TBDEV['pic_base_url']}del.png' border='0' alt='Delete'/></a></td>
<td>".$fetch_assoc['status']."</td></tr>";
}
}
$HTMLOUT .= "<tr class='tableb'><td colspan='6' align='center'><form action='?do=create_invite' method='post'><input type='submit' value='{$lang['invites_create']}' style='height: 20px' /></form></td></tr>";
$HTMLOUT .= "</table>";
print stdhead('Invites') . $HTMLOUT . stdfoot();
die;
}
/**
* @action Create Invites
*/
elseif ($do =='create_invite') {
if ($CURUSER['invites'] <= 0)
stderr($lang['invites_error'], $lang['invites_noinvite']);
if ($CURUSER["invite_rights"] == 'no' || $CURUSER['suspended'] == 'yes')
stderr($lang['invites_deny'], $lang['invites_disabled']);
$res = sql_query("SELECT COUNT(*) FROM users") or sqlerr(__FILE__, __LINE__);
$arr = mysql_fetch_row($res);
if ($arr[0] >= $TBDEV['invites'])
stderr($lang['invites_error'], $lang['invites_limit']);
$invite = md5(mksecret());
sql_query('INSERT INTO invite_codes (sender, invite_added, code) VALUES ( ' . sqlesc((int)$CURUSER['id']) . ', ' . sqlesc(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");
}
/**
* @action Send e-mail
*/
elseif ($do =='send_email') {
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$email = (isset($_POST['email'])? htmlentities($_POST['email']) : '');
$invite = (isset($_POST['code'])? $_POST['code'] : '');
if (!$email) stderr($lang['invites_error'], $lang['invites_noemail']);
$check = (mysql_fetch_row(sql_query('SELECT COUNT(*) FROM users WHERE email = ' . sqlesc($email)))) or sqlerr(__FILE__, __LINE__);
if ($check[0] != 0) stderr('Error', 'This email address is already in use!');
if (!validemail($email)) stderr($lang['invites_error'], $lang['invites_invalidemail']);
$inviter = htmlspecialchars($CURUSER['username']);
$body = <<<EOD
You have been invited to {$TBDEV['site_name']} by $inviter. They have
specified this address ($email) as your email. If you do not know this person, please ignore this email. Please do not reply.
This is a private site and you must agree to the rules before you can enter:
{$TBDEV['baseurl']}/useragreement.php
{$TBDEV['baseurl']}/rules.php
{$TBDEV['baseurl']}/faq.php
------------------------------------------------------------
To confirm your invitation, you have to follow this link and type the invite code:
{$TBDEV['baseurl']}/invite_signup.php
Invite Code: $invite
------------------------------------------------------------
After you do this, your inviter need's to confirm your account.
We urge you to read the RULES and FAQ before you start using {$TBDEV['site_name']}.
EOD;
$sendit = mail($email, "You have been invited to {$TBDEV['site_name']}", $body, "From: {$TBDEV['site_email']}", "-f{$TBDEV['site_email']}");
if (!$sendit) stderr($lang['invites_error'], $lang['invites_unable']);
else stderr('', $lang['invites_confirmation']); }
$id = (isset($_GET['id']) ? (int)$_GET['id'] : (isset($_POST['id']) ? (int)$_POST['id'] : ''));
if (!is_valid_id($id)) stderr($lang['invites_error'], $lang['invites_invalid']);
$query = sql_query('SELECT * FROM invite_codes WHERE id = ' . sqlesc($id) . ' AND sender = ' . sqlesc($CURUSER['id']).' AND status = "Pending"') or sqlerr(__FILE__, __LINE__);
$fetch = mysql_fetch_assoc($query) or stderr($lang['invites_error'], $lang['invites_noexsist']);
$HTMLOUT .= "<form method='post' action='?do=send_email'><table border='1' cellspacing='0' cellpadding='10'>
<tr><td class='rowhead'>E-Mail</td><td><input type='text' size='40' name='email' /></td></tr><tr><td colspan='2' align='center'><input type='hidden' name='code' value='".$fetch['code']."' /></td></tr><tr><td colspan='2' align='center'><input type='submit' value='Send e-mail' class='btn' /></td></tr></table></form>";
print stdhead('Invites') . $HTMLOUT . stdfoot();
}
/**
* @action Delete Invites
*/
elseif ($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)
stderr($lang['invites_error'],$lang['invites_noexsist']);
isset($_GET['sure']) && $sure = htmlspecialchars($_GET['sure']);
if (!$sure)
stderr($lang['invites_delete1'], $lang['invites_sure'].' Click <a href="'.$_SERVER['PHP_SELF'].'?do=delete_invite&id='.$id.'&sender='.$CURUSER['id'].'&sure=yes">here</a> to delete it or <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");
}
/**
* @action Confirm Accounts
*/
elseif ($do ='confirm_account') {
$userid = (isset($_GET["userid"]) ? (int)$_GET["userid"] : (isset($_POST["userid"]) ? (int)$_POST["userid"] : ''));
if (!is_valid_id($userid))
stderr($lang['invites_error'], $lang['invites_invalid']);
$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)
stderr($lang['invites_error'], $lang['invites_errorid']);
isset($_GET['sure']) && $sure = htmlspecialchars($_GET['sure']);
if (!$sure)
stderr($lang['invites_confirm1'], $lang['invites_sure1'].' '.htmlspecialchars($assoc['username']).'\'s account? Click <a href="?do=confirm_account&userid='.$userid.'&sender='.$CURUSER['id'].'&sure=yes">here</a> to confirm it or <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__);
//==pm to new invitee/////
$msg = sqlesc("Hey there :wave:
Welcome to {$TBDEV['site_name']}!
We have made many changes to the site, and we hope you enjoy them!
We have been working hard to make {$TBDEV['site_name']} somethin' special!
{$TBDEV['site_name']} has a strong community (just check out forums), and is a feature rich site. We hope you'll join in on all the fun!
Be sure to read the [url={$TBDEV['baseurl']}/rules.php]Rules[/url] and [url={$TBDEV['baseurl']}/faq.php]FAQ[/url] before you start using the site.
We are a strong friendly community here :D {$TBDEV['site_name']} is so much more then just torrents.
Just for kicks, we've started you out with 200.0 Karma Bonus Points, and a couple of bonus GB to get ya started!
so, enjoy
cheers,
{$TBDEV['site_name']} Staff");
$id = $assoc["id"];
$subject = sqlesc("Welcome to {$TBDEV['site_name']} !");
$added = sqlesc(time());
sql_query("INSERT INTO messages (sender, subject, receiver, msg, added) VALUES (0, $subject, $id, $msg, $added)") or sqlerr(__FILE__, __LINE__);
///////////////////end////////////
header("Location: ?do=view_page");
}
?>