<?php
include "../database.php";
session_start();
$user_id = $_GET["id"];

?>
<div class="pt-3 pb-3" style="color: black;">
                <?php
$sql = "SELECT * FROM transfer WHERE user_id = '" . $user_id . "' ORDER BY id DESC";

$result = mysqli_query($con, $sql);
if ($result->num_rows > 0) {
 ?>
    <table id="person_transfer_table" class="display">
        <thead class="text-dark fs-4" style="background-color: lightgray;">
            <tr style="font-size: 12px;">
                <th class="border-bottom-0">
                    <h6 class="fw-semibold mb-0" style="font-size: 12px;">ID</h6>
                </th>
                <th class="border-bottom-0">
                    <h6 class="fw-semibold mb-0" style="font-size: 12px;">Inizio/fine</h6>
                </th>
                <th class="border-bottom-0">
                    <h6 class="fw-semibold mb-0" style="font-size: 12px;">Destinazione</h6>
                </th>
                <th class="border-bottom-0">
                    <h6 class="fw-semibold mb-0" style="font-size: 12px;">Stato</h6>
                </th>
                <th>

                </th>
            </tr>
        </thead>
        <tbody>
    <?php
while ($row = mysqli_fetch_assoc($result)) {
  $sql_status    = "SELECT * FROM justification_status WHERE id='" . $row["status_id"] . "'";
  $result_status = mysqli_query($con, $sql_status);
  $stmt_status   = mysqli_fetch_assoc($result_status);
  ?>
<tr>
    <td class='border-bottom-0'>
        <p class='mb-0 fw-normal' style="font-size: 12px;"><?php echo $row["id"]; ?></p>
    </td>
    <td class='border-bottom-0'>
        <h6 class='fw-semibold mb-0' style="font-size: 12px;"><?php echo date("d/m/Y", strtotime($row["start_date"])); ?><br><?php echo date("d/m/Y", strtotime($row["end_date"])); ?></h6>
    </td>
    <td class='border-bottom-0'>
        <p class='mb-0 fw-normal' style="font-size: 12px;"><?php echo $row["destination"]; ?></p>
    </td>
    <td class='border-bottom-0'>
        <?php
if ($row["status_id"] == 1) {
   echo "<p class='mb-0 fw-normal' style='font-size: 12px;'><span style='color: orange'><b>" . $stmt_status["name"] . "</b></span></p>";
  } else if ($row["status_id"] == 2) {
   echo "<p class='mb-0 fw-normal' style='font-size: 12px;'><span style='color: green'><b>" . $stmt_status["name"] . "</b></span></p>";
  } else if ($row["status_id"] == 3) {
   echo "<p class='mb-0 fw-normal' style='font-size: 12px;'><span style='color: red'><b>" . $stmt_status["name"] . "</b></span></p>";
  }
  ?>
    </td>
    <td>
        <i class="fa-solid fa-magnifying-glass" onclick="transferDetail(<?php echo $row["id"] ?>)"></i>
        </td>
</tr>
    <?php
}
 ?>
</tbody>
</table>
<?php
} else {
 echo "<h5 style='color:black;text-align: center; font-size: 20px'>Non ci sono timbrature</h5>";
}
?>

                </div>