-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedit.player.execute.php
103 lines (81 loc) · 2.77 KB
/
edit.player.execute.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
<?php
require_once 'vendor/autoload.php';
use FileListPoker\Main\Site;
use FileListPoker\Main\Database;
use FileListPoker\Main\Config;
use FileListPoker\Content\PlayerContent;
use FileListPoker\Main\Cache\CacheFactory;
use PDO as PDO;
$site = new Site();
$adminPass = Config::getValue('admin_pass');
if (! isset($_POST['flpokerpassword']) || $_POST['flpokerpassword'] !== $adminPass) {
die('nice try.');
}
if (! isset ($_POST['pname']) ||
! isset ($_POST['fname']) ||
! isset ($_POST['fid']) ||
! isset ($_POST['pid']))
{
die('Some data is missing.');
}
$content = new PlayerContent();
$playerDetails = $content->getGeneral($_POST['pid']);
if (count($playerDetails) == 0) {
die('Player with this ID does not exist (' . $_POST['pid'] . ')');
}
$db = Database::getConnection();
$updateQuery = 'UPDATE players SET ';
$binds = array();
$bindIndex = 1;
$edits = array();
if ($playerDetails['name_pokerstars'] != $_POST['pname']) {
$updateQuery .= 'name_pokerstars = ?';
$binds[] = array($bindIndex, $_POST['pname'], PDO::PARAM_STR);
$bindIndex++;
$edits[] = array('name' => 'PokerStars Name', 'old' => $playerDetails['name_pokerstars'], 'new' => $_POST['pname']);
}
if ($playerDetails['name_filelist'] != $_POST['fname']) {
if ($bindIndex > 1) {
$updateQuery .= ', ';
}
$updateQuery .= 'name_filelist = ?';
$binds[] = array($bindIndex, $_POST['fname'], PDO::PARAM_STR);
$bindIndex++;
$edits[] = array('name' => 'FileList Name', 'old' => $playerDetails['name_filelist'], 'new' => $_POST['fname']);
}
if ($playerDetails['id_filelist'] != $_POST['fid']) {
if ($bindIndex > 1) {
$updateQuery .= ', ';
}
$updateQuery .= 'id_filelist = ?';
$binds[] = array($bindIndex, $_POST['fid'], PDO::PARAM_INT);
$bindIndex++;
$edits[] = array('name' => 'FileList ID', 'old' => $playerDetails['id_filelist'], 'new' => $_POST['fid']);
}
if (empty($binds)) {
die('Nothing to update');
}
$updateQuery .= ' WHERE player_id = ?';
$binds[] = array($bindIndex, $_POST['pid'], PDO::PARAM_INT);
$updateSt = $db->prepare($updateQuery);
foreach ($binds as $bind) {
$updateSt->bindParam($bind[0], $bind[1], $bind[2]);
}
$updateSt->execute();
if ($updateSt->rowCount () !== 1) {
die('There was an error while editing the player');
} elseif (Config::getValue('enable_cache')) {
$cache = CacheFactory::getCacheInstance();
if (! is_null($cache)) {
$key = Config::getValue('cache_key_player_general') . $_POST['pid'];
$cache->delete($key);
}
}
echo 'For the player with ID ' . $_POST['pid'] . ', the following information was changed: ';
echo '<ul>';
foreach ($edits as $edit) {
echo '<li>';
echo $edit['name'] . ' was changed from ' . $edit['old'] . ' to ' . $edit['new'];
echo '</li>';
}
echo '</ul>';