-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathgangs.php
224 lines (216 loc) · 5.7 KB
/
gangs.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
<?php
declare(strict_types=1);
/**
* MCCodes v2 by Dabomstew & ColdBlooded
*
* Repository: https://github.com/davemacaulay/mccodesv2
* License: MIT License
*/
global $db, $h;
require_once('globals.php');
if (!isset($_GET['ID']))
{
$_GET['ID'] = 0;
}
$_GET['ID'] = abs((int) $_GET['ID']);
if (!$_GET['ID'])
{
echo 'Invalid use of file';
}
else
{
$gq =
$db->query(
"SELECT `gangPRESIDENT`, `gangVICEPRES`, `gangNAME`,
`gangID`, `gangRESPECT`, `gangDESC`
FROM `gangs`
WHERE `gangID` = {$_GET['ID']}");
$gangdata = $db->fetch_row($gq);
if (!isset($_GET['action']))
{
$_GET['action'] = '';
}
switch ($_GET['action'])
{
case 'userlist':
gang_userlist();
break;
case 'apply':
gang_applyform();
break;
case 'applys':
gang_applysubmit();
break;
default:
gang_view();
break;
}
}
/**
* @return void
*/
function gang_view(): void
{
global $db, $gangdata;
$pq =
$db->query(
"SELECT `userid`, `username`
FROM `users`
WHERE `userid` = {$gangdata['gangPRESIDENT']}
LIMIT 1");
if ($db->num_rows($pq) == 0)
{
$ldr = ['userid' => 0];
}
else
{
$ldr = $db->fetch_row($pq);
}
$db->free_result($pq);
$vpq =
$db->query(
"SELECT `userid`, `username`
FROM `users`
WHERE `userid` = {$gangdata['gangVICEPRES']}");
if ($db->num_rows($vpq) == 0)
{
$coldr = ['userid' => 0];
}
else
{
$coldr = $db->fetch_row($vpq);
}
$db->free_result($vpq);
echo "<h3><u>{$gangdata['gangNAME']} Gang</u></h3><hr />";
if ($ldr['userid'] > 0)
{
print
"President: <a href='viewuser.php?u={$ldr['userid']}'>{$ldr['username']}</a><br />";
}
else
{
print 'President: N/A<br />';
}
if ($coldr['userid'] > 0)
{
print
"Vice-President: <a href='viewuser.php?u={$coldr['userid']}'>{$coldr['username']}</a><hr />";
}
else
{
print 'Vice-President: N/A<hr />';
}
$cnt =
$db->query(
"SELECT COUNT(`userid`)
FROM `users`
WHERE `gang` = {$gangdata['gangID']}");
echo '<b>Members:</b> ' . $db->fetch_single($cnt)
. "<br />
<b>Description: </b> {$gangdata['gangDESC']}<br />
<b>Respect Level: </b> {$gangdata['gangRESPECT']}<br />
> <a href='gangs.php?action=userlist&ID={$gangdata['gangID']}'>
User List
</a><br />
> <a href='gangs.php?action=apply&ID={$gangdata['gangID']}'>
Apply
</a>";
$db->free_result($cnt);
}
/**
* @return void
*/
function gang_userlist(): void
{
global $db, $gangdata;
echo "<h3>Userlist for {$gangdata['gangNAME']}</h3>
<table>
<tr style='background: gray;'>
<th>User</th>
<th>Level</th>
<th>Days In Gang</th>
</tr>";
$q =
$db->query(
"SELECT `userid`, `username`, `level`, `daysingang`
FROM `users`
WHERE `gang` = {$gangdata['gangID']}
ORDER BY `daysingang` DESC, `level` DESC");
while ($r = $db->fetch_row($q))
{
echo "<tr>
<td><a href='viewuser.php?u={$r['userid']}'>
{$r['username']}
</a></td>
<td>{$r['level']}</td>
<td>{$r['daysingang']}</td>
</tr>";
}
$db->free_result($q);
echo "</table><br />
> <a href='gangs.php?action=view&ID={$gangdata['gangID']}'>
Back
</a>";
}
/**
* @return void
*/
function gang_applyform(): void
{
global $ir;
if ($ir['gang'] == 0)
{
$apply_csrf = request_csrf_code('gang_apply');
echo "<form action='gangs.php?action=applys&ID={$_GET['ID']}' method='post'>
Type the reason you should be in this faction.<br />
<textarea name='application' rows='7' cols='40'></textarea><br />
<input type='hidden' name='verf' value='{$apply_csrf}' />
<input type='submit' value='Apply' /></form>";
}
else
{
echo 'You cannot apply for a gang when you are already in one.';
}
}
/**
* @return void
*/
function gang_applysubmit(): void
{
global $db, $ir, $h, $gangdata, $userid;
$application =
(isset($_POST['application']) && is_string($_POST['application']))
? $db->escape(
htmlentities(
stripslashes($_POST['application']),
ENT_QUOTES, 'ISO-8859-1')) : '';
if (!isset($_POST['verf'])
|| !verify_csrf_code('gang_apply', stripslashes($_POST['verf'])))
{
echo "
Your request to apply to this gang has expired. Please try again.<br />
> <a href='gangs.php?action=apply&ID={$_GET['ID']}'>Back</a>
";
$h->endpage();
exit;
}
if (!$ir['gang'])
{
$db->query(
"INSERT INTO `applications`
VALUES(NULL, $userid, {$_GET['ID']}, '{$application}')");
$gev =
$db->escape(
"<a href='viewuser.php?u={$userid}'>{$ir['username']}</a>"
. ' sent an application to join this gang.');
$db->query(
"INSERT INTO `gangevents`
VALUES(NULL, {$_GET['ID']}, " . time() . ", '{$gev}')");
echo "You sent your application to the {$gangdata['gangNAME']} gang.";
}
else
{
echo 'You cannot apply for a gang when you are already in one.';
}
}
$h->endpage();