<?php
session_start();
include "php/database.php";

if (!isset($_SESSION['loggedin'])) {
	header('Location: login.php');
	exit;
}

$id = $_GET["id"];

$sql    = "SELECT * FROM stamps WHERE id='" . $id . "'";
$result = mysqli_query($con, $sql);
$stamp  = mysqli_fetch_assoc($result);

$sql_user    = "SELECT * FROM users WHERE id='" . $stamp["user_id"] . "'";
$result_user = mysqli_query($con, $sql_user);
$user        = mysqli_fetch_assoc($result_user);

$index_page = false;
$page_title = "Info timbratura ".$stamp["id"];
$prev_page = "openStampsList()";

include "public/header.php";
?>

    
<div id="stamp_detail_content_user" class="card bg-transparent mb-0">
    <div class="card card-style" style="padding-bottom: 10px;">
        <div class="content" style="text-align: center;">
            <div class="row">
                <div class="col-6">
                    <h5 class="font-16 font-500" style="font-weight:900; margin-top: 20px;">Registrazione</h5>
                    <p class="font-16 mb-0"><?php echo date("d/m/Y H:i", strtotime($stamp["stamp_datetime"])); ?></p>
                </div>
                <div class="col-6">
                    <h5 class="font-16 font-500" style="font-weight:900; margin-top: 20px;">Tipo</h5>
                    <p class="font-16 mb-0"><?php echo $stamp["type"]; ?></p>
                </div>
                <div class="col-6">
                    <h5 class="font-16 font-500" style="font-weight:900; margin-top: 20px;">Data</h5>
                    <p class="font-16 mb-0"><?php echo date("d/m/Y", strtotime($stamp["date"])); ?></p>
                </div>
                <div class="col-6">
                    <h5 class="font-16 font-500" style="font-weight:900; margin-top: 20px;">Ora</h5>
                    <p class="font-16 mb-0"><?php echo date("H:i", strtotime($stamp["time"])); ?></p>
                </div>
                <div class="col-6">
                    <h5 class="font-16 font-500" style="font-weight:900; margin-top: 20px;">Trasferta</h5>
                    <?php if ($stamp["in_transfer"] == 0) { echo "<p class='font-16 mb-0'>No</p>"; } else { echo "<p class='font-16 mb-0'>".$stamp["transfer_location"]."</p>"; } ?>
                </div>
                <div class="col-6">
                    <h5 class="font-16 font-500" style="font-weight:900; margin-top: 20px;">Badge</h5>
                    <?php if ($stamp["badge"] == 0) { echo "<p class='font-16 mb-0'>No</p>"; } else { echo "<p class='font-16 mb-0'>Sì</p>"; } ?>
                </div>
                <div class="col-12">
                    <h5 class="font-16 font-500" style="font-weight:900; margin-top: 20px;">Note</h5>
                    <p class="font-16 mb-0"><?php echo $stamp["note"] ?></p>
                </div>
            </div>
            <?php 
            if($stamp["delete_request"] == true) {
                if($stamp["delete_request_rejected"] == true) {
                    echo "<br><p style='color: red'>Richiesta eliminazione inviata.<br>La richiesta è stata rifiutata</p>"; 
                } else {
                    echo "<br><p style='color: red'>Richiesta eliminazione inviata.<br>Attendi l'approvazione</p>"; 
                }
            } else {?>
                <br><br>
                <button type="button" onclick="deleteStamp(<?php echo $stamp['id']; ?>)" class="btn btn-m btn-full mb-3 rounded-0 text-uppercase font-900 shadow-s bg-dark-dark" style="margin: auto; background-color: black !important">Elimina</button><?php 
            } ?>
        </div>
    </div>

    <?php
    $con->close();
    ?>
</div>

<?php include "public/footer.php" ?>