<?php 
include("header.php"); // memanggil file header.php
include("koneksi.php"); // memanggil file koneksi.php untuk koneksi ke database
?>
	<div class="container">
		<div class="content">
			<h2>Data siswa &raquo; Bukti Pendaftaran Peminatan</h2>
			<hr />
			
			<?php
			$nisn = $_GET['nisn']; // assigment nisn dengan nilai nisn yang akan diedit
			$sql = mysqli_query($koneksi, "SELECT * FROM peminatan_online WHERE nisn='$nisn'"); // query untuk memilih entri data dengan nilai nisn terpilih
			if(mysqli_num_rows($sql) == 0){
				header("Location: index.php");
			}else{
				$row = mysqli_fetch_assoc($sql);
			}
			if(isset($_POST['save'])){ // jika tombol 'Simpan' dengan properti name="save" pada baris 162 ditekan
				$nisn	    = $_POST['nisn'];
				$no_daftar  = $_POST['no_daftar'];
				$nama		= $_POST['nama'];
				$jk 		= $_POST['jk'];
				$asal_smp	= $_POST['asal_smp'];
				$alamat		= $_POST['alamat'];
				$no_hp		= $_POST['no_hp'];
				$hp_ortu	= $_POST['hp_ortu'];
				$pil1		= $_POST['pil1'];
				$pil2		= $_POST['pil2'];
				$prov		= $_POST['prov'];
				$status 	= $_POST['status'];
				$tgl_daftar	= $_POST['tgl_daftar'];
				
				
				$update = mysqli_query($koneksi, "UPDATE peminatan_online SET nisn='$nisn', nama='$nama', jk='$jk', asal_smp='$asal_smp', alamat='$alamat', no_hp='$no_hp', hp_ortu='$hp_ortu', pil1='$pil1', pil2='$pil2', prov='$prov', status='$status' WHERE nisn='$nisn'") or die(mysqli_error()); // query untuk mengupdate nilai entri dalam database
				if($update){ // jika query update berhasil dieksekusi
					header("Location: edit.php?nisn=".$nisn."&pesan=sukses"); // tambahkan pesan=sukses pada url
				}else{ // jika query update gagal dieksekusi
					echo '<div class="alert alert-danger alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>Data gagal disimpan, silahkan coba lagi.</div>'; // maka tampilkan 'Data gagal disimpan, silahkan coba lagi.'
				}
			}
			
			if(isset($_GET['pesan']) == 'sukses'){
						echo "<script>alert('Data Telah Berhasil Disimpan Tunggu Sampai Status Menjadi Berhasil');window.location='data.php'</script>";
						}
			?>
			<!-- bagian ini merupakan bagian form untuk mengupdate data yang akan dimasukkan ke database -->
			<form class="form-horizontal" action="" method="post">
				<div class="form-group">
					<label class="col-sm-3 control-label">NISN</label>
					<div class="col-sm-2">
						<input type="text" name="nisn" value="<?php echo $row ['nisn']; ?>" class="form-control" placeholder="NISN" readonly>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-3 control-label">Nama</label>
					<div class="col-sm-4">
						<input type="text" name="nama" value="<?php echo $row ['nama']; ?>" class="form-control" placeholder="Nama" readonly>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-3 control-label">Nomor Pendaftaran</label>
					<div class="col-sm-4">
						<input type="text" name="no_daftar" value="<?php echo $row ['no_daftar']; ?>" class="form-control" placeholder="Nama" readonly>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-3 control-label">Jenis Kelamin</label>
					<div class="col-sm-2">
						<input type="text" name="jk" value="<?php echo $row ['jk']; ?>" class="form-control" placeholder="Jenis Kelamin" readonly>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-3 control-label">Asal SMP</label>
					<div class="col-sm-4">
						<input type="textarea" name="asal_smp" value="<?php echo $row ['asal_smp']; ?>" class="form-control" placeholder="Asal SMP" readonly> 
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-3 control-label">Alamat</label>
					<div class="col-sm-4">
						<?php echo $row ['alamat']; ?>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-3 control-label">No. HP Siswa</label>
					<div class="col-sm-4">
						<input type="text" name="no_hp" value="<?php echo $row ['no_hp']; ?>" class="form-control" placeholder="telp" readonly>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-3 control-label">No. HP Orang Tua</label>
					<div class="col-sm-4">
						<input type="text" name="hp_ortu" value="<?php echo $row ['hp_ortu']; ?>" class="form-control" placeholder="telp" readonly>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-3 control-label">Pilihan 1</label>
					<div class="col-sm-4">
						<input type="text" name="pil1" value="<?php echo $row ['pil1']; ?>" class="form-control" placeholder="pilihan 1" readonly>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-3 control-label">Pilihan 2</label>
					<div class="col-sm-4">
						<input type="text" name="pil2" value="<?php echo $row ['pil2']; ?>" class="form-control" placeholder="pilihan 2" readonly>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-3 control-label">Provinsi Sesuai KK</label>
					<div class="col-sm-4">
						<input type="text" name="prov" value="<?php echo $row ['prov']; ?>" class="form-control" placeholder="provinsi sesuai kk" readonly>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-3 control-label">Status</label>
					<div class="col-sm-4">
						<input type="text" name="status" value="<?php echo $row ['status']; ?>" class="form-control" placeholder="isi" readonly>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-3 control-label">Tanggal Daftar</label>
					<div class="col-sm-4">
						<input type="text" name="tgl_daftar" value="<?php echo $row ['tgl_daftar']; ?>" class="form-control" placeholder="isi" readonly>
					</div>
				</div>
								
				<div class="form-group">
					<label class="col-sm-3 control-label">&nbsp;</label>
					<div class="col-sm-6">
						<a href="<?php echo 'print.php?nisn='.$row ['nisn']; ?>" class="btn btn-primary btn-lg" title="CETAK"><i class="fa fa-database" aria-hidden="true"></i>CETAK</a>
						<a href="index.php" class="btn btn-danger btn-lg" data-toggle="tooltip" title="Kembali">Kembali</a>
					</div>
				</div>
			</form>
		</div> <!-- /.content -->
	</div> <!-- /.container -->
<?php 
include("footer.php"); // memanggil file footer.php
?>