<?php 
session_start();
	if($_SESSION['status']!="admin"){
		header("location:../logout.php");
	}
include("header.php"); // memanggil file header.php
include("koneksi.php"); // memanggil file koneksi.php untuk koneksi ke database
?>
	<div class="container">
		<div class="content">
			<h2>Halo <b><?php echo $_SESSION['nama']; ?></b> Anda telah login sebagai <b>ADMIN</b>.</p></h2>
			<hr />
			<!-- <iframe width="360" height="203" src="https://www.youtube.com/embed/ZYECvO2Yzvk" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> -->
			<hr/>
			<P> KLIK TOMBOL "PENGUMUMAN" UNTUK MEMBUAT PENGUMUMAN </P>
						<P> <a href="edit.php" class="btn btn-warning" <a href="password.php">PENGUMUMAN</span></a>
			<hr/>
			<P> KLIK TOMBOL "STATUS VOTE" UNTUK BUKA/TUTUP VOTING </P>
						<P> <a href="edit_voting.php" class="btn btn-danger" <a href="password.php">STATUS VOTE</span></a>
						
			<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">Filter Urutan</option>
						<?php $filter = (isset($_GET['filter']) ? strtolower($_GET['filter']) : NULL);  ?>
											<option value="X AKL 1" <?php if($filter == 'X AKL 1'){ echo 'selected'; } ?>>X AKL 1</option>
					<option value="X AKL 2" <?php if($filter == 'X AKL 2'){ echo 'selected'; } ?>>X AKL 2</option>
					<option value="X AKL 3" <?php if($filter == 'X AKL 3'){ echo 'selected'; } ?>>X AKL 3</option>
					<option value="X AKL 4" <?php if($filter == 'X AKL 4'){ echo 'selected'; } ?>>X AKL 4</option>
					<option value="X BDP 1" <?php if($filter == 'X BDP 1'){ echo 'selected'; } ?>>X BDP 1</option>
					<option value="X BDP 2" <?php if($filter == 'X BDP 2'){ echo 'selected'; } ?>>X BDP 2</option>
					<option value="X BDP 3" <?php if($filter == 'X BDP 3'){ echo 'selected'; } ?>>X BDP 3</option>
					<option value="X BDP 4" <?php if($filter == 'X BDP 4'){ echo 'selected'; } ?>>X BDP 4</option>
					<option value="X MM" <?php if($filter == 'X MM'){ echo 'selected'; } ?>>X MM</option>
					<option value="X OTP 1" <?php if($filter == 'X OTP 1'){ echo 'selected'; } ?>>X OTP 1</option>
					<option value="X OTP 2" <?php if($filter == 'X OTP 2'){ echo 'selected'; } ?>>X OTP 2</option>
					<option value="X OTP 3" <?php if($filter == 'X OTP 3'){ echo 'selected'; } ?>>X OTP 3</option>
					<option value="X PHT 1" <?php if($filter == 'X PHT 1'){ echo 'selected'; } ?>>X PHT 1</option>
					<option value="X PHT 2" <?php if($filter == 'X PHT 2'){ echo 'selected'; } ?>>X PHT 2</option>
					<option value="X UPW" <?php if($filter == 'X UPW'){ echo 'selected'; } ?>>X UPW</option>
					<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 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 MM" <?php if($filter == 'XI MM'){ echo 'selected'; } ?>>XI MM</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 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="XII AKL 1" <?php if($filter == 'XII AKL 1'){ echo 'selected'; } ?>>XII AKL 1</option>
					<option value="XII AKL 2" <?php if($filter == 'XII AKL 2'){ echo 'selected'; } ?>>XII AKL 2</option>
					<option value="XII AKL 3" <?php if($filter == 'XII AKL 3'){ echo 'selected'; } ?>>XII AKL 3</option>
					<option value="XII AKL 4" <?php if($filter == 'XII AKL 4'){ echo 'selected'; } ?>>XII AKL 4</option>
					<option value="XII BDP 1" <?php if($filter == 'XII BDP 1'){ echo 'selected'; } ?>>XII BDP 1</option>
					<option value="XII BDP 2" <?php if($filter == 'XII BDP 2'){ echo 'selected'; } ?>>XII BDP 2</option>
					<option value="XII BDP 3" <?php if($filter == 'XII BDP 3'){ echo 'selected'; } ?>>XII BDP 3</option>
					<option value="XII BDP 4" <?php if($filter == 'XII BDP 4'){ echo 'selected'; } ?>>XII BDP 4</option>
					<option value="XII MM" <?php if($filter == 'XII MM'){ echo 'selected'; } ?>>XII MM</option>
					<option value="XII OTP 1" <?php if($filter == 'XII OTP 1'){ echo 'selected'; } ?>>XII OTP 1</option>
					<option value="XII OTP 2" <?php if($filter == 'XII OTP 2'){ echo 'selected'; } ?>>XII OTP 2</option>
					<option value="XII OTP 3" <?php if($filter == 'XII OTP 3'){ echo 'selected'; } ?>>XII OTP 3</option>
					<option value="XII PHT 1" <?php if($filter == 'XII PHT 1'){ echo 'selected'; } ?>>XII PHT 1</option>
					<option value="XII PHT 2" <?php if($filter == 'XII PHT 2'){ echo 'selected'; } ?>>XII PHT 2</option>
					<option value="XII UPW" <?php if($filter == 'XII UPW'){ echo 'selected'; } ?>>XII UPW</option>
					<option value="GURU" <?php if($filter == 'GURU'){ echo 'selected'; } ?>>GURU</option>
               
						
					</select>
				</div>
			</form> <!-- end filter -->
			</th>
			
			<br />
			<!-- memulai tabel responsive -->
			<div class="table-responsive">
				<table class="table table-striped table-hover">
					<tr>
						<th>No</th>
						<th>Waktu Vote</th>
						<th>Nama</th>
						<th>Kelas</th>
						<th>Status</th>
						
						
						
						
					</tr>
					<?php
					if($filter){
						$sql = mysqli_query($koneksi, "SELECT * FROM vote WHERE kelas='$filter' ORDER BY tanggal DESC "); // query jika filter dipilih
					}
					else {
						$sql = mysqli_query($koneksi, "SELECT * FROM vote where status='PENDING' ORDER BY tanggal DESC "); // 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['tanggal'].'</td>
								<td>'.$row['nama'].'</td>
								<td>'.$row['kelas'].'</td>
								<td>';
								if($row['status'] == 'BERHASIL'){
									echo '<span class="btn btn-primary">SUDAH VOTE</span>';
								}
								else if ($row['status'] == 'PENDING' ){
									echo '<span class="btn btn-danger">BELUM VOTE</span>';
								}
								
									echo '</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
?>
