<?php
defined('APK') or exit('Anda tidak dizinkan mengakses langsung script ini!');
$skl = mysqli_fetch_array(mysqli_query($koneksi, "SELECT * FROM skl  WHERE id_skl='1'"));
?>           
	<?php if ($ac == '') : ?>
                   <div class="row">
                          <div class="col-md-8">
                                <div class="card">
                                    <div class="card-header">
                                        <h5 class="card-title">JADWAL MAPEL</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>ROMBEL</th>													                                                  
                                                    <th>HARI</th>
													 <th>MAPEL</th>
													  <th>GURU</th>
													<th></th>
                                                </tr>
                                            </thead>
                                            <tbody>
											<?php
											$no=0;							
											$query = mysqli_query($koneksi, "SELECT * FROM jadwal_mapel"); 											
											  while ($data = mysqli_fetch_array($query)) :	
											  $hari = fetch($koneksi,'m_hari',['inggris'=>$data['hari']]);
											  $peg = fetch($koneksi,'users',['id_user'=>$data['guru']]);
											$no++;
											   ?>
                                                <tr>
                                                    <td><?= $no; ?></td>
                                                     <td><?= $data['kelas'] ?></td>
                                                       <td>
													   <?= $hari['hari'] ?>
													    - <?= $data['dari'] ?> -  <?= $data['sampai'] ?>
													   </td>
													   <td><?= $data['mapel'] ?></td>
													  <td><?= $peg['nama'] ?></td>
													  <td>
													  <button data-id="<?= $data['idj'] ?>"  class="hapus btn btn-sm btn-danger" data-bs-toggle="tooltip" data-bs-placement="top" title="Hapus"><i class="material-icons">delete</i> </button>
													  </td>
                                                </tr>
												<?php endwhile; ?>
												</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">
									 <div class="d-grid gap-2">
									<button class="btn btn-dark" type="button" disabled>
										<span class="spinner-grow spinner-grow-sm" role="status" aria-hidden="true"></span>
										 JADWAL MAPEL
									</button>
											</div>
											
									  <form id='menu'   class="form-horizontal" >                        
                               
							     <div class="row">								 
							<div class="col-md-6">
								<label class="form-label bold">Rombel</label>
								<select name="kelas" class='form-select' required='true' style="width: 100%">
										<?php													
										$kls = mysqli_query($koneksi, "SELECT * FROM kelas");
										while ($kelas = mysqli_fetch_array($kls)) {										
										echo "<option value='$kelas[kelas]'>$kelas[kelas]</option>";
													}
													?>				
									 </select>
							     </div>	            
								 <div class="col-md-6">
								<label class="form-label bold">Hari</label>
								<select name="hari" class='form-select' required='true' style="width: 100%">
										<?php													
										$hr = mysqli_query($koneksi, "SELECT * FROM m_hari");
										while ($hari = mysqli_fetch_array($hr)) {										
										echo "<option value='$hari[inggris]'>$hari[hari]</option>";
													}
													?>				
									 </select>
							     </div>
								  </div>
								<div class="row">								 
							<div class="col-md-6">
								<label class="form-label bold">Dari Jam</label>
								<input type="text" name="dari" class="form-control" required="true">
							</div>
							 
								 <div class="col-md-6">
								<label class="form-label bold">Sampai Jam</label>
								<input type="text" name="sampai" class="form-control" required="true">
							          </div>
									   </div>
									   <div class="col-md-12">
								<label class="form-label bold">Mapel</label>
								<select name="mapel" class='form-select' required='true' style="width: 100%">
								<option value=''></option>
										<?php													
										$query = mysqli_query($koneksi, "SELECT * FROM mata_pelajaran");
										while ($map = mysqli_fetch_array($query)) {										
										echo "<option value='$map[kode]'>$map[nama_mapel]</option>";
													}
													?>				
									 </select>
							          </div>
							<div class="row">								 
							<div class="col-md-4">
								<label class="form-label bold">JJM</label>
								<input type="number" name="jjm" class="form-control" required="true">
							</div>
								<div class="col-md-8">
								<label class="form-label bold">Guru</label>
								<select name="guru" class='form-select' required='true' style="width: 100%">
								<option value=''></option>
										<?php													
										$que = mysqli_query($koneksi, "SELECT * FROM users where level='guru'");
										while ($peg = mysqli_fetch_array($que)) {										
										echo "<option value='$peg[id_user]'>$peg[nama]</option>";
													}
													?>				
									 </select>
							          </div>	  
									    </div>
									<div class="row">								 						
								<div class="col-md-6">
								<label class="form-label bold">Jenis Pegawai</label>
								<select name="jenis" class='form-select' required='true' style="width: 100%">
										<option value=''></option>				  					
									<option value='0'>Honorer</option>
										<option value='1'>PNS</option>					
									 </select>
							          </div>
									<div class="col-md-6">
								<label class="form-label bold">Honor per jjm</label>
								<input type="number" name="honor" value="0" class="form-control" required="true">
								<p>Untuk PNS biarkan 0</p>
							          </div>									  
									    </div>	
									  <p>
									  
								           <div class="d-grid gap-2">
                                       <button id="blockui-3" class="btn btn-primary">SIMPAN</button>
                           
                                            </div>
									    </form>
										</div>
									 </div>
					            </div>
								</div>
							</div>
						</div>
					</div>
				
				<script>
				  $('#menu').submit(function(e) {
        e.preventDefault();
        var data = new FormData(this);
      
        $.ajax({
            type: 'POST',
            url: 'cbtserver_ptm/tjadwal.php?pg=tambah',
            enctype: 'multipart/form-data',
            data: data,
            cache: false,
            contentType: false,
            processData: false,
            success: function(data) {
          
                setTimeout(function() {
                    window.location.reload();
                }, 2000);

            }
        });
        return false;
    });
</script>
<?php endif ?>
					  
		                             <script>
									$('#datatable1').on('click', '.hapus', function() {
									var id = $(this).data('id');
									console.log(id);
									swal({
											  title: 'Yakin hapus data?',
											  text: "You won't be able to revert this!",
											  type: 'warning',
											  showCancelButton: true,
											  confirmButtonColor: '#3085d6',
											  cancelButtonColor: '#d33',
											  confirmButtonText: 'Ya, Hapus!',
											  cancelButtonText: "Batal"				  
									}).then((result) => {
										if (result.value) {
											$.ajax({
											   url: 'cbtserver_ptm/tjadwal.php?pg=hapus',
												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>  			  
					  
					  	  
					  
					  
					