<?php
if ($c['level'] == "superadmin") {
?>

<div class="page-breadcrumb">
    <div class="row">
        <div class="col-5 align-self-center">
            <h4 class="page-title">Popular Game</h4>
        </div>
    </div>
</div>

<div class="container-fluid">
<div class="row">

<!-- FORM INPUT -->
<div class="col-lg-4">
<div class="card">
<div class="card-body">
<h4 class="card-title">Tambah Popular</h4>

<form method="POST" action="?page=tambah_popular" enctype="multipart/form-data">

<div class="form-group">
<label>Title</label>
<input type="text" name="title" class="form-control" required>
</div>

<div class="form-group">
<label>Provider</label>
<input type="text" name="provider" class="form-control" required>
</div>

<div class="form-group">
<label>Image</label>
<input type="file" name="image" class="form-control" required>
</div>

<div class="form-group">
<label>Players</label>
<input type="number" name="players" class="form-control" value="0">
</div>

<div class="form-group">
<label>Status</label>
<select name="status" class="form-control">
<option value="active">Active</option>
<option value="inactive">Inactive</option>
</select>
</div>

<div class="form-group">
<label>Sort</label>
<input type="number" name="sort" class="form-control" value="0">
</div>

<button type="submit" name="submit" class="btn btn-success">Submit</button>

</form>
</div>
</div>
</div>

<!-- TABLE -->
<div class="col-lg-8">
<div class="card">
<div class="card-body">
<h4 class="card-title">Daftar Popular</h4>
</div>

<div class="table-responsive">
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>#</th>
<th>Image</th>
<th>Title</th>
<th>Provider</th>
<th>Players</th>
<th>Status</th>
<th>Aksi</th>
</tr>
</thead>
<tbody>

<?php
$no=1;
$q = mysqli_query($koneksi,"SELECT * FROM tb_popular ORDER BY sort ASC, id DESC");
while($d=mysqli_fetch_array($q)){
?>
<tr>
<td><?= $no++; ?></td>
<td><img src="../../uploads/popular/<?= $d['image']; ?>" width="60"></td>
<td><?= $d['title']; ?></td>
<td><?= $d['provider']; ?></td>
<td><?= number_format($d['players']); ?></td>
<td>
<span class="badge badge-<?= $d['status']=="active"?"success":"secondary"; ?>">
<?= $d['status']; ?>
</span>
</td>
<td>
<a href="?page=edit_popular&id=<?= $d['id']; ?>" class="btn btn-primary btn-sm">Edit</a>
<a href="?page=hapus_popular&id=<?= $d['id']; ?>" class="btn btn-danger btn-sm"
onclick="return confirm('Hapus data?')">Hapus</a>
</td>
</tr>
<?php } ?>

</tbody>
</table>
</div>
</div>
</div>

</div>
</div>

<?php
}else{
echo "<script>window.location='?page=dashboard'</script>";
}
?>