<?php
defined('APK') or exit('Anda tidak dizinkan mengakses langsung script ini!');
 if (empty($_GET['kelas'])) {
        $kelas = "";
    } else {
        $kelas = $_GET['kelas'];
    }
	 if (empty($_GET['rombel'])) {
        $rombel = "";
    } else {
        $rombel = $_GET['rombel'];
    }
	 if (empty($_GET['tingkat'])) {
        $tingkat = "";
    } else {
        $tingkat = $_GET['tingkat'];
    }
?>           
	       
                   <div class="row">
                          <div class="col-md-8">
                                <div class="card">
                                    <div class="card-header">
                                        <h5 class="bold">MUTASI KELAS <span class="badge badge-secondary"><?= $kelas ?> KE <?= $rombel ?> </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>ROMBEL</th>
													<th></th>
                                                </tr>
                                            </thead>
                                            <tbody>
											<?php
											$no=0;
											
											$query = mysqli_query($koneksi, "SELECT * FROM siswa WHERE kelas='$kelas'"); 	
											  while ($data = mysqli_fetch_array($query)) :
											
											$no++;
											   ?>
                                                <tr>
												
                                                    <td><?= $no; ?></td>
                                                     <td><?= $data['nis'] ?></td>
                                                      <td>
													<?= $data['nama'] ?>
													 
													  </td>
													   <td><?= $data['kelas'] ?></td>
													   <td>
													    <form id="formedit<?= $no ?>">
													   <button type="submit" class="btn btn-sm btn-primary"><i class="material-icons">edit</i></button>
													   <input type="hidden" name="nis" value="<?= $data['nis'] ?>" >
													   <input type="hidden" name="level" value="<?= $tingkat ?>" >
													    <input type="hidden" name="kelas" value="<?= $rombel ?>" >
													   <script>
												$('#formedit<?= $no ?>').submit(function(e) {
														e.preventDefault();
														var data = new FormData(this);
														$.ajax({
															type: 'POST',
															 url: 'cbtserver_rapor/tkuri.php?pg=naik',
															enctype: 'multipart/form-data',
															data: data,
															cache: false,
															contentType: false,
															processData: false,
															beforeSend: function() {},
															success: function(data) {
															   iziToast.info(
															{
																 title: 'Sukses!',
																message: 'Data berhasil disimpan',
																titleColor: '#FFFF00',
																messageColor: '#fff',
																backgroundColor: 'rgba(0, 0, 0, 0.5)',
																 progressBarColor: '#FFFF00',
																  position: 'topRight'				  
																}); 
																setTimeout(function() {
																	window.location.reload();
																}, 1500);
															}
														})
														return false;
													});
													</script>
													</form>
													 </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>
										 MUTASI NAIK KELAS
									</button>
											</div>
											<p>
									<div class="row g-3">	
								<div class="col-md-6">
								<label class="form-label bold">Tingkat</label>
								<select  name="level" id="level" class='form-select level' required='true' style="width: 100%">
								    <option value=''>Pilih Tingkat</option>		
                                       <?php
											$query = mysqli_query($koneksi, "SELECT * FROM kelas GROUP BY level");
										while ($tkt = mysqli_fetch_array($query)) {										
										echo "<option value='$tkt[level]'>$tkt[level]</option>";
													}
													?>						
									 </select>
							     </div>	
                               <div class="col-md-6">
								<label class="form-label bold">Dari Rombel</label>
								<select name="kelas" id="kelas" class='form-select kelas' required='true' style="width: 100%">
								   					
									 </select>
							     </div>	
								 <div class="col-md-6">
								<label class="form-label bold">Ke Tingkat</label>
								<select name="tingkat" id="tingkat" class='form-select tingkat' required='true' style="width: 100%">
								<option value=''>Pilih Ke Tingkat</option>		
                                       <?php
											$query = mysqli_query($koneksi, "SELECT * FROM kelas GROUP BY level");
										while ($tkt = mysqli_fetch_array($query)) {										
										echo "<option value='$tkt[level]'>$tkt[level]</option>";
													}
													?>						
									 </select>
							     </div>	
								  <div class="col-md-6">
								<label class="form-label bold">Dari Rombel</label>
								<select name="rombel" id="rombel" class='form-select rombel' required='true' style="width: 100%">
								  
                                      					
									 </select>
							     </div>	
							       </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 level = $('.level').val();
									 var kelas = $('.kelas').val();
									  var tingkat = $('.tingkat').val();
									var rombel = $('.rombel').val();
                                    location.replace("?pg=mutasi&kelas=" + kelas + "&rombel=" + rombel + "&tingkat=" + tingkat + "&level=" + level);
                                }); 
                            </script>
                                            </div>
										
										</div>
									 </div>
					            </div>
								</div>
							</div>
						</div>
					</div>
				</div>
						
		<script>	
		$("#level").change(function() {
		var level = $(this).val();
		console.log(level);
		$.ajax({
		type: "POST",
		url: "cbtserver_rapor/tjadwal.php?pg=kelas", 
		data: "level=" + level, 
	    success: function(response) { 
		$("#kelas").html(response);
		
				}
			});
		});
		$("#tingkat").change(function() {
		var tingkat = $(this).val();
		console.log(tingkat);
		$.ajax({
		type: "POST",
		url: "cbtserver_rapor/tjadwal.php?pg=rombel", 
		data: "tingkat=" + tingkat, 
	    success: function(response) { 
		$("#rombel").html(response);
		
				}
			});
		});
		</script>
							   
					  <?php endif ?>
					  
					  
				