<?php
function paginator($data)
{
require_once(__DIR__ . './../files/request_url.php');
$page = isset($_GET['page']) ?
intval( $_GET['page'] ) : 1 ; $currentUrl = request_url();
$nextPage = $page + 1;
$previousPage = $page - 1;
$firstPage = 1;
$countPerPage = 3;
$countStudents = count($data); $pageCount = ceil( $countStudents / $countPerPage); $noteNumber = $page * $countPerPage;?>
<div class="panel panel-default">
<!-- Default panel contents -->
<div class="panel-heading">Список уже зарегистрированных абитуриентов</div>
<div class="panel-body">
</div>
<table class="table">
<tr><td>Имя</td><td>Фамилия</td><td>Пол</td><td>Группа</td>
<td>Email</td><td>Средний Бал</td><td>Местный/Приезжий</td><td>Год Рождения</td>
</tr>
<?php for ($k = $noteNumber - $countPerPage; $k < $noteNumber; $k++): ?>
<tr><td> <?=$data[$k]['Name'] ?></td>
<td><?= $data[$k]['Surname'] ?></td>
<td><?=$data[$k]['Sex'] ?></td>
<td><?=$data[$k]['GroupNumber'] ?></td>
<td><?=$data[$k]['Email'] ?></td>
<td><?=$data[$k]['Mark'] ?></td>
<td><?=$data[$k]['Local'] ?></td>
<td><?=$data[$k]['BirthDate'] ?></td></tr>
<? endfor ?>
</table>
</div>
<nav>
<ul class="pagination">
<li>
<a href="http://localhost/php/register/index.php?page=<?=$firstPage?>" aria-label="Previous">
<span aria-hidden="true">«</span>
</a>
</li>
<?php if($previousPage >= $firstPage):?>
<li><a href="http://localhost/php/register/index.php?page=<?=$previousPage?>"><?=$previousPage?></a></li>
<?php endif ?>
<li><a href="http://localhost/php/register/index.php?page=<?=$page?>"><?=$page?></a></li>
<?php $page++;
if ($nextPage <= $pageCount):?>
<li><a href="http://localhost/php/register/index.php?page=<?=$nextPage?>"><?=$nextPage?></a></li>
<?php endif ?>
<li><a href="http://localhost/php/register/index.php?page=<?=$pageCount?>" aria-label="Next">
<span aria-hidden="true">»</span>
</a>
</li>
</ul>
</nav>
<?php
}