
<?php if ($ac == '') { ?>
<div class='row'>
        <div class='col-md-12'>
            <div class="card">
             <div class="card-header">	
			   <div class='right '>
                         <a href="?pg=rfidsiswa&ac=regsiswa" 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 Siswa</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%'>NIS</th>
                                    <th>Nama Siswa</th>
									<th width='5%'>Action</th>							  
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                               
                                    $rfidQ = mysqli_query($koneksi, "SELECT * FROM datarfid WHERE level='siswa' ORDER BY id ASC");
                                ?>
                                <?php while ($rfid = mysqli_fetch_array($rfidQ)) : ?>
								
                                    <?php
                                    $siswa = fetch($koneksi,'siswa',['id_siswa'=>$rfid['idsiswa']]);
                                    $no++;
                                    ?>
                                    <tr>
                                       
                                           <td><?= $no ?></td>
										   
                                           <td><?= $rfid['nokartu'] ?></td>
                                           <td><?= $siswa['nis'] ?></td>
										   <td><?= $siswa['nama'] ?></td>
                                           	<td><button data-id="<?= $siswa['id_siswa'] ?>" 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!',
			type: 'warning',
            showCancelButton: true,
            confirmButtonColor: '#3085d6',
            cancelButtonColor: '#d33',
            confirmButtonText: 'iya, hapus'
        }).then((result) => {
            if (result.value) {
                $.ajax({
                    url: 'sandik_ptm/crud_kartu.php?pg=hapus_siswa',
                    method: "POST",
                    data: 'id=' + id,
                    success: function(data) {
                        iziToast.info(
            {
                title: 'Sukses!',
                message: 'RFID 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 == 'regsiswa') { ?> 
 <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 Siswa</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='12%'>NIS</th>
                                    <th>Nama Siswa</th>
									<th width='5%'>Tingkat</th>
									<th width='10%'>Rombel</th>
									<th width='10%'>Kelamin</th>
									<th width='10%'>Agama</th>
									<th width='5%'>Action</th>							  
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                               
                                    $rfidQ = mysqli_query($koneksi, "SELECT * FROM siswa WHERE sts='0'");
                                ?>
                                <?php while ($rfid = mysqli_fetch_array($rfidQ)) : ?>
                                    <?php
                                    
                                    $no++;
                                    ?>
                                    <tr>
                                       
                                           <td><?= $no ?></td>
                                           <td><?= $rfid['nis'] ?></td>
                                           <td><?= $rfid['nama'] ?></td>
										   <td><?= $rfid['level'] ?></td>
										   <td><?= $rfid['id_kelas'] ?></td>
										    <td><?= $rfid['jenis_kelamin'] ?></td>
											 <td><?= $rfid['agama'] ?></td>
                                            <td><a href="?pg=tambahkartu&id=<?= $rfid['id_siswa'] ?>" class="btn btn-sm btn-outline-primary" ><i class='fa fa-plus-circle'></i></a></td>								
												
                                    </tr>
									<?php endwhile; ?>
                            </tbody>
                        </table>
                       </div>
                      </div>
					 </div>
                    </div>
				</div>		
           </div>
     </div>
</div>


<?php } ?>