<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- Custom styles for this template -->
    <link href="../css/sb-admin-2.min.css" rel="stylesheet">

    <!-- Custom styles for this page -->
    <link href="../vendor/datatables/dataTables.bootstrap4.min.css" rel="stylesheet">

</head>
	<body>
		<!-- Membuat Menu Header / Navbar -->
		<div class="row">
			<div class="col-sm-12 col-md-8">
				<div class="dataTables_paginate paging_simple_numbers" id="dataTable_paginate">
					<!-- Buat Paginationnya -->
					<ul class="pagination">
						<!-- LINK FIRST AND PREV -->
						<?php
						if($page == 1){ // Jika page adalah page ke 1, maka disable link PREV
						?>
							<li class="paginate_button page-item previous disabled" id="dataTable_previous">
								<a href="#" aria-controls="dataTable" data-dt-idx="0" tabindex="0" class="page-link">First</a>
							</li>
							<li class="paginate_button page-item previous disabled" id="dataTable_previous">
								<a href="#" aria-controls="dataTable" data-dt-idx="0" tabindex="0" class="page-link">&laquo;</a>
							</li>
						<?php
						}else{ // Jika page bukan page ke 1
							$link_prev = ($page > 1)? $page - 1 : 1;
						?>
							<li class="paginate_button page-item ">
								<a href="Personal_Info-Nav.php?page=1" aria-controls="dataTable" data-dt-idx="0" tabindex="0" class="page-link">First</a>
							</li>
							<li  class="paginate_button page-item " id="dataTable_previous">
								<a href="Personal_Info-Nav.php?page=<?php echo $link_prev; ?>" aria-controls="dataTable" data-dt-idx="0" tabindex="0" class="page-link">&laquo;</a>
							</li>
						<?php
						}
						?>
						
						<!-- LINK NUMBER -->
						<?php
						// Buat query untuk menghitung semua jumlah data
						$sql2 = ("SELECT COUNT(*) AS jumlah FROM personal");
						$query2 = mysqli_query($koneksi, $sql2);
						$get_jumlah = mysqli_fetch_array($query2);
						$jumlah_page = ceil($get_jumlah['jumlah'] / $limit); // Hitung jumlah halamannya		
						$jumlah_number = 3; // Tentukan jumlah link number sebelum dan sesudah page yang aktif
						$start_number = ($page > $jumlah_number)? $page - $jumlah_number : 1; // Untuk awal link number
						$end_number = ($page < ($jumlah_page - $jumlah_number))? $page + $jumlah_number : $jumlah_page; // Untuk akhir link number
						
						for($i = $start_number; $i <= $end_number; $i++){
							$link_active = ($page == $i)? ' class="active"' : '';
						?>
							<li class="paginate_button page-item" <?php echo $link_active; ?>>
								<a href="Personal_Info-Nav.php?page=<?php echo $i; ?>" aria-controls="dataTable" data-dt-idx="0" tabindex="0" class="page-link active"><?php echo $i; ?></a>
							</li>
						<?php
						}
						?>

						<!-- LINK NEXT AND LAST -->
						<?php
						// Jika page sama dengan jumlah page, maka disable link NEXT nya
						// Artinya page tersebut adalah page terakhir 
						if($page == $jumlah_page){ // Jika page terakhir
						?>
							<li class="paginate_button page-item next disabled" id="dataTable_next">
								<a href="#" aria-controls="dataTable" data-dt-idx="0" tabindex="0" class="page-link">&raquo;</a>
							</li>
							<li class="paginate_button page-item next disabled" id="dataTable_next">
								<a href="#" aria-controls="dataTable" data-dt-idx="0" tabindex="0" class="page-link">Last</a>
							</li>
						<?php
						}else{ // Jika Bukan page terakhir
							$link_next = ($page < $jumlah_page)? $page + 1 : $jumlah_page;
						?>
							<li class="paginate_button page-item" id="dataTable_next">
								<a href="Personal_Info-Nav.php?page=<?php echo $link_next; ?>" aria-controls="dataTable" data-dt-idx="0" tabindex="0" class="page-link">&raquo;</a>
							</li>
							<li class="paginate_button page-item">
								<a href="Personal_Info-Nav.php?page=<?php echo $jumlah_page; ?>" aria-controls="dataTable" data-dt-idx="0" tabindex="0" class="page-link">Last</a>
							</li>
						<?php
						}
						?>
					</ul>
				</div>
			</div>
			<div class="col-sm-12 col-md-4">
				<div class="dataTables_info" id="dataTable_info" role="status" aria-live="polite">Halaman <?php echo $page; ?> of <?php echo $jumlah_page; ?> </div>
			</div>

		</div>
	<!---Loading Bootstrap js--->
<!---		<script src="js/jquery-1.11.1.min.js" type="text/javascript"></script>	--->
<!---		<script src="js/bootstrap.min.js"></script>	--->
  </body>
</html>