1
|
<?php
|
2
|
if (isset($_SESSION['role']) && $_SESSION['role'] == "admin") {
|
3
|
$loggedUserId = $_SESSION['id'];
|
4
|
echo "<script>
|
5
|
//what to do when page renders
|
6
|
window.onload = function() {
|
7
|
fetchUsers();
|
8
|
};
|
9
|
</script>
|
10
|
|
11
|
<div class=\"search-results my-4\">
|
12
|
<table class=\"table table-striped\">
|
13
|
<thead>
|
14
|
<tr>
|
15
|
<th scope=\"col\">Uživatel</th>
|
16
|
<th scope=\"col\">Práva</th>
|
17
|
<th scope=\"col\"><button class=\"btn ml-1\" title=\"Přidat\" data-toggle=\"modal\" data-target=\"#edit-modal\" data-title=\"Nový uživatel\"><i class=\"fa fa-plus\"></i></button></th>
|
18
|
</tr>
|
19
|
</thead>
|
20
|
<tbody id=\"search-table\">
|
21
|
<script>
|
22
|
let users;
|
23
|
function fetchUsers () {
|
24
|
// (A1) GET SEARCH TERM
|
25
|
const formData = new FormData();
|
26
|
|
27
|
// (A2) AJAX - USE HTTP:// NOT FILE:/
|
28
|
let xhr = new XMLHttpRequest();
|
29
|
xhr.open(\"POST\", \"./controller/UsersListController.php\");
|
30
|
xhr.onload = function(){
|
31
|
let search = this.response;
|
32
|
let parsedJSON = JSON.parse(search);
|
33
|
users = parsedJSON;
|
34
|
renderUsers(parsedJSON);
|
35
|
};
|
36
|
xhr.send(formData);
|
37
|
}
|
38
|
|
39
|
|
40
|
function renderUsers(users) {
|
41
|
let result = \"\";
|
42
|
users.forEach((item,id) => {
|
43
|
result += \"<tr>\";
|
44
|
result += \"<td>\" + item.username + \"</td>\";
|
45
|
result += \"<td>\" + item.role + \"</td>\";
|
46
|
|
47
|
if (item['id'] != \"$loggedUserId\") {
|
48
|
result += \"<td class='action-td'>\" +
|
49
|
\"<button class='btn ml-1' title='Upravit' data-toggle='modal' data-target='#edit-modal' data-pseudo-id='\" + id + \"' data-title='Upravit uživatele'><i class='fa fa-pencil'></i></button>\" +
|
50
|
\"<button class='btn ml-1' title='Odstranit' data-toggle='modal' data-target='#remove-modal' data-pseudo-id='\" + id + \"'><i class='fa fa-trash'></i></button>\" +
|
51
|
\"</td>\"} else {result += \"<td></td>\"}
|
52
|
|
53
|
|
54
|
result += \"</tr>\";
|
55
|
});
|
56
|
document.getElementById(\"search-table\").innerHTML = result;
|
57
|
}
|
58
|
</script>
|
59
|
</tbody>
|
60
|
</table>
|
61
|
</div>";
|
62
|
} else {
|
63
|
echo "<h3 class=\"mx-auto text-center\">Pro navštívení stránky nemáte dostatečná oprávnění</h3>";
|
64
|
}
|
65
|
|
66
|
|