-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.php
230 lines (173 loc) · 5.99 KB
/
index.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
<!--
Made by Zua @ https://githhub.com/thatziv
-->
<?php
session_start();
//CHECKS IF USER LOGGED IN IF NOT, GOES TO LOGIN
if (empty($_SESSION['name'])) {
header( "refresh:0;url=login.php" );
}
include 'inc/config.php';
// CONFIGURATION
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$identifier = strtolower( $_POST["identifier"]);
$column_name = strtolower( $_POST["column_name"]);
$value = strtolower( $_POST["value"]);
update_player_data($identifier, $column_name, $value);
}
?>
<!DOCTYPE html>
<html>
<head>
<?php include 'inc/head.php' ?>
</div>
</div>
</head>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<?php include 'inc/preloader.php' ?>
<h1 class="center" ><?php echo $title ?></h1>
<center>
<button class='btn-small center' id="bootn">Toggle</button>
</center>
<!-- PHP -->
<?php
//Essential mode uses the Users table by default. Change the "users" below if you want to use a different table. If you do this, YOU HAVE TO CHANGE THE ROWS FOR BOTH THE MYSQL FETCH AND THE COLUMN NAMES.
$dbServername= $GLOBALS['dbServername'];
$dbUsername = $GLOBALS['dbUsername'];
$dbPassowrd = $GLOBALS['dbPassowrd'];
$dbName = $GLOBALS['dbName'];
$conn = mysqli_connect($dbServername, $dbUsername, $dbPassowrd, $dbName);
if ($conn->connect_error) {
die("connectio_failed" . $conn->connect_error);
}
//CHECK PERMISSION LEVEL
$sql = "SELECT * FROM $dbName.users WHERE name='$_SESSION[name]'";
$result = mysqli_query($conn, $sql);
$resultCheck = mysqli_num_rows($result);
if ($resultCheck > 0) {
$row = mysqli_fetch_assoc($result);
$permission_level = $row['permission_level'];
}
//DEBUG STUFF
//echo " Permission level: " . $permission_level . " </h4>";
if($permission_level > $perm_levelForAdmin) {
//ADMIN VIEW WITH 'DATA EDITOR'
$sql = "SELECT * FROM essentialmode.users";
echo '<form class="center_info" style="text-align: center;" action="index.php" method="POST">
<h5>
Name: <b>' . $_SESSION['name'] . '</b><br>
Permission level: <b>' . $permission_level . '</b><br> <br>
</h5>
<h3>Change player stats </h3><br>
<h5>
Identifier: <br> <input type="text" name="identifier"> <br>
Column name: <br> <input type="text" name="column_name"> <br>
Value: <br> <input type="text" name="value"> <br>
<input class="btn" type="submit" style="margin-bottom:60px" value="Change stats"> <br>
</h5>
</form>
<div class="center">
<input class="btn" style="margin-bottom:20px" type="button" value="Log out" onclick="log_out()" >
</div>';
$result = mysqli_query($conn, $sql);
$resultCheck = mysqli_num_rows($result);
echo "<table class='highlight'>";
//Follow this same format to make a new row. Make the Columns the same order as listed for the mysql fetch below
echo "<tr>
<th>Identifier</th>
<th>License</th>
<th>Name</th>
<th>Money</th>
<th>Bankbalance</th>
<th>Job</th>
<th>Permission</th>
<th>Group</th>
<th>gunlicense</th>
<th>Guns</th>
<th>Position</th>
</tr>";
if ($resultCheck > 0) {
while ($row = mysqli_fetch_assoc($result)) {
echo "<tr><th>";
echo $row['identifier'];
echo "<th>";
echo $row['license'];
echo "<th>";
echo $row['name'];
echo "<th>";
echo $row['money'];
echo "<th>";
echo $row['bankbalance'];
echo "<th>";
echo $row['job']; //esx probably idek
echo "<th>";
echo $row['permission_level'];
echo "<th>";
echo $row['group'];
echo "<th>";
echo $row['gunlicense']; //esx
echo "<th>";
echo $row['loadout']; //guns (esx)
echo "<th>";
echo $row['position'];
echo "</th></td>";
}
}
} else {
//USER VIEW
$sql = "SELECT * FROM $dbName.users WHERE name='$_SESSION[name]'";
$result = mysqli_query($conn, $sql);
$resultCheck = mysqli_num_rows($result);
// I know, this part is very inefficient but it still works.
if ($resultCheck > 0) {
$row = mysqli_fetch_assoc($result);
echo '
<div class="center_infoCard" >
<h7>
Name: <b>' . $row['name'] . '</b> <br>
Identifier: <b>' . $row['identifier'] . '</b> <br>
Money: <b>' . $row['money'] . '</b> <br>
Bank balance: <b>' . $row['bankbalance'] . '</b> <br>
Job: <b>' . $row['job'] . '</b> <br>
Group: <b>' . $row['group'] . '</b> <br>
Guns: ' . $row['loadout'] . ' <br>
</h7>
</div>
<div class="center">
<input class="btn" type="button" value="Log out" onclick="log_out()" >
</div>
<center>
<img class="smal center" src=' . $ServerLogo . '>
</center>
';
} else {
die("An error occured with loading the data.");
}
}
function update_player_data($identifier, $column_name, $value) {
$dbServername= $GLOBALS['dbServername'];
$dbUsername = $GLOBALS['dbUsername'];
$dbPassowrd = $GLOBALS['dbPassowrd'];
$dbName = $GLOBALS['dbName'];
$conn = mysqli_connect($dbServername, $dbUsername, $dbPassowrd, $dbName);
//CHECK CONNECTION
if ($conn->connect_error) {
die("connectio_failed" . $conn->connect_error);
}
$sql = "UPDATE $dbName.users SET $column_name='$value' WHERE identifier='$identifier'";
if ($conn->query($sql) === TRUE) {
echo "<h5 class='green'>Record updated with no errors </h5>";
header("refresh:0;url=index.php");
} else {
echo "<h5 class='red'>Error updating record: " . $conn->error . "</h5>";
}
$conn->close();
}
?>
</div>
<?php include 'inc/up.php' ?>
<?php echo $footer ?>
<?php include 'inc/core.php' ?>
</body>
</html>