<?php
defined('APK') or exit('Anda tidak dizinkan mengakses langsung script ini!');
$smt = $setting['semester'];
?>           
	<?php if ($ac == '') : ?>
                   <div class="row">
                          <div class="col-md-8">
                                <div class="card">
                                    <div class="card-header">
                                        <h5 class="card-title">INPUT DESKRIPSI RAPOR</h5>
										 <a href="erapor" class="btn btn-secondary kanan" data-bs-toggle="tooltip" data-bs-placement="top" title="Kembali"><i class="material-icons">arrow_back</i></a>						
                                    </div>
                                    <div class="card-body">
									
									<div class="card-box table-responsive">
                                        <table id="datatable1" class="table table-bordered table-hover" style="width:100%;font-size:12px">
                                            <thead>
                                                <tr>
                                                    <th width="5%">NO</th> 
													<th>KELAS</th>													                                                  
                                                    <th>MATA PELAJARAN</th>
													 <th>GURU PENGAMPU</th>
													  <th>KI-3</th>
													   <th>KI-4</th>
                                                </tr>
                                            </thead>
                                            <tbody>
											<?php
											$no=0;
											if($user['level']=='admin'):
											$query = mysqli_query($koneksi, "SELECT * FROM nilai_rapor GROUP BY kelas"); 
											else:
											$query = mysqli_query($koneksi, "SELECT * FROM nilai_rapor WHERE idguru='$user[id_user]' GROUP BY kelas"); 	
											endif;
											  while ($data = mysqli_fetch_array($query)) :
											 $mapel = fetch($koneksi,'mata_pelajaran',['kode'=>$data['kode']]);
											  $guru = fetch($koneksi,'users',['id_user'=>$data['idguru']]);
											$no++;
											   ?>
                                                <tr>
                                                    <td><?= $no; ?></td>
                                                     <td><?= $data['kelas'] ?></td>                               
													   <td><?= $mapel['nama_mapel'] ?></td>													   
													  <td><?= $guru['nama'] ?></td>
													  <td>
													  <a href="?pg=deskriprapor&ac=input3&m=<?= $data['kode'] ?>&k=<?= $data['kelas'] ?>" class="btn btn-sm btn-primary" data-bs-toggle="tooltip" data-bs-placement="top" title="Deskripsi Rapor"><i class="material-icons">add</i> </a>
													  </td>
													  <td>
													  <a href="?pg=deskriprapor&ac=input4&m=<?= $data['kode'] ?>&k=<?= $data['kelas'] ?>" class="btn btn-sm btn-success" data-bs-toggle="tooltip" data-bs-placement="top" title="Deskripsi Rapor"><i class="material-icons">add</i> </a>
													  </td>
                                                </tr>
												<?php endwhile; ?>
                                                </table>
												 </div>
											</div>
										</div>
										
									</div>
									
					       <div class="col-md-4">
                     
                                <div class="card widget widget-payment-request">
                                    <div class="card-header">
                                  
                                    </div>
                                    <div class="card-body">
                                        <div class="widget-payment-request-container">
                                            <div class="widget-payment-request-author">
                                                <div class="avatar m-r-sm">
                                                    <img src="../images/user.png" alt="">
                                                </div>
                                                <div class="widget-payment-request-author-info">
                                                    <span class="widget-payment-request-author-name"><?= strtoupper($user['nama']) ?></span>
                                                    <span class="widget-payment-request-author-about"><?= $setting['sekolah'] ?></span>
                                               
											   </div>
                                            </div>
											<?php $idj = $_GET['idj']; ?>
											<?php $desQ = fetch($koneksi,'jadwal_rapor',['id'=>$idj]); ?>
									<div class="widget-payment-request-info m-t-md">
									 <div class="d-grid gap-2">
									<button class="btn btn-dark" type="button" disabled>
										<span class="spinner-grow spinner-grow-sm" role="status" aria-hidden="true"></span>
										 PILIH MAPEL DAN KELAS
									</button>
											</div>
											
									
										<div class="widget-payment-request-info m-t-md">
										 <div class="d-grid gap-2">
										<button class="btn btn-secondary" type="button" disabled>Pastikan Semua KD Mapel ini Sudah di isi</button>
										 </div>
										  </div>
										
										</div>
									 </div>
					            </div>
								</div>
							</div>
						</div>
					</div>
				</div>
							
							
							
             <?php elseif ($ac == 'input3'): ?>
			<?php $kode = $_GET['m']; ?>
			<?php $kelas = $_GET['k']; ?>
			<?php $tk = fetch($koneksi,'kelas',['kelas'=>$kelas]); ?>
	                <div class="row">
                          <div class="col-md-12">
                                <div class="card">
                                    <div class="card-header">
                                        <h5 class="bold">DESKRIPSI RAPOR <span class="badge badge-secondary">PENGETAHUAN <?= $kode ?> <?= $kelas ?></span></h5>
										 <a href="erapor" class="btn btn-secondary pull-right" data-bs-toggle="tooltip" data-bs-placement="top" title="Kembali"><i class="material-icons">arrow_back</i></a>						
                                    </div>
                                    <div class="card-body">
									
									<div class="card-box table-responsive">
                                        <table id="datatable1" class="table table-bordered table-hover" style="width:100%;font-size:12px">
                                            <thead>
                                                <tr>
                                                    <th width="5%">NO</th> 
                                                    <th  width="20%">NAMA SISWA</th>
													 <th width="5%">NR</th>
													   <th>CAPAIAN KOMPETENSI DASAR TERENDAH</th>
													    <th>CAPAIAN KOMPETENSI DASAR TERTINGGI</th>
														<th width="5%"></th>
                                                </tr>
                                            </thead>
                                            <tbody>
											<?php
											$no=0;
											
											$query = mysqli_query($koneksi, "SELECT * FROM nilai_rapor WHERE kelas='$kelas' AND kode='$kode'"); 	
											  while ($data = mysqli_fetch_array($query)) :
											
											$no++;
											   ?>
											   		<?php $siswa = fetch($koneksi,'siswa',['nis'=>$data['nis']]); ?>
													
                                                <tr>
                                                    <td><?= $no; ?></td>                                              
													   <td><?= $siswa['nama'] ?></td>																											   
													  <td><?= $data['nilai3'] ?></td>
													    <td><?= $data['desmin3'] ?></td>
													<td><?= $data['desmax3'] ?></td>
													 <td>
													 <a href="?pg=deskriprapor&ac=edit&id=<?= $data['id'] ?>"  class="btn btn-sm btn-primary"><i class="material-icons">edit</i></a>
												</td>
                                                </tr>
												<?php endwhile; ?>
                                                </table>
												 </div>
											</div>
										</div>
										
									
								</div>
							</div>
						</div>
					</div>
				</div>
							
							
			 <?php elseif ($ac == 'edit'): ?>
			  <?php include"cbtserver_rapor/radio.php"; ?>
			<?php $id = $_GET['id']; ?>	
			<?php 
			$nl = fetch($koneksi,'nilai_rapor',['id'=>$id]);
			$kode = $nl['kode'];
			$kelas = $nl['kelas'];
			 ?>
			<?php $siswa = fetch($koneksi,'siswa',['nis'=>$nl['nis']]); ?>
	                <div class="row">
                          <div class="col-md-12">
                                <div class="card">
                                    <div class="card-header">
                                        <h5 class="bold">DESKRIPSI RAPOR <span class="badge badge-secondary"><?= $siswa['nama'] ?></span> | <span class="badge badge-primary"><?= $nl['nilai3'] ?></span></h5>
													
                                    </div>
                                    <div class="card-body">
									<form id='formmapel3' >
									<input type="hidden" name="nis" value="<?= $id; ?>" required>
									<div class="card-box table-responsive">
                                        <table id="datatable1" class="table table-bordered" style="width:100%;font-size:12px">
                                            <thead>
                                                <tr>   
                                                    <th>
													<button class="btn btn-secondary" type="button" disabled>
													<span class="spinner-grow spinner-grow-sm" role="status" aria-hidden="true"></span>
													Capaian Kompetensi Dasar Terendah
												</button>
													</th>											
													 <th>
													 <button class="btn btn-success" type="button" disabled>
													<span class="spinner-grow spinner-grow-sm" role="status" aria-hidden="true"></span>
													Capaian Kompetensi Dasar Tertinggi
												</button>
													 </th>													  
														<th width="5%">SIMPAN</th>
                                                </tr>
                                            </thead>
                                            <tbody>
												
											   		
                                                <tr>
												
                                                    <td>
													<?php
											$query = mysqli_query($koneksi, "SELECT * FROM deskrip WHERE tingkat='$siswa[level]' AND kodemap='$nl[kode]' AND ket='KI3' AND smt='$smt'"); 	
											  while ($data = mysqli_fetch_array($query)) :
										
											   ?>
											   
											  <div class="row mb-3">										  
											  <label class="radio col-sm-1"><input type='radio' name="desmin" id="desmin" value="<?= $data['deskripsi'] ?>" required="true"> 
							              <span class="check"></span></label>
										  <div class="col-sm-11">
										  <?= $data['deskripsi'] ?>
										  </div>
											  </div> 
													<?php endwhile; ?>
													</td>                                              
													   					   
													  
													    <td>														
														<?php
											$query2 = mysqli_query($koneksi, "SELECT * FROM deskrip WHERE tingkat='$siswa[level]' AND kodemap='$nl[kode]' AND ket='KI3' AND smt='$smt' ORDER BY id DESC"); 	
											  while ($data2 = mysqli_fetch_array($query2)) :
										
											   ?>
											 <div class="row mb-3">										  
											  <label class="radio col-sm-1"><input type='radio' name="desmax" id="desmax" value="<?= $data2['deskripsi'] ?>" required="true"> 
							              <span class="check"></span></label>
										  <div class="col-sm-11">
										  <?= $data2['deskripsi'] ?>
										  </div>
											  </div> 
													<?php endwhile; ?>
														</td>
													 <td>
													 <button type="submit" class="bn btn-dark" id="blockui-2"><i class="material-icons">edit</i></button>
													 </td>
													
                                                </tr>
												</tbody>
                                                </table>
												</form>
												 </div>
											</div>
										</div>
									
								</div>
							
							<script>
								$('#formmapel3').submit(function(e){
									e.preventDefault();
									var data = new FormData(this);
									$.ajax(
									{
										type: 'POST',
										 url: 'cbtserver_rapor/tnilai.php?pg=tambah',
										 enctype: 'multipart/form-data',
										data: data,
										cache: false,
										contentType: false,
										processData: false,
										success: function(data){   		
										if (data == 'OK') {		
										
										setTimeout(function()
										{
										   window.location.replace('?pg=deskriprapor&ac=input3&m=<?= $kode ?>&k=<?= $kelas ?>');
										}, 1500);
										 } else {
										 iziToast.warning(
										{
											title: 'Gagal!',
											message: 'Data Tidak boleh sama',
											titleColor: '#FFFF00',
											messageColor: '#fff',
											backgroundColor: '#8b0000',
											 progressBarColor: '#FFFF00',
											  position: 'topRight'
										});
										setTimeout(function(){
											window.location.reload();
										}, 2000);	
									   }			
									}
								});
								return false;
							});	
											
									</script>


				
             <?php elseif ($ac == 'input4'): ?>
			<?php $kode = $_GET['m']; ?>
			<?php $kelas = $_GET['k']; ?>
			<?php $tk = fetch($koneksi,'kelas',['kelas'=>$kelas]); ?>
	                <div class="row">
                          <div class="col-md-12">
                                <div class="card">
                                    <div class="card-header">
                                        <h5 class="bold">DESKRIPSI RAPOR <span class="badge badge-secondary">KETERAMPILAN <?= $kode ?> <?= $kelas ?></span></h5>
										 <a href="erapor" class="btn btn-secondary pull-right" data-bs-toggle="tooltip" data-bs-placement="top" title="Kembali"><i class="material-icons">arrow_back</i></a>						
                                    </div>
                                    <div class="card-body">
									
									<div class="card-box table-responsive">
                                        <table id="datatable1" class="table table-bordered table-hover" style="width:100%;font-size:12px">
                                            <thead>
                                                <tr>
                                                    <th width="5%">NO</th> 
                                                    <th  width="20%">NAMA SISWA</th>
													 <th width="5%">NR</th>
													   <th>CAPAIAN KOMPETENSI DASAR TERENDAH</th>
													    <th>CAPAIAN KOMPETENSI DASAR TERTINGGI</th>
														<th width="5%"></th>
                                                </tr>
                                            </thead>
                                            <tbody>
											<?php
											$no=0;
											
											$query = mysqli_query($koneksi, "SELECT * FROM nilai_rapor WHERE kelas='$kelas' AND kode='$kode'"); 	
											  while ($data = mysqli_fetch_array($query)) :
											
											$no++;
											   ?>
											   		<?php $siswa = fetch($koneksi,'siswa',['nis'=>$data['nis']]); ?>
													
                                                <tr>
                                                    <td><?= $no; ?></td>                                              
													   <td><?= $siswa['nama'] ?></td>																											   
													  <td><?= $data['nilai4'] ?></td>
													    <td><?= $data['desmin4'] ?></td>
													<td><?= $data['desmax4'] ?></td>
													 <td>
													 <a href="?pg=deskriprapor&ac=edit4&id=<?= $data['id'] ?>"  class="btn btn-sm btn-primary"><i class="material-icons">edit</i></a>
												</td>
                                                </tr>
												<?php endwhile; ?>
                                                </table>
												 </div>
											</div>
										</div>
										
									
								</div>
							</div>
						</div>
					</div>
				</div>
							
          <?php elseif ($ac == 'edit4'): ?>
			<?php $id = $_GET['id']; ?>	
			<?php 
			$nl = fetch($koneksi,'nilai_rapor',['id'=>$id]);
			$kode = $nl['kode'];
			$kelas = $nl['kelas'];
			 ?>
			<?php $siswa = fetch($koneksi,'siswa',['nis'=>$nl['nis']]); ?>
	                <div class="row">
                          <div class="col-md-12">
                                <div class="card">
                                    <div class="card-header">
                                        <h5 class="bold">DESKRIPSI RAPOR <span class="badge badge-secondary"><?= $siswa['nama'] ?></span> | <span class="badge badge-primary"><?= $nl['nilai3'] ?></span></h5>
													
                                    </div>
                                    <div class="card-body">
									<form id='formmapel4' >
									<input type="hidden" name="nis" value="<?= $id; ?>" required>
									<div class="card-box table-responsive">
                                        <table id="datatable1" class="table table-bordered" style="width:100%;font-size:12px">
                                            <thead>
                                                <tr>   
                                                    <th>
													<button class="btn btn-secondary" type="button" disabled>
													<span class="spinner-grow spinner-grow-sm" role="status" aria-hidden="true"></span>
													Capaian Kompetensi Dasar Terendah
												</button>
													</th>											
													 <th>
													 <button class="btn btn-success" type="button" disabled>
													<span class="spinner-grow spinner-grow-sm" role="status" aria-hidden="true"></span>
													Capaian Kompetensi Dasar Tertinggi
												</button>
													 </th>													  
														<th width="5%">SIMPAN</th>
                                                </tr>
                                            </thead>
                                            <tbody>
												
											   		
                                                <tr>
												
                                                    <td>
													<?php
											$query = mysqli_query($koneksi, "SELECT * FROM deskrip WHERE tingkat='$siswa[level]' AND kodemap='$nl[kode]' AND ket='KI4'"); 	
											  while ($data = mysqli_fetch_array($query)) :
										
											   ?>
											  <p><input class="form-check-input" type="radio" name="desmin" id="desmin" value="<?= $data['deskripsi'] ?>" required="true">
												<label class="form-check-label" for="desmin">
													<?= $data['deskripsi'] ?>
													</label></p>
													<?php endwhile; ?>
													</td>                                              
													   					   
													  
													    <td>														
														<?php
											$query2 = mysqli_query($koneksi, "SELECT * FROM deskrip WHERE tingkat='$siswa[level]' AND kodemap='$nl[kode]' AND ket='KI4' ORDER BY id DESC"); 	
											  while ($data2 = mysqli_fetch_array($query2)) :
										
											   ?>
											  <p><input class="form-check-input" type="radio" name="desmax" id="desmax" value="<?= $data2['deskripsi'] ?>" required="true">
												<label class="form-check-label" for="desmax">
													<?= $data2['deskripsi'] ?>
													</label></p>
													<?php endwhile; ?>
														</td>
													 <td>
													 <button type="submit" class="bn btn-dark" id="blockui-2"><i class="material-icons">edit</i></button>
													 </td>
													
                                                </tr>
												
                                                </table>
												</form>
												 </div>
											</div>
										</div>
									
								</div>
							
							<script>
								$('#formmapel4').submit(function(e){
									e.preventDefault();
									var data = new FormData(this);
									$.ajax(
									{
										type: 'POST',
										 url: 'cbtserver_rapor/tnilai.php?pg=tambah4',
										 enctype: 'multipart/form-data',
										data: data,
										cache: false,
										contentType: false,
										processData: false,
										success: function(data){   		
										if (data == 'OK') {		
										
										setTimeout(function()
										{
										   window.location.replace('?pg=deskriprapor&ac=input4&m=<?= $kode ?>&k=<?= $kelas ?>');
										}, 1500);
										 } else {
										 iziToast.warning(
										{
											title: 'Gagal!',
											message: 'Data Tidak boleh sama',
											titleColor: '#FFFF00',
											messageColor: '#fff',
											backgroundColor: '#8b0000',
											 progressBarColor: '#FFFF00',
											  position: 'topRight'
										});
										setTimeout(function(){
											window.location.reload();
										}, 2000);	
									   }			
									}
								});
								return false;
							});	
											
									</script>









									
					  <?php endif ?>
					  
					  
					  
					  	  
					  
					  
					