 <?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">									
                               
                    <div class='right'>
				   <form id="formcopy">
                    <button type="submit" class="btn btn-outline-success"><i class="fas fa-copy"></i>Salin Data</button>
				</form>					
		  </div>
		  <h5 class="card-title"><i class="fas fa-graduation-cap fa-fw"></i> Keterangan Peserta Didik</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>Tmp Lahir</th>
                                    <th>Tgl Lahir</th>
                                    <th>Kelamin</th>									 
									 <th>Alamat</th>
									<th width='5%'>Photo</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['t_lahir'] ?></td>
									<td><?= $siswa['tgl_lahir'] ?></td>
									<td><?= $siswa['jk'] ?></td>
									<td><?= $siswa['alamat'] ?></td>
									 <td>
									<?php if($siswa['foto']<>''){ ?>
									<center><img src="../foto/fotosiswa/<?= $siswa['foto'] ?>" width="30" ></center>
									<?php }else{ ?>
									<center><img src="../dist/img/avatar.png" width="30" ></center>
									<?php } ?>
									</td>
                                    <td>
									<?php if($siswa['warga']<>''){ ?>
									<b style="color:blue">Lengkap</b>
									<?php }else{ ?>
									<b style="color:red" class="siskolah">Belum Lengkap</b>
									<?php } ?>
									</td>
								   <td>
								   <a href="?pg=siswa&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>
