<?php
session_start();
if (!isset($_SESSION['admin_logged_in'])) {
    header("Location: login.php");
    exit;
}
include '../includes/db.php';

// Fetch Pages
$result = $conn->query("SELECT * FROM pages");
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Manage Pages</title>
    <link rel="shortcut icon" href="/bm/BM LOGO.jpg" type="image/jpeg">
    <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="dashboard.css">
</head>
<body>
    <div class="sidebar d-flex flex-column flex-shrink-0 p-3 text-white" style="width: 280px;">
        <a href="dashboard.php" class="d-flex align-items-center mb-3 mb-md-0 me-md-auto text-white text-decoration-none">
            <span class="fs-4">Admin Panel</span>
        </a>
        <hr>
        <ul class="nav nav-pills flex-column mb-auto">
            <li class="nav-item">
                <a href="dashboard.php"><i class="fas fa-tachometer-alt me-2"></i> Dashboard</a>
            </li>
            <li>
                <a href="manage_services.php"><i class="fas fa-tools me-2"></i> Manage Services</a>
            </li>
            <li>
                <a href="manage_pages.php" class="active"><i class="fas fa-file-alt me-2"></i> Manage Content</a>
            </li>
            <li>
                <a href="manage_blogs.php"><i class="fas fa-blog me-2"></i> Manage Blogs</a>
            </li>
            <li>
                <a href="job_applications.php"><i class="fas fa-briefcase me-2"></i> Job Applications</a>
            </li>
            <li>
                <a href="contact_messages.php"><i class="fas fa-envelope me-2"></i> Messages</a>
            </li>
            <li>
                <a href="wp/post.php"><i class="fas fa-pen me-2"></i> Add New Post</a>
            </li>
            <li>
                <a href="#"><i class="fas fa-newspaper me-2"></i> Blog</a>
            </li>
            <li>
                <a href="logout.php" class="text-danger"><i class="fas fa-sign-out-alt me-2"></i> Logout</a>
            </li>
        </ul>
    </div>

    <div class="content">
        <h2>Manage Page Content</h2>
        <p>Edit dynamic content for Home and About pages.</p>

        <table class="table table-bordered">
            <thead class="table-dark">
                <tr>
                    <th>Page Section</th>
                    <th>Current Content Preview</th>
                    <th>Action</th>
                </tr>
            </thead>
            <tbody>
                <?php while($row = $result->fetch_assoc()): ?>
                <tr>
                    <td><strong><?php echo ucfirst(str_replace('_', ' ', $row['page_name'])); ?></strong></td>
                    <td><?php echo substr($row['content'], 0, 100) . '...'; ?></td>
                    <td>
                        <a href="page_form.php?id=<?php echo $row['id']; ?>" class="btn btn-warning btn-sm">Edit</a>
                    </td>
                </tr>
                <?php endwhile; ?>
            </tbody>
        </table>
    </div>
</body>
</html>
