<?php
session_start();
if (!isset($_SESSION['loggedin'])) {
    exit("unauthorized");
}

include "../../php/database.php";

$user_id = $_GET["user_id"];

$sql_user        = "SELECT * FROM users WHERE id=" . $user_id . "";
$result_user     = mysqli_query($con, $sql_user);
$user = mysqli_fetch_assoc($result_user);
?>
<div style="position: absolute; width: 100%">
    <h4 style="text-align: center;">
        <?php
        if ($_SESSION["role"] == "Admin") {
            echo "Elenco timbrature " . $user["name"] . " " . $user["surname"] . "";
        }
        ?>
    </h4>
</div>

<table id="stamps_list_table" class="display" style="width:100%">
    <thead>
        <tr>
            <!-- <th>ID</th> -->
            <th>Data</th>
            <th>Ora</th>
            <th>Tipo</th>
            <th>Note</th>
            <th>In trasferta</th>
            <th></th>
        </tr>
    </thead>
    <tbody>
        <?php
        $sql    = "SELECT * FROM stamps WHERE user_id = " . $user_id . "";
        $result = mysqli_query($con, $sql);
        while ($row = mysqli_fetch_assoc($result)) {
            echo "<tr>";
            /* echo "<td>". $row["id"] ."</td>"; */
            echo "<td data-sort='" . $row["date"] . "'>" . date("d/m/Y", strtotime($row["date"])) . "</td>";
            echo "<td>" . date("H:i", strtotime($row["time"])) . "</td>";
            echo "<td>" . $row["type"] . "</td>";
            echo "<td>" . $row["note"] . "</td>";
            if ($row["in_transfer"] == 0) {
                echo "<td>NO</td>";
            } else {
                echo  "<td>SI</td>";
            }
            echo "<td>";
            echo "<a onclick='editStamp(" . $row["user_id"] . "," . $row["id"] . ")' style='cursor: pointer; margin-right:10px'><i class='fa-solid fa-magnifying-glass'></i></a>";
            if ($_SESSION["role"] == "Admin") {
                if ($row["delete_request"] == true) {
                    if ($row["delete_request_rejected"] == false) {
                        echo "<i class='fa-solid fa-triangle-exclamation' style='color: red'></i>";
                    }
                }
            } else {
                if ($row["delete_request"] == true) {
                    if ($row["delete_request_rejected"] == false) {
                        echo "<i class='fa-solid fa-trash-arrow-up' style='color: green'></i>";
                    }
                }
            }
            echo "</td>";
            echo "</tr>";
        }
        ?>
    </tbody>
</table>