hjkhjkjhkhjkgjghjhgjhgjghjhghjghjhgjjnbvnvbnvk
bnmbnmbnhjkhjkhjkhjktyutyutyuytutyutyutyhgjgjghjgjghjguytutyry
/
home
/
wjcvelqp
/
public_html
/
admin
/
Upload FileeE
HOME
<?php include 'header.php'; // ====================== // HANDLE DELETE POST // ====================== if (isset($_GET['delete'])) { $id = (int)$_GET['delete']; // Get image name before deleting $stmt = $pdo->prepare("SELECT featured_image FROM posts WHERE id = ?"); $stmt->execute([$id]); $post = $stmt->fetch(); if ($post && $post['featured_image']) { $image_path = '../uploads/' . $post['featured_image']; if (file_exists($image_path)) { unlink($image_path); } } // Delete the post $stmt = $pdo->prepare("DELETE FROM posts WHERE id = ?"); if ($stmt->execute([$id])) { $success = "Post deleted successfully!"; } else { $error = "Failed to delete post."; } } // Fetch all posts $stmt = $pdo->query("SELECT p.*, c.name as category_name FROM posts p LEFT JOIN categories c ON p.category_id = c.id ORDER BY p.created_at DESC"); $posts = $stmt->fetchAll(PDO::FETCH_ASSOC); ?> <div class="p-8"> <div class="flex justify-between items-center mb-8"> <h2 class="text-3xl font-bold text-green-800">Manage Posts (<?= count($posts) ?> Total)</h2> <a href="create-post.php" class="bg-green-800 hover:bg-green-900 text-white px-6 py-3 rounded-xl font-medium flex items-center gap-2"> <i class="fas fa-plus"></i> New Post </a> </div> <?php if(isset($success)): ?> <div class="bg-green-100 border border-green-400 text-green-700 px-6 py-4 rounded-2xl mb-6"> <?= $success ?> </div> <?php endif; ?> <?php if(isset($error)): ?> <div class="bg-red-100 text-red-700 px-6 py-4 rounded-2xl mb-6"><?= $error ?></div> <?php endif; ?> <?php if(empty($posts)): ?> <div class="text-center py-20 text-gray-500"> <p class="text-2xl">No posts yet.</p> <a href="create-post.php" class="text-green-700 underline mt-4 inline-block">Create your first post</a> </div> <?php else: ?> <div class="bg-white rounded-3xl shadow overflow-hidden"> <table class="w-full"> <thead class="bg-gray-100"> <tr> <th class="px-6 py-5 text-left font-semibold">Title</th> <th class="px-6 py-5 text-left font-semibold">Category</th> <th class="px-6 py-5 text-center font-semibold">Views</th> <th class="px-6 py-5 text-center font-semibold">Likes</th> <th class="px-6 py-5 text-center font-semibold">Date</th> <th class="px-6 py-5 text-center font-semibold">Actions</th> </tr> </thead> <tbody class="divide-y"> <?php foreach($posts as $post): ?> <tr class="hover:bg-gray-50"> <td class="px-6 py-5 font-medium"><?= htmlspecialchars($post['title']) ?></td> <td class="px-6 py-5"><?= htmlspecialchars($post['category_name'] ?? 'Uncategorized') ?></td> <td class="px-6 py-5 text-center"><?= number_format($post['views']) ?></td> <td class="px-6 py-5 text-center"><?= number_format($post['likes']) ?></td> <td class="px-6 py-5 text-center text-sm text-gray-500"> <?= date('M j, Y', strtotime($post['created_at'])) ?> </td> <td class="px-6 py-5 text-center"> <a href="edit-post.php?id=<?= $post['id'] ?>" class="text-blue-600 hover:text-blue-700 font-medium">Edit</a> <a href="?delete=<?= $post['id'] ?>" onclick="return confirm('Are you sure you want to delete this post?\nThis action cannot be undone.')" class="text-red-600 hover:text-red-700 font-medium ml-6"> Delete </a> </td> </tr> <?php endforeach; ?> </tbody> </table> </div> <?php endif; ?> </div> <?php include 'footer.php'; ?>