 <?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='panel panel-default'>
               <div class="panel-heading" style="height:45px">                  
                    <div class='box-tools pull-right'>
				   <form id="formcopy">
                    <button type="submit" class="btn btn-success"><i class="fas fa-copy"></i> Salin Data</button>
				</form>					
		  </div>
		   <h4 class='box-title'><i class="fas fa-graduation-cap fa-fw"></i> Data Nilai</h4>
		   </div>
				<div class='box-header with-border'>
			   <div class='box-tools pull-right '>
         <table>
			   <tr>
			   <td>
			   <div class="form-group-sm">
			  <select name='jenjang' class='form-control text-md'  required='true' >
              <option value=""><?= $setting['sekolah'] ?></option>
               </select>
			   </div>
				</td>
			   <td>
			   <div class="form-group-sm">
			  <select name='jenjang' class='form-control'  required='true' >
              <option value=""><?= $setting['jenjang'] ?></option>
               </select>
			   </div>
				</td>
				<td>
				<div class="form-group-sm">
			  <select name='jenjang' class='form-control'  required='true'>
               <option value=""><?= $setting['kota'] ?></option>
               </select>
			   </div>
				</td>
				<td>
				<div class="form-group-sm">
			  <select name='jenjang' class='form-control'  required='true' >
               <option value=""><?= $setting['kecamatan'] ?></option>
               </select>
			   </div>
				</td>
				</tr>					
			</table>
			</div>
			  <h4 class='box-title'></h4>
			  </div>
			  <div class="box-body">
                    <ul class="nav nav-tabs">
                        <li class="active"><a href="#tab_1" data-toggle="tab" aria-expanded="true" >Buku Induk</a></li>
					</ul>					
					<div class="tab-content">
                        <div class="tab-pane active" id="tab_1" >
						<div class="panel panel-default">	
						<div class="box-body">
                    <div class='table-responsive'>
                        <table style="font-size: 11px" id='example1' class='table  table-hover'>
                            <thead>
                            <tr>
                              
                                    <th width='3px'></th>
                                    <th>NIS</th>									                                 
                                    <th>Nama</th>
									<th>Kelas</th>
									<th>Smt</th>
									<th>Tahun</th>
								   <th>Mapel</th>
                                    <th>KI-3</th>
                                    <th>KI-4</th>
                                   
									
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                            $query = mysqli_query($koneksi, "select * from binduk_nilai ORDER BY smt ASC");
                            $no = 0;
                            while ($nilai = mysqli_fetch_array($query)) {
							$siswa=fetch($koneksi,'binduk_siswa',['nis'=>$nilai['nis']]);
                          	
								$no++;
                              
                            ?>
                                <tr>
                                    <td><?= $no; ?></td>
                                    <td><?= $siswa['nis'] ?></td>									
                                    <td><?= $siswa['nama'] ?></td>
									<td><?= $nilai['kelas'] ?></td>
									<td><?= $nilai['smt'] ?></td>
									<td><?= $nilai['tahun'] ?></td>
									<td><?= $nilai['mapel'] ?></td>
                                    <td><?= round($nilai['nilai3']) ?></td>
									<td><?= round($nilai['nilai4']) ?></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: 'binduk/copynilai.php',
            enctype: 'multipart/form-data',
            data: data,
            cache: false,
            contentType: false,
            processData: false,
            success: function(data) {
                Swal.fire({	
				title: '<a href="#" class="sandik" style="color:blue">Data berhasil disalin</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;
    });
</script>
			
<?php } elseif ($ac == 'edit') { ?>	
<?php $siswa=fetch($koneksi,'binduk_siswa',['nis'=>$_GET['nis']]); ?>		
<div class='row'>
        <div class='col-md-12'>
            <div class='box box-solid'>
                <div class='box-header with-border '>
                    <h3 class='box-title'><i class="fas fa-graduation-cap fa-fw"></i> Keterangan Peserta Didik</h3>
                    <div class='box-tools pull-right'>
				   				
														  </div>
														 </div>
														 
														   <div class='box-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'>
														<h4 class='box-title'> &nbsp;&nbsp;&nbsp;A. Keterangan Peserta Didik</h4>
															<div class='col-md-6'>
														 <label>Nama Lengkap</label>
                                                            <input type="text" class="form-control" value="<?= $siswa['nama'] ?>" readonly>
                                                        </div>
														<div class='col-md-6'>
														 <label>Nama Panggilan</label>
                                                            <input type="text" name="panggilan" class="form-control" value="<?= $siswa['panggilan'] ?>" required >
                                                        </div>
                                                          <div class='col-md-4'>
														    <label>Jenis Kelamin</label>
                                                            <select name="jk"  class="form-control" 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>Tempat Lahir</label>
                                                             <input type="text" name="t_lahir" class="form-control" value="<?= $siswa['t_lahir'] ?>" required >
                                                        </div>
														<div class='col-md-4'>
														 <label>Tanggal Lahir</label>
                                                             <input type="text" name="tgl_lahir" class="form-control" value="<?= $siswa['tgl_lahir'] ?>" required>
                                                        </div>
															 <div class='col-md-4'>
														    <label>Agama</label>
                                                             <select name="agama"  class="form-control" 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>Kewarganegaraan</label>
                                                              <select name="warga"  class="form-control" 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>Anak ke</label>
                                                             <input type="number" name="anakke" class="form-control" value="<?= $siswa['anakke'] ?>" required >
                                                        </div>
														<div class='col-md-2'>
														 <label>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>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>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>Status <small>( Kosongkan Jika masih ada oang tua )</small></label>
                                                             <select name="status"  class="form-control" 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>Bahasa Sehari hari</label>
                                                             <input type="text" name="bahasa" class="form-control" value="<?= $siswa['bahasa'] ?>" required >                                               
														   </div>	
														</div>
														
														<hr>
														<div class='row'>
														<h4 class='box-title'> &nbsp;&nbsp;&nbsp;B. Keterangan Tempat Tinggal</h4>
																<div class='col-md-4'>
														    <label>Alamat</label>
                                                             <input type="text" name="alamat" class="form-control" value="<?= $siswa['alamat'] ?>" required >                                               
														   </div>	
                                                           <div class='col-md-2'>
														 <label>RT</label>
                                                             <input type="text" name="rt" class="form-control" value="<?= $siswa['rt'] ?>" required >
                                                        </div>
														<div class='col-md-2'>
														 <label>RW</label>
                                                             <input type="text" name="rw" class="form-control" value="<?= $siswa['rw'] ?>" required >
                                                        </div>
                                                        <div class='col-md-4'>
														    <label>Desa/Kelurahan</label>
                                                             <input type="text" name="desa" class="form-control" value="<?= $siswa['desa'] ?>" required >                                               
														   </div>	
                                                           
														   <div class='col-md-4'>
														 <label>Kecamatan</label>
                                                             <input type="text" name="kecamatan" class="form-control" value="<?= $siswa['kecamatan'] ?>" required >
                                                        </div>
														<div class='col-md-4'>
														 <label>Kabupaten/Kota</label>
                                                             <input type="text" name="kabupaten" class="form-control" value="<?= $siswa['kabupaten'] ?>" required >
                                                        </div>
                                                         <div class='col-md-4'>
														 <label>Provinsi</label>
                                                             <input type="text" name="propinsi" class="form-control" value="<?= $siswa['propinsi'] ?>" required >
                                                        </div>
														   <div class='col-md-3'>
														 <label>Kode Pos</label>
                                                             <input type="text" name="pos" class="form-control" value="<?= $siswa['pos'] ?>" placeholder="jika ada" >
                                                        </div>
                                                         <div class='col-md-3'>
														 <label>No Handphone</label>
                                                             <input type="text" name="hp" class="form-control" value="<?= $siswa['hp'] ?>" placeholder="jika ada" >
                                                        </div>
														<div class='col-md-3'>
														 <label>Tinggal Bersama</label>
                                                             <select name="tinggal"  class="form-control" 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>Jarak ke sekolah (Km)</label>
                                                             <input type="number" name="jarak" class="form-control" value="<?= $siswa['jarak'] ?>" >
                                                        </div>
														
														</div>
														 <div class="main-footer">
														 <button type='submit' name='submit' class='btn btn-sm btn-success pull-right' ><i class='fa fa-check' ></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: 'binduk/crud_edit.php?pg=edit_siswa',
            enctype: 'multipart/form-data',
            data: data,
            cache: false,
            contentType: false,
            processData: false,
            success: function(data) {
              Swal.fire({	
				title: '<a href="#" class="sandik" style="colo:blue;">Data berhasil disimpan</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.replace('?pg=siswa');
                }, 2000);

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