<?php
$limit = 0;
$noOfPages = 0;
$_total_rows = $_GET['total_rows'];
$_records_per_page = $_GET['records_per_page'];
$_page = $_GET['page'];
$_page_url = $_GET['page_url'];
$noOfPages = ceil($_total_rows * 1.0 / $_records_per_page);
$dotshow = true;
if ($_page == 2 || $_page == $noOfPages - 1) {
    $limit = 2;
} else if ($_page >= 3 && $_page != $noOfPages) {
    $limit = 1;
} else {
    $limit = 3;
}
//for course page
$value = "";
if (isset($_GET['mode']) && isset($_GET['view'])) {
    $value = "&mode=" . $_GET['mode'] . "&view=" . $_GET['view'];
}
?>
<div class="row justify-center pt-30">
    <div class="col-auto">
        <div class="pagination -buttons">
            <?php $page_prev_dis = $_page <= 1 ? "pagination__button-disabled" : "pagination__button"; ?>
            <a class="<?php echo $page_prev_dis ?> -prev" <?php if ($_page <= 1) { ?> disabled="" <?php } ?> href="<?php if ($_page > 1) { ?><?php echo $_page_url ?>?page=<?php echo $_page - 1 . $value ?><?php } else { ?>javascript:;<?php } ?>"><i class="fa fa-chevron-left"></i></a>
            <div class="pagination__count">
                <?php
                for ($i = 1; $i <= $noOfPages; $i++) {
                    if ($i == 1 || $i == $noOfPages || ($i >= $_page - $limit && $i <= $_page + $limit)) {
                        $dotshow = true;
                        if ($i != $_page) {
                            echo "<a href='$_page_url?page=$i$value'>$i</a>";
                        } else {
                            echo "<a class='-count-is-active' href='javascript:;'>$i</a>";
                        }
                    } else if ($dotshow) {
                        $dotshow = false;
                        echo "<span>...</span>";
                    }
                }
                ?>
            </div>
            <?php $page_next_dis = $_page >= $noOfPages ? "pagination__button-disabled" : "pagination__button"; ?>
            <a class="<?php echo $page_next_dis ?> -next" <?php if ($_page >= $noOfPages) { ?>disabled=""<?php } ?> href="<?php if ($_page < $noOfPages) { ?><?php echo $_page_url ?>?page=<?php echo $_page + 1 . $value ?><?php } else { ?>javascript:;<?php } ?>">
                <i class="fa fa-chevron-right"></i>
            </a>
        </div>
    </div>
</div>


