Projekt

Obecné

Profil

Stáhnout (3.02 KB) Statistiky
| Větev: | Revize:
1
<p>Vítejte na stránce správy uživatelů. Pro nápovědu klikněte <a href="userManual.php">zde</a></p>
2
<?php
3
if (isset($_SESSION['role']) && $_SESSION['role'] == "admin") {
4
    $loggedUserId = $_SESSION['id'];
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\">Práva</th>
18
                <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>
19
            </tr>
20
            </thead>
21
            <tbody id=\"search-table\">
22
                <script>
23
                    let users;
24
                    function fetchUsers () {
25
                        // (A1) GET SEARCH TERM
26
                        const formData = new FormData();
27

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

    
40

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

    
67

    
(7-7/8)