<?php
defined('APK') or exit('Anda tidak dizinkan mengakses langsung script ini!');
 if (empty($_GET['kelas'])) {
        $kelas = "";
    } else {
        $kelas = $_GET['kelas'];
    }
	 if (empty($_GET['eskul'])) {
        $eskul = "";
    } else {
        $eskul = $_GET['eskul'];
    }
?>           
	
                   <div class="row">
                          <div class="col-md-8">
                                <div class="card">
                                    <div class="card-header">
                                        <h5 class="bold">INPUT NILAI ESKUL <span class="badge badge-secondary"><?= strtoupper($eskul) ?> <?= $kelas ?></span></h5>
										
                                    </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>NIS</th>													                           
                                                    <th>NAMA SISWA</th>
													 <th>NILAI</th>
													
													  <th>INPUT</th>
                                                </tr>
                                            </thead>
                                            <tbody>
											<?php
											$no=0;
											
											$query = mysqli_query($koneksi, "SELECT * FROM siswa_eskul WHERE eskuler='$eskul' AND kelas='$kelas'"); 	
											  while ($dt = mysqli_fetch_array($query)) :
											 $data = fetch($koneksi,'siswa',['nis'=>$dt['nis'],'kelas'=>$kelas]);
											$no++;
											   ?>
                                                <tr>
                                                    <td><?= $no; ?></td>
                                                     <td><?= $data['nis'] ?></td>
                                                      <td><?= $data['nama'] ?></td>
													   <td><?= $dt['nilai'] ?></td>
													   
													   <td>
													  <?php if($data['nis'] !=''): ?>
													    <button type="button" class="btn btn-sm btn-primary" data-bs-toggle="modal" data-bs-target="#example<?= $data['nis'] ?>"><i class="material-icons">edit</i></button>
                                                  <?php endif; ?>
                                                <div class="modal fade" id="example<?= $data['nis'] ?>" tabindex="-1" aria-labelledby="exampleModalCenterTitle" style="display: none;" aria-hidden="true">
                                                    <div class="modal-dialog modal-dialog-centered">
                                                        <div class="modal-content">
                                                            <div class="modal-header">
                                                                <h5 class="modal-title" id="exampleModalCenterTitle"><?= $data['nama'] ?></h5>
                                                                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                                                            </div>
                                                            <div class="modal-body">
                                                               <form id="form<?= $data['nis'] ?>" class="row g-1">
																<input type="hidden" class="form-control" name="id" value="<?= $dt['id'] ?>" >
																<div class="col-md-12">
																	<label  class="form-label bold">Ekstrakurikuler</label>
																	<input type="text" class="form-control" name="eskuler" value="<?= $eskul ?>" readonly>
																</div>
															   <div class="col-md-12">
																	<label  class="form-label bold">Nilai</label>
																	<select  class='form-select' name="nilai" required='true' style="width: 100%">
																	<option value=''>Pilih Nilai</option>
																	<option value='A'>A</option>
																	<option value='B'>B</option>
																	<option value='C'>C</option>
																	</select>
																</div>
															   <div class="col-md-12">
																	<label  class="form-label bold">Keterangan</label>
																	<input type="text" class="form-control" name="ket"  required >
																</div>
															   
                                                            </div>
                                                            <div class="modal-footer">
                                                                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">BATAL</button>
                                                                <button type="submit" id="blockui-<?= $data['nis'] ?>" class="btn btn-primary">SIMPAN</button>
                                                            </div>
															</form>
                                                        </div>
                                                    </div>
                                                </div>
												<script>
											   $('#form<?= $data[nis] ?>').submit(function(e) {
												e.preventDefault();
												var data = new FormData(this);
												$.ajax({
													type: 'POST',
													 url: 'cbtserver_rapor/catatan/tcatat.php?pg=nilai',
													enctype: 'multipart/form-data',
													data: data,
													cache: false,
													contentType: false,
													processData: false,
													beforeSend: function() {},
													success: function(data) {
													   
														setTimeout(function() {
															window.location.reload();
														}, 1500);
													}
												})
												return false;
											});
											$('#blockui-<?= $data[nis] ?>').on('click', function() { 
												$.blockUI({ 
													message: '<div class="spinner-grow text-primary" role="status"><span class="visually-hidden">Loading...</span><div>',
													timeout: 2000 
												}); 
											}); 
											</script>
							
													   </td>
                                                </tr>
												<?php endwhile; ?>
												</tbody>
                                                </table>
												 </div>
											</div>
										</div>
										
									</div>
									<?php if ($ac == '') : ?>
					               <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>
											
									<div class="widget-payment-request-info m-t-md">
									 <div class="d-grid gap-2">
									<button class="btn btn-primary" type="button" disabled>
										<span class="spinner-grow spinner-grow-sm" role="status" aria-hidden="true"></span>
										 NILAI ESKUL
									</button>
											</div>
										
								
                               <div class="col-md-12">
								<label class="form-label bold">Rombel</label>
								<select  class='form-select kelas' required='true' style="width: 100%">
								    
                                       <?php
										if($user['level']=='admin'):
											$query = mysqli_query($koneksi, "SELECT * FROM kelas");
											echo "<option value=''>Pilih Rombel</option>";											
											else:
											$query = mysqli_query($koneksi, "SELECT * FROM kelas WHERE kelas='$user[walas]'"); 	
										  endif;
										while ($tkt = mysqli_fetch_array($query)) {										
										echo "<option value='$tkt[kelas]'>$tkt[kelas]</option>";
													}
													?>						
									 </select>
							     </div>	
								 <div class="col-md-12">
								<label class="form-label bold">Ekstrakurikuler</label>
								<select  class='form-select eskul' required='true' style="width: 100%">
								  <?php
										
									$query = mysqli_query($koneksi, "SELECT * FROM m_eskul"); 	
										  
										while ($pes = mysqli_fetch_array($query)) {										
										echo "<option value='$pes[ekstra]'>$pes[ekstra]</option>";
													}
													?>	
								</select>
							     </div>	
							       
							<p>
									  
								         <div class="d-grid gap-2">
                                       
                                         <button class="btn btn-primary flex-grow-1 m-l-xxs" id="cari">PILIH</button>
                                           <script type="text/javascript">
                                $('#cari').click(function() {
                                    var kelas = $('.kelas').val();
									var eskul = $('.eskul').val();
                                    location.replace("?pg=nilskul&kelas=" + kelas + "&eskul=" + eskul);
                                }); 
                            </script>
                                            </div>
										
										</div>
									 </div>
					            </div>
								</div>
							</div>
						</div>
					</div>
				</div>
							
		
							   
					  <?php endif ?>
					  
					  
					  
					  	  
					  
					  
					