<?php 
include("header.php"); // memanggil file header.php
include("koneksi3.php"); // memanggil file koneksi.php untuk koneksi ke database
?>
	<div class="container">
		<div class="content">
			<h2>Data Siswa</h2>
			<hr />
			
			
			<div class="table-responsive">
				<table class="table table-striped table-hover">
				<tr>
				<th>
			<!-- bagian ini untuk memfilter data berdasarkan kelompok -->
			<form class="form-inline" method="get">
				<div class="form-group">
					<select name="filter" class="form-control" onchange="form.submit()">
						<option value="1">PILIH JURUSAN</option>
						<?php $filter = (isset($_GET['filter']) ? strtolower($_GET['filter']) : NULL);  ?>
						<option value="XI AKL 1" <?php if($filter == 'XI AKL 1'){ echo 'selected'; } ?>>XI AKL 1</option>
						<option value="XI AKL 2" <?php if($filter == 'XI AKL 2'){ echo 'selected'; } ?>>XI AKL 2</option>
<option value="XI AKL 3" <?php if($filter == 'XI AKL 3'){ echo 'selected'; } ?>>XI AKL 3</option>
<option value="XI AKL 4" <?php if($filter == 'XI AKL 4'){ echo 'selected'; } ?>>XI AKL 4</option>
<option value="XI OTP 1" <?php if($filter == 'XI OTP 1'){ echo 'selected'; } ?>>XI OTP 1</option>
<option value="XI OTP 2" <?php if($filter == 'XI OTP 2'){ echo 'selected'; } ?>>XI OTP 2</option>
<option value="XI OTP 3" <?php if($filter == 'XI OTP 3'){ echo 'selected'; } ?>>XI OTP 3</option>
<option value="XI BDP 1" <?php if($filter == 'XI BDP 1'){ echo 'selected'; } ?>>XI BDP 1</option>
<option value="XI BDP 2" <?php if($filter == 'XI BDP 2'){ echo 'selected'; } ?>>XI BDP 2</option>
<option value="XI BDP 3" <?php if($filter == 'XI BDP 3'){ echo 'selected'; } ?>>XI BDP 3</option>
<option value="XI BDP 4" <?php if($filter == 'XI BDP 4'){ echo 'selected'; } ?>>XI BDP 4</option>
<option value="XI PHT 1" <?php if($filter == 'XI PHT 1'){ echo 'selected'; } ?>>XI PHT 1</option>
<option value="XI PHT 2" <?php if($filter == 'XI PHT 2'){ echo 'selected'; } ?>>XI PHT 2</option>
<option value="XI UPW" <?php if($filter == 'XI UPW'){ echo 'selected'; } ?>>XI UPW</option>
<option value="XI MM" <?php if($filter == 'XI MM'){ echo 'selected'; } ?>>XI MM</option>
						

						
					</select>
				</div>
			</form> <!-- end filter -->
			</th>
			
			</tr>
			<br />
			<!-- memulai tabel responsive -->
			<div class="table-responsive">
				<table class="table table-striped table-hover">
					<tr>
						<th>No</th>
						<th>NIPD</th>
						<th>Kelas</th>
						<th>NAMA</th>
						<th>PROVIDER</th>
						<th>NO PAKET</th>
						
					</tr>
					<?php
					if($filter){
						$sql = mysqli_query($koneksi, "SELECT * FROM kta WHERE kelas='$filter' ORDER BY nama ASC"); // query jika filter dipilih
					}
					else {
						$sql = mysqli_query($koneksi, "SELECT * FROM kta ORDER BY nama asc"); // jika tidak ada filter maka tampilkan semua entri
					}
					if(mysqli_num_rows($sql) == 0){ 
						echo '<tr><td colspan="14">Data Tidak Ada.</td></tr>'; // jika tidak ada entri di database maka tampilkan 'Data Tidak Ada.'
					}else{ // jika terdapat entri maka tampilkan datanya
						$no = 1; // mewakili data dari nomor 1
						while($row = mysqli_fetch_assoc($sql)){ // fetch query yang sesuai ke dalam array
							echo '
							<tr>
								<td>'.$no.'</td>
								<td>'.$row['nipd'].'</td>
								<td>'.$row['kelas'].'</td>
								<td><a href="edit.php?nipd='.$row['nipd'].'">'.$row['nama'].'</a></td>
								<td>'.$row['provider'].'</td>
								<td>'.$row['no_paket'].'</td>
								
								
							</tr>
							';
							$no++; // mewakili data kedua dan seterusnya <a href="password.php?id_peminat='.$row['id_peminat'].'" title="Ganti Password" data-toggle="tooltip" class="btn btn-warning btn-sm"><span class="glyphicon glyphicon-refresh" aria-hidden="true"></span></a>
						}
					}
					?>
				</table>
			</div> <!-- /.table-responsive -->
		</div> <!-- /.content -->
	</div> <!-- /.container -->
<?php 
include("footer.php"); // memanggil file footer.php
?>