<?php
	require_once("koneksi.php");
    include 'header.php';

    $per_hal		= 10;
	$jumlah_record	= mysqli_query($koneksi, "SELECT * FROM t_user WHERE role=2");
	$no 			= 1;
	$jum 			= mysqli_num_rows($jumlah_record);
	$halaman 		= ceil($jum / $per_hal);
	$page 			= (isset($_GET['page'])) ? (int)$_GET['page'] : 1;
	$start 			= ($page - 1) * $per_hal;

	global $sql;
	$sql = mysqli_query($koneksi, "SELECT * FROM t_user WHERE role = 2 LIMIT $start, $per_hal"); 
?>

	<!-- breadcrumbs -->
		<div class="breadcrumbs">
			<div class="container">
				<ol class="breadcrumb breadcrumb1">
					<li><span><i class="fa fa-sign-in" aria-hidden="true"></i><a href="login.php"> Masuk</a></span></li>
					<li class="active">Kelola Data Pelanggan</li>
					<?php 
						if(isset($_POST['cari'])) {
							$cari 	= $_POST['search'];
							$sql 	= mysqli_query($koneksi, "SELECT * FROM t_user WHERE username LIKE '%$cari%' ORDER BY id_user");
						}
					?>
					<div class="w3l_search">
						<form action="" method="post">
							<input type="search" name="search" placeholder="Cari Nama Pelanggan" required="">
							<button type="submit" class="btn btn-default search" aria-label="Left Align" name="cari">
								<i class="fa fa-search" aria-hidden="true"> </i>
							</button>
							<div class="clearfix"></div>
						</form>
					</div>
				</ol>
			</div>
		</div>
	<!-- //breadcrumbs -->
		<div class="col-md-12">
			<table class="col-md-3">
				<tr>
					<br>
					<td>Jumlah Pelanggan</td>		
					<td>: <b><?php echo $jum; ?></b></td>
				</tr>
			</table>
		</div>
	<!-- checkout -->
			<div class="container"><br><br><br>
				<h2>Daftar Pelanggan : </h2><br>
				<div class="checkout-right">
					<table class="timetable_sub">
						<thead>
							<tr>
								<th>ID Pelanggan</th>
								<th>Nama Lengkap</th>
								<th>Alamat</th>
								<th>Nomor Ponsel</th>
								<th>Email</th>
								<th>Opsi</th>
							</tr>
						</thead>
						<?php
							while($data = mysqli_fetch_array($sql)) {	
						?>
						<tr class="rem1">
							<td class="invert"><?php echo $data['id_user']; ?></td>
							<td class="invert"><?php echo $data['nama_lengkap']; ?></td>
							<td class="invert"><?php echo $data['alamat']; ?></td>
							<td class="invert">0<?php echo $data['nomor_ponsel']; ?></td>
							<td class="invert"><?php echo $data['email']; ?></td>
							<td class="invert">
								<div class="rem">
									<div>
						                <a onclick="if(confirm('Apakah Anda yakin ingin menghapus data ini ?')){ location.href='deleteprofile_process.php?id=<?php echo $data['id_user']; ?>' }">
						                	<img src="images/close_1.png" />
						                </a>
									</div>
								</div>
							</td>
						</tr>
						<?php
							}
						?>
						<?php
							if(	isset($_SESSION['administrator'])){
								echo '	';
							}
							else {
								echo '
									<tr><td colspan="7" align="center" style="background-color:#ffffff"> Data pelanggan kosong ! </td></tr></table>
								';
							}
						?>
					</table>
				</div>
			<nav class="numbering">
				<ul class="pagination paging">
					<li>
						<?php 
							for($page=1;$page<=$halaman;$page++){
								?>
								<li><a href="?page=<?php echo $page ?>"><?php echo $page ?></a></li>
								<?php
							}
						?>
					</li>
					<!--<li>
						<a href="?page=<?php echo $x++ ?>" aria-label="Next">
						<span aria-hidden="true">&raquo;</span>
						</a>
					</li>-->
					<br><br><br>
				</ul>
			</nav>		
		</div>
	<!-- //checkout -->

<?php
	include 'footer.php';
?>