Projekt

Obecné

Profil

Stáhnout (2.96 KB) Statistiky
| Větev: | Revize:
1
<?php
2

    
3
session_start();
4
if (isset($_SESSION['role']) && $_SESSION['role'] == "admin") {
5
    echo "<script>
6
        //what to do when page renders
7
        window.onload = function() {
8
            fetchUsers();
9
        };
10
    </script>
11

    
12
    <div class=\"search-results my-4\">
13
        <table class=\"table table-striped\">
14
            <thead>
15
            <tr>
16
                <th scope=\"col\">Uživatel</th>
17
                <th scope=\"col\">Email</th>
18
                <th scope=\"col\">Práva</th>
19
                <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>
20
            </tr>
21
            </thead>
22
            <tbody id=\"search-table\">
23
                <script>
24
                    let users;
25
                    function fetchUsers () {
26
                        // (A1) GET SEARCH TERM
27
                        const formData = new FormData();
28

    
29
                        // (A2) AJAX - USE HTTP:// NOT FILE:/
30
                        let xhr = new XMLHttpRequest();
31
                        xhr.open(\"POST\", \"./controller/UsersListController.php\");
32
                        xhr.onload = function(){
33
                            let search = this.response;
34
                            let parsedJSON = JSON.parse(search);
35
                            users = parsedJSON;
36
                            renderUsers(parsedJSON);
37
                        };
38
                        xhr.send(formData);
39
                    }
40

    
41

    
42
                    function renderUsers(users) {
43
                        let result = \"\";
44
                        users.forEach((item,id) => {
45
                            result += \"<tr>\";
46
                            result += \"<td>\" + item.username + \"</td>\";
47
                            result += \"<td>\" + ((item.email !== undefined && item.email !== null) ? item.email : \"-\") + \"</td>\";
48
                            result += \"<td>\" + item.role + \"</td>\";
49
                            (item.role !== \"admin\") ? (result += \"<td class='action-td'>\" +
50
                                \"<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>\" +
51
                                \"<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>\" +
52
                                \"</td>\") : result += \"<td class='action-td'/>\";
53
                            result += \"</tr>\";
54
                        });
55
                        document.getElementById(\"search-table\").innerHTML = result;
56
                    }
57
                </script>
58
            </tbody>
59
        </table>
60
    </div>";
61
} else {
62
    echo "<h3 class=\"mx-auto text-center\">Pro navštívení stránky nemáte dostatečná oprávnění</h3>";
63
}
64

    
65

    
(8-8/8)