<?php 
session_start();
	if($_SESSION['status']!="USER"){
		header("location:../logout.php");
	}
include("header.php"); // memanggil file header.php
include("koneksi.php"); // memanggil file koneksi.php untuk koneksi ke database
$id_author = $_SESSION['username'];
$id_id = $_SESSION['id'];
?>
	<div class="container">
		<div class="content">
			<h2>Selamat datang <b><?php echo $_SESSION['nama']; ?></b> di Aplikasi E-Voting PILKETOS <br>SMK Negeri 1 Magetan</b></p></h2>
			<hr />
			<P> JIKA STATUS = VOTE MENANDAKAN ANDA BELUM MELAKUKAN VOTING, SILAKAN MELAUKAN VOTE DENGAN KLIK TOMBOL "VOTE". JIKA STATUS = BERHASIL MENANDAKAN ANDA SUDAH MELAKUKAN VOTE DAN SUDAH TERCATAT </P>
						<!-- <P><a href="cetak.php" class="btn btn-success" data-toggle="tooltip" title="Cetak Kegiatan"><span class="glyphicon glyphicon-print"> </span>  CETAK KEGIATAN (PDF)</a> -->				
			<!-- <P><?echo '<a href="berkas/'.$id_author.'" class="btn btn-success" data-toggle="tooltip" title="Cetak Kegiatan"><span class="glyphicon glyphicon-print"> </span>  CETAK KEGIATAN (PDF)</a>';?>		-->		
			 <!-- <P><?echo '<a href="bio.php?id='.$id_id.'" class="btn btn-success" data-toggle="tooltip" title="Entry Biodata"><span class="glyphicon glyphicon-user"> </span>  BIODATA</a>';?>				
			--><hr/>
			<H4><strong>PENGUMUMAN :</strong><i>
			<?PHP
			$sql = mysqli_query($koneksi, "SELECT * FROM pengumuman"); 
			while($row = mysqli_fetch_assoc($sql)){ // fetch query yang sesuai ke dalam array
							echo $row['pengumuman']; }?>
			</i></h4><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">Filter</option>
						<?php $filter = (isset($_GET['filter']) ? strtolower($_GET['filter']) : NULL);  ?>
						<option value="siswa" <?php if($filter == 'siswa'){ echo 'selected'; } ?>>SISWA</option>
						                 
						
					</select>
				</div>
			</form> -->
			</th>
			
			<br />
			<!-- memulai tabel responsive -->
			<div class="table-responsive">
				<table class="table table-striped table-hover">
					<tr>
						<th>Tanggal Vote</th>
						<th>Nama</th>
						
						<th>Status Vote</th>
									
						
						
						
					</tr>
					<?php
					if($filter){
						$sql = mysqli_query($koneksi, "SELECT * FROM vote WHERE id_siswa='$id_author' ORDER BY id DESC"); // query jika filter dipilih
					}
					else {
						$sql = mysqli_query($koneksi, "SELECT * FROM vote WHERE id_siswa='$id_author' and status='BERHASIL' OR id_siswa='$id_author' and status='ANTRI' OR id_siswa='$id_author' and status='PENDING' ORDER BY id 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>'.$row['tanggal'].'</td>
								<td>'.$row['nama'].'</td>
								
								<td>';
								if($row['status'] == 'BERHASIL'){
									echo '<button type="button" class="btn btn-success" data-toggle="modal" data-target="#modal-default"> BERHASIL </button>';
								}
								else if ($row['status_vote'] == 'TUTUP' ){
									echo '<button type="button" class="btn btn-warning" data-toggle="modal" data-target="#modal-default2"> VOTE DITUTUP </button>';
								}
								else if ($row['status'] == 'PENDING' and $row['status_vote'] == 'BUKA' ){
									echo '<a href="edit.php?id='.$_SESSION['id'].'" class ="btn btn-danger">VOTE</span>';
								}

									echo '</td>
								<td>';
								if($row['status'] == 'ANTRI'){
									echo '<a href="form_cabut.php?id='.$row['id'].'" class ="btn btn-danger">HAPUS</span>';
								}
								echo '</td>
								</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>
							$time=$row['tanggal'];
							$nama_cpd=$row['nama'];
							$pilihan_cpd=$row['pilihan'];
							$uraian_cpd=$row['uraian'];

						}
					}
					?>
				</table>
			</div> <!-- /.table-responsive -->
		</div> <!-- /.content -->
	</div> <!-- /.container -->
	<div class="modal fade" id="modal-default">
        <div class="modal-dialog">
          <div class="modal-content">
            <div class="modal-header">
              <h4 class="modal-title">Status BERHASIL</h4>
              <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                <span aria-hidden="true">&times;</span>
              </button>
            </div>
            <div class="modal-body">
              <p><?php echo "<b>$nama_cpd</b> Pilihan anda sudah terekam dan <b>BERHASIL</B> pilihan anda adalah No Urut <b>$pilihan_cpd</b>" ?></p>            </div>
            <div class="modal-footer justify-content-between">
              <button type="button" class="btn btn-primary" data-dismiss="modal">Close</button>
            </div>
          </div>
          <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
      </div>
	  <div class="modal fade" id="modal-default2">
        <div class="modal-dialog">
          <div class="modal-content">
            <div class="modal-header">
              <h4 class="modal-title">VOTING DITUTUP</h4>
              <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                <span aria-hidden="true">&times;</span>
              </button>
            </div>
            <div class="modal-body">
              <p><?php echo "<b>$nama_cpd</b> VOTING TELAH DITUTUP" ?></p>            </div>
            <div class="modal-footer justify-content-between">
              <button type="button" class="btn btn-primary" data-dismiss="modal">Close</button>
            </div>
          </div>
          <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
      </div>

<?php 
include("footer.php"); // memanggil file footer.php
?>
