<?php
defined('APK') or exit('Anda tidak dizinkan mengakses langsung script ini!');
?>

<?php if ($ac == '') : ?>
	
			<div class='row'>
             <div class='col-md-12'>
             <div class='panel panel-default'>
               <div class="panel-heading" style="height:45px">
                    <div class='box-tools pull-right '>
                    </div>
					<h4 class='box-title'><i class="fas fa-rss"></i> Daftar Kelas</h4>
                </div>
				<div class='box-header with-border '>
			   <div class='box-tools pull-right '>
			   <table>
			   <tr>
			   <td>
			   <div class="form-group-sm">
			  <select name='jenjang' class='form-control' >
              <option value=""><?= $setting['sekolah'] ?></option>
               </select>
			   </div>
				</td>
			   <td>
			   <div class="form-group-sm">
			  <select name='jenjang' class='form-control' >
              <option value=""><?= $setting['jenjang'] ?></option>
               </select>
			   </div>
				</td>
				<td>
				<div class="form-group-sm">
			  <select name='jenjang' class='form-control'>
               <option value=""><?= $setting['kota'] ?></option>
               </select>
			   </div>
				</td>
				<td>
				<div class="form-group-sm">
			  <select name='jenjang' class='form-control' >
               <option value=""><?= $setting['kecamatan'] ?></option>
               </select>
			   </div>
				</td>
				</tr>					
			</table>
			</div>
			 <h4 class='box-title'></h4>
			  </div>
			  <div class="box-body">
                    <ul class="nav nav-tabs">
                        <li class="active"><a href="#tab_1" data-toggle="tab" aria-expanded="true" >Rekap Nilai</a></li>                        
                    </ul>					
					<div class="tab-content">
                        <div class="tab-pane active" id="tab_1" >						
				<div class="panel panel-default">
				<div class="col-md-1"></div>
				<div class="col-md-10">
				<div class='box-body'><?= $info ?>
					<?php $jq = mysqli_query($koneksi, "SELECT * FROM kelas WHERE id_kelas<>'' "); ?>
					<?php while ($jenis = mysqli_fetch_array($jq)) : ?>
						<div class="col-lg-4 ">
							<div class="small-box bg-green">
								<div class="inner">
									<h4 class="siskolah text-center">Kelas <?= $jenis['id_kelas'] ?></h4>

								</div>
								
								<a href="?pg=<?= $pg ?>&ac=lihat&idk=<?= $jenis['id_kelas'] ?>" class="small-box-footer">Lihat Nilai <i class="fa fa-arrow-circle-right"></i></a>
							</div>
						</div>

					<?php endwhile; ?>
				</div>
			</div>
		</div>
	</div>
