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

include "../../php/database.php";

?>
<div class="modal-header">
    <h5 class="modal-title" id="exampleModalLabel">Eliminazioni timbrature da approvare</h5>
    <button class="close" type="button" data-dismiss="modal" aria-label="Close"><span aria-hidden="true" id="close_stamps_to_approve">×</span></button>
</div>
<div class="modal-body">
    <table id="stamps_to_approve_table" class="display" style="width:100%">
        <thead>
            <tr>
                <th>Utente</th>
                <th>Data</th>
                <th>Ora</th>
                <th>Tipo</th>
                <th>Note</th>
                <th>In trasferta</th>
                <th>Motivazione</th>
                <th></th>
            </tr>
        </thead>
        <tbody>
            <?php
            $sql    = "SELECT * FROM stamps WHERE delete_request = 1 AND delete_request_rejected = 0 ORDER BY id DESC";
            $result = mysqli_query($con, $sql);
            while ($row = mysqli_fetch_assoc($result)) {
                $sql        = "SELECT * FROM users WHERE id='" . $row["user_id"] . "'";
                $result     = mysqli_query($con, $sql);
                $user = mysqli_fetch_assoc($result);

                echo "<tr>";
                echo "<td>" . $user["name"] . " " . $user["surname"] . "</td>";
                echo "<td>" . 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>" . $row["delete_motivation"] . "</td>";
                echo "<td>";
                echo "<a onclick='approveStampDelete(" . $row["user_id"] . "," . $row["id"] . ")' style='cursor: pointer; margin-right:10px'><i class='fa-solid fa-thumbs-up' style='color: green'></i></a>";
                echo "<a onclick='rejectStampDelete(" . $row["user_id"] . "," . $row["id"] . ")' style='cursor: pointer; margin-right:10px'><i class='fa-solid fa-thumbs-down' style='color: red'></i></a>";
                echo "<a onclick='editStamp(" . $row["user_id"] . "," . $row["id"] . ")' style='cursor: pointer; margin-right:10px'><i class='fa-solid fa-magnifying-glass'></i></a>";
                echo "</td>";
                echo "</tr>";
            }
            ?>
        </tbody>
    </table>
</div>
<div class="modal-footer">
    <button class="btn btn-secondary" type="button" data-dismiss="modal">Chiudi</button>
</div>