-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin_users.php
More file actions
118 lines (111 loc) · 4.97 KB
/
admin_users.php
File metadata and controls
118 lines (111 loc) · 4.97 KB
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
<div id="admin_users" style="display: none">
<?php
$con= mysqli_connect($host, $username, $password, $db_name);
if (isset($_POST["EditUser"])) {
$id = $_POST["editId"];
$name = $_POST["editName"];
$type = $_POST["editType"];
$sql = 'UPDATE `users` SET `username`="' . $name . '",`type`="' . $type . '" WHERE `id`="' . $id . '"';
mysqli_query($con, $sql);
}
if (isset($_POST["DeleteUser"])) {
$id = $_POST["editId"];
$sql = 'DELETE FROM `users` WHERE `id` ' . $id;
mysqli_query($con, $sql);
}
?>
<table style="width: 100%;">
<thead>
<tr>
<th>ID </th>
<th>Gebruikersnaam </th>
<th>Type </th>
<th>Bewerken</th>
<th></th>
</tr>
</thead>
<tbody>
<?php
$query = "SELECT * FROM users ORDER BY id";
if ($result = mysqli_query($con, $query)) {
// Fetch one and one row
while ($row = mysqli_fetch_row($result)) {
$row['id'] = $row['0'];
printf("<tr>");
printf("<td>" . $row['0'] . "</td>");
printf("<td>" . $row['1'] . "</td>");
printf("<td>" . $row['3'] . "</td>");
printf("<td><button onclick='Edit(" . $row["0"] . ", \"" . $row["1"] . "\", \"" . $row['3'] . "\")' id='change' data-toggle='modal' data-target='#editModal'><i class='fa fa-pencil-square-o fa-2x' aria-hidden='true'> </i></button></td>");
printf("<td><button onclick='Delete(" . $row["0"] . ", \"" . $row["1"] . "\")' id='change' data-toggle='modal' data-target='#deleteModal'><i class='fa fa-trash fa-2x' aria-hidden='true'></i></button></td>");
printf("</tr>");
}
// Free result set
mysqli_free_result($result);
}
mysqli_close($con);
?>
</tbody>
<!-- Modal -->
<div id="editModal" class="modal fade" role="dialog">
<form method="post" action="admin_index.php">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Edit user</h4>
</div>
<div class="modal-body">
<input type="text" id="editId" name="editId" readonly value="id" style="width: 25px; padding: 2px; text-align: center; color: gray; border: 1px solid gray; background-color: lightgray;"/>
<input type="text" id="editName" name="editName" placeholder=" name" style="margin-bottom: 5px;"/><br/>
<input type="radio" id="editRadioUser" name="editType" value="user">gebruiker</input>
<input type="radio" id="editRadioAdmin" name="editType" value="admin">administrator</input>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Sluiten</button>
<input type="submit" value="Verstuur" name="EditUser" class="btn btn-default" />
</div>
</div>
</div>
</form>
</div>
<!-- Modal -->
<div id="deleteModal" class="modal fade" role="dialog">
<form method="post" action="admin_index.php">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Weet u zeker dat u <i id="deleteShowName">username</i> wilt verwijderen?</h4>
</div>
<div class="modal-body">
<input type="text" id="deleteId" name="deleteId" readonly value="id" style="width: 25px; padding: 2px; text-align: center; color: gray; border: 1px solid gray; background-color: lightgray;"/>
<input type="text" id="deleteName" name="deleteName" placeholder=" name" style="margin-bottom: 5px;"/><br/>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Sluiten</button>
<input type="submit" value="Verstuur" name="DeleteUser" class="btn btn-default" />
</div>
</div>
</div>
</form>
</div>
</table>
<!-- Made by Sander Nieuwenhuisen, Sander van Osch is a fraud -->
<script type="text/javascript">
function Edit(id, name, type) {
document.getElementById("editId").setAttribute("value", id);
document.getElementById("editName").setAttribute("value", name);
if (type == "admin")
document.getElementById("editRadioAdmin").setAttribute("checked", "true");
else
document.getElementById("editRadioUser").setAttribute("checked", "true");
}
function Delete(id, name) {
document.getElementById("deleteId").setAttribute("value", id);
document.getElementById("deleteName").setAttribute("value", name);
document.getElementById("deleteShowName").innerHTML = name;
}
</script>
</div>