<?php 
include 'header.php';

if(isset($_GET['page'])){
	$id = $_GET['id'];
	$result = mysqli_query($conn, "DELETE FROM admin WHERE id = '$id'");

	if($result){
		echo "
		<script>
		alert('DATA BERHASIL DIHAPUS');
		window.location = 'm_admin.php';
		</script>
		";
	}
}

?>

<!DOCTYPE html>
<html lang="id">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Master Produk - UMKM Galeri 3D</title>
<style>
body {
    background: #f3f4f6;
    font-family: 'Poppins', sans-serif;
    margin: 0;
    padding: 0;
}
.container {
  	max-width: 1200px;
    margin: 5px auto;
    padding: 0 30px;
}
</style>
</head>
<body>
<div class="container">
	<h2 style=" width: 100%; border-bottom: 4px solid gray"><b>Master Admin</b></h2>
	<table class="table table-striped">
		<thead>
			<tr>
				<th scope="col">No</th>
				<th scope="col">Detail</th>
				<th scope="col">Username</th>
				<th scope="col">Level</th>
				<th scope="col">Action</th>
			</tr>
		</thead>
		<tbody>
			<?php 
			$result = mysqli_query($conn, "SELECT * FROM admin order by id asc");
			$no =1;
			while ($row = mysqli_fetch_assoc($result)) {
				?>
				<tr>

					<th scope="row"><?php echo $no; ?></th>
					<td>
					<b><?= $row['nama_toko']; ?></b><br>
					<?= $row['nama_admin']; ?><br>
					<small><?=$row['tanggal']; ?></small>
					</td>
					<td><?= $row['username'];  ?></td>
					<td><?= $row['level'];  ?></td>
					<td>
						 <a href="edit_admin.php?id=<?= $row['id']; ?>" class="btn btn-warning"><i class="glyphicon glyphicon-edit"></i></a>
                        <a href="proses/del_admin.php?id=<?= $row['id']; ?>" class="btn btn-danger" onclick="return confirm('Yakin ingin menghapus admin ini?')"><i class="glyphicon glyphicon-trash"></i></a>
                    </td>
				</tr>
				<?php 
				$no++;
			}
			?>
		</tbody>
	</table>
    <a href="tm_admin.php" class="btn btn-success"><i class="glyphicon glyphicon-plus-sign"></i> Tambah Admin</a>
</div>
<!-- Button trigger modal -->

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
				<h4 class="modal-title" id="myModalLabel">Modal title</h4>
			</div>
			<div class="modal-body">
				...
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
				<button type="button" class="btn btn-primary">Save changes</button>
			</div>
		</div>
	</div>
</div>

</body>
</html>

