 <?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'><i class="fas fa-graduation-cap fa-fw"></i> Keterangan Kesehatan</h5>
		   </div>
			
						<div class="card-body">
                    <div class='table-responsive'>
                        <table  id='datatable1' class='table  table-hover'>
                            <thead>
                            <tr>
                              
                                    <th width='3px'></th>
                                    <th>NIS</th>									                                 
                                    <th>Nama</th>
                                    <th>Gol Darah</th>
                                    <th width="15%" class="text-center">Penyakit pernah diderita</th>
                                    <th>Kelainan Jasmani</th>									 
									 <th width='5%'>Tinggi Badan</th>
									<th width='5%'>Berat Badan</th>
									<th>Ket</th>			
									 <th width='5%'>Action</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                            $query = mysqli_query($koneksi, "select * from binduk_siswa");
                            $no = 0;
                            while ($siswa = mysqli_fetch_array($query)) {
							
                                $no++;
                              
                            ?>
                                <tr>
                                    <td><?= $no; ?></td>
                                    <td><?= $siswa['nis'] ?></td>									
                                    <td><?= $siswa['nama'] ?></td>
                                    <td><?= $siswa['goldarah'] ?></td>
									<td><?= $siswa['penyakit'] ?></td>
									<td><?= $siswa['dis'] ?></td>
									<td><?= $siswa['tb'] ?> cm</td>
									 <td><?= $siswa['bb'] ?> kg</td>
                                    <td>
									<?php if($siswa['bb']<>''){ ?>
									<b style="color:blue">Lengkap</b>
									<?php }else{ ?>
									<b style="color:red" class="siskolah">Belum Lengkap</b>
									<?php } ?>
									</td>
								   <td class="text-center">
								   <a href="?pg=kesehatan&ac=edit&nis=<?= $siswa['nis'] ?>" class="btn btn-sm btn-outline-success"><i class="fas fa-edit"></i></a>
									</td>
									</tr>
									<?php } ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
			
<?php } elseif ($ac == 'edit') { ?>	
<?php $siswa=fetch($koneksi,'binduk_siswa',['nis'=>$_GET['nis']]); ?>		
<div class='row'>
        <div class='col-md-12'>
            <div class="card">
             <div class="card-header">	
                    <h5 class='card-title'><i class="fas fa-graduation-cap fa-fw"></i> Keterangan Kesehatan</h5>
                   </div>
											 
						                   <div class="card-body">
												  <form id="formedit" method="post" action="" enctype="multipart/form-data">
                                                    <div class="modal-body">
                                                        <input type="hidden" value="<?= $siswa['nis'] ?>" name='nis'>
                                                        
                                                        <div class='form-group-sm'>
														<div class='row'>
														<h5 class='card-title'> &nbsp;&nbsp;&nbsp;C. Keterangan Kesehatan</h5>
															<div class='col-md-6'>
														 <label class="bold">Nama Lengkap</label>
                                                            <input type="text" class="form-control" value="<?= $siswa['nama'] ?>" readonly>
                                                        </div>
														</div>
														<div class='row'>
														<div class='col-md-6'>
														 <label class="bold">Golongan Darah</label>
                                                             <input type="text" name="goldarah" class="form-control" value="<?= $siswa['goldarah'] ?>" placeholder="jika ada" >
                                                        </div>
														 <div class='col-md-6'>
														 <label class="bold">Penyakit yang pernah diderita</label>
                                                             <input type="text" name="penyakit" class="form-control" value="<?= $siswa['penyakit'] ?>" placeholder="jika ada" >
                                                        </div>
														 <div class='col-md-6'>
														 <label class="bold">Kelainan Jasmani</label>
                                                             <input type="text" name="dis" class="form-control" value="<?= $siswa['dis'] ?>" placeholder="jika ada" >
                                                        </div>
														 <div class='col-md-3'>
														 <label class="bold">Tinggi Badan (Cm)</label>
                                                             <input type="number" name="tb" class="form-control" value="<?= $siswa['tb'] ?>" required >
                                                        </div>
														 <div class='col-md-3'>
														 <label class="bold">Berat Badan (Kg)</label>
                                                             <input type="number" name="bb" class="form-control" value="<?= $siswa['bb'] ?>" required >
                                                        </div>
														</div>
														<p>
														 <div class="right">
														 <button type='submit' name='submit' class='btn btn-sm btn-success' ><i class='fa fa-check-circle' ></i> Simpan</button>
														</div>
														</form>
														</div>
													</div>
												</div>
											</div>
<script>
   $('#formedit').submit(function(e) {
        e.preventDefault();
        var data = new FormData(this);
      
        $.ajax({
            type: 'POST',
            url: 'sandik_binduk/crud_edit.php?pg=edit_kesehatan',
            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=kesehatan');
                }, 2000);

            }
        });
        return false;
    });
   
</script>
<?php } ?>