<?php
session_start();
if (!isset($_SESSION['loggedin'])) {
    exit("unauthorized");
}

include "../../php/database.php";
?>

<table id="users_list_table" class="display" style="width:100%">
    <thead>
        <tr>
            <th></th>
            <th>Nome</th>
            <th>Cognome</th>
            <th>Email</th>
            <th>Codice fiscale</th>
            <th>Matricola</th>
            <th>Qualifica</th>
            <th>Qualifica 2</th>
            <th>Ruolo</th>
            <th>Ufficio</th>
            <th>Abilitato</th>
            <th>Pubblicazioni</th>
            <th>Cartellini</th>
        </tr>
    </thead>
    <tbody>
        <?php
        $sql    = "SELECT * FROM users";
        $result = mysqli_query($con, $sql);
        while ($row = mysqli_fetch_assoc($result)) {
            echo "<tr>";
            echo "<td>
                    <a onclick='UserCalendar(" . $row["id"] . ")' style='cursor: pointer; margin-right:10px'><i class='fa-regular fa-calendar-days'></i></a>
                    <a onclick='EditUser(" . $row["id"] . ")' style='cursor: pointer'><i class='fa-solid fa-user-pen'></i></a>
                </td>";
            echo "<td>" . $row["name"] . "</td>";
            echo "<td>" . $row["surname"] . "</td>";
            echo "<td>" . $row["email"] . "</td>";
            echo "<td>" . $row["fiscal_code"] . "</td>";
            echo "<td>" . $row["registration_number"] . "</td>";
            echo "<td>" . $row["qualification"] . "</td>";
            echo "<td>" . $row["qualification_2"] . "</td>";
            echo "<td>" . $row["role"] . "</td>";
            echo "<td>" . $row["office"] . "</td>";
            if ($row["enable"] == 0) {
                echo "<td>NO</td>";
            } else {
                echo  "<td>SI</td>";
            }
            if ($row["bacheca_notifies"] == 0) {
                echo "<td>NO</td>";
            } else {
                echo  "<td>SI</td>";
            }
            if ($row["attendance"] == 0) {
                echo "<td>NO</td>";
            } else {
                echo  "<td>SI</td>";
            }
            echo "</tr>";
        }
        ?>
    </tbody>
</table>