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

    $stamper_id = $_GET["stamper_id"];

    $sql        = "SELECT * FROM stampers WHERE id='" . $stamper_id . "'";
    $result     = mysqli_query($con, $sql);
    $stamper = mysqli_fetch_assoc($result);
?>
<div class="modal-header">
    <h5 class="modal-title" id="exampleModalLabel">Modifica timbratore</h5>
    <button class="close" type="button" data-dismiss="modal" aria-label="Close" id="close_edit_stamper"><span aria-hidden="true">×</span></button>
</div>
<div class="modal-body">
    <form>
        <div class="form-group row">
            <label class="col-sm-2 col-form-label" for="inputEmail3">Nome</label>
            <div class="col-sm-10">
                <input class="form-control" id="name" type="text" placeholder="Nome" value="<?php echo $stamper["name"] ?>">
            </div>
        </div>
        <div class="form-group row">
            <label class="col-sm-2 col-form-label" for="inputEmail3">Indirizzo IP</label>
            <div class="col-sm-10">
                <input class="form-control" id="ip_address" type="text" placeholder="Indirizzo IP" value="<?php echo $stamper["ip_address"] ?>">
            </div>
        </div>
        <div class="form-group row">
            <label class="col-sm-2 col-form-label" for="inputEmail3">Descrizione</label>
            <div class="col-sm-10">
                <input class="form-control" id="description" type="text" placeholder="Descrizione" value="<?php echo $stamper["description"] ?>">
            </div>
        </div>
        <div class="form-group row">
            <label class="col-sm-2 col-form-label" for="inputEmail3">Ubicazione</label>
            <div class="col-sm-10">
                <input class="form-control" id="location" type="text" placeholder="Ubicazione" value="<?php echo $stamper["location"] ?>">
            </div>
        </div>
        <div class="form-group row">
            <label class="col-sm-2 col-form-label" for="inputEmail3">Nome file importazione</label>
            <div class="col-sm-10">
                <input class="form-control" id="file_name" type="text" placeholder="Nome file" value="<?php echo $stamper["file_name"] ?>">
            </div>
        </div>
    </form>
</div>
<div class="modal-footer">
    <button class="btn btn-secondary" type="button" data-dismiss="modal">Chiudi</button>
    <button class="btn btn-danger ml-2" type="button" onclick="deleteStamper(<?php echo $stamper['id']; ?>)">Elimina</button>
    <button class="btn btn-primary ml-2" type="button" onclick="updateStamper(<?php echo $stamper['id']; ?>)" id="update_stamper_button">Aggiorna</button>
    <div class="spinner spinner-primary mr-3" style="display: none;" id="update_stamper_loader"></div>
</div>