<?php
include 'db.php';
session_start();

if (!isset($_SESSION['email'])) {
    header("Location: login.php");
    exit();
}

$email = $_SESSION['email'];
$name = $_SESSION['name'];

$result = mysqli_query($conn, "SELECT * FROM image WHERE access_type='private' AND user_email='$email'");
?>
<link rel="stylesheet" href="style.css">

<h2 style="color:purple;"><?php echo $name; ?>'s Private Memories</h2>
<a href="display.php">Back</a> | 
<a href="logout.php">Logout</a><br><br>

<?php
while ($row = mysqli_fetch_assoc($result)) {
    echo "<div style='margin:10px; border:1px solid #ccc; padding:10px; display:inline-block;'>";
    echo "<img src='uploads/{$row['filename']}' width='200'><br>";
    echo "<b>Comment:</b> " . htmlspecialchars($row['comment']);

    // ✅ Delete button for private images (own images only)
    echo "<br><a href='delete.php?id={$row['id']}' 
             onclick=\"return confirm('Are you sure you want to delete this memory?');\" 
             class='delete-btn'>Delete</a>";

    echo "</div>";
}
?>
