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

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

?>
<div class="modal-header">
    <h5 class="modal-title" id="exampleModalLabel">Trasferte da approvare</h5>
    <button class="close" type="button" data-dismiss="modal" aria-label="Close"><span aria-hidden="true" id="close_transfer_to_approve">×</span></button>
</div>
<div class="modal-body">
    <table id="transfers_to_approve_table" class="display" style="width:100%">
        <thead>
            <tr>
                <th>Utente</th>
                <th>Data inizio</th>
                <th>Data fine</th>
                <th>Italia/Estero</th>
                <th>Destinazione</th>
                <th></th>
            </tr>
        </thead>
        <tbody>
            <?php
            $sql    = "SELECT * FROM transfers WHERE status_id = 1 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_users     = mysqli_query($con, $sql);
                $user = mysqli_fetch_assoc($result_users);

                echo "<tr>";
                echo "<td>" . $user["name"] . " " . $user["surname"] . "</td>";
                echo "<td>" . date("d/m/Y", strtotime($row["start_date"])) . "</td>";
                echo "<td>" . date("d/m/Y", strtotime($row["end_date"])) . "</td>";
                echo "<td>" . $row["location"] . "</td>";
                echo "<td>" . $row["destination"] . "</td>";
                echo "<td>";
                echo "<a onclick='approveTransfer(" . $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='rejectTransfer(" . $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='editTransfer(" . $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>