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

<div class='row'>			
	<div class='col-md-4'>
           <div class="panel panel-default">
                <div class='box-header with-border '>
                    <h3 class='box-title'><i class="fas fa-globe fa-fw"></i> Input Absen Tidak Hadir</h3>
                    <div class='box-tools pull-right'>
					
										</div>
									</div>
									<form id="formabsen" action='' method='post'>
									<div class='box-body'>
									  <div class='form-group-sm'>									
									                                        
                                        <label>Tanggal</label>
									   <input type="text"  name="tanggal" class="form-control" value="<?= date('Y-m-d') ?>" readonly >
                                                   
                                                </div>
												 <div class='form-group-sm'>
                                                   <label>Nama Pegawai</label>
												   <select class="form-control" name="idpeg" id="idpeg" required>
													 <option value="" selected="">Pilih Pegawai</option>
												<?php $q = mysqli_query($koneksi, "select * from datarfid WHERE level='pegawai' ");
												while ($lok = mysqli_fetch_array($q)) { ?>
													<option value="<?= $lok['idpeg'] ?>"><?= $lok['nama'] ?></option>
												<?php } ?>
												</select>    
                                                </div>
												 <div class='form-group-sm'>
                                                   <label>No Kartu RFID</label>
												   <select class="form-control" name="nokartu" id="nokartu" required>
		
												</select>    
                                                </div>
												<div class='form-group-sm'>
                                                   <label>Ketidak hadiran</label>
												   <select class="form-control" name="ket" required>
													 <option value="" selected="">Pilih Alasan Tidak Hadir</option>
												      <option value="S">Sakit</option>
													   <option value="I">Izin</option>
													      <option value="A">Tanpa Keterangan</option>
												</select>    
                                                </div>
												</div>
                                                <div class='modal-footer'>
                                            <div class='box-tools pull-right btn-group'>
                                                <button type='submit' name='submit' class='btn btn-sm btn-primary'><i class='fa fa-check'></i> Simpan</button>
                                               
                                            </div>
                                        </div>
                                    </form>
                               
                        </div>
                    </div>
	        <script>
  $('#formabsen').submit(function(e) {
        e.preventDefault();
        $.ajax({
            type: 'POST',
            url: 'sandik_ptm/m_absen/crud_absen.php?pg=tambah_rfid',
            data: $(this).serialize(),
            beforeSend: function() {
                $('form button').on("click", function(e) {
                    e.preventDefault();
                });
            },
            success: function(data) {
                console.log(data);
                if (data == 'OK') {
                   iziToast.info(
            {
                title: 'Sukses!',
                message: 'Absen berhasil disimpan',
				titleColor: '#FFFF00',
				messageColor: '#fff',
				backgroundColor: 'rgba(0, 0, 0, 0.5)',
				 progressBarColor: '#FFFF00',
                  position: 'topRight'
                    });
                    setTimeout(function() {
                        window.location.reload();
                    }, 2000);
                } else {
                    Swal.fire({	
				title: '<a href="#" class="sandik" style="color:red">Gagal.. Absen sudah tercatat</a>',				
				showConfirmButton: false,
				 animation: false,
				  customClass: 'animated tada',				  
				  imageUrl: '../dist/img/sandik_kecil.gif',
                 footer: '<a href="#"><b style="color:red">Sistem Administrasi Pendidik (SANDIK)</b></a>'
                    });
					setTimeout(function() {
                        window.location.reload();
                    }, 2000);
                }

            }
        });
        return false;
    });
   $("#idpeg").change(function() {
        var idpeg = $(this).val();
        console.log(idpeg);
        $.ajax({
            type: "POST",
            url: "sandik_ptm/m_absen/crud_absen.php?pg=ambilkartu", 
            data: "idpeg=" + idpeg, 
            success: function(response) { 
                $("#nokartu").html(response);
            }
        });
    });

</script>	


				<div class="col-md-8">
                    <div class="panel panel-default">
                         
                        <div class='box-body'>
                            <div class='box-header with-border '>
                    <h3 class='box-title'><i class="fas fa-globe fa-fw"></i> Absensi RFID Pegawai <?= date('d-m-Y') ?></h3>
                    <div class='box-tools pull-right '>
				 
                </div>
				</div>
				<br>
                <div class='row'>
				
                  
        <div class='col-md-12'>
            <div class="panel panel-default">
                
                <div class='box-body'>
                    <div class='table-responsive'>
                        <table style="font-size: 12px" id='example1' class='table'>
                            <thead>
                                <tr>
                                    <th width='3px' style="text-align: center">No</th>
									
                                    <th>Nama</th>  
                                     <th style="text-align: center" width="15%">Jam Absen</th> 
										
										<th style="text-align: center" width="10%">Ket</th>
											<th style="text-align: center" width="5%">Level</th> 
									
                                </tr>
                            </thead>
							
							<tbody>
							
                                <?php
								$no = 0;
								$tanggal=date('Y-m-d');
							
								$query = mysqli_query($koneksi,"select * from absensi 
								JOIN users ON users.id_user=absensi.idguru
								WHERE absensi.tanggal='$tanggal' ");
                                while ($absen = mysqli_fetch_array($query)) {
							
                                $no++;
                            ?>
							 <tr>
                                    <td style="text-align: center"><?= $no; ?></td>
									 
							        <td><?= $absen['nama'] ?></td>
									  <td style="text-align: center"><?= $absen['jam_masuk'] ?></td>
									  
									    <td style="text-align: center">
										<?php if($absen['ket']=="H"){ ?>
										<b>Hadir</b>
										<?php } ?>
										<?php if($absen['ket']=="S"){ ?>
										<b>Sakit</b>
										<?php } ?>
										<?php if($absen['ket']=="I"){ ?>
										<b>Izin</b>
										<?php } ?>
										<?php if($absen['ket']=="A"){ ?>
										<b style="color : red;">Alpha</b>
										<?php } ?>
										</td>
										 <td style="text-align: center">
										 
										  <b><?= strtoupper($absen['level']) ?></b>
										 
										 </td>
                                  
                              		
							       </tr>
                            <?php } ?>
                        </tbody>
                        </table>
                    </div>
                    </div>
					</div>
					</div>
					
                </div>
            </div>
        </div>
    </div>