<?php
session_start();


$servername = "localhost";
$username = "itladevprubycom_enma";
$password = "53gNpj4t.xDc";
$database = "itladevprubycom_enma1";

$conexion = new mysqli($servername, $username, $password, $database);

if ($conexion->connect_error) {
    die("Error de conexi贸n: " . $conexion->connect_error);
}

$name = $_SESSION['nombre'];
$id = $_SESSION['id'];

$query = "SELECT * FROM historial";
$todo = $conexion->query($query);

$historial = []; 

while ($total = $todo->fetch_assoc()) {
    $historial[] = $total; 
}


?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Editar Registro</title>
    <link rel="stylesheet" href="css/index.css" />
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/uikit@3.18.1/dist/css/uikit.min.css" />
    <script src="https://cdn.jsdelivr.net/npm/uikit@3.18.1/dist/js/uikit.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/uikit@3.18.1/dist/js/uikit-icons.min.js"></script>
</head>
<body>
    <?php include "navbar.php";?>
    <div class="uk-background-cover" style="height: 100vh;" data-src="<?php echo $path . $img['backs'][0]['backs']; ?>" uk-img>
    <div class="uk-container uk-margin-top uk-margin-bottom">
        <div class="uk-card uk-card-body">
            <h3 class="uk-card-title uk-text-center">Historial:</h3>
            <div class="uk-grid uk-child-width-1-1@s uk-child-width-1-2@m uk-child-width-1-3@l uk-margin-large-top" uk-grid>
                <?php foreach($historial as $row): ?>
                    <div>
                        <div class="uk-card uk-card-default uk-card-body">
                            <h4 class="uk-card-title"><?php echo $row["usuario"]; ?></h4>
                            <p><?php echo $row["producto"]; ?></p>
                            <a class="uk-button uk-button-danger" onclick="confirmarEliminacion(<?php echo $row["id"]; ?>)">Eliminar mensaje</a>
                        </div>
                    </div>
                <?php endforeach; ?>
            </div>
        </div>
    </div>
    </div>
    <script>
        function confirmarEliminacion(id) {
            if (confirm("¿Estás seguro de que quieres eliminar este mensaje?")) {
                window.location.href = "eliminar3.php?id=" + id;
            }
        }
    </script>
    <?php include "../include/offcanvas.php";?>
</body>
</html>
