
<?php if ($ac == '') { ?>
<div class='row'>
        <div class='col-md-12'>
             <div class="card">
             <div class="card-header">	
			    <div class='right '>
                         <a href="?pg=rfidpeg&ac=inputpeg" class="btn btn-sm btn-success"><i class='fa fa-plus-circle'></i>Register</a>
                    </div>
                  <h5 class='card-title'><i class="fas fa-users-cog"></i> Data RFID Pegawai</h5></div>    
			                   
						<div class='card-body'>
						
                   <div id='tablereset' class='table-responsive'>
                        <table id='example1' class='table table-hover'>
                            <thead>
                                <tr>
                                   
                                    <th width='5%'>No</th>
									<th width='15%'>Kartu RFID</th>
									<th width='20%'>NIP</th>
                                    <th>Nama Pegawai</th>
									<th width='5%'>Action</th>							  
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                               
                                    $rfidQ = mysqli_query($koneksi, "SELECT * FROM datarfid WHERE level='pegawai' ORDER BY id ASC");
                                ?>
                                <?php while ($rfid = mysqli_fetch_array($rfidQ)) : ?>
								
                                    <?php
                                   $peg = fetch($koneksi,users,['id_user'=>$rfid['idpeg']]);
                                    $no++;
                                    ?>
                                    <tr>
                                       
                                           <td><?= $no ?></td>
										   
                                           <td><?= $rfid['nokartu'] ?></td>
                                           <td><?=  $peg['nip'] ?></td>
										   <td><?=  $peg['nama'] ?></td>
                                           		<td><button data-id="<?=  $peg['id_user'] ?>" class="hapus btn-sm btn btn-outline-danger"><i class="fas fa-trash"></i></button></td>								
												
                                    </tr>
									<?php endwhile; ?>
                            </tbody>
                        </table>
                        </div>
                        </div>
					 </div>
                        </div>
						  </div>
						
        </div>
    </div>
</div>
<script>
$('#example1').on('click', '.hapus', function() {
        var id = $(this).data('id');
        console.log(id);
        swal({
            title: 'Are you sure?',
            text: 'Akan menghapus data ini!',
            showCancelButton: true,
			type:'warning',
            confirmButtonColor: '#3085d6',
            cancelButtonColor: '#d33',
            confirmButtonText: 'iya, hapus'
        }).then((result) => {
            if (result.value) {
                $.ajax({
                    url: 'sandik_ptm/crud_kartu.php?pg=hapus_peg',
                    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 } elseif ($ac == 'inputpeg') { ?> 
 <div class='row'>
        <div class='col-md-12'>
            <div class="card">
             <div class="card-header">
                  <h5 class='card-title'><i class="fas fa-tools"></i> Register RFID Pegawai</h5></div>    
			 
			 
                       
						<div class='card-body'>
						
                   <div class='table-responsive'>
                        <table style="font-size: 12px" id='example1' class='table table-hover'>
                            <thead>
                                <tr>
                                   
                                    <th width='5%'>No</th>
									<th width='20%'>NIP</th>
                                    <th>Nama Pegawai</th>
									<th width='15%'>Jabatan</th>
									<th width='5%'>Action</th>							  
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                               
                                    $rfidQ = mysqli_query($koneksi, "SELECT * FROM users WHERE level<>'admin'");
                                ?>
                                <?php while ($rfid = mysqli_fetch_array($rfidQ)) : ?>
                                    <?php
                                    
                                    $no++;
                                    ?>
                                    <tr>
                                       
                                           <td><?= $no ?></td>
										  
                                           <td><?= $rfid['nip'] ?></td>
                                           <td><?= $rfid['nama'] ?></td>
										   <td><?= $rfid['level'] ?></td>
                                            <td><a href="?pg=tambahkartupeg&id=<?= $rfid['id_user'] ?>" class="btn btn-sm btn-outline-primary" ><i class='fa fa-plus-circle'></i></button></a></td>								
												
                                    </tr>
									<?php endwhile; ?>
                            </tbody>
                        </table>
                        </div>
                        </div>
					 </div>
                   </div>
			</div>
						
        </div>
    </div>
</div>


<?php } ?>