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

?>           <?php if ($ac == '') : ?>
	        <div class="alert alert-dark" role="alert">
                  Asesmen Formatif bertujuan untuk memperbaiki proses pembelajaran baik bagi guru maupun siswa. Hasil asesmen formatif tidak 
				  digunakan dalam pengolahan rapor namun sebagai bahan pertimbangan <b>untuk membuat deskripsi</b> pada laporan hasil belajar siswa. 
				  Isikan TP sesuai jumlah TP pada menu Tujuan Pembelajaran
				<?php
	if (empty($_GET['level'])) {
        $tingkat = "";
    } else {
        $tingkat = $_GET['level'];
    }			
    if (empty($_GET['kelas'])) {
        $kelas = "";
    } else {
        $kelas = $_GET['kelas'];
    }
     if (empty($_GET['mapel'])) {
        $mapel = "";
    } else {
        $mapel = $_GET['mapel'];
    }
	  if (empty($_GET['guru'])) {
        $guru = "";
    } else {
        $guru = $_GET['guru'];
    }
    ?>
	 <?php include"cbtserver_rapor/radio.php"; ?>
				   </div>	
                   <div class="row">
                          <div class="col-md-8">
                                <div class="card">
                                    <div class="card-header">
                                        <h5 class="bold">NILAI FORMATIF <span class="badge badge-secondary"><?= $mapel ?> <?= $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>TP TERCAPAI</th>
													  <th>TP KURANG TERCAPAI</th>
													
													  <th></th>
                                                </tr>
                                            </thead>
                                            <tbody>
											<?php
											$smt = $setting['semester'];
											$no=0;								
											$query = mysqli_query($koneksi, "SELECT * FROM siswa WHERE kelas='$kelas'"); 				
											  while ($data = mysqli_fetch_array($query)) :
											 $formatif = fetch($koneksi,'nilai_formatif',['nis'=>$data['nis']]);
											$no++;
											   ?>
                                                <tr>
                                                    <td><?= $no; ?></td>
                                                     <td><?= $data['nis'] ?></td>
                                                      <td><?= $data['nama'] ?></td>
													   <td><?= $formatif['tinggi'] ?></td>
													   <td><?= $formatif['rendah'] ?></td>
													  <td>
											<button type="button" class="btn btn-sm btn-success" data-bs-toggle="modal" data-bs-target="#example<?= $data['id_siswa'] ?>"><i class="material-icons">edit</i> </button>
											<div class="modal fade" id="example<?= $data['id_siswa'] ?>" tabindex="-1" aria-labelledby="example<?= $data['id_siswa'] ?>" aria-hidden="true">
                                                    <div class="modal-dialog modal-lg">
                                                        <div class="modal-content">
                                                            <div class="modal-header">
                                                                <h5>NILAI FORMATIF <span class="badge badge-secondary"><?= strtoupper($data['nama']) ?></span></h5>
                                                                
                                                            </div>
                                                            <div class="modal-body">
													 <div class="alert alert-dark" role="alert">                   
													   Plihan pada TP Tercapai tidak boleh sama pada pilihan TP Kurang Tercapai, dan data ini akan Tampil pada <b>Capaian Kompetensi Rapor</b>
													  </div>
											           <form id="form<?= $data['id_siswa'] ?>" action=''>
													   <input type="hidden" name="nis" value="<?= $data['nis'] ?>" >
													   <input type="hidden" name="kelas" value="<?= $data['kelas'] ?>" >
													   <input type="hidden" name="mapel" value="<?= $mapel ?>" >
											           <div class="col-md-12">
								                      <label class="form-label bold">Pilih Tujuan Pembelajaran Tercapai <span class="badge badge-primary"><?= strtoupper($data['nama']) ?></span></label>
													   <?php  $TP = mysqli_query($koneksi, "SELECT * FROM tujuan WHERE kodemap='$mapel' AND tingkat='$tingkat' AND smt='$smt'");?>
						                               <?php while ($tuju = mysqli_fetch_array($TP)){ ?>
													  <label class="checkbox"><input class='hidden radio-label' type='checkbox' name="tinggi[]" value="<?= $tuju['pembelajaran'] ?>" /> 
								                       <span class="check"></span><?= $tuju['tp'] ?>. <?= $tuju['pembelajaran'] ?></label>
													   <?php } ?>
													   </div>
													   <hr>
													    <div class="col-md-12">
								                      <label class="form-label bold">Pilih Tujuan Pembelajaran Kurang Tercapai <span class="badge badge-warning"><?= strtoupper($data['nama']) ?></span></label>
													   <?php  $TP = mysqli_query($koneksi, "SELECT * FROM tujuan WHERE kodemap='$mapel' AND tingkat='$tingkat' AND smt='$smt'");?>
						                               <?php while ($tuju = mysqli_fetch_array($TP)){ ?>
													  <label class="checkbox"><input class='hidden radio-label' type='checkbox' name="rendah[]" value="<?= $tuju['pembelajaran'] ?>" /> 
								                       <span class="check"></span><?= $tuju['tp'] ?>. <?= $tuju['pembelajaran'] ?></label>
													   <?php } ?>
													   </div>
                                                            </div>
                                                            <div class="modal-footer">
                                                                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">BATAL</button>
                                                                <button type="submit" class="btn btn-primary" id="blockui-<?= $data['id_siswa'] ?>">SIMPAN</button>
                                                            </div>
															</form>
                                                        </div>
                                                    </div>
                                                </div>
											</td>
											<script>
												$('#form<?= $data[id_siswa] ?>').submit(function(e) {								
														e.preventDefault();
														var data = new FormData(this);
														$.ajax({
															type: 'POST',
														   url: 'cbtserver_rapor/kurmer/tnilaiformatif.php',
															enctype: 'multipart/form-data',
															data: data,
															cache: false,
															contentType: false,
															processData: false,
															success: function(data) {
															if (data == 'OK') {		
															
															setTimeout(function()
															{
															   window.location.reload();
															}, 1500);
															 } else {
															 iziToast.warning(
															{
																title: 'Gagal!',
																message: 'Data Tidak boleh sama',
																titleColor: '#FFFF00',
																messageColor: '#fff',
																backgroundColor: '#8b0000',
																 progressBarColor: '#FFFF00',
																  position: 'topRight'
															});
																
														   }			
														}
													});
													return false;
												});	
													$('#blockui-<?= $data[id_siswa] ?>').on('click', function() { 
													$.blockUI({ 
														message: '<div class="spinner-grow text-primary" role="status"><span class="visually-hidden">Loading...</span><div>',
														timeout: 2000 
													}); 
												}); 			
												</script>		
                                                </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>
											
									<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>
										 INPUT NILAI FORMATIF
									</button>
											</div>
								
                               <div class="col-md-12">
								<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
										if($user['level']=='admin'):
											$query = mysqli_query($koneksi, "SELECT * FROM jadwal_rapor WHERE kurikulum='K-Merdeka' GROUP BY tingkat"); 
											else:
											$query = mysqli_query($koneksi, "SELECT * FROM jadwal_rapor WHERE kurikulum='K-Merdeka' AND idguru='$user[id_user]' GROUP BY tingkat"); 	
										  endif;
										while ($tkt = mysqli_fetch_array($query)) {										
										echo "<option value='$tkt[tingkat]'>$tkt[tingkat]</option>";
													}
													?>						
									 </select>
							     </div>	
							    <div class="col-md-12">
								<label class="form-label bold">Pilih Rombel</label>
								<select name='kelas' id='kelas' class='form-select kelas' required='true' style="width: 100%">         
								
								 </select>
							     </div>
							<div class="col-md-12">
								<label class="form-label bold">Mata Pelajaran</label>
								<select name='mapel' id='mapel' class='form-select mapel' required='true' style="width: 100%">
								  <?php
										if($user['level']=='admin'):
											$query = mysqli_query($koneksi, "SELECT * FROM jadwal_rapor WHERE kurikulum='K-Merdeka'"); 
											else:
											$query = mysqli_query($koneksi, "SELECT * FROM jadwal_rapor WHERE kurikulum='K-Merdeka' AND idguru='$user[id_user]'"); 	
										  endif;
										while ($mpl = mysqli_fetch_array($query)) {										
										echo "<option value='$mpl[kodemap]'>$mpl[kodemap]</option>";
													}
													?>						
									 </select>
									
							</div>
							
								 <div class="col-md-12">
								<label class="form-label bold">Guru Pengampu</label>
								<select name="guru" class='form-select guru' required='true' style="width: 100%" >
										 <?php
										if($user['level']=='admin'):
											$query = mysqli_query($koneksi, "SELECT * FROM jadwal_rapor WHERE kurikulum='K-Merdeka'"); 
											else:
											$query = mysqli_query($koneksi, "SELECT * FROM jadwal_rapor WHERE kurikulum='K-Merdeka' AND idguru='$user[id_user]'"); 	
										  endif;
										while ($guru = mysqli_fetch_array($query)) {
                                          $peg = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM users  WHERE id_user='$guru[idguru]'"));											
										echo "<option value='$guru[idguru]'>$peg[nama]</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 level = $('.level').val();
                                    var kelas = $('.kelas').val();
                                    var mapel = $('.mapel').val();
									 var guru = $('.guru').val();
                                    location.replace("?pg=formatif&level=" + level + "&kelas=" + kelas + "&mapel=" + mapel + "&guru=" + guru);
                                }); 
                            </script>
                                            </div>
									
										</div>
									 </div>
					            </div>
								</div>
							</div>
						</div>
					</div>
				</div>
							<script>
						$('#formlingkup').submit(function(e) {
								e.preventDefault();
								var data = new FormData(this);
								$.ajax({
									type: 'POST',
									 url: 'cbtserver_rapor/kurmer/tkurmer.php?pg=lingkup',
									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;
							});
							</script>
							<script>	
		$("#level").change(function() {
		var level = $(this).val();
		console.log(level);
		$.ajax({
		type: "POST",
		url: "cbtserver_rapor/kurmer/tnilai.php?pg=kelas", 
		data: "level=" + level, 
	    success: function(response) { 
		$("#kelas").html(response);
		
				}
			});
		});</script>
							
            
							   
					  <?php endif ?>
					  
					  
					  
					  	  
					  
					  
					