<?php
session_start();
include("config.php");
$current = isset($_SESSION['user_name']) ? $_SESSION['user_name'] : '';

$sql = "SELECT * FROM gallery WHERE visibility_type='public' OR user_id='$current' ORDER BY id DESC";
$res = mysqli_query($conn, $sql);

while ($row = mysqli_fetch_assoc($res)) {
    $icon = ($row['visibility_type'] == 'private') ? "🔒" : "🌐";
    echo '<div class="gallery-item">
            <div style="font-size:12px; margin-bottom:5px;">'.$icon.' '.$row['visibility_type'].'</div>
            <img src="upload/'.$row['picname'].'">
            <p>'.$row['description'].'</p>';
    if ($row['user_id'] == $current) {
        echo '<button class="delete-btn" onclick="deletePic('.$row['id'].')">Delete</button>';
    }
    echo '</div>';
}
?>