Projekt

Obecné

Profil

Stáhnout (2.94 KB) Statistiky
| Větev: | Revize:
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
            fetchUsers();
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\">Uživatel</th>
15
                <th scope=\"col\">Email</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.email !== undefined && item.email !== null) ? item.email : \"-\") + \"</td>\";
46
                            result += \"<td>\" + item.role + \"</td>\";
47
                            (item.role !== \"admin\") ? (result += \"<td class='action-td'>\" +
48
                                \"<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>\" +
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>\") : result += \"<td class='action-td'/>\";
51
                            result += \"</tr>\";
52
                        });
53
                        document.getElementById(\"search-table\").innerHTML = result;
54
                    }
55
                </script>
56
            </tbody>
57
        </table>
58
    </div>";
59
} else {
60
    echo "<h3 class=\"mx-auto text-center\">Pro navštívení stránky nemáte dostatečná oprávnění</h3>";
61
}
62

    
63

    
(8-8/8)