<?php elseif ($ac == 'lihat') : ?>
	<?php
	$id_kelas = $_GET['idk'];
	$mapel = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM mapel WHERE groupsoal='CBT' ")); ?>
	
			<div class='row'>
             <div class='col-md-12'>
				<div class='panel panel-default'>
					<div class="panel-heading" style="height:45px">
						<div class='box-tools pull-right '>
							<a class='btn btn-sm btn-success' href='cbt/report_excel_all.php?k=<?= $id_kelas ?>'><i class='fa fa-download'></i> Excel</a>
							<a class='btn btn-sm btn-danger' href='?pg=semuanilai'><i class='fa fa-times'></i> Keluar</a>
                    </div>
					<h4 class='box-title'><i class="fas fa-rss"></i> Rekap Nilai Kelas <?= $id_kelas ?></h4>
                </div>
					<div class='box-header with-border '>
			   <div class='box-tools pull-right '>
			   <table>
			   <tr>
			   <td>
			   <div class="form-group-sm">
			  <select name='jenjang' class='form-control' >
              <option value=""><?= $setting['sekolah'] ?></option>
               </select>
			   </div>
				</td>
			   <td>
			   <div class="form-group-sm">
			  <select name='jenjang' class='form-control' >
              <option value=""><?= $setting['jenjang'] ?></option>
               </select>
			   </div>
				</td>
				<td>
				<div class="form-group-sm">
			  <select name='jenjang' class='form-control'>
               <option value=""><?= $setting['kota'] ?></option>
               </select>
			   </div>
				</td>
				<td>
				<div class="form-group-sm">
			  <select name='jenjang' class='form-control' >
               <option value=""><?= $setting['kecamatan'] ?></option>
               </select>
			   </div>
				</td>
				</tr>					
			</table>
			</div>
			 <h4 class='box-title'></h4>
			  </div>
			  <div class="box-body">
                    <ul class="nav nav-tabs">
                        <li class="active"><a href="#tab_1" data-toggle="tab" aria-expanded="true" >Rekap Nilai</a></li>                        
                    </ul>					
					<div class="tab-content">
                        <div class="tab-pane active" id="tab_1" >						
				<div class="panel panel-default">
				<div class='box-body'>
					<div class='table-responsive'>
						<table id='example' class='table table-bordered table-hover'>
							<thead>
								<tr>
									<th rowspan='3' style="vertical-align:middle; width:5px">#</th>
									<th style='text-align:center;vertical-align:middle' rowspan='3'>No Peserta</th>
									<th style='text-align:center;vertical-align:middle' rowspan='3'>Nama Peserta</th>
									<th style='text-align:center;vertical-align:middle' rowspan='3'>Kelas</th>
									<?php
									$kodeujian = mysqli_fetch_array(mysqli_query($koneksi, "select * from jenis where status='aktif'"));
									$mapelQ = mysqli_query($koneksi, "SELECT * FROM mapel a JOIN nilai b ON a.id_mapel=b.id_mapel where b.kode_ujian='$kodeujian[id_jenis]' GROUP BY b.id_mapel ");
									while ($mapel = mysqli_fetch_array($mapelQ)) :
										echo "<th style='text-align:center' colspan='3'>$mapel[nama]</th>";
									endwhile;
									?>
								</tr>
								<tr>
									<?php
									$kode = mysqli_query($koneksi, "SELECT * FROM mapel a JOIN nilai b ON a.id_mapel=b.id_mapel where b.kode_ujian='$kodeujian[id_jenis]' GROUP BY b.id_mapel");
									while ($mapel = mysqli_fetch_array($kode)) :
										echo "<th style='text-align:center' colspan='3'>$mapel[kode_ujian]</th>";
									endwhile;
									?>
								</tr>
								<tr>
									<?php $mapelQ = mysqli_query($koneksi, "SELECT * FROM mapel a JOIN nilai b ON a.id_mapel=b.id_mapel where b.kode_ujian='$kodeujian[id_jenis]' GROUP BY b.id_mapel "); ?>
									<?php while ($mapel = mysqli_fetch_array($mapelQ)) : ?>
										<th style='text-align:center'>B</th>
										<th style='text-align:center'>S</th>
										<th style='text-align:center'>SKOR</th>
									<?php endwhile; ?>
								</tr>
							</thead>
							<tbody>
								<?php $siswaQ = mysqli_query($koneksi, "SELECT * FROM siswa WHERE id_kelas='$id_kelas' ORDER BY nama ASC"); ?>
								<?php while ($siswa = mysqli_fetch_array($siswaQ)) : ?>
									<?php
									$no++;
									$ket = '';
									$esai = $lama = $jawaban = $skor = $total = '--';
									?>
									<tr>
										<td><?= $no ?></td>
										<td style="text-align:center"><?= $siswa['no_peserta'] ?></td>
										<td><?= $siswa['nama'] ?></td>
										<td style="text-align:center"><?= $siswa['id_kelas'] ?></td>
										<?php $mapelQ = mysqli_query($koneksi, "SELECT * FROM mapel a JOIN nilai b ON a.id_mapel=b.id_mapel where b.kode_ujian='$kodeujian[id_jenis]' GROUP BY b.id_mapel "); ?>
										<?php while ($mapel = mysqli_fetch_array($mapelQ)) : ?>
											<?php
											$nilaiQ = mysqli_query($koneksi, "SELECT * FROM nilai WHERE id_mapel='$mapel[id_mapel]' AND id_siswa='$siswa[id_siswa]' ");
											$nilaiC = mysqli_num_rows($nilaiQ);
											$nilai = mysqli_fetch_array($nilaiQ);
											?>
											<td style="text-align:center"><?= $nilai['jml_benar'] ?></td>
											<td style="text-align:center"><?= $nilai['jml_salah'] ?></td>
											<td style="text-align:center"><?= $nilai['skor'] ?></td>
										<?php endwhile; ?>
									</tr>
								<?php endwhile; ?>
							</tbody>
						</table>
					</div>
				</div><!-- /.box-body -->
			</div><!-- /.box -->
		</div>
	</div>
<?php endif; ?>