<?php
defined('APK') or exit('Anda tidak dizinkan mengakses langsung script ini!');
?>	
 <?php $mapel=fetch($koneksi,'jadwal_mapel',['id_jadwal'=>$_GET['id']]); ?>			
		 <div class="row">
     <div class="col-md-12">
		<div class="card">
             <div class="card-header">									
                  <h5 class="card-title">Edit Jadwal Mapel</h5>
					</div>
                      <div class="card-body">
                                <form id="formeditjadwal" >
								<input type="hidden" name="idj" value="<?= $_GET['id'] ?>" >
								 <div class="row">
                                        <div class="col-md-6">
                                        <div class='form-group'>
                                                   <label class="bold">Kelas</label>
                                                    <select name='kelas' class='form-control' readonly>
                                                        <option value='<?= $mapel[kelas] ?>' ><?= $mapel['kelas'] ?></option>
                                                      
                                                    </select>
                                                </div>
												</div>
												<div class="col-md-6">
                                          <div class='form-group'>
                                                   <label class="bold">Kode Mapel</label>
                                                    <select name='kode' class='form-control' readonly>
                                                        <option value='<?= $mapel['kode'] ?>'><?= $mapel['kode'] ?></option>
                                                      
                                                    </select>
                                                </div>
												</div>
												<div class="col-md-12">
                                          <div class='form-group'>
                                                   <label class="bold">Nama Mapel</label>
                                                    <select name='mapel' class='form-control' readonly>
                                                        <option value='<?= $mapel['mapel'] ?>'><?= $mapel['mapel'] ?></option>
                                                       
                                                    </select>
                                                </div>
												</div>
												
												<div class="col-md-12">
                                                             <div class="form-group-sm">
                                                        <label class="bold">Hari</label>
														<?php $poe=fetch($koneksi,'m_hari',['inggris'=>$mapel['hari']]); ?>
															<select name='hari' class='form-select' style='width:100%' required>
                                                                <option value="<?= $mapel[hari] ?>" ><?= $poe['hari'] ?></option>
                                                                <option value='' >--Pilih Hari--</option>
                                                                <?php
														$queryh = mysqli_query($koneksi, "select * from m_hari");
														while ($hari = mysqli_fetch_array($queryh)) {
																	?>
															<option value="<?= $hari['inggris'] ?>"><?= $hari['hari'] ?></option>
														<?php } ?>
															</select>
                                                        </div>
                                                        </div>
														<div class="col-md-12">
                                                             <div class="form-group-sm">
                                                        <label class="bold">Jam Pelajaran Ke - Sampai</label>
														<select name='ke[]' class='form-control select2' style='width:100%' multiple required='true'>
                                                          <?php $lev = mysqli_query($koneksi, "SELECT * FROM m_jam"); ?>
                                                                        <?php while ($k = mysqli_fetch_array($lev)) : ?>
                                                                            <?php if (in_array($k['ke'], unserialize($mapel['ke']))) : ?>
                                                                                <option value="<?= $k['ke'] ?>" selected><?= $k['ke'] ?></option>
                                                                            <?php else : ?>
                                                                                <option value="<?= $k['ke'] ?>"><?= $k['ke'] ?></option>
                                                                            <?php endif; ?>
                                                                        <?php endwhile ?>
																		
                                                                    </select>
																	 </div>
                                                        </div>
														<div class="col-md-6">
                                                             <div class="form-group-sm">
														  <label class="bold">Dari Jam</label>
														<input type="text"  name="dari" class="form-control" value="<?= $mapel['dari'] ?>" required>
														 </div>   
														</div> 
														
															<div class="col-md-6">
                                                             <div class="form-group-sm">
														  <label class="bold">Sampai Jam</label>
														<input type="text"  name="sampai" class="form-control" value="<?= $mapel['sampai'] ?>" required>
														 </div>
                                                      </div>
														
												<div class="col-md-12">
											   <div class='form-group-sm'>
                                                   <label class="bold">Guru Mapel</label>
												  <?php $user=fetch($koneksi,'users',['id_user'=>$mapel['guru']]); ?>
                                                    <select name='guru' class='form-select' >
                                                        <option value="<?= $mapel[guru] ?>"><?= $user['nama'] ?></option>
                                                         
                                                        <?php
                                                        $kelasQ = mysqli_query($koneksi, "SELECT * FROM users WHERE level='guru'");
                                                        while ($ekstra = mysqli_fetch_array($kelasQ)) {
                                                            echo "<option value='$ekstra[id_user]'>$ekstra[nama]</option>";
                                                        }
                                                        ?>
													 
                                                    </select>
                                                </div>
												</div>
												
									<div class='modal-footer'>
								   <div class='box-tools pull-right btn-group'>
									  <button type='submit'  class='btn btn-outline-primary'><i class='fa fa-check-circle'></i>Simpan</button>
										 
											</div>
											 </div>
								 
                                </form>
                            </div>
                        </div>
                    </div>
					<script>
 $('#formeditjadwal').submit(function(e) {
    e.preventDefault();
    var data = new FormData(this);
    
    $.ajax(
    {
        type: 'POST',
         url: 'sandik_ptm/crud_jadwal.php?pg=editjadwal',
        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=jadwalmapel');
            }, 2000);
            
        }
    });
    return false;
});
</script>		

			      