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

<?php if ($ac == '') { ?>
				  <div class="row">
					 <div class="col-md-12">
						<div class="card">
							 <div class="card-header">									
								  <h5 class="card-title">Tambah Berita Acara</h5>
									</div>
									  <div class="card-body">
											 
											<div class="example-container">
                                            <div class="example-content">
                                               <form id="formberita">
                                                    <div class="row">
                                                  <div class="col-md-4">
													<div class="form-group">
                                                        <label class="bold">Nama Ujian</label>
                                                       <select name="id_ujian" class='form-select' style="width: 100%" required='true'>
                                                <?php $sql_mapel = mysqli_query($koneksi, "SELECT * FROM ujian group by id_bank"); ?>
                                                <option value=''>Pilih Jadwal Ujian</option>
                                                <?php while ($mapel = mysqli_fetch_array($sql_mapel)) : ?>
                                                    <option value="<?= $mapel['id_ujian'] ?>"><?php echo "$mapel[nama] $mapel[level] ";
                                                                                                foreach (unserialize($mapel['id_pk']) as $jur) {
                                                                                                    echo $jur . " ";
                                                                                                } ?></option>
                                                <?php endwhile ?>
                                            </select>
                                                    </div>
                                                    </div>
													 <div class="col-md-4">
													<div class="form-group">												
                                                        <label class="bold">Sesi</label>
                                                      <select class="form-select" id="bcsesi" name="sesi" required>
                                                <option>Sesi</option>
                                                <?php $sesi = mysqli_query($koneksi, "select * from siswa group by sesi"); ?>
                                                <?php while ($ses = mysqli_fetch_array($sesi)) : ?>
                                                    <option value="<?= $ses['sesi'] ?>"><?= $ses['sesi'] ?></option>
                                                <?php endwhile; ?>
                                            </select>
													</div>
													</div>
                                                   
                                                  <div class="col-md-4">
													<div class="form-group">
                                                        <label class="bold">Ruang</label>
                                                       <select class="form-select" id="bcruang" name="ruang" required>
                                                <option>Ruang</option>
                                                <?php $ruang = mysqli_query($koneksi, "select * from siswa group by ruang"); ?>
                                                <?php while ($ruang = mysqli_fetch_array($ruang)) : ?>
                                                    <option value="<?= $ruang['ruang'] ?>"><?= $ruang['ruang'] ?></option>
                                                <?php endwhile; ?>
                                            </select>
                                                    </div>
													</div>
													</div><p>
													 <div class="row">
													 <div class="col-md-4">
														<div class="form-group">
															 <label class="bold">Tanggal Ujian</label>
														   <input name='tgl_ujian' class='datepicker form-control' autocomplete=off />
														</div>
													</div>
													 
													  <div class="col-md-2">
														<div class="form-group">
															 <label class="bold">Mulai</label>
														  <input id='waktumulai' type='text' name='mulai' class='timer form-control' autocomplete=off />
														</div>
													</div>
													 <div class="col-md-2">
														<div class="form-group">
															 <label class="bold">Selesai</label>
														 <input id='waktumulai' type='text' name='selesai' class='timer form-control' autocomplete=off />
														</div>
													</div>
													<div class='col-md-2'>
                                        <div class='form-group'>
                                            <label class="bold">Hadir</label>
                                            <input type='number' name='hadir' class='form-control' required='true' />
                                        </div>
                                    </div>
                                    <div class='col-md-2'>
                                        <div class='form-group'>
                                            <label class="bold">Absen</label>
                                            <input type='number' name='tidakhadir' class='form-control' required='true' />
                                        </div>
                                    </div>
									 </div>
									<p>
									        <div class="row">
                                                    <div class="col-md-12">
													<div class="form-group">
													<label class="bold">Siswa Tidak Hadir</label>
													  <select name='nosusulan[]' id="bcsiswaabsen" class='form-select select2' multiple='multiple' style='width:100%'>
														   </select>
															</div>
															</div>
															</div><p>
													
                                                    
												<div class='row'>
													 <div class='col-md-6'>
                                        <div class='form-group'>
                                            <label class="bold">Nama Proktor</label>
                                            <input type='text' name='nama_proktor' value="<?= $setting['proktor'] ?>" class='form-control' required='true' />
                                        </div>
                                    </div>
                                    <div class='col-md-6'>
                                        <div class='form-group'>
                                            <label class="bold">NIP Proktor</label>
                                            <input type='text' name='nip_proktor' value="<?= $setting['nipproktor'] ?>" class='form-control' required='true' />
                                        </div>
                                    </div><p>
                                    <div class='col-md-6'>
                                        <div class='form-group'>
                                            <label class="bold">Nama Pengawas</label>
                                            <input type='text' name='nama_pengawas' class='form-control' required='true' />
                                        </div>
                                    </div>
                                    <div class='col-md-6'>
                                        <div class='form-group'>
                                            <label class="bold">NIP Pengawas</label>
                                            <input type='text' name='nip_pengawas' class='form-control' required='true' />
                                        </div>
                                    </div><p>
                                    <div class='col-md-12'>
                                        <div class='form-group'>
                                            <label class="bold">Catatan</label>
                                            <textarea type='text' name='catatan' class='form-control' required='true'></textarea>
                                        </div>
                                    </div>

                                </div>
                                <div class="modal-footer">
                                    
                                    <button type="submit" class="btn btn-sm btn-outline-primary">Simpan</button>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
												
		                               <?php } ?>									
											
				
<script>
    $('#formberita').submit(function(e) {
        e.preventDefault();
        $.ajax({
            type: 'POST',
            url: 'sandik_ujian/crud_berita.php?pg=tambah',
            data: $(this).serialize(),
            success: function(data) {
                if (data == 'oke') {
                    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=berita');
                    }, 2000);
                } else {
                 iziToast.info({
					title: 'GAGAL!',
					message: 'Data Gagal disimpan',
					titleColor: '#FFFF00',
					messageColor: '#fff',
					backgroundColor: 'rgba(0, 0, 0, 0.5)',
					progressBarColor: '#FFFF00',
					position: 'topRight'
                    });
					setTimeout(function() {
                        window.location.reload();
                    }, 2000);
                }

            }
        });
        return false;
    });
	
    $("#bcruang").change(function() {
        var sesi = $('#bcsesi').val();
        var ruang = $(this).val();
        console.log(ruang + sesi);
        $.ajax({
            type: "POST", // Method pengiriman data bisa dengan GET atau POST
            url: 'sandik_ujian/crud_berita.php?pg=list_siswa',
            data: "ruang=" + ruang + '&sesi=' + sesi, // data yang akan dikirim ke file yang dituju
            success: function(response) { // Ketika proses pengiriman berhasil
                $("#bcsiswaabsen").html(response);
                console.log(response);
            },
            error: function(xhr, status, error) {
                console.log(error);
            }
        });
    });
    
</script>