1
|
<?php
|
2
|
if (isset($_SESSION['role']) && $_SESSION['role'] == "admin") {
|
3
|
echo "<script>
|
4
|
//what to do when page renders
|
5
|
window.onload = function() {
|
6
|
fetchChanges();
|
7
|
};
|
8
|
</script>
|
9
|
|
10
|
<div class=\"search-results my-4\">
|
11
|
<table class=\"table table-striped\">
|
12
|
<thead>
|
13
|
<tr>
|
14
|
<th scope=\"col\">Lemma</th>
|
15
|
<th scope=\"col\">Slovní tvar</th>
|
16
|
<th scope=\"col\">Návrh změny</th>
|
17
|
<th scope=\"col\"></th>
|
18
|
</tr>
|
19
|
</thead>
|
20
|
<tbody id=\"search-table\">
|
21
|
<script>
|
22
|
let changes;
|
23
|
function fetchChanges () {
|
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/GetChangeRequests.php\");
|
30
|
xhr.onload = function(){
|
31
|
let search = this.response;
|
32
|
let parsedJSON = JSON.parse(search);
|
33
|
changes = parsedJSON;
|
34
|
renderChanges(parsedJSON);
|
35
|
};
|
36
|
xhr.send(formData);
|
37
|
}
|
38
|
|
39
|
|
40
|
function renderChanges(changesList) {
|
41
|
let result = \"\";
|
42
|
if(changesList !== null){
|
43
|
changesList.forEach((item,id) => {
|
44
|
result +=\" <tr>\";
|
45
|
result += \" <td>\" + item.lemma + \" </td> \";
|
46
|
result += \" <td>\" + item.word + \" </td> \";
|
47
|
result += \" <td>\" + item.message + \" <td>\";
|
48
|
result += \" <td class='action-td'> \" +
|
49
|
\" <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 > \" +
|
50
|
\" </td>\";
|
51
|
result += \" </tr> \";
|
52
|
});
|
53
|
document.getElementById(\"search-table\").innerHTML = result;
|
54
|
document.getElementById(\"no-data-label\").style.display = \"none\";
|
55
|
} else {
|
56
|
document.getElementById(\"search-table\").innerHTML = result;
|
57
|
document.getElementById(\"no-data-label\").style.display = \"\";
|
58
|
}
|
59
|
}
|
60
|
</script>
|
61
|
</tbody>
|
62
|
</table>
|
63
|
|
64
|
<h3 id=\"no-data-label\" class=\"mx-auto text-center font-italic\">Žádná data nebyla nalezena</h3>
|
65
|
</div>";
|
66
|
} else {
|
67
|
echo "<h3 class=\"mx-auto text-center\">Pro navštívení stránky nemáte dostatečná oprávnění</h3>";
|
68
|
}
|
69
|
|
70
|
|