<?php
defined('APK') or exit('Anda tidak dizinkan mengakses langsung script ini!');
?>
<?php if ($ac == '') { ?>
<div class='row'>
<div class="col-md-8">
			<div class="card">
             <div class="card-header">URUTAN MAPEL IJAZAH</div>	
                  <div class="card-body">
                    <div class='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>JURUSAN</th>
				           <th>KODE</th>
						    <th>NAMA MAPEL</th>
							 <th>URUT</th>
						   <th>GROUP</th>
						   <th></th>
													   
                            </tr>
                          </thead>
                        <tbody>
							 <?php
							 $no=0;
							  $query = mysqli_query($koneksi, "select * from mapel_ijazah ORDER BY idmapel DESC");
							  while ($mapel = mysqli_fetch_array($query)) {
								  $no++;
							 ?>
							 <tr>
							  <td><?= $no; ?></td>
								
								<td><?= $mapel['jurusan'] ?></td>
							        <td><?= $mapel['kode'] ?></td>
									<td><?= $mapel['namamapel'] ?></td>
									<td><?= $mapel['urut'] ?></td>
									<td><?= $mapel['kelompok'] ?></td>
									<td><button data-id="<?= $mapel['idmapel'] ?>" class="hapus btn-sm btn btn-danger"><i class="material-icons">delete</i></button></td>
							</tr>
                            <?php } ?>
                        </tbody>
                        </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">
									<form id='formmapel' class="row g-1">                         
                               <div class="col-md-12">
							<label  class="bold">Tingkat</label>
							   <select id='level' name='level' class='form-control' required='true'>
                                     
                                       <?php $quem = mysqli_query($koneksi, "SELECT * FROM skl"); ?>
                                                <?php while ($m = mysqli_fetch_array($quem)) : ?>
                                                    <option value="<?= $m['tingkat'] ?>"><?= $m['tingkat'] ?></option>
                                                <?php endwhile ?>
                                                    </select>            
										   </div>
						          
							 <div class="col-md-12">
							<label  class="bold">Jurusan </label>
							 <select id='jurusan' name='jurusan' class='form-select' required>
							 <option value=''>Pilih Jurusan</option>
							  <?php $query = mysqli_query($koneksi, "SELECT * FROM skl JOIN kelas ON kelas.level=skl.tingkat GROUP BY pk"); ?>
                                                <?php while ($j = mysqli_fetch_array($query)) : ?>
                                                    <option value="<?= $j['pk'] ?>"><?= $j['pk'] ?></option>
                                                <?php endwhile ?>
                                                    </select>    
                            
                                            </div>
                                       
							 <div class="col-md-12">
							<label  class="bold">Kode Mapel</label>
							   <select id='kodemap' name='kodemap' class='form-select' required='true'>
                                      <option value=''>Pilih Kode Mapel</option>
                                       <?php $q = mysqli_query($koneksi, "SELECT * FROM mata_pelajaran"); ?>
                                                <?php while ($mp = mysqli_fetch_array($q)) : ?>
                                                    <option value="<?= $mp['kode'] ?>"><?= $mp['kode'] ?></option>
                                                <?php endwhile ?>
                                                    </select>            
										   </div>
						            </div>
							 <div class="col-md-12">
							<label  class="bold">Mata Pel</label>
							<select name='mapel' id="mapel" class='form-select'  required='true'>
                            
                                                </select>
                                            </div>
                                       
							 <div class="col-md-12">
							<label  class="bold">Group</label>
							   <select id='kelompok' name='kelompok' class='form-select' required='true'>
                                      <option value=''>Pilih Kelompok Mapel</option>													
													<?php if($setting['jenjang']=='SD' OR $setting['jenjang']=='SMP'): ?>                                                       
                                                         <option value='A'>A. Umum</option>
														  <option value='B'>B. Muatan Lokal</option>													  
													   <?php elseif($setting['jenjang']=='SMA'): ?>
													    <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>
						         
							 <div class="col-md-12">
							<label  class="bold">No urut</label>
							  <select name='urut' class='form-select' required='true'>
							  <option value=''>Pilih Nomor Urut Mapel</option>	
                                                 <?php
														for($i=1; $i<=20;$i++){
																					?>
															<option value="<?= $i ?>"><?= $i ?></option>
														<?php } ?>
                                                    </select>
                                       </div>
									  <p>
								           <div class="d-grid gap-2">
                                         <button type="submit" class="btn btn-primary flex-grow-1 m-l-xxs" id="blockui-2">Simpan</button>
                                            </div>
									           </form>
								            
											</div>
										</div>
									</div>
								
                          		 <script>
				 
        			   $("#kodemap").change(function() {
					var kodemap = $(this).val();
					console.log(kodemap);
					$.ajax({
						type: "POST", 
						url: "cbtserver_skl/crud_skl.php?pg=ambil_mapel", 
						data: "kodemap=" + kodemap, 
						success: function(response) { 
							$("#mapel").html(response);
						}
					});
				});				
			</script>
			                          <script>
                                        $('#formmapel').submit(function(e) {
                                            e.preventDefault();
                                            var data = new FormData(this);
                                            $.ajax({
                                                type: 'POST',
                                                url: 'cbtserver_skl/edit_mapel.php',
                                                 enctype: 'multipart/form-data',
												data: data,
												cache: false,
												contentType: false,
												processData: false,
												success: function(data) {
													console.log(data);
								                if (data == 'OK') {
												   
													setTimeout(function() {
														window.location.reload();
													}, 2000);

												} else {
									 iziToast.info(
									{
										title: 'GAGAL!',
										message: 'Kode Mapel sudah ada',
										titleColor: '#FFFF00',
										messageColor: '#fff',
										backgroundColor: 'rgba(0, 0, 0, 0.5)',
										 progressBarColor: '#FFFF00',
										  position: 'topRight'					  
									});
									setTimeout(function() {
									window.location.reload();
								}, 2000);
								}

							}
						});
						return false;
					});
                                    </script>		 
			
									  
                                    
						<script>
		$('#datatable1').on('click', '.hapus', function() {
        var id = $(this).data('id');
        console.log(id);
        swal({
            title: 'Are you sure?',
            text: 'Akan menghapus data ini!',
			type:'warning',
            showCancelButton: true,
            confirmButtonColor: '#3085d6',
            cancelButtonColor: '#d33',
            confirmButtonText: 'iya, hapus'
        }).then((result) => {
            if (result.value) {
                $.ajax({
                    url: 'cbtserver_skl/crud_skl.php?pg=hapusmapel',
                    method: "POST",
                    data: 'id=' + id,
                    success: function(data) {
                       iziToast.info(
									{
										title: 'Sukses!',
										message: 'Data Berhasil dihapus',
										titleColor: '#FFFF00',
										messageColor: '#fff',
										backgroundColor: 'rgba(0, 0, 0, 0.5)',
										 progressBarColor: '#FFFF00',
										  position: 'topRight'					  
						});
                        setTimeout(function() {
                            window.location.reload();
                        }, 2000);
                    }
                });
            }
            return false;
        })

    });
	</script>
						
						 
						
		
		 

					 
<?php } ?>	