����JFIF��`�`�����Viewing File: /home/u820193700/domains/throtllr.in/public_html/admin/manage_gallery.php
<?php
require_once '../includes/db.php';
require_once '../includes/functions.php';

if(!is_logged_in()) {
    redirect("login.php");
}

$error = '';
$success = '';

// Handle Image Upload
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['upload_image'])) {
    $likes = sanitize($_POST['likes_count'] ?? '0');
    $comments = sanitize($_POST['comments_count'] ?? '0');
    
    if (isset($_FILES['gallery_image']) && $_FILES['gallery_image']['error'] === UPLOAD_ERR_OK) {
        $uploadDir = '../assets/uploads/gallery/';
        if (!file_exists($uploadDir)) {
            mkdir($uploadDir, 0777, true);
        }
        
        $fileName = uniqid() . '_' . basename($_FILES['gallery_image']['name']);
        $targetPath = $uploadDir . $fileName;
        
        if (move_uploaded_file($_FILES['gallery_image']['tmp_name'], $targetPath)) {
            $dbPath = 'assets/uploads/gallery/' . $fileName;
            
            $stmt = $pdo->prepare("INSERT INTO homepage_gallery (image_url, likes_count, comments_count) VALUES (?, ?, ?)");
            $stmt->execute([$dbPath, $likes, $comments]);
            
            $success = "Image uploaded successfully!";
        } else {
            $error = "Failed to move uploaded file.";
        }
    } else {
        $error = "Please select a valid image file.";
    }
}

// Handle Delete
if (isset($_GET['delete'])) {
    $del_id = intval($_GET['delete']);
    // Get file path to delete from server
    $stmt = $pdo->prepare("SELECT image_url FROM homepage_gallery WHERE id = ?");
    $stmt->execute([$del_id]);
    $img = $stmt->fetchColumn();
    
    if ($img) {
        $fullPath = '../' . $img;
        if (file_exists($fullPath)) {
            unlink($fullPath);
        }
        $pdo->prepare("DELETE FROM homepage_gallery WHERE id = ?")->execute([$del_id]);
        $success = "Image deleted successfully!";
    }
}

// Fetch existing images
$stmt = $pdo->query("SELECT * FROM homepage_gallery ORDER BY created_at DESC");
$gallery = $stmt->fetchAll();

?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Manage Homepage Gallery - ReOwn Admin</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="admin.css">
</head>
<body>

<?php include 'admin_sidebar.php'; ?>

<div id="main-content">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h2>Manage Homepage Gallery</h2>
        <a href="../index.php" target="_blank" class="btn btn-outline-light"><i class="fas fa-external-link-alt me-2"></i>View Live Homepage</a>
    </div>

    <?php if($error): ?>
        <div class="alert alert-danger"><?php echo htmlspecialchars($error); ?></div>
    <?php endif; ?>
    <?php if($success): ?>
        <div class="alert alert-success"><?php echo htmlspecialchars($success); ?></div>
    <?php endif; ?>

    <div class="glass-card p-4 mb-5">
        <h4 class="mb-3">Upload New Image</h4>
        <p class="text-muted small">Upload photos to display in the "Follow Our Journey" section on the homepage. The homepage displays up to 4 recent images.</p>
        <form method="POST" enctype="multipart/form-data" class="row g-3">
            <div class="col-md-6">
                <label>Select Image</label>
                <input type="file" name="gallery_image" class="form-control bg-dark text-white border-secondary" accept="image/*" required>
            </div>
            <div class="col-md-3">
                <label>Likes (Text)</label>
                <input type="text" name="likes_count" class="form-control bg-dark text-white border-secondary" placeholder="e.g. 1.2k" required>
            </div>
            <div class="col-md-3">
                <label>Comments (Text)</label>
                <input type="text" name="comments_count" class="form-control bg-dark text-white border-secondary" placeholder="e.g. 240" required>
            </div>
            <div class="col-12 mt-3">
                <button type="submit" name="upload_image" class="btn btn-danger"><i class="fas fa-upload me-2"></i>Upload Image</button>
            </div>
        </form>
    </div>

    <div class="glass-card p-4">
        <h4 class="mb-4">Current Gallery Images</h4>
        <?php if (count($gallery) > 0): ?>
            <div class="row g-4">
                <?php foreach ($gallery as $img): ?>
                <div class="col-md-3">
                    <div class="card bg-dark border-secondary">
                        <img src="../<?php echo htmlspecialchars($img['image_url']); ?>" class="card-img-top" style="height: 200px; object-fit: cover;" alt="Gallery Image">
                        <div class="card-body">
                            <p class="mb-1 text-white"><i class="fas fa-heart text-danger me-1"></i> <?php echo htmlspecialchars($img['likes_count']); ?> &nbsp;&nbsp; <i class="fas fa-comment me-1"></i> <?php echo htmlspecialchars($img['comments_count']); ?></p>
                            <p class="text-muted small mb-3">Added: <?php echo date('M d, Y', strtotime($img['created_at'])); ?></p>
                            <a href="?delete=<?php echo $img['id']; ?>" class="btn btn-sm btn-outline-danger w-100" onclick="return confirm('Are you sure you want to delete this image?');"><i class="fas fa-trash me-1"></i> Delete</a>
                        </div>
                    </div>
                </div>
                <?php endforeach; ?>
            </div>
        <?php else: ?>
            <p class="text-muted text-center py-4">No images in the gallery yet. Upload one above!</p>
        <?php endif; ?>
    </div>
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
Back to Directory �������}�!1AQa"q2���#B��R��$3br� %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz�������������������������������������������������������������������������������� ������w�!1AQaq"2�B���� #3R�br� $4�%�&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz������������������������������������������������������������������������ ��?��_��+��?��(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(�����