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

    <div class='row'>
	 <div class='col-md-12'>
             <div class="card">
             <div class="card-header">		
                  <h5 class='card-title'><i class="fas fa-graduation-cap"></i> Urutan Mapel</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 Nomor Urut Mapel 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 table-hover'>
                            <thead >
                                <tr>
                                    <th width='5px'>No</th>
                                    <th>Kode</th>  
									<th>Nama Mapel</th> 
									<th width='5%'>No Urut</th>
									<th width='15%'>Kelompok</th>								  
									<th width='5%'>Action</th>
									
										</tr>
									</thead>							
							<tbody>							
                                <?php
								$no=0;
								$query = mysqli_query($koneksi, "select * FROM mata_pelajaran");
								 while ($mapel = mysqli_fetch_array($query)) {
								
									 $no++;
                                ?>
							 <tr>
                                    <td><?= $no; ?></td>
							      
									<td ><?= $mapel['kode_mapel'] ?></td>
									<td ><?= $mapel['nama_mapel'] ?></td>
									 <td><?= $mapel['urut'] ?></td>
									<td><?= $mapel['kelompok'] ?></td>	
									
									<td>
									  <button type="button" class="btn btn-outline-success btn-sm" data-bs-toggle="modal" data-bs-target="#modaledit<?= $no ?>">
                                                    <i class="fas fa-edit    "></i>
                                                </button>
									</td>
   			                       <div class="modal fade" id="modaledit<?= $no ?>" 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">Urut Mapel</h5>
											   <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
													</div>
													  <div class="modal-body">
                                                <form id="formedit<?= $no ?>">
												<input type="hidden" name="kode" value="<?= $mapel['kode_mapel'] ?>" >
                                      
												<div class="col-md-12">
                                         
                                                   <label class="bold">Kode Mapel</label>
                                                    <select name='kode' class='form-control' >
                                                        <option value='<?= $mapel['kode_mapel'] ?>'><?= $mapel['kode_mapel'] ?></option>
                                                       
                                                    </select>
                                                </div>
												
												<div class="col-md-12">
                                        
                                                   <label class="bold">No Urut Rapor</label>
                                                    <input type="number" name="urut" value="<?= $mapel['urut'] ?>" class="form-control" required="true" >
                                                </div>
												
												<div class="col-md-12">
                                         
                                                   <label class="bold">Kelompok Mapel</label>
                                                    <select name='kelompok' class='form-control' required='true'>
													<option value=''></option>
													<?php if($setting['jenjang']=='SD' OR $setting['jenjang']=='SMP' OR $setting['jenjang']=='PAKET-A' OR $setting['jenjang']=='PAKET-B'): ?>
                                                       
                                                         <option value='A'>A. Umum</option>
														  <option value='B'>B. Muatan Lokal</option>
													  
													   <?php elseif($setting['jenjang']=='SMA' OR $setting['jenjang']=='PAKET-C'): ?>
													    <option value='A'>A. Umum</option>
														  <option value='B'>B. Umum</option>
														   <option value='C'>C. Peminatan</option>
														   <?php elseif($setting['jenjang']=='SMK'): ?>
													    <option value='A'>A. Muatan Nasional</option>
														  <option value='B'>B. Muatan Kewilayahan</option>
														   <option value='C1'>C1. Dasar Bidang Keahlian</option>
														    <option value='C2'>C2. Dasar Program Keahlian</option>
															 <option value='C3'>C3. Kompetensi Keahlian</option>
															
													<?php endif; ?>
                                                    </select>
                                                </div>
                                                 <p>
                                            <div class='right' >
											
                                                <button type='submit' class='btn btn-outline-primary'><i class='fa fa-check-circle'></i> Simpan</button>
                                          
                                        </div>
										
                                                </form>
                                            </div>
                                        </div>
                                    </div>
                                    <script>
                        $("#formedit<?= $no ?>").submit(function(e) {
                            e.preventDefault();
                            $.ajax({
                                type: 'POST',
                                url: 'sandik_rapor/crud_mapel.php?pg=editmapel',
                                data: $(this).serialize(),
                                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();
                                    }, 2000);
                                }
                            });
                            return false;
                        });
                    </script>
   			
							       </tr>
                            <?php } ?>
                        </tbody>
                        </table>
                       
                      </div>
                     </div>
					</div>
                  </div>
				</div>
                