<script>
		$('#formcopy').submit(function(e) {
        e.preventDefault();
        var data = new FormData(this);
      
        $.ajax({
            type: 'POST',
            url: 'sandik_binduk/copy.php',
            enctype: 'multipart/form-data',
            data: data,
            cache: false,
            contentType: false,
            processData: false,
            success: function(data) {
              iziToast.info(
					{
					title: 'Sukses!',
					message: 'Data Siswa berhasil disalin',
					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 == '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 Peserta Didik</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;A. Keterangan Peserta Didik</h5>
															<div class='col-md-6'>
														 <label class="bold">Nama Lengkap</label>
                                                            <input type="text" class="form-control" value="<?= $siswa['nama'] ?>" readonly>
                                                        </div>
														<div class='col-md-6'>
														 <label class="bold">Nama Panggilan</label>
                                                            <input type="text" name="panggilan" class="form-control" value="<?= $siswa['panggilan'] ?>" required >
                                                        </div>
                                                          <div class='col-md-4'>
														    <label class="bold">Jenis Kelamin</label>
                                                            <select name="jk"  class="form-select" style="width: 100%;" required >
                                                             <option value="<?= $siswa['jk'] ?>"><?= $siswa['jk'] ?></option>    													
															<option value="Laki-laki">Laki-laki</option>
															<option value="Perempuan">Perempuan</option>
															 </select>                             
														   </div>	
                                                           <div class='col-md-4'>
														 <label class="bold">Tempat Lahir</label>
                                                             <input type="text" name="t_lahir" class="form-control" value="<?= $siswa['t_lahir'] ?>" required >
                                                        </div>
														<div class='col-md-4'>
														 <label class="bold">Tanggal Lahir</label>
                                                             <input type="text" name="tgl_lahir" class="form-control" value="<?= $siswa['tgl_lahir'] ?>" required>
                                                        </div>
															 <div class='col-md-4'>
														    <label class="bold">Agama</label>
                                                             <select name="agama"  class="form-select" style="width: 100%;" required >
                                                             <option value="<?= $siswa['agama'] ?>"><?= $siswa['agama'] ?></option>    												
															<option value="Islam">Islam</option>
															<option value="Kristen">Kristen</option>
                                                            <option value="Katolik">Katolik</option>
															<option value="Hindu">Hindu</option>
															<option value="Budha">Budha</option>
															<option value="Konghucu">Konghucu</option>
															 </select>
														   </div>	
                                                           <div class='col-md-4'>
														 <label class="bold">Kewarganegaraan</label>
                                                              <select name="warga"  class="form-select" style="width: 100%;" required >
                                                             <option value="<?= $siswa['warga'] ?>"><?= $siswa['warga'] ?></option>    															
															<option value="WNI">WNI</option>
															<option value="WNI Keturunan">WNI Keturunan</option>
															<option value="WNA">WNA</option>
															 </select>    
                                                        </div>
														<div class='col-md-2'>
														 <label class="bold">Anak ke</label>
                                                             <input type="number" name="anakke" class="form-control" value="<?= $siswa['anakke'] ?>" required >
                                                        </div>
														<div class='col-md-2'>
														 <label class="bold">Jml Sdr Kandung</label>
                                                             <input type="number" name="sdrkandung" class="form-control" value="<?= $siswa['sdrkandung'] ?>" placeholder="jika ada" >
                                                        </div>
														<div class='col-md-2'>
														 <label class="bold">Jml Sdr Tiri</label>
                                                             <input type="number" name="sdrtiri" class="form-control" value="<?= $siswa['sdrtiri'] ?>" placeholder="jika ada" >
                                                        </div>
														<div class='col-md-2'>
														 <label class="bold">Jml Sdr Angkat</label>
                                                             <input type="number" name="sdrangkat" class="form-control" value="<?= $siswa['sdrangkat'] ?>" placeholder="jika ada" >
                                                        </div>
														<div class='col-md-4'>
														 <label class="bold">Status <small>( Kosongkan Jika masih ada oang tua )</small></label>
                                                             <select name="status"  class="form-select" style="width: 100%;"  >
                                                             <option value="<?= $siswa['status'] ?>"><?= $siswa['status'] ?></option>    															
															<option value="Piatu">Piatu</option>
															<option value="Yatim">Yatim</option>
															<option value="Yatim Piatu">Yatim Piatu</option>
															 </select>    
                                                        </div>
														<div class='col-md-4'>
														    <label class="bold">Bahasa Sehari hari</label>
                                                             <input type="text" name="bahasa" class="form-control" value="<?= $siswa['bahasa'] ?>" required >                                               
														   </div>	
														</div>
														
														<hr>
														<div class='row'>
														<h5 class='card-title'> &nbsp;&nbsp;&nbsp;B. Keterangan Tempat Tinggal</h5>
																<div class='col-md-4'>
														    <label class="bold">Alamat</label>
                                                             <input type="text" name="alamat" class="form-control" value="<?= $siswa['alamat'] ?>" required >                                               
														   </div>	
                                                           <div class='col-md-2'>
														 <label class="bold">RT</label>
                                                             <input type="text" name="rt" class="form-control" value="<?= $siswa['rt'] ?>" required >
                                                        </div>
														<div class='col-md-2'>
														 <label class="bold">RW</label>
                                                             <input type="text" name="rw" class="form-control" value="<?= $siswa['rw'] ?>" required >
                                                        </div>
                                                        <div class='col-md-4'>
														    <label class="bold">Desa/Kelurahan</label>
                                                             <input type="text" name="desa" class="form-control" value="<?= $siswa['desa'] ?>" required >                                               
														   </div>	
                                                           
														   <div class='col-md-4'>
														 <label class="bold">Kecamatan</label>
                                                             <input type="text" name="kecamatan" class="form-control" value="<?= $siswa['kecamatan'] ?>" required >
                                                        </div>
														<div class='col-md-4'>
														 <label class="bold">Kabupaten/Kota</label>
                                                             <input type="text" name="kabupaten" class="form-control" value="<?= $siswa['kabupaten'] ?>" required >
                                                        </div>
                                                         <div class='col-md-4'>
														 <label class="bold">Provinsi</label>
                                                             <input type="text" name="propinsi" class="form-control" value="<?= $siswa['propinsi'] ?>" required >
                                                        </div>
														   <div class='col-md-3'>
														 <label class="bold">Kode Pos</label>
                                                             <input type="text" name="pos" class="form-control" value="<?= $siswa['pos'] ?>" placeholder="jika ada" >
                                                        </div>
                                                         <div class='col-md-3'>
														 <label class="bold">No Handphone</label>
                                                             <input type="text" name="hp" class="form-control" value="<?= $siswa['hp'] ?>" placeholder="jika ada" >
                                                        </div>
														<div class='col-md-3'>
														 <label class="bold">Tinggal Bersama</label>
                                                             <select name="tinggal"  class="form-select" style="width: 100%;" required >
                                                             <option value="<?= $siswa['tinggal'] ?>"><?= $siswa['tinggal'] ?></option>    															
															<option value="Orang Tua">Oang Tua</option>
															<option value="Wali">Wali</option>
															<option value="Saudara">Saudara</option>
															<option value="Asrama">Asrama</option>
															 </select>    
                                                        </div>
														 <div class='col-md-3'>
														 <label class="bold">Jarak ke sekolah (Km)</label>
                                                             <input type="number" name="jarak" class="form-control" value="<?= $siswa['jarak'] ?>" >
                                                        </div>
														
														</div>
														<p>
														 <div class="right">
														 <button type='submit' name='submit' class='btn btn-sm btn-success'><i class='fa fa-check-circle' ></i><span> Simpan</span></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_siswa',
									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=siswa');
										}, 2000);

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