<!DOCTYPE html>
<html lang="en">

<head>
    <?php include("include/meta.php");?>
    <?php include("include/css.php");?>
</head>

<body>

    <!-- header area -->
    <?php include("include/header.php");?>
    <!-- header area end -->


    <main class="main">

        <!-- breadcrumb -->
        <?php
            $banner_sql = "SELECT * FROM data_table WHERE up_by = $x && page_type = 'slider' && recycle = '1' ORDER BY id DESC";
            $banner_run = mysqli_query($con, $banner_sql);
            if ($banner_row = mysqli_fetch_assoc($banner_run)) {
            ?>
        <div class="site-breadcrumb" style="background: url(./login/upload/<?php echo $banner_row['image_one']?>)">
            <div class="container">
                <h2 class="breadcrumb-title">Notice Board</h2>
                <ul class="breadcrumb-menu">
                    <li><a href="index.html">Home</a></li>
                    <li class="active">Notice Board</li>
                </ul>
            </div>
        </div>
        <?php }?>
        <!-- breadcrumb end -->


        <!-- notice board -->
        <div class="notice-board py-120">
            <div class="container">
                <?php
                    // Number of items per page
                    $limit = 10;

                    // Current page from URL, default is 1
                    $page = isset($_GET['page']) && is_numeric($_GET['page']) ? (int)$_GET['page'] : 1;

                    // Calculate offset
                    $offset = ($page - 1) * $limit;

                    // Count total records
                    $count_sql = "SELECT COUNT(*) as total FROM data_table WHERE page_type = 'notice' AND recycle = '1'";
                    $count_result = mysqli_query($con, $count_sql);
                    $count_row = mysqli_fetch_assoc($count_result);
                    $total_records = $count_row['total'];

                    // Total pages
                    $total_pages = ceil($total_records / $limit);

                    // Fetch paginated records
                    $notice_sql = "SELECT * FROM data_table WHERE page_type = 'notice' AND recycle = '1' ORDER BY id DESC LIMIT $offset, $limit";
                    $notice_run = mysqli_query($con, $notice_sql);
                    ?>

                <div class="notice-wrap">
                    <?php while ($notice_row = mysqli_fetch_assoc($notice_run)) { ?>
                    <div class="notice-item">
                        <h4>
                            <a href="notice-details.php?title=<?= $notice_row['title']; ?>">
                                <?= htmlspecialchars($notice_row['title']); ?>
                            </a>
                        </h4>
                        <div class="notice-meta">
                            <span><i class="far fa-user"></i> MACAW Public School</span>
                            <span><i class="far fa-calendar-alt"></i> <?= $notice_row["up_date"]; ?></span>
                            <span><i class="far fa-eye"></i> <?= $notice_row["view_count"]; ?> Views</span>
                        </div>
                    </div>
                    <?php } ?>
                </div>

                <!-- Pagination -->
                <div class="pagination-area">
                    <div aria-label="Page navigation example">
                        <ul class="pagination">

                            <!-- Previous Button -->
                            <li class="page-item <?= ($page <= 1) ? 'disabled' : ''; ?>">
                                <a class="page-link" href="?page=<?= $page - 1; ?>" aria-label="Previous">
                                    <span aria-hidden="true"><i class="far fa-arrow-left"></i></span>
                                </a>
                            </li>

                            <!-- Page Numbers -->
                            <?php for ($i = 1; $i <= $total_pages; $i++) { ?>
                            <li class="page-item <?= ($i == $page) ? 'active' : ''; ?>">
                                <a class="page-link" href="?page=<?= $i; ?>"><?= $i; ?></a>
                            </li>
                            <?php } ?>

                            <!-- Next Button -->
                            <li class="page-item <?= ($page >= $total_pages) ? 'disabled' : ''; ?>">
                                <a class="page-link" href="?page=<?= $page + 1; ?>" aria-label="Next">
                                    <span aria-hidden="true"><i class="far fa-arrow-right"></i></span>
                                </a>
                            </li>

                        </ul>
                    </div>
                </div>
                <!-- Pagination End -->

            </div>
        </div>
        <!-- notice board end-->

    </main>



    <!-- footer area -->
    <?php include("include/footer.php");?>
    <!-- footer area end -->

    <!-- js -->
    <?php include("include/js.php");?>

</body>

</html>