<?php
defined('APK') or exit('Anda tidak dizinkan mengakses langsung script ini!');
?>
<?php if ($ac == '') { ?>
   <div class='row'>
   <div class='col-md-7'>
              <div class="card">
             <div class="card-header">
					<h5 class='card-title'><i class="fas fa-graduation-cap"></i> Setting KKM</h5>
                </div>
			
						<div class="card-body">
               <div class="alert alert-custom" role="alert">
                     <div class="custom-alert-icon icon-dark"><i class="fa fa-check fa-2x"></i></div>
                       <div class="alert-content">
                          <span class="alert-text" style="text-align:justify"> Pastikan Seluruh Mapel Sudah diisi di Jadwal Mapel pada Menu PTM, Jika Belum diisi maka KKM tidak Tersimpan di Jadwal Mapel, Data ini akan digunakan pada Pengisian dan Cetak Rapor</span>
                                </div>
                         </div>
                    <div class='table-responsive'>
                        <table style="font-size: 11px" id='example1' class='table'>
                            <thead>
                                <tr>
                                    <th width='3%'>No</th>
									<th>Tingkat</th>
									  <th>Kelas</th>
                                 
                                        <th>Model KKM</th>
                                     									
									<th width='10%'>Action</th>
                                </tr>
                            </thead>
							
							<tbody>
							
                                <?php
								$no = 0;
								
							$query = mysqli_query($koneksi, "select * from jadwal_mapel JOIN kelas ON kelas.id_kelas=jadwal_mapel.kelas 
							WHERE kelas.kurikulum='K-13' GROUP BY jadwal_mapel.kelas");
                            while ($mapel = mysqli_fetch_array($query)) {
							
							 $no++;
                            ?>
							 <tr>
                                    <td><?= $no; ?></td>
									 <td><?= $mapel['tingkat'] ?></td>
									 <td><?= $mapel['kelas'] ?></td>
							      
									<td><b style="color:blue"><?= strtoupper($mapel['model_kkm']) ?></b></td>
								
                                   <td style="text-align:center">
								   <?php if($mapel['model_kkm']=='singgle'): ?>
                                       <button type="button" class="btn btn-outline-success btn-sm" data-bs-toggle="modal" data-bs-target="#modaledit<?= $mapel['kelas'] ?>">
                                         <i class="fas fa-edit"></i></button>
									<?php else: ?>
                                         <a href="?pg=kkm&ac=multi&kelas=<?= $mapel['kelas'] ?>" class="btn btn-outline-success btn-sm">
                                         <i class="fas fa-edit"></i></a>
                                        <?php endif; ?>									
                                   </td>
								   <div class="modal fade" id="modaledit<?= $mapel['kelas'] ?>" tabindex="-1" role="dialog" aria-labelledby="modelTitleId" aria-hidden="true">
                                       <div class="modal-dialog">
									   <div class="modal-content">
										  <div class="modal-header">
											<h5 class="modal-title" id="tambahjadwal">KKM Kelas</h5>
											   <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
													</div>
													  <div class="modal-body">
                                                <form id="formedit<?= $mapel['kelas'] ?>">
									             <div class="col-md-9">
                                                   <label class="bold">Kelas</label>
                                                    <select name='kelas' id="kelas" class='form-select'>
                                                        <option value='<?= $mapel[kelas] ?>' ><?= $mapel['kelas'] ?></option>
                                                  
                                                    </select>
                                                </div>
												
														<div class="col-md-12">                                                           
														  <label class="bold">KKM</label>
														<input type="number"  name="kkm" value="<?= $mapel['kkm'] ?>" class="form-control" required>
														 </div>   
														<p>
                                            <div class='right' >											
                                                <button type='submit' class='btn btn-outline-success'><i class='fa fa-check-circle'></i> Simpan</button>                                               
                                            </div>
                                       
										
                                                </form>
                                            </div>
                                        </div>
                                    </div>
									
                                    <script>
                        $("#formedit<?= $mapel['kelas'] ?>").submit(function(e) {
                            e.preventDefault();
                            $.ajax({
                                type: 'POST',
                                url: 'sandik_rapor/crud_jadwal.php?pg=editjadwal',
                                data: $(this).serialize(),
                                success: function(data) {
                                    iziToast.info(
								{
									title: 'Sukses!',
									message: 'Jadwal berhasil disimpan',
									titleColor: '#FFFF00',
									messageColor: '#fff',
									backgroundColor: 'rgba(0, 0, 0, 0.5)',
									 progressBarColor: '#FFFF00',
									  position: 'topRight'	
										});
                                    setTimeout(function() {
                                        window.location.reload();
                                    }, 2000);
                                }
                            });
                            return false;
                        });
                    </script>
   			
							       </tr>
                            <?php } ?>
                        </tbody>
                        </table>
                    </div>
                    </div>
					</div>
					</div>
					
					
                      <div class='col-md-5'>
						<div class="card">
                             <div class="card-header"></div>
						<div class="card-body">
                          <div class='table-responsive'>
                        <table style="font-size: 11px" id='example' class='table'>
                            <thead>
                                <tr>
                                    <th width='3%'>No</th>
									<th>Tingkat</th>
									  <th>Kelas</th>                          
                                        <th>Mapel</th>
                                      <th>KKM</th>								
                                </tr>
                            </thead>
							<tbody>
							  <?php
								$no = 0;
								
							$query = mysqli_query($koneksi, "select * from jadwal_mapel JOIN kelas ON kelas.id_kelas=jadwal_mapel.kelas 
							WHERE kelas.kurikulum='K-13' ORDER BY kelas,urut ASC");
                            while ($mapel = mysqli_fetch_array($query)) {
							
							 $no++;
                            ?>
							 <tr>
                             <td><?= $no; ?></td>
							<td><?= $mapel['tingkat'] ?></td>
							<td><?= $mapel['kelas'] ?></td>
							<td><?= $mapel['mapel'] ?></td>
							<td><?= $mapel['kkm'] ?></td>
							</tr>
                            <?php } ?>
							 </tbody>
                        </table>
					</div>
				</div>
			</div>
		</div>
 </div>
 <?php } elseif ($ac == 'multi') { ?>
 <div class='row'>
   <div class='col-md-12'>
             <div class='panel panel-default'>
              <div class="card">
             <div class="card-header">
					<h5 class='card-title'><i class="fas fa-graduation-cap"></i> Setting Multi KKM</h5>
                </div>			  	
						<div class="card-body">
						 <form id='menu'   class="form-horizontal" >
						<div class='table-responsive'>
                        <table style="font-size: 11px" id='datatable' class='table table-hover'>
                            <thead>
                                <tr>
                                    <th width='3%' height="40px">No</th>
									<th>Tingkat</th>
									  <th>Kelas</th>                          
                                        <th>Mapel</th>
                                      <th>KKM</th>								
                                </tr>
                            </thead>
							<tbody>
							  <?php
								$no = 0;
								
							$query = mysqli_query($koneksi, "select * from jadwal_mapel WHERE kelas='$_GET[kelas]'");
                            while ($mapel = mysqli_fetch_array($query)) {
							
							 $no++;
                            ?>
							 <tr>
                             <td class="hidden-xs"><?= $no; ?></td>
							<td><?= $mapel['tingkat'] ?></td>
							<td><?= $mapel['kelas'] ?></td>
							<td><?= $mapel['mapel'] ?></td>
							<td>
							<input type="hidden" name="kelas[]" value="<?= $mapel['kelas'] ?>" >
								<input type="hidden" name="mapel[]" value="<?= $mapel['kode'] ?>" >
							<input type="number" name="kkm[]" class="form-control" value="<?= $mapel['kkm'] ?>" required="true" >
							</td>
							</tr>
                            <?php } ?>
							 </tbody>
                        </table>
						<p>
                               <div class='right'>							
                              <button type='submit' class='btn btn-outline-success'><i class='fa fa-check-circle'></i> Simpan</button>                                               
                                         
                                        </div>
						</div>
						</form>
				</div>
			</div>
		</div>
 </div>	
						
			  <script>
				  $('#menu').submit(function(e) {
        e.preventDefault();
        var data = new FormData(this);
      
        $.ajax({
            type: 'POST',
            url: 'sandik_rapor/crud_jadwal.php?pg=editmulti',
            enctype: 'multipart/form-data',
            data: data,
            cache: false,
            contentType: false,
            processData: false,
            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.replace('?pg=kkm');
                }, 2000);

            }
        });
        return false;
    });
</script>					
 <?php } ?>