-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadmin_edit_players.php
337 lines (309 loc) · 10.3 KB
/
admin_edit_players.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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
<?php
require_once(__DIR__ . "/global.php");
require_once(__DIR__ . "/view/form_view.php");
require_once(__DIR__ . "/players/player_lib.php");
session_start();
HtmlHeader("Admin Players", "jungle.css");
// lill helper func from stackoverflow
// credits go to https://stackoverflow.com/a/7112596/6287070
function contains($needle, $haystack)
{
return strpos($haystack, $needle) !== false;
}
function PrintEditInfo($status, $type, $editor, $editors, $lasteditdate, $id)
{
?>
<div class="edit-info-box">
<?php
echo "<b>STATUS:</b> $status</br>";
echo "<b>TYPE:</b> $type</br>";
echo "<b>LAST EDITOR:</b> $editor</br>";
echo "<b>ALL EDITORS:</b> $editors</br>";
echo "<b>LastEdit:</b> $lasteditdate</br>";
echo "<b>ID:</b> $id</br>";
//TODO: add buttons to delete/archive/release the entry
if ($status === "0")
{
echo "<h1>ARCHIVED!</h1>";
}
else
{
?>
<form action="admin_edit_players.php" method="post">
<input type="hidden" name="id" value="<?php echo $id; ?>">
<input type="submit" name="action" value="archive" />
</form>
<?php
}
?>
<form action="delete_player.php" method="post">
<input type="hidden" name="id" value="<?php echo $id; ?>">
<input type="submit" name="action" value="delete" />
</form>
<form action="admin_edit_players.php" method="post">
<input type="hidden" name="id" value="<?php echo $id; ?>">
<input type="submit" name="action" value="release" />
</form>
<input type="button" value="edit" onclick="window.location.href='edit_player.php?id=<?php echo $id?>'"></br>
</div>
<style>
.edit-info-box {
padding: 5%;
padding-top: 2%;
margin-top: 5%;
margin-bottom: 5%;
/* old */
/*margin-right: 20%;*/
/*margin-left: 20%;*/
/* new */
min-width: 200px;
max-width: 700px;
margin-right: auto;
margin-left: auto;
border: 2px solid darkgrey;
/*border-bottom-left-radius: 16px;*/
/*border-bottom-right-radius: 16px;*/
border-radius: 10px;
background: rgba(77,255,77,0.5);
box-shadow: 0 3px 5px rgba(0, 0, 0, 0.3);
}
</style>
<?php
}
function PrintPlayerInfo($name, $aka, $clan, $clan_page, $info, $yt_name, $yt_link, $ddnet, $ddnet_link, $ddnet_mapper, $ddnet_mapper_link, $teerace, $skill)
{
echo "<h1>$name</h1>";
if (file_exists("players/img_players/Teeworlds_$name.png"))
echo "<img src=\"players/img_players/Teeworlds_$name.png\"><br>";
if ($aka)
{
echo "<a><strong>AKA:</strong> $aka<br></a>";
}
if ($clan)
{
if ($clan_page)
{
echo "<a><strong>Clan:</strong><a href=\"$clan_page\">$clan</a><br></a>";
}
else
{
echo "<a><strong>Clan:</strong> $clan<br></a>";
}
}
if ($info)
echo "<a><strong>Info:</strong> $info<br></a>";
if ($yt_name and $yt_link)
echo "<a><strong>YouTube:</strong> <a href=\"$yt_link\">$yt_name</a><br></a>";
if ($ddnet)
{
echo "<a><strong>DDNet:</strong> <a href=\"$ddnet_link\">$name</a><br></a>";
}
if ($ddnet_mapper)
{
echo "<a><strong>DDNet Mapper:</strong><a href=\"$ddnet_mapper_link\">$name</a><br></a>";
}
if ($teerace)
echo "<a><strong>Teerace:</strong> <a href=\"$teerace\">$name</a><br></a>";
if ($skill)
echo "<a><strong>Skill:</strong> $skill</a></br>";
}
function GetTotalPages($items_per_page, $hide)
{
if ($hide)
{
$SQL_pages_base = "SELECT COUNT(*) AS TotalPages FROM Players WHERE Status <> 3 AND Status <> 0";
}
else
{
$SQL_pages_base = "SELECT COUNT(*) AS TotalPages FROM Players WHERE Status <> 3";
}
$db = new PDO(PLAYER_CONTRIBUTE_DATABASE);
$rows = $db->query($SQL_pages_base);
$rows = $rows->fetchAll();
$db = NULL;
if ($rows)
{
$TotalPlayers = $rows[0]['TotalPages'];
//PROBLEM: if the value is not a float but an int the last page is full but it says there is another one
//HACKY WORK AROUND:
$float_pages = $TotalPlayers / $items_per_page;
$int_pages = (int)$float_pages;
if ($float_pages > $int_pages) //only say there is a new page if its more than a even number (1 = 0, 1.1 = 2, 2 = 1, 2.1 = 3)
return $int_pages;
else
return $int_pages - 1;
}
return -1;
}
/********************************************
* *
* Global Scope start! *
* from here on the execution starts *
* *
* *
********************************************/
if (!IsAdmin())
{
echo "Missing permission<br>";
ViewOkayButton('index.php', false); // no auto forwarding
fok();
}
if (!empty($_POST['action']))
{
$action = (string)$_POST['action'];
$id = (int)$_POST['id'];
if ($action === "archive")
{
echo "yo archivvin!!! ID=$id";
$db = new PDO(PLAYER_CONTRIBUTE_DATABASE);
$db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING );
$stmt = $db->prepare("UPDATE Players SET Status = 0 WHERE ID = ?;");
$stmt->execute(array($id));
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
if ($rows)
{
echo "SQL output: <br/>";
print_r($rows);
}
}
else if ($action === "delete")
{
// moved to delete_player.php
}
else if ($action === "release")
{
echo "yo releasin!!! ID=$id<br>";
MoveRowToOtherDataBase(PLAYER_CONTRIBUTE_DATABASE, PLAYER_DATABASE, $id);
}
else
{
echo "Error: unknown action!";
fok();
}
}
$hide_archive = false;
if (!empty($_GET['hide_archive']))
{
$hide = $_GET['hide_archive'];
if ($hide === "1")
{
$hide_archive = true;
}
else if ($hide === "0")
{
$hide_archive = false;
}
}
$SQL_playerlist_query_base = "SELECT * FROM Players WHERE ID > ? ";
if ($hide_archive)
{
$SQL_playerlist_query_hide = " AND Status <> 3 AND Status <> 0 ";
}
else
{
$SQL_playerlist_query_hide = " AND Status <> 3 ";
}
//$SQL_playerlist_query_condition = "AND Status = 3 ";
//$SQL_playerlist_query_order_by = "ORDER BY x DESC ";
$SQL_playerlist_query_range = "LIMIT 10 OFFSET 0 ";
$players_per_page = 10;
$players_page = 0;
$players_offset = 0;
if (!empty($_GET['players']) && is_numeric($_GET['players']))
{
$players_per_page = $_GET['players'];
$players_per_page = (int)$players_per_page;
}
if (!empty($_GET['page']) && is_numeric($_GET['page']))
{
$players_page = $_GET['page'];
$players_page = (int)$players_page;
if ($players_page < 0)
$players_page = 0;
$players_offset = $players_page * $players_per_page;
}
$SQL_playerlist_query_range = "LIMIT $players_per_page OFFSET $players_offset ";
$db = new PDO(PLAYER_CONTRIBUTE_DATABASE);
$db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING );
$SQL_execution_string = $SQL_playerlist_query_base . $SQL_playerlist_query_hide . $SQL_playerlist_query_range;
$stmt = $db->prepare($SQL_execution_string);
//echo "ececuted: $SQL_execution_string <br>";
$stmt->execute(array(0));
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
if ($rows)
{
#print_r($rows);
#$name = $rows[0]['Username'];
#$_SESSION['csID'] = $rows[0]['ID'];
/***************************** MAIN PLAYER FORMAT START **********************************/
foreach ($rows as $row)
{
// actual data
$name = $row['Name'];
$aka = $row['AKA'];
$info = $row['Info'];
$clan = $row['Clan'];
$clan_page = $row['ClanPage'];
$skill = $row['Skills'];
$yt_name = $row['yt_name'];
$yt_link = $row['yt_link'];
$teerace = $row['Teerace'];
$ddnet = $row['DDNet'];
$ddnet_mapper = $row['DDNetMapper'];
$ddnet_link = $ddnet;
$ddnet_mapper_link = $ddnet_mapper;
// edit data
$status = $row['Status'];
$type = $row['Type'];
$editor = $row['LastEditor'];
$editors = $row['Editors'];
$lasteditdate = $row['LastEditDate'];
$id = $row['ID'];
if ($ddnet)
{
//if ($ddnet == "name") // old using hardcodet name value
if (!contains('https://ddnet.tw', $ddnet)) // no ddnet link found -> create one
{
$ddnet_link = "https://ddnet.tw/players/$ddnet/";
}
}
if ($ddnet_mapper)
{
//if ($ddnet_mapper == "name") // old using hardcodet name value
if (!contains('https://ddnet.tw', $ddnet_mapper)) // no ddnet link found -> create one
{
$ddnet_mapper_link = "https://ddnet.tw/mappers/$ddnet_mapper/";
}
}
echo "
<div id=\"$name\"\>
";
PrintEditInfo($status, $type, $editor, $editors, $lasteditdate, $id);
PrintPlayerInfo($name, $aka, $clan, $clan_page, $info, $yt_name, $yt_link, $ddnet, $ddnet_link, $ddnet_mapper, $ddnet_mapper_link, $teerace, $skill);
echo "
</div><br><hr><br>
";
}
/****************************** MAIN PLAYER FORMAT END ************************************/
$total_pages = GetTotalPages($players_per_page, $hide_archive);
if ($total_pages == 0 and $players_page == 0) //all players fitt on one page --> dont show that we are on page 0/0
fok();
echo "<a><br>page: $players_page/$total_pages<br></a>";
$nxt_page = $players_page + 1;
$prv_page = $players_page - 1;
if ($players_page > 0)
{
echo "<input type=\"button\" value=\"<- Previous page\" onclick=\"window.location.href='players.php?players=$players_per_page&page=$prv_page'\"/>";
}
if ($players_page < $total_pages)
{
echo "<input type=\"button\" value=\"Next page -->\" onclick=\"window.location.href='players.php?players=$players_per_page&page=$nxt_page'\"/>";
}
}
else
{
echo "All player entries are released.</br>";
echo "<input type=\"button\" value=\"view released players\" onclick=\"window.location.href='players.php'\"/>";
}
fok();
